KEYCTL_SETPERM(3)

πŸ“¦
version 1.6.3 Β· 2 versions
  • 1.6.3 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 1.6.1 Β· ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’… keyctl_setperm β€” like, the key permission glow-up page

okay bestie, pull up a chair 🫢 this is keyctl_setperm(3), one of the Linux Key Management Calls, and it's genuinely so useful. no cap.


✨ NAME ✨

keyctl_setperm β€” change the permissions mask on a key πŸ”


🌸 SYNOPSIS 🌸

#include <keyutils.h>

long keyctl_setperm(key_serial_t key, key_perm_t perm);

πŸŽ€ DESCRIPTION πŸŽ€

keyctl_setperm() changes the permissions mask on a key. that's the whole vibe. it's giving "who gets to do what with this key" ✨

now. plot twist. a process that does not have the SysAdmin capability may not change the permissions mask on a key that doesn't have the same UID as the caller. so if it's not your key and you're not sysadmin-coded, hands off bestie πŸ™ˆ

also, the caller must have setattr permission on a key to be able to change its permissions mask. like, you need the pass to change the pass. iykyk πŸ’…

the permissions mask is a bitwise-OR of the following flags:

  • KEY_xxx_VIEW β€” grant permission to view the attributes of a key. peek at the metadata, not the payload πŸ‘€
  • KEY_xxx_READ β€” grant permission to read the payload of a key or to list a keyring πŸ“–
  • KEY_xxx_WRITE β€” grant permission to modify the payload of a key or to add or remove links to/from a keyring ✍️
  • KEY_xxx_SEARCH β€” grant permission to find a key or to search a keyring πŸ”Ž
  • KEY_xxx_LINK β€” grant permission to make links to a key πŸ”—
  • KEY_xxx_SETATTR β€” grant permission to change the ownership and permissions attributes of a key πŸ› οΈ
  • KEY_xxx_ALL β€” grant all the above. the whole menu, no substitutions πŸ‘‘

the xxx in the above should be replaced by one of:

  • POS β€” grant the permission to a process that possesses the key (has it attached searchably to one of the process's keyrings). the main character category πŸ’–
  • USR β€” grant the permission to a process with the same UID as the key.
  • GRP β€” grant the permission to a process with the same GID as the key, or with a match for the key's GID amongst that process's Groups list.
  • OTH β€” grant the permission to any other process. everyone else, come on in 🌈

examples include: KEY_POS_VIEW, KEY_USR_READ, KEY_GRP_SEARCH and KEY_OTH_ALL. see how the pattern goes? KEY_ + category + _ + action. slay ✨

okay this next part is the part people get wrong, so listen up fr fr:

user, group and other grants are exclusive: if a process qualifies in the user category, it will not qualify in the groups category; and if a process qualifies in either user or groups then it will not qualify in the other category. it's giving strict clique rules β€” you're in one lane, not all of them πŸ’€

possessor grants are cumulative with the grants from the user, groups and other categories. so POS stacks on top of whatever else you got 🫢


⭐ RETURN VALUE ⭐

on success keyctl_setperm() returns 0. on error, the value -1 will be returned and errno will have been set to an appropriate error. classic. 😌


πŸ”₯ ERRORS πŸ”₯

  • ENOKEY β€” the specified key does not exist. it's not there bestie, it never was 😭
  • EKEYEXPIRED β€” the specified key has expired. it had its moment, and its moment is over ⏳
  • EKEYREVOKED β€” the specified key has been revoked. cancelled, literally 🚫
  • EACCES β€” the named key exists, but does not grant setattr permission to the calling process. the key is right there and it's still not letting you in πŸ’€

🧚 LINKING 🧚

this is a library function that can be found in libkeyutils. when linking, -lkeyutils should be specified to the linker. don't forget it, or the linker will simply not know her πŸŽ€


πŸ¦‹ SEE ALSO πŸ¦‹

keyctl(1), add_key(2), keyctl(2), request_key(2), keyctl(3), keyrings(7), keyutils(7)


and that's the whole page, bestie. go forth and set some perms responsibly πŸ’œ

this one came out of the Linux corner of the world, dated 4 May 2006, and it lives at KEYCTL_SETPERM(3) in the manual. periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from