Commit df7a458
committed
[SONiC] Implement comprehensive local user management system
SONiC currently lacks a comprehensive local user management system that can:
- Manage users through CONFIG_DB with role-based access control
- Provide secure password hashing and authentication policies
- Support SSH key management and PAM integration
- Enable/disable users dynamically without system restarts
- Integrate with SONiC's configuration management framework
This implementation addresses the User Management HLD requirements for centralized user administration in SONiC.
**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 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
- Integrated PAM faillock configuration using Jinja2 templates
- Used posix_spawn() for secure command execution without shell interpretation
- Added efficient change detection to avoid unnecessary system calls
**3. CLI Interface:**
- Extended sonic-utilities with 'config user' and 'show user' commands
- Added user import functionality to migrate existing system users
- Implemented secure password hashing using system's default method (yescrypt/SHA-512)
- 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
**5. Security & Authentication:**
- Implemented secure password storage using system's native hashing
- Added PAM faillock integration for login attempt limiting
- Proper file permissions for SSH keys and user directories
- Role-based access control with predefined group assignments
**1. Basic User Management:**
```bash
sudo config user add testuser --role administrator --password-prompt
show user
sudo config user modify --enabled testuser
sudo config user modify --disabled testuser
sudo config user delete testuser
```
**2. Import Existing Users:**
```bash
sudo config user import-existing
```
**3. SSH Key Management:**
```bash
sudo config user add-ssh-key testuser "ssh-rsa AAAAB3NzaC1yc2E..."
sudo config user remove-ssh-key testuser "ssh-rsa AAAAB3NzaC1yc2E..."
```
**4. Verify Configuration:**
```bash
redis-cli -n 4 hgetall "LOCAL_USER|testuser"
redis-cli -n 4 hget "DEVICE_METADATA|localhost" local_user_management
getent passwd testuser
sudo cat /etc/shadow | grep testuser
groups testuser
```
**5. Verify Daemon Operation:**
```bash
systemctl status userd
journalctl -u userd -f
cat /etc/security/faillock.conf
```
**6. Test Authentication:**
```bash
su - testuser
ssh testuser@localhost
```
The implementation provides a complete user management solution integrated with SONiC's configuration framework, supporting both CLI and programmatic management of local users with proper security controls.1 parent 7f7f726 commit df7a458
File tree
13 files changed
+156
-3
lines changed- files/build_templates
- platform/vs
- docker-sonic-vs
- rules
- src/sonic-yang-models
- tests/files
- yang-models
13 files changed
+156
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
323 | 324 | | |
324 | 325 | | |
325 | 326 | | |
| |||
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
389 | | - | |
| 390 | + | |
| 391 | + | |
390 | 392 | | |
391 | 393 | | |
392 | 394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
206 | 216 | | |
207 | 217 | | |
208 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
349 | 351 | | |
350 | 352 | | |
351 | 353 | | |
| |||
635 | 637 | | |
636 | 638 | | |
637 | 639 | | |
638 | | - | |
| 640 | + | |
639 | 641 | | |
640 | 642 | | |
641 | 643 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1398 | 1398 | | |
1399 | 1399 | | |
1400 | 1400 | | |
| 1401 | + | |
1401 | 1402 | | |
1402 | 1403 | | |
1403 | 1404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| |||
0 commit comments