Skip to main content

PAM Auto-Unlock

When an earlier PAM module such as pam_unix supplies a password, pam_rosec.so starts rosec-pam-unlock during authentication. This lets a screen locker such as swaylock unlock the vault without opening a login session. At initial login, the module also saves the password for a second attempt when PAM opens the session, in case rosecd was still starting.

The helper connects to the user session bus or, if that bus is unavailable, to rosec’s embedded bus at $XDG_RUNTIME_DIR/rosec/bus. It verifies the recipient before handing over the password. During a PAM password change, it uses the same check before sending the old and new passwords to update unlocked native vaults and enrolled providers.

Setup​

1. Install the PAM module and helper:

# From the AUR package (installed automatically):
# /usr/lib/security/pam_rosec.so
# /usr/lib/rosec/rosec-pam-unlock
# /etc/pam.d/rosec

# From the repository root, after building the release binaries:
sudo install -Dm755 target/release/rosec-pam-unlock /usr/lib/rosec/rosec-pam-unlock
make -C contrib/pam
sudo make -C contrib/pam install

2. Enroll your Linux login password for each eligible provider you want PAM to unlock. The provider must advertise OfflineCache, have offline caching enabled, and support login-password enrollment. For a native rosec vault, add a wrapping entry when its existing vault password differs from your Linux login password.

# Eligible OfflineCache provider
rosec provider <id> password add --login-password --label pam

# Native vault
rosec provider <id> password add --label pam

Before handing over the terminal for cached-provider enrollment or removal, the CLI verifies the installed daemon and pins its D-Bus connection. A hardened daemon requires the system identity service for these commands.

Every enrollment, including replacement, prompts for your primary provider credential and verifies it online, even when the provider is already unlocked. After writing a fresh offline snapshot, rosec verifies your Linux login password through the dedicated rosec-enroll PAM service before saving the slot. Its default stack uses pam_unix. Sites using a directory password should configure this service to verify that password. On a password change, place the rosec password module after the module that updates the Linux password. Rosec verifies the replacement through the same service before rewrapping a cached provider. The enrollment applies to this installation. PAM can open a fresh snapshot after reboot or screen unlock. A provider that supports session recovery can resume sync while its cached session is valid. Use rosec provider <id> password list to find the slot ID and rosec provider <id> password remove <entry-id> to remove it.

If the snapshot expires, authenticate with the provider through rosec to refresh it. If the provider password used to encrypt the snapshot changes, or PAM misses a Linux password change, enroll the Linux login password again. Before sync checks the remote session, rosec records the suspension of local unlock in the enrollment data. If the check is interrupted after dispatch, PAM unlock stays suspended, even if you restore the cached password wrapper or a later sync succeeds. Authenticate online and enroll again to restore access. The PAM helper uses local unlock operations for native vaults and enrolled providers. Install the matching daemon and helper together. Other providers use their normal rosec authentication flow.

Enrollment belongs to the root config path and the provider’s account or token registration. Replacing a token registration requires fresh enrollment. Disabling a provider keeps its enrollment dormant. Removing the entry revokes enrollment when the daemon next reads the config. The provider remove and detach commands record revocation immediately and can be retried after interruption. If another program saves the config during detach, rosec preserves its edit and reports the conflict. A subsequent config load recovers an interrupted publication. If recovery cannot identify the staged config or confirm a live config file, rosec keeps the journal and reports its location so you can recover the document.

Eligible providers write snapshots scoped to the config and account. After upgrading from an unscoped cache, authenticate online once to populate the new snapshot and enroll any login password you want to use.

A full backup of the rosec data directory includes the installation secret. Restoring it with the same config path, account, enrolled password, and a usable snapshot can enable local unlock on another machine. A backup taken before revocation can restore the earlier enrollment. With a different config path or a fresh installation secret, authenticate online and enroll again. The enrollment record in the data directory identifies the exact current password wrapper and snapshot key. A separate logout record in the rosec data directory holds the authorization epoch. Restoring cached files cannot undo a logout. When upgrading from a version that kept the epoch in the cache, authenticate online and enroll the Linux password again. If neither the logout record nor the enrollment owner can identify the configured account, rosecd leaves that provider unavailable and retries automatically. Other providers remain available.

3. Add rosec to the PAM config for your display manager and screen locker. A drop-in snippet is installed at /etc/pam.d/rosec — include it from whichever PAM service files are used for login and screen unlock on your system.

The include needs to appear in the PAM files that are actually executed during login and screen unlock. Whether system-local-login is in that chain depends on your distribution and display manager — check which files your DM and screen locker include, and add the rosec include to the appropriate ones.

Common configurations​

# /etc/pam.d/system-local-login — covers any DM or locker that includes this file:
auth include rosec
session include rosec
password include rosec

Do not add rosec to /etc/pam.d/system-login — that file is also used by SSH and other remote services where there is no D-Bus session bus.

