PAM_NAMESPACE(8)

๐Ÿ’… NAME ๐Ÿ’…

okay bestie, meet pam_namespace โ€” the PAM module that sets up a private namespace for a session. it's pam_namespace(8), from the Linux-PAM Manual, and it's lowkey one of the most iconic ones in the whole family. ๐Ÿซถ


โœจ SYNOPSIS โœจ

pam_namespace.so [debug] [unmnt_remnt] [unmnt_only] [require_selinux]
                 [gen_hash] [ignore_config_error]
                 [ignore_instance_parent_mode] [unmount_on_close]
                 [use_current_context] [use_default_context]
                 [mount_private]

๐ŸŒธ DESCRIPTION ๐ŸŒธ

so basically, the pam_namespace PAM module sets up a private namespace for a session, with polyinstantiated directories. and a polyinstantiated directory is literally a directory that gives you a different instance of itself depending on user name โ€” or, when you're using SELinux, based on user name, security context, or both. it's giving โœจone directory, many livesโœจ.

if an executable script at /etc/security/namespace.init exists, it gets used to initialize the instance directory after it's been set up and mounted on the polyinstantiated directory. that script receives these as its arguments:

  1. the polyinstantiated directory path
  2. the instance directory path
  3. a flag for whether the instance directory was newly created (0 for no, 1 for yes)
  4. the user name
โš ๏ธ bestie, listen. that script is invoked with full root privileges, and accessing the instance directory in this context needs to be done with caution, because it is controlled by the unprivileged user for which it has been created. root powers + user-controlled stuff = be careful, fr fr.

the pam_namespace module disassociates the session namespace from the parent namespace. meaning: any mounts/unmounts performed in the parent namespace โ€” like mounting of devices โ€” are not reflected in the session namespace. no bleed-through, periodt.

but if you do want some of those events to travel, an administrator may use the special shared-subtree feature to propagate selected mount/unmount events from the parent namespace into the disassociated session namespace. for the tea on shared-subtree, go read the mount(8) man page and the shared-subtree description at http://lwn.net/Articles/159077 and http://lwn.net/Articles/159092. ๐Ÿ“š


๐ŸŽ€ OPTIONS ๐ŸŽ€

  • debug โ€” logs a lot of debug information using syslog. noise? yes. useful? also yes. ๐Ÿ™ˆ
  • unmnt_remnt โ€” for programs like su and newrole, the login session has already set up a polyinstantiated namespace. for these programs, polyinstantiation is performed based on the new user id or security context, but the command first needs to undo the polyinstantiation that login did. this argument tells it to undo the previous polyinstantiation first, before proceeding with new polyinstantiation based on the new id/context. out with the old, in with the new ๐Ÿ’…
  • unmnt_only โ€” for trusted programs that want to undo any existing bind mounts and process instance directories on their own, this argument lets them unmount currently mounted instance directories. do-it-yourself energy ๐Ÿซก
  • require_selinux โ€” if selinux is not enabled, return failure. no selinux, no service. ๐Ÿ’€
  • gen_hash โ€” instead of using the security context string for the instance name, generate and use its md5 hash. shorter name, same vibe.
  • ignore_config_error โ€” if a line in the configuration file corresponding to a polyinstantiated directory contains a format error, skip that line and process the next line. without this option, pam will return an error to the calling program, which results in termination of the session. so likeโ€ฆ forgiving mode, but the default is not forgiving. ๐Ÿ˜ญ
  • ignore_instance_parent_mode โ€” instance parent directories are by default expected to have the restrictive mode of 000. with this option, an administrator can choose to ignore the mode of the instance parent.
๐Ÿšจ this option should be used with caution, because it will reduce the security and isolation goals of the polyinstantiation mechanism. it's a tradeoff, bestie, and not a cute one.
  • unmount_on_close โ€” explicitly unmount the polyinstantiated directories instead of relying on automatic namespace destruction after the last process in a namespace exits.
โš ๏ธ use this one only in case it is ensured by other means that there cannot be any processes running in the private namespace left after the session close. it's also useful only in case there are multiple pam session calls in sequence from the same process.
  • use_current_context โ€” useful for services which do not change the SELinux context with setexeccon call. the module will use the current SELinux context of the calling process for the level and context polyinstantiation. ๐Ÿ‘‘
  • use_default_context โ€” useful for services which do not use pam_selinux for changing the SELinux context with setexeccon call. the module will use the default SELinux context of the user for the level and context polyinstantiation. the fallback queen ๐ŸŒˆ
  • mount_private โ€” this option can be used on systems where the / mount point or its submounts are made shared (for example with a mount --make-rshared / command). the module will mark the whole directory tree so any mount and unmount operations in the polyinstantiation namespace are private. normally pam_namespace will try to detect the shared / mount point and make the polyinstantiated directories private automatically. this option has to be used just when only a subtree is shared and / is not.

note that mounts and unmounts done in the private namespace will not affect the parent namespace if this option is used, or when the shared / mount point is autodetected. isolation slay ๐Ÿฆ‹


๐Ÿงš MODULE TYPES PROVIDED ๐Ÿงš

only the session module type is provided. and listen โ€” the module must not be called from multithreaded processes. like, don't. not the vibe. ๐Ÿšซ


๐Ÿ’œ RETURN VALUES ๐Ÿ’œ

  • PAM_SUCCESS โ€” namespace setup was successful. we ate. ๐ŸŽ‰
  • PAM_SERVICE_ERR โ€” an unexpected system error occurred while setting up the namespace. ๐Ÿ’€
  • PAM_SESSION_ERR โ€” an unexpected namespace configuration error occurred. ๐Ÿ˜ญ

๐Ÿ“ FILES ๐Ÿ“

  • /etc/security/namespace.conf โ€” the main configuration file ๐Ÿ‘‘
  • /etc/security/namespace.d โ€” directory for additional configuration files ๐Ÿ“
  • /etc/security/namespace.init โ€” init script for instance directories โœจ

๐ŸŒˆ EXAMPLES ๐ŸŒˆ

for the <service>s you need polyinstantiation on (login, for example), put the following line in /etc/pam.d/<service> as the last line for the session group:

session required pam_namespace.so [arguments]

and to use polyinstantiation with the graphical display manager gdm, please refer to gdm's documentation. iykyk ๐Ÿ“–


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

namespace.conf(5), pam.d(5), mount(8), pam(8).


๐Ÿ’– AUTHORS ๐Ÿ’–

the namespace setup scheme was designed by Stephen Smalley, Janak Desai and Chad Sellers. the pam_namespace PAM module was developed by Janak Desai <janak@us.ibm.com>, Chad Sellers <csellers@tresys.com> and Steve Grubb <sgrubb@redhat.com>. additional improvements by Xavier Toth <txtoth@gmail.com> and Tomas Mraz <tmraz@redhat.com>. absolute legends, every single one ๐Ÿซถ


and that's the whole page, bestie โ€” brought to you by Linux-PAM, dated 09/27/2026, filed under PAM_NAMESPACE(8). go forth and polyinstantiate responsibly ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from