Skip to main content

User

The users of the host. osapi dsl behavior get --name user and osapi dsl behavior method get show the same.

Behavior​

Nameuser
DescriptionThe users of the host
Placementnode
Areasecurity
Internalno
APIyes
CLIyes
Nextno
Platformsdebian, linux, darwin
Sudonone
Runsnone
Writesnone
Keeps stateno
Usesnone
Used bypassword, sshkey

Methods (5)​

NAMEVERBHTTPROUTEPERMISSIONDESCRIPTION
listreadGET/api/node/{hostname}/useruser:readList the users of the host
getreadGET/api/node/{hostname}/user/{name}user:readGet one user
createwritePOST/api/node/{hostname}/useruser:writeAdd a user
updatewritePUT/api/node/{hostname}/user/{name}user:writeChange a user
deletewriteDELETE/api/node/{hostname}/user/{name}user:writeRemove a user

Types (5)​

NAMEINPUTOUTPUT
listListInput[]Account { name, uid, gid, home, shell, groups, locked }
getGetInput { name* }Account { name, uid, gid, home, shell, groups, locked }
createCreateInput { name*, uid, gid, home, shell, groups, system, password, password_hash }Result { name, changed }
updateUpdateInput { name*, shell, home, groups, lock }Result { name, changed }
deleteDeleteInput { name* }Result { name, changed }

Settings (0)​

None. Declare them with behavior.Config.

Telemetry​

Spanbehavior.user.<method>
Child spansexec useradd, exec chpasswd, exec usermod, exec userdel, exec id, exec dscl
Metricsosapi_behavior_calls_total, osapi_behavior_duration_seconds, osapi_behavior_changes_total
Attributesosapi.behavior.name, osapi.behavior.method, osapi.behavior.verb, osapi.behavior.outcome, osapi.behavior.changed
Recorded inputsname (get, create, update, delete)

Method list​

Namelist
Verbread
DescriptionList the users of the host
DetailLists 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.
HTTPGET
Route/api/node/{hostname}/user
Permissionuser:read
Commandosapi client node user list
Input typeListInput
Output type[]Account

Input (0)​

None. The method takes no input; its command needs only --target.

Output (7)​

FIELDTYPEDESCRIPTION
namestringThe user
uidintegerIts numeric user ID
gidintegerIts primary group ID
homestringIts home directory
shellstringIts login shell
groupsarrayThe groups it is a member of, besides its primary group
lockedbooleanWhether a login with its password is refused

Examples (1)​

EXAMPLEINPUTOUTPUT
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​

Nameget
Verbread
DescriptionGet one user
DetailReads one user from the same list. A user that the host does not have is not found.
HTTPGET
Route/api/node/{hostname}/user/{name}
Permissionuser:read
Commandosapi client node user get
Input typeGetInput
Output typeAccount

Input (1)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^[a-z_][a-z0-9_-]*$?$, max length 32The user, such as alice

Output (7)​

FIELDTYPEDESCRIPTION
namestringThe user
uidintegerIts numeric user ID
gidintegerIts primary group ID
homestringIts home directory
shellstringIts login shell
groupsarrayThe groups it is a member of, besides its primary group
lockedbooleanWhether a login with its password is refused

Examples (1)​

EXAMPLEINPUTOUTPUT
A username=alicename=alice, uid=1000, gid=1000, home=/home/alice, shell=/bin/bash, groups=[developers], locked=false

Method create​

Namecreate
Verbwrite
DescriptionAdd a user
DetailAdds 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.
HTTPPOST
Route/api/node/{hostname}/user
Permissionuser:write
Commandosapi client node user create
Input typeCreateInput
Output typeResult

Input (9)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^[a-z_][a-z0-9_-]*$?$, max length 32The user to add, such as alice
uidintegernomin 0Its numeric user ID; the system assigns one when it is 0
gidintegernomin 0Its primary group ID; a group of its own when it is 0
homestringnopattern ^[^\r\n]*$Its home directory; /home/<name> when empty
shellstringnopattern ^[^\r\n]*$Its login shell, such as /bin/bash; the system's default when empty
groupsarraynoThe groups it is a member of, besides its primary group
systembooleannoAdd it as a system user, with an ID from the system range
passwordstringnopattern ^[^\r\n]*$, format passwordIts password, which osapi hashes on the controller; none when empty. A secret: a reference, secret://<vault>/<key>, or the value.
password_hashstringnoThe sha512-crypt hash of the password, which the controller sets

Output (2)​

FIELDTYPEDESCRIPTION
namestringThe user
changedbooleanWhether the host changed

Examples (4)​

EXAMPLEINPUTOUTPUT
Add a username=osapitestname=osapitest, changed=true
Add a user with a shell, groups and a passwordname=osapitest, shell=/bin/sh, groups=[root], password=[redacted], password_hash=$6$osapitest$ixskR1vdsZl2JBlRPn/2rqKZK4DltHGVEnTxDn.wN68cQnKpsMNWzH5Hxu6jZgEHWjcnzvFneyk/KHl6bEYtj1name=osapitest, changed=true
Add a system user with its IDs and its homename=osapitest, uid=1999, gid=100, home=/home/osapitest, system=truename=osapitest, changed=true
A user that the host hasname=osapitestname=osapitest, changed=false

Method update​

Nameupdate
Verbwrite
DescriptionChange a user
DetailChanges 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.
HTTPPUT
Route/api/node/{hostname}/user/{name}
Permissionuser:write
Commandosapi client node user update
Input typeUpdateInput
Output typeResult

Input (5)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^[a-z_][a-z0-9_-]*$?$, max length 32The user, such as alice
shellstringnopattern ^[^\r\n]*$Its login shell, such as /bin/bash
homestringnopattern ^[^\r\n]*$Its home directory, which usermod moves the files to
groupsarraynoThe groups it is a member of, which replace the groups it has
lockstringnoone of locked unlockedWhether to refuse logins with its password: locked refuses them, unlocked allows them

Output (2)​

FIELDTYPEDESCRIPTION
namestringThe user
changedbooleanWhether the host changed

Examples (4)​

EXAMPLEINPUTOUTPUT
Set the shellname=osapitest, shell=/bin/bashname=osapitest, changed=true
The shell it hasname=osapitest, shell=/bin/bashname=osapitest, changed=false
Move the home, set the groups and lock itname=osapitest, home=/home/osapitest2, groups=[root], lock=lockedname=osapitest, changed=true
Unlock itname=osapitest, lock=unlockedname=osapitest, changed=true

Method delete​

Namedelete
Verbwrite
DescriptionRemove a user
DetailRemoves 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.
HTTPDELETE
Route/api/node/{hostname}/user/{name}
Permissionuser:write
Commandosapi client node user delete
Input typeDeleteInput
Output typeResult

Input (1)​

FIELDTYPEREQUIREDCONSTRAINTSDESCRIPTION
namestringyespattern ^[a-z_][a-z0-9_-]*$?$, max length 32The user to remove, with its home directory, such as alice

Output (2)​

FIELDTYPEDESCRIPTION
namestringThe user
changedbooleanWhether the host changed

Examples (2)​

EXAMPLEINPUTOUTPUT
Remove a username=osapitestname=osapitest, changed=true
A user that the host does not havename=osapitestname=osapitest, changed=false