Skip to content

Conversation

manoharan-nexthop
Copy link

@manoharan-nexthop manoharan-nexthop commented Sep 8, 2025

This implementation addresses the User Management HLD requirements for centralized user administration in SONiC. sonic-net/SONiC#2018

1. 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 and ownership
  • Used posix_spawn() for secure command execution without shell interpretation
  • Integrated PAM faillock configuration using Jinja2 templates

2. Build System Integration:

  • Added CMakeLists.txt for C++ compilation with SWSS dependencies
  • Created debian packaging with proper control files and dependencies
  • Added systemd service configuration for userd daemon
  • Integrated Makefile for building and installation

3. Security Features:

  • Secure password handling using system's native hashing methods
  • Role-based group assignments with predefined security groups
  • PAM faillock integration for login attempt limiting

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@manoharan-nexthop manoharan-nexthop changed the title [userd] Add user management daemon feat: Add user management daemon Sep 8, 2025
%:
dh $@

override_dh_auto_build:

Choose a reason for hiding this comment

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

I believe these changes have no effect?

You override the default behaviour (dh_auto_build) and then invoke the default behaviour (dh_auto_build).

@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +494 to +651
// Add user to role-specific groups
for (const std::string& group : it->second) {
if (!is_user_in_group(username, group)) {
std::vector<std::string> cmd = {"/usr/sbin/usermod", "-a", "-G", group, username};
SystemCommand::execute(cmd); // Don't fail if group doesn't exist
SWSS_LOG_DEBUG("Added user %s to group %s", username.c_str(), group.c_str());
} else {
SWSS_LOG_DEBUG("User %s already in group %s", username.c_str(), group.c_str());
}
}

Choose a reason for hiding this comment

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

Would we ever need to remove users from a group? For example if one is downgraded from admin to operator?

bool set_user_password(const std::string& username, const std::string& password_hash) {
std::vector<std::string> cmd = {"/usr/sbin/usermod", "-p", password_hash, username};

if (!SystemCommand::execute(cmd)) {

Choose a reason for hiding this comment

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

SystemCommand::execute with log the hash as well. Do we want that?

SONiC needed a centralized user management daemon that can:
- Monitor CONFIG_DB for user configuration changes
- Manage local system users based on SONiC configuration
- Provide role-based access control with predefined groups
- Handle SSH key management with proper security
- Integrate with PAM for authentication policies
- Support efficient change detection to minimize system calls

**1. User Management Daemon (userd):**
- Implemented C++ daemon using SWSS framework for CONFIG_DB integration
- Added comprehensive user lifecycle management (create/update/delete/enable/disable)
- Implemented role-based group assignment (administrator, operator roles)
- Added SSH key management with proper file permissions and ownership
- Used posix_spawn() for secure command execution without shell interpretation
- Added efficient change detection using UserInfo comparison to avoid unnecessary system calls
- Integrated PAM faillock configuration using Jinja2 templates

**2. Build System Integration:**
- Added CMakeLists.txt for C++ compilation with SWSS dependencies
- Created debian packaging with proper control files and dependencies
- Added systemd service configuration for userd daemon
- Integrated Makefile for building and installation

**3. Security Features:**
- Secure password handling using system's native hashing methods
- Proper file permissions for SSH keys (600) and directories (700)
- Role-based group assignments with predefined security groups
- PAM faillock integration for login attempt limiting
- Input validation and sanitization for all user operations

**4. Testing Framework:**
- Added comprehensive unit tests for userd functionality
- Integration tests for CONFIG_DB interaction
- User lifecycle testing with proper cleanup
- SSH key management testing
- Role-based access control validation
@mssonicbld
Copy link

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants