Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-131285 / 25.10 / Add API to migrate from root user #15441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anodos325
Copy link
Contributor

This commit adds an API endpoint to migrate root user to one with the specified username and password combination. If password is omitted then the one currently used for root is preserved for the new admin account. Various root account parameters are migrated to the new admin account such as:

  • ssh keys
  • password enabled status
  • two factor authentication configuration and secret
  • email address
  • shell
  • home directory

@anodos325 anodos325 added the WIP label Jan 20, 2025
@bugclerk bugclerk changed the title Add API to migrate from root user NAS-131285 / 25.04 / Add API to migrate from root user Jan 20, 2025
@bugclerk
Copy link
Contributor

This commit adds an API endpoint to migrate root user to one
with the specified username and password combination. If password
is omitted then the one currently used for root is preserved
for the new admin account. Various root account parameters are
migrated to the new admin account such as:

* ssh keys
* password enabled status
* two factor authentication configuration and secret
* email address
* shell
* home directory
@yocalebo yocalebo changed the title NAS-131285 / 25.04 / Add API to migrate from root user NAS-131285 / 25.10 / Add API to migrate from root user Jan 28, 2025
class UserMigrateRootArgs(BaseModel):
username: LocalUsername
"""Username of new local user account to which to migration the root account.
NOTE: user account nust not exist."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NOTE: user account nust not exist."""
NOTE: user account must not exist."""

if filter_list(local_groups, [['group', '=', username]]):
raise CallError(f'{username!r} group already exists, setting up local administrator is not possible',
errno.EEXIST)
# This should be relatively invexpensive even though it's a job since we
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# This should be relatively invexpensive even though it's a job since we
# This should be relatively inexpensive even though it's a job since we


os.chown(homedir, ADMIN_UID, ADMIN_GID)
os.chmod(homedir, 0o700)
home_copy_job = self.middleware.call_sync('user.do_home_copy', '/root', homedir, '700', ADMIN_UID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this can take awhile, we should go ahead and print progress via the job object so we have some idea of what's going on. Probably should add job progress for the entirety of this method actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants