Skip to main content

Crate coqui_access_system

Crate coqui_access_system 

Source
Expand description

The operating system’s own accounts as an authenticator and a directory.

§coqui-access-system

Version Rust version License: MPL-2.0 Docs CI

Signs people in with the operating system’s own accounts and resolves them as a directory: PAM and NSS on Linux, FreeBSD and macOS (so SSSD or LDAP accounts the machine knows appear too), LogonUserW and the NetUser API on Windows. It is read only: accounts are managed with the OS’s own tools.

§Features

  • Authenticator — a name and a password, checked by PAM (pam_authenticate, then pam_acct_mgmt, so an expired or locked account is refused) or by a Windows network logon.
  • Directory — Person { id, name, display_name, groups }: the uid, or the SID on Windows; the GECOS or full name; the account’s groups (local groups on Windows).
  • Narrowing — a lowest uid (by default the platform’s first person uid, so root and service accounts stay out) and a list of groups an account must be in.

§Installation

cargo add coqui-access-system --git https://github.com/Boriken-Dev/coqui-access

Build coqui-access-system-plugin for the loadable library. No Cargo features.

§Quick start

Provider id coqui_access_system; every key is optional:

pam_service = "coqui-access"   # /etc/pam.d/coqui-access on Unix
min_uid = 1000                 # the platform's first person uid by default; 0 admits root
groups = ["staff"]             # empty admits any account
domain = "."                   # Windows: the machine's own accounts

In code:

use coqui_access::{Attempt, Authenticator, Verdict};
use coqui_access_system::SystemAccounts;

let accounts = SystemAccounts::builder().groups(["staff"]).build()?;
let verdict = accounts.authenticate(Attempt {
    name: Some("alice".into()),
    secret: Some("correct horse".into()),
    ..Attempt::default()
})?;
assert!(matches!(verdict, Verdict::Valid(_) | Verdict::Invalid | Verdict::Unknown));

§API overview

ItemPurpose
SystemAccountsThe provider: builder(), new(config), config(), Authenticator and Directory.
SystemAccountsConfigThe Guatiao configuration; non_defaults() reports what it admits beyond the defaults.
NonDefaultAdmitsRoot, AdmitsServiceAccounts.
SUPPORTED, DEFAULT_*Whether this build reaches an account database, and the defaults.

§PAM service

The provider checks passwords under the PAM service pam_service (default coqui-access). Give it a file in /etc/pam.d that does what the machine’s login does, for example on Fedora:

auth     include  system-auth
account  include  system-auth

and on FreeBSD auth include system / account include system. On macOS the stock chkpasswd service does the job: set pam_service = "chkpasswd". With no such file, Linux-PAM and OpenPAM use other, which refuses everyone on Fedora and macOS. Under pam_unix (Linux, FreeBSD) checking another account’s password needs root; macOS’s pam_opendirectory does not.

§Development

cargo test -p coqui-access-system
cargo clippy -p coqui-access-system --all-targets -- -D warnings

Building on Unix links the system’s libpam (Debian and Ubuntu: libpam0g-dev; Fedora: pam-devel). The real sign-in tests are ignored by default; tests/real_login.rs says how to run them against a throwaway account.

§Releasing

This project follows Semantic Versioning and keeps a CHANGELOG.md. Pushing a tag matching v* triggers the release workflow of the repository.

§License

MPL-2.0 — see LICENSE.

Structs§

SystemAccounts
The operating system’s accounts: who may sign in is who the OS lets sign in, narrowed by SystemAccountsConfig::min_uid and SystemAccountsConfig::groups.
SystemAccountsBuilder
Options for SystemAccounts; every one has a default.
SystemAccountsConfig
Options of SystemAccounts, as a host’s configuration holds them. Every key is optional.

Enums§

NonDefault
A setting that admits more than the defaults do. Reported, never refused: the host decides what to do about it.

Constants§

DEFAULT_DOMAIN
The Windows domain an account belongs to unless the configuration names another: ., the machine’s own accounts.
DEFAULT_MIN_UID
The lowest uid admitted unless the configuration says otherwise: the first uid this platform gives a person (Linux 1000, FreeBSD 1001, macOS 501; 0 elsewhere).
DEFAULT_PAM_SERVICE
The PAM service checked unless the configuration names another.
SUPPORTED
Whether this build can reach the operating system’s accounts: Unix and Windows.

Traits§

SystemAccountsConfigSetters
The typed setters of SystemAccountsConfig, for any builder that holds its settings.