If your display manager uses a dedicated PAM config that does not include system-local-login, add the rosec include there directly:

Display manager / lockerPAM config
greetd/etc/pam.d/greetd
GDM/etc/pam.d/gdm-password
SDDM/etc/pam.d/sddm
hyprlock/etc/pam.d/hyprlock
swaylock/etc/pam.d/swaylock
i3lock/etc/pam.d/i3lock

For example, on a greetd + hyprlock setup where greetd does not include system-local-login:

# /etc/pam.d/greetd — add at the end:
auth include rosec
session include rosec
password include rosec

# /etc/pam.d/hyprlock — add at the end:
auth include rosec
session include rosec

For swaylock, the auth hook alone is enough. If its stack does not already include rosec, place this line after the password authentication rule in /etc/pam.d/swaylock.

auth include rosec

Fallback: pam_exec (no native module)​

If you prefer not to install pam_rosec.so, the helper works standalone via pam_exec. This only works for screen unlock (not initial login), because pam_exec expose_authtok runs during the auth phase only — there is no stash-and-replay for the session phase:

# /etc/pam.d/hyprlock — after auth:
auth optional pam_exec.so expose_authtok quiet /usr/lib/rosec/rosec-pam-unlock

Daemon identity​

The helper resolves the unique D-Bus connection that owns the Secret Service name and checks that it belongs to the login user. It then compares the running executable with a trusted, root-owned installation of rosecd. Only that same verified connection receives the password pipe.

When Linux lets the helper inspect the executable directly, it completes the check itself. A hardened rosecd is non-dumpable, so Linux normally denies that lookup to an ordinary user. In that case the session or embedded broker must provide a process file descriptor (ProcessFD). The way the helper was started determines who can inspect that process.

How auto-unlock startsWho verifies a hardened rosecd?
Password login through a root-started PAM application such as greetdBefore dropping privileges, pam_rosec.so creates a short-lived worker and a private socket. The user-side helper sends the process descriptor to that worker. This works with only rosec’s embedded bus, even on a system without systemd.
Screen unlock through a user-run locker such as swaylockThe locker runs its PAM stack as the desktop user. The helper asks org.rosec.PamIdentity1 on the system bus to verify the process. If verification fails, a correct password still unlocks the screen and the vault stays locked.
A user unit launches rosec-pam-unlock directly after auto-loginThe helper has no privileged PAM parent and uses the same system-bus verifier as swaylock.

Both verifiers check the process owner and return the executable’s device and inode. The password travels separately to the verified daemon. If verification fails, the helper withholds the password. For example, a standalone user helper can reach the embedded bus with no system bus present, but cannot verify a hardened daemon in that setup. You can still unlock the vault manually.

On-demand activation of the system verifier​

The AUR packages ship the D-Bus activation file, system-bus policy, and rosec-pam-identity.service. For a source install that needs the user-run paths above, run this from the repository root.

sudo make -C contrib/pam install-identity

Installing the activation file registers the name org.rosec.PamIdentity1. On the first request, D-Bus launches rosec-pam-unlock --identity-service directly or asks systemd to start rosec-pam-identity.service. There is no systemctl enable or manual start step. On Arch, package hooks reload the system bus and systemd after installation. For a manual install into a running system, reload the system-bus configuration and, if using systemd activation, run sudo systemctl daemon-reload. The verifier begins shutting down as soon as it sends a successful reply. An activation with no successful request starts shutting down after two seconds. Configuring the locker’s PAM stack is a separate setup step.

Trusted daemon paths​

The helper looks for bin/rosecd in its own installation, including when the helper lives under lib/rosec or libexec/rosec. It also checks /usr/bin/rosecd. A user profile can point into a system-managed package store. For split packages or custom layouts, set ROSEC_PAM_DAEMON_PATH at build time to a comma-separated list of absolute or helper-relative daemon paths. This replaces the default list.

Security​

  • Cannot block login: pam_rosec.so returns PAM_SUCCESS on every error path — stash failure, fork failure, helper timeout, helper crash. The PAM config line uses optional as defence-in-depth.
  • Password zeroization: The stashed password is zeroized with explicit_bzero() + volatile barrier on cleanup (PAM transaction end, stash overwrite, or explicit clear after use).
  • Password sent via pipe: Never appears as a D-Bus message, argv argument, or environment variable. rosec-pam-unlock reads from stdin, passes to rosecd via pipe fd (SCM_RIGHTS).
  • Fire-and-forget: The helper runs in the background (double-forked). Login and screen unlock are never delayed.
  • The PAM module depends on libc and libpam. The user-side helper handles D-Bus communication with the daemon.
  • Process isolation: The child closes inherited application descriptors above stderr and redirects stdout and stderr to /dev/null. For root-started PAM it also passes the newly created private verifier socket to the helper.