User
The users of the host. osapi dsl behavior get --name user and
osapi dsl behavior method get show the same.
Behavior
| Name | user |
| Description | The users of the host |
| Placement | node |
| Area | security |
| Internal | no |
| API | yes |
| CLI | yes |
| Next | no |
| Platforms | debian, linux, darwin |
| Sudo | none |
| Runs | none |
| Writes | none |
| Keeps state | no |
| Uses | none |
| Used by | password, sshkey |
Methods (5)
| NAME | VERB | HTTP | ROUTE | PERMISSION | DESCRIPTION |
|---|---|---|---|---|---|
| list | read | GET | /api/node/{hostname}/user | user:read | List the users of the host |
| get | read | GET | /api/node/{hostname}/user/{name} | user:read | Get one user |
| create | write | POST | /api/node/{hostname}/user | user:write | Add a user |
| update | write | PUT | /api/node/{hostname}/user/{name} | user:write | Change a user |
| delete | write | DELETE | /api/node/{hostname}/user/{name} | user:write | Remove a user |
Types (5)
| NAME | INPUT | OUTPUT |
|---|---|---|
| list | ListInput | []Account { name, uid, gid, home, shell, groups, locked } |
| get | GetInput { name* } | Account { name, uid, gid, home, shell, groups, locked } |
| create | CreateInput { name*, uid, gid, home, shell, groups, system, password, password_hash } | Result { name, changed } |
| update | UpdateInput { name*, shell, home, groups, lock } | Result { name, changed } |
| delete | DeleteInput { name* } | Result { name, changed } |
Settings (0)
None. Declare them with behavior.Config.
Telemetry
| Span | behavior.user.<method> |
| Child spans | exec useradd, exec chpasswd, exec usermod, exec userdel, exec id, exec dscl |
| Metrics | osapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total |
| Attributes | osapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed |
| Recorded inputs | name (get, create, update, delete) |
Method list
| Name | list |
| Verb | read |
| Description | List the users of the host |
| Detail | Lists each user with its IDs, home, shell, groups and whether it is locked, through gohai: from /etc/passwd, /etc/group and /etc/shadow on Linux, and from the directory service with dscl on macOS. The groups are those that list the user as a member, besides its primary group. |
| HTTP | GET |
| Route | /api/node/{hostname}/user |
| Permission | user:read |
| Command | osapi client node user list |
| Input type | ListInput |
| Output type | []Account |
Input (0)
None. The method takes no input; its command needs only --target.
Output (7)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The user |
| uid | integer | Its numeric user ID |
| gid | integer | Its primary group ID |
| home | string | Its home directory |
| shell | string | Its login shell |
| groups | array | The groups it is a member of, besides its primary group |
| locked | boolean | Whether a login with its password is refused |
Examples (1)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| A host with users | (none) | [gid=1000, groups=[developers], home=/home/alice, locked=false, name=alice, shell=/bin/bash, uid=1000] [gid=0, home=/root, locked=true, name=root, shell=/bin/bash, uid=0] |
Method get
| Name | get |
| Verb | read |
| Description | Get one user |
| Detail | Reads one user from the same list. A user that the host does not have is not found. |
| HTTP | GET |
| Route | /api/node/{hostname}/user/{name} |
| Permission | user:read |
| Command | osapi client node user get |
| Input type | GetInput |
| Output type | Account |
Input (1)
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|---|---|---|---|
| name | string | yes | pattern ^[a-z_][a-z0-9_-]*$?$, max length 32 | The user, such as alice |
Output (7)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The user |
| uid | integer | Its numeric user ID |
| gid | integer | Its primary group ID |
| home | string | Its home directory |
| shell | string | Its login shell |
| groups | array | The groups it is a member of, besides its primary group |
| locked | boolean | Whether a login with its password is refused |
Examples (1)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| A user | name=alice | name=alice, uid=1000, gid=1000, home=/home/alice, shell=/bin/bash, groups=[developers], locked=false |
Method create
| Name | create |
| Verb | write |
| Description | Add a user |
| Detail | Adds the user with useradd, with its home directory, and sets its password with chpasswd when one is given. The controller hashes the password, so the job and NATS have only the hash. A user that the host has already does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped. |
| HTTP | POST |
| Route | /api/node/{hostname}/user |
| Permission | user:write |
| Command | osapi client node user create |
| Input type | CreateInput |
| Output type | Result |
Input (9)
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|---|---|---|---|
| name | string | yes | pattern ^[a-z_][a-z0-9_-]*$?$, max length 32 | The user to add, such as alice |
| uid | integer | no | min 0 | Its numeric user ID; the system assigns one when it is 0 |
| gid | integer | no | min 0 | Its primary group ID; a group of its own when it is 0 |
| home | string | no | pattern ^[^\r\n]*$ | Its home directory; /home/<name> when empty |
| shell | string | no | pattern ^[^\r\n]*$ | Its login shell, such as /bin/bash; the system's default when empty |
| groups | array | no | The groups it is a member of, besides its primary group | |
| system | boolean | no | Add it as a system user, with an ID from the system range | |
| password | string | no | pattern ^[^\r\n]*$, format password | Its password, which osapi hashes on the controller; none when empty. A secret: a reference, secret://<vault>/<key>, or the value. |
| password_hash | string | no | The sha512-crypt hash of the password, which the controller sets |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The user |
| changed | boolean | Whether the host changed |
Examples (4)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| Add a user | name=osapitest | name=osapitest, changed=true |
| Add a user with a shell, groups and a password | name=osapitest, shell=/bin/sh, groups=[root], password=[redacted], password_hash=$6$osapitest$ixskR1vdsZl2JBlRPn/2rqKZK4DltHGVEnTxDn.wN68cQnKpsMNWzH5Hxu6jZgEHWjcnzvFneyk/KHl6bEYtj1 | name=osapitest, changed=true |
| Add a system user with its IDs and its home | name=osapitest, uid=1999, gid=100, home=/home/osapitest, system=true | name=osapitest, changed=true |
| A user that the host has | name=osapitest | name=osapitest, changed=false |
Method update
| Name | update |
| Verb | write |
| Description | Change a user |
| Detail | Changes what the input gives and the user does not have already, with usermod: its shell, its home, which usermod moves the files to, its groups, which replace the groups it has, and whether it is locked. The same values report changed: false. A user that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped. |
| HTTP | PUT |
| Route | /api/node/{hostname}/user/{name} |
| Permission | user:write |
| Command | osapi client node user update |
| Input type | UpdateInput |
| Output type | Result |
Input (5)
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|---|---|---|---|
| name | string | yes | pattern ^[a-z_][a-z0-9_-]*$?$, max length 32 | The user, such as alice |
| shell | string | no | pattern ^[^\r\n]*$ | Its login shell, such as /bin/bash |
| home | string | no | pattern ^[^\r\n]*$ | Its home directory, which usermod moves the files to |
| groups | array | no | The groups it is a member of, which replace the groups it has | |
| lock | string | no | one of locked unlocked | Whether to refuse logins with its password: locked refuses them, unlocked allows them |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The user |
| changed | boolean | Whether the host changed |
Examples (4)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| Set the shell | name=osapitest, shell=/bin/bash | name=osapitest, changed=true |
| The shell it has | name=osapitest, shell=/bin/bash | name=osapitest, changed=false |
| Move the home, set the groups and lock it | name=osapitest, home=/home/osapitest2, groups=[root], lock=locked | name=osapitest, changed=true |
| Unlock it | name=osapitest, lock=unlocked | name=osapitest, changed=true |
Method delete
| Name | delete |
| Verb | write |
| Description | Remove a user |
| Detail | Removes the user and its home directory with userdel -r. A user that the host does not have does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped. |
| HTTP | DELETE |
| Route | /api/node/{hostname}/user/{name} |
| Permission | user:write |
| Command | osapi client node user delete |
| Input type | DeleteInput |
| Output type | Result |
Input (1)
| FIELD | TYPE | REQUIRED | CONSTRAINTS | DESCRIPTION |
|---|---|---|---|---|
| name | string | yes | pattern ^[a-z_][a-z0-9_-]*$?$, max length 32 | The user to remove, with its home directory, such as alice |
Output (2)
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
| name | string | The user |
| changed | boolean | Whether the host changed |
Examples (2)
| EXAMPLE | INPUT | OUTPUT |
|---|---|---|
| Remove a user | name=osapitest | name=osapitest, changed=true |
| A user that the host does not have | name=osapitest | name=osapitest, changed=false |