Skip to content

Conversation

@manoharan-nexthop
Copy link

@manoharan-nexthop manoharan-nexthop commented Jun 17, 2025

Currently the local users that are created are not persistent across upgrades. This HLD proposes to manage the users across upgrades by storing the configuration in CONFIG_DB and a daemon to manage them in Linux.

Implementation Pull requests:

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@zhangyanzhao zhangyanzhao moved this from 📋 In Plan Features to 🏗 In Progress in SONiC 202511 Release Aug 12, 2025
manoharan-nexthop added a commit to manoharan-nexthop/sonic-buildimage that referenced this pull request Sep 8, 2025
This implementation addresses the User Management HLD requirements for centralized user administration in SONiC.
sonic-net/SONiC#2018

**1. YANG Model & Configuration Schema:**
- Added sonic-user.yang model defining LOCAL_USER and LOCAL_ROLE_SECURITY_POLICY tables
- Integrated user management into CONFIG_DB schema with role-based configuration
- Added DEVICE_METADATA.local_user_management feature flag

**2. User Management Daemon (userd):**
- Implemented C++ daemon using SWSS framework for CONFIG_DB integration
- Added user lifecycle management (create/update/delete/enable/disable)
- Implemented role-based group assignment (administrator, operator roles)
- Added SSH key management with proper file permissions
- Integrated PAM faillock configuration using Jinja2 templates

**3. CLI Interface:**
- Extended sonic-utilities with 'config user' and 'show user' commands
- Added user import functionality to migrate existing system users
- Added role-based user management with proper validation

**4. Build System Integration:**
- Added sonic-host-services package with userd daemon and systemd service
- Integrated user management into SONiC image build process
- Added template-based configuration generation for init_cfg.json
- Added build dependencies for JSON processing and password hashing
@anders-nexthop
Copy link

@manoharan-nexthop - Do you have some draft implementation or just HLD changes? If you have any specific details or examples, please share them.

@vitaliibylinka PRs with implementation details have been posted.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

Copy link

@spandan-nexthop spandan-nexthop left a comment

Choose a reason for hiding this comment

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

LGTM!
Just added some comments/questions.

@arlakshm
Copy link
Contributor

arlakshm commented Oct 8, 2025

@qiluo-msft can you please help signoff on this feature?

manoharan-nexthop added a commit to manoharan-nexthop/sonic-buildimage that referenced this pull request Nov 18, 2025
This implementation addresses the User Management HLD requirements for
centralized user administration in SONiC.
sonic-net/SONiC#2018

nexthop-ai/private-sonic-host-services#54
nexthop-ai/private-sonic-utilities#120

**1. YANG Model & Configuration Schema:**
- Added sonic-user.yang model defining LOCAL_USER and
LOCAL_ROLE_SECURITY_POLICY tables
- Integrated user management into CONFIG_DB schema with role-based
configuration
- Added DEVICE_METADATA.local_user_management feature flag

**2. User Management Daemon (userd):**
- Implemented C++ daemon using SWSS framework for CONFIG_DB integration
- Added user lifecycle management (create/update/delete/enable/disable)
- Implemented role-based group assignment (administrator, operator
roles)
- Added SSH key management with proper file permissions
- Integrated PAM faillock configuration using Jinja2 templates

**3. CLI Interface:**
- Extended sonic-utilities with 'config user' and 'show user' commands
- Added user import functionality to migrate existing system users
- Added role-based user management with proper validation

**4. Build System Integration:**
- Added sonic-host-services package with userd daemon and systemd
service
- Integrated user management into SONiC image build process
- Added template-based configuration generation for init_cfg.json
- Added build dependencies for JSON processing and password hashing

Tested for all the features that are implemented.
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

|:---:|:--------------:|:-----------:|:----------------------------------------------------------------------------------------------------------------------------------------------------:|
| 1.0 | June 16, 2025 | Manoharan Sundaramoorthy | Initial HLD |


Copy link
Collaborator

@venkatmahalingam venkatmahalingam Nov 26, 2025

Choose a reason for hiding this comment

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

Currently the local users that are created are not persistent across upgrades. This HLD proposes to manage the users across upgrades by storing the configuration in CONFIG_DB and a daemon to manage them in Linux.

-> For this requirement, is it not better to migrate the users from one partition to another partition during upgrade operation instead of exposing the users & password keys in the CONFIG_DB, filtering them in the tech bundle for security reasons?

Copy link
Author

Choose a reason for hiding this comment

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

There were few things that we had considered for this:

  1. SSH keys - we would have to create the user directories and the authorized_keys to set this up. It would be possible with scripts but would be cumbersome.
  2. We would not know which were local users and which were from RADIUS / TACACS.
  3. We wont be able to port another device (incase device has to be replaced).

@BYGX-wcr
Copy link
Contributor

Password hashes are also considered sensitive data since they can be used for reverse-engineering to get the password. Normally, /etc/shadow is only readable to root-level user. Making this change in SONiC essentially expose the /etc/shadow file content to general users and breaks the security policy of Linux.

- `/etc/sonic/config_db.json` file permissions changed from `644` to `640` (root:redis)
- Password hashes only visible in show commands when run with `sudo` privileges
- `show user` displays usernames only, `sudo show user` displays hashes
- `show runningconfiguration` redacts password_hash fields unless run with `sudo`
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the user just writes a script/process to connect to the running CONFIG_DB and read content? Right now, there is no table-level protection in redis.

Choose a reason for hiding this comment

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

I think currently a user only has to be part of the docker group to view the redis database.

admin@sonic:~$ sudo su - newusername 
$ groups
newusername docker
$ redis-cli
127.0.0.1:6379> KEYS *
 1) "GEARBOX_TABLE_KEY_SET"
 2) "PORT_TABLE:Ethernet96"
 3) "PORT_TABLE:Ethernet80"
 4) "PORT_TABLE:Ethernet88"
 5) "PORT_TABLE:Ethernet16"
...

Can/should this be changed so only users who are part of the redis group can view the db?

@aidan-gallagher
Copy link

Password hashes are also considered sensitive data since they can be used for reverse-engineering to get the password. Normally, /etc/shadow is only readable to root-level user. Making this change in SONiC essentially expose the /etc/shadow file content to general users and breaks the security policy of Linux.

I believe the CLI show command will only show password hashes when the user is root.
See can_view_passwords in https://github.com/sonic-net/sonic-utilities/pull/4053/files#diff-3311722931fe6ac91c84f68dc5b09d27dbc6624d78e59165e1f0c54564a5b947R29.

I believe the file /etc/sonic/config_db.json is currently world readable

-rw-r--r-- 1 root root 17K Sep 23 09:07 /etc/sonic/config_db.json

And it will need to be changed to this

-rw--r---- 1 root redis 731 Sep 16 14:25 /etc/sonic/config_db.json

I don't see the code to do that in this PR? I would expect something like the following code at the end of generate_config() (
https://github.com/sonic-net/sonic-buildimage/blob/master/files/image_config/config-setup/config-setup#L255)

sudo chmod 640 ${DEST_FILE}
sudo chown root:redis ${DEST_FILE}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🏗 In Progress

Development

Successfully merging this pull request may close these issues.