debian-mirror-gitlab/doc/raketasks/user_management.md

184 lines
5.6 KiB
Markdown
Raw Normal View History

2021-01-29 00:20:46 +05:30
---
2022-07-23 23:45:48 +05:30
stage: Systems
2021-03-11 19:13:27 +05:30
group: Distribution
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2023-03-04 22:38:38 +05:30
# User management Rake tasks **(FREE SELF)**
2020-05-24 23:13:21 +05:30
2023-03-04 22:38:38 +05:30
GitLab provides Rake tasks for managing users. Administrators can also use the Admin Area to
[manage users](../user/admin_area/index.md#administering-users).
2014-09-02 18:07:02 +05:30
## Add user as a developer to all projects
2020-05-24 23:13:21 +05:30
To add a user as a developer to all projects, run:
2020-03-13 15:44:24 +05:30
```shell
2014-09-02 18:07:02 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:import:user_to_projects[username@domain.tld]
2015-04-26 12:48:37 +05:30
# installation from source
bundle exec rake gitlab:import:user_to_projects[username@domain.tld] RAILS_ENV=production
2014-09-02 18:07:02 +05:30
```
## Add all users to all projects
2020-05-24 23:13:21 +05:30
To add all users to all projects, run:
2014-09-02 18:07:02 +05:30
2020-03-13 15:44:24 +05:30
```shell
2014-09-02 18:07:02 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:import:all_users_to_all_projects
2015-04-26 12:48:37 +05:30
# installation from source
bundle exec rake gitlab:import:all_users_to_all_projects RAILS_ENV=production
2014-09-02 18:07:02 +05:30
```
2021-11-18 22:05:49 +05:30
Administrators are added as maintainers.
2020-05-24 23:13:21 +05:30
2014-09-02 18:07:02 +05:30
## Add user as a developer to all groups
2020-05-24 23:13:21 +05:30
To add a user as a developer to all groups, run:
2020-03-13 15:44:24 +05:30
```shell
2014-09-02 18:07:02 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:import:user_to_groups[username@domain.tld]
2015-04-26 12:48:37 +05:30
# installation from source
bundle exec rake gitlab:import:user_to_groups[username@domain.tld] RAILS_ENV=production
2014-09-02 18:07:02 +05:30
```
## Add all users to all groups
2020-05-24 23:13:21 +05:30
To add all users to all groups, run:
2014-09-02 18:07:02 +05:30
2020-03-13 15:44:24 +05:30
```shell
2014-09-02 18:07:02 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:import:all_users_to_all_groups
2015-04-26 12:48:37 +05:30
# installation from source
bundle exec rake gitlab:import:all_users_to_all_groups RAILS_ENV=production
2014-09-02 18:07:02 +05:30
```
2015-09-11 14:41:01 +05:30
2021-02-22 17:27:13 +05:30
Administrators are added as owners so they can add additional users to the group.
2020-05-24 23:13:21 +05:30
2021-02-22 17:27:13 +05:30
## Update all users in a given group to `project_limit:0` and `can_create_group: false`
To update all users in given group to `project_limit: 0` and `can_create_group: false`, run:
```shell
# omnibus-gitlab
sudo gitlab-rake gitlab:user_management:disable_project_and_group_creation\[:group_id\]
# installation from source
bundle exec rake gitlab:user_management:disable_project_and_group_creation\[:group_id\] RAILS_ENV=production
```
It updates all users in the given group, its subgroups and projects in this group namespace, with the noted limits.
## Control the number of billable users
2015-09-11 14:41:01 +05:30
2020-05-24 23:13:21 +05:30
Enable this setting to keep new users blocked until they have been cleared by the administrator.
Defaults to `false`:
2015-09-11 14:41:01 +05:30
2020-04-22 19:07:51 +05:30
```plaintext
2015-09-11 14:41:01 +05:30
block_auto_created_users: false
```
2015-10-24 18:46:33 +05:30
2020-05-24 23:13:21 +05:30
## Disable two-factor authentication for all users
2015-10-24 18:46:33 +05:30
2020-05-24 23:13:21 +05:30
This task disables two-factor authentication (2FA) for all users that have it enabled. This can be
2021-02-22 17:27:13 +05:30
useful if the GitLab `config/secrets.yml` file has been lost and users are unable
2022-11-25 23:54:43 +05:30
to sign in, for example.
2020-05-24 23:13:21 +05:30
To disable two-factor authentication for all users, run:
2015-10-24 18:46:33 +05:30
2020-03-13 15:44:24 +05:30
```shell
2015-10-24 18:46:33 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:two_factor:disable_for_all_users
# installation from source
bundle exec rake gitlab:two_factor:disable_for_all_users RAILS_ENV=production
```
2016-11-03 12:29:30 +05:30
2020-05-24 23:13:21 +05:30
## Rotate two-factor authentication encryption key
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
GitLab stores the secret data required for two-factor authentication (2FA) in an encrypted
database column. The encryption key for this data is known as `otp_key_base`, and is
2017-09-10 17:25:29 +05:30
stored in `config/secrets.yml`.
If that file is leaked, but the individual 2FA secrets have not, it's possible
to re-encrypt those secrets with a new encryption key. This allows you to change
the leaked key without forcing all users to change their 2FA details.
2020-05-24 23:13:21 +05:30
To rotate the two-factor authentication encryption key:
2017-09-10 17:25:29 +05:30
2022-08-13 15:12:31 +05:30
1. Look up the old key in the `config/secrets.yml` file, but **make sure you're working
2021-02-22 17:27:13 +05:30
with the production section**. The line you're interested in looks like this:
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
```yaml
production:
2021-02-22 17:27:13 +05:30
otp_key_base: fffffffffffffffffffffffffffffffffffffffffffffff
2020-05-24 23:13:21 +05:30
```
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
1. Generate a new secret:
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
```shell
# omnibus-gitlab
sudo gitlab-rake secret
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
# installation from source
bundle exec rake secret RAILS_ENV=production
```
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
1. Stop the GitLab server, back up the existing secrets file, and update the database:
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
```shell
# omnibus-gitlab
sudo gitlab-ctl stop
sudo cp config/secrets.yml config/secrets.yml.bak
sudo gitlab-rake gitlab:two_factor:rotate_key:apply filename=backup.csv old_key=<old key> new_key=<new key>
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
# installation from source
sudo /etc/init.d/gitlab stop
cp config/secrets.yml config/secrets.yml.bak
bundle exec rake gitlab:two_factor:rotate_key:apply filename=backup.csv old_key=<old key> new_key=<new key> RAILS_ENV=production
```
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
The `<old key>` value can be read from `config/secrets.yml` (`<new key>` was
2021-02-22 17:27:13 +05:30
generated earlier). The **encrypted** values for the user 2FA secrets are
2020-05-24 23:13:21 +05:30
written to the specified `filename`. You can use this to rollback in case of
error.
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
1. Change `config/secrets.yml` to set `otp_key_base` to `<new key>` and restart. Again, make sure
you're operating in the **production** section.
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
```shell
# omnibus-gitlab
sudo gitlab-ctl start
# installation from source
sudo /etc/init.d/gitlab start
```
2017-09-10 17:25:29 +05:30
If there are any problems (perhaps using the wrong value for `old_key`), you can
restore your backup of `config/secrets.yml` and rollback the changes:
2020-04-08 14:13:33 +05:30
```shell
2017-09-10 17:25:29 +05:30
# omnibus-gitlab
sudo gitlab-ctl stop
sudo gitlab-rake gitlab:two_factor:rotate_key:rollback filename=backup.csv
sudo cp config/secrets.yml.bak config/secrets.yml
sudo gitlab-ctl start
# installation from source
sudo /etc/init.d/gitlab start
bundle exec rake gitlab:two_factor:rotate_key:rollback filename=backup.csv RAILS_ENV=production
cp config/secrets.yml.bak config/secrets.yml
sudo /etc/init.d/gitlab start
```
2022-01-26 12:08:38 +05:30
## Related topics
2023-06-20 00:43:36 +05:30
- [Reset a user's password](../security/reset_user_password.md#use-a-rake-task)