Documentation
¶
Overview ¶
Package auth is the backend-agnostic authentication conversation (crates/wayle-auth): a backend — PAM for the lock screen, greetd for the greeter — asks one or more questions (password, OTP, "your password expired, enter a new one") and the UI answers each in turn.
A backend implements Conversation and drives the whole exchange on a worker goroutine, calling ask whenever it needs the user. Spawn wires ask to the UI: every prompt goes out through onEvent, and the UI replies through the returned Handle. The package has no GUI dependency, so the lock screen and the greeter drive it identically.
Index ¶
- Constants
- Variables
- func AwaitLoginKeyring(ctx context.Context, env xdg.Env, password, previous []byte) error
- func CheckLibrary() error
- func CurrentUsername() string
- func WriteGreetdError(w io.Writer, authFailure bool, description string) error
- func WriteGreetdPrompt(w io.Writer, p Prompt) error
- func WriteGreetdSuccess(w io.Writer) error
- type Ask
- type Conversation
- type Event
- type EventKind
- type Greetd
- type GreetdRequest
- type Handle
- type Login
- type PAM
- type Prompt
- type PromptKind
- type Refusal
- type RefusedError
- type Session
- type Start
- type Verified
Constants ¶
const ( GreetdCreateSession = "create_session" GreetdPostResponse = "post_auth_message_response" GreetdStartSession = "start_session" GreetdCancelSession = "cancel_session" )
The request types.
const GreetdSockEnv = "GREETD_SOCK"
GreetdSockEnv names the IPC socket greetd hands its greeter.
const SessionTypeEnv = "XDG_SESSION_TYPE"
SessionTypeEnv is the variable pam_systemd registers a session's type with, and sessions read to tell what they run on.
Variables ¶
var ErrCancelled = errors.New("cancelled")
ErrCancelled is the failure a backend reports when the user cancelled an input prompt.
Functions ¶
func AwaitLoginKeyring ¶
AwaitLoginKeyring is unlockOrRekey for a session with environment env that is still starting: it activates a keyring on the session's bus and tries until lys-secrets or gnome-keyring answers, and returns what that keyring said, or what it found instead when none answered before ctx ended.
func CheckLibrary ¶
func CheckLibrary() error
func CurrentUsername ¶
func CurrentUsername() string
CurrentUsername is the session user's login name from the environment: USER, then LOGNAME, then "". A locked graphical session always carries one of them.
func WriteGreetdError ¶
WriteGreetdError answers with an error: an authentication failure, or any other.
func WriteGreetdPrompt ¶
WriteGreetdPrompt sends a PAM prompt for the greeter to show and answer.
func WriteGreetdSuccess ¶
WriteGreetdSuccess answers a request with success.
Types ¶
type Ask ¶
Ask is how a backend reaches the user. For prompts that want input it blocks until the UI answers and returns the answer, with ok false when the user cancelled; for info and error prompts it returns ("", false) at once.
type Conversation ¶
Conversation is a backend that drives one authentication to completion. Run executes on a worker goroutine (blocking I/O is fine) and must never touch the GUI. username may be empty to let the backend ask for it. The error is the failure reason.
type Event ¶
type Event struct {
Kind EventKind
// Prompt is set for EventPrompt.
Prompt Prompt
// Reason is set for EventFailure: the detail for the log, not for the
// person logging in.
Reason string
// Refusal is set for EventFailure when PAM refused the login.
Refusal Refusal
}
Event is surfaced to the UI as a conversation progresses.
type EventKind ¶
type EventKind uint8
EventKind is what an Event reports.
const ( // EventPrompt: the backend asks something (see Prompt.WantsInput). EventPrompt EventKind = iota // EventSuccess: authentication succeeded; the conversation is over. EventSuccess // EventFailure: authentication failed or was aborted; the // conversation is over, a retry starts a fresh one. EventFailure )
Event kinds.
type Greetd ¶
type Greetd struct {
// contains filtered or unexported fields
}
Greetd is the pre-login backend (greetd_backend.rs): an unprivileged greeter does not talk to PAM, greetd does, over its IPC socket — a native-endian u32 length prefix before each JSON body. One Run is the whole login: create the session, answer every auth message, and on success start the session; greetd then replaces the greeter.
func NewGreetd ¶
func NewGreetd(conn io.ReadWriter, start Start) *Greetd
NewGreetd runs the protocol over an established connection.
func NewGreetdFromEnv ¶
NewGreetdFromEnv connects to the socket in $GREETD_SOCK.
type GreetdRequest ¶
type GreetdRequest struct {
Type string `json:"type"`
Username string `json:"username"`
Response *string `json:"response"`
Cmd []string `json:"cmd"`
Env []string `json:"env"`
}
GreetdRequest is one request a greeter sends over the greetd protocol, as the server side reads it.
func ReadGreetdRequest ¶
func ReadGreetdRequest(r io.Reader) (GreetdRequest, error)
ReadGreetdRequest reads one request from a greeter; an unknown type is an error.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is the UI's side of a running conversation: it answers the pending prompt. The zero value is not usable; Spawn returns one.
func Spawn ¶
func Spawn(conv Conversation, username string, onEvent func(Event)) *Handle
Spawn runs conv on a worker goroutine. Prompts reach onEvent (called from the worker: marshal it onto the UI loop), and the UI answers through the returned Handle. Exactly one terminal EventSuccess or EventFailure is emitted before the worker exits.
type Login ¶
type Login struct {
// contains filtered or unexported fields
}
Login is a display manager's PAM login: one transaction from the authentication through the session it opens, ended by Close. PAM keeps per-thread state, and pam_loginuid writes /proc/self/loginuid, which the kernel lets only the main thread write, so every call must come from the process's main thread; a session worker stays on it for its whole life.
func Authenticate ¶
Authenticate starts service's transaction for user, authenticates it through ask and checks the account. A failure ends the transaction.
func Greeter ¶
Greeter starts service's transaction for the greeter's user, who signs nothing in: only its session opens.
func (*Login) Close ¶
Close closes an opened session, deletes the credentials it established, and ends the transaction.
func (*Login) OpenSession ¶
OpenSession hands env (KEY=value: the session's type, class, seat and VT, which pam_systemd registers it with) to the transaction, establishes the credentials, opens the session, and returns the environment the session's process starts with.
func (*Login) TakePrevious ¶
func (*Login) TakeSecret ¶
TakeSecret hands over the last secret the user authenticated with (the password, for a password login), nil without one, and forgets it: the caller clears it after use.
type PAM ¶
type PAM struct {
// Service is the PAM service name (/etc/pam.d/<service>).
Service string
// contains filtered or unexported fields
}
PAM authenticates against a PAM service (e.g. system-auth): the in-session backend of the lock screen. The conversation runs on the worker goroutine Spawn creates, locked to its OS thread for the transaction's lifetime, so the UI loop never blocks on PAM. The password is never logged.
func NewPAM ¶
NewPAM returns the backend for service over the system libpam, whose verified passwords go to verified.
func (*PAM) Run ¶
Run implements Conversation. The transaction opens for username (the session user when empty), authenticates, then checks the account (pam_authenticate + pam_acct_mgmt), and always ends with pam_end carrying the last call's status, as nonstick's transaction does; it sets no credentials, an unlock needs none. On success the last secret answered goes to Verified, which does not hold up the result: it unlocks the session keyring's login collection (lys-secrets, else gnome-keyring), best effort, and reports its own failures.
type Prompt ¶
type Prompt struct {
Kind PromptKind
Text string
}
Prompt is one thing a backend wants from the user.
func (Prompt) WantsInput ¶
WantsInput reports whether the prompt expects a typed answer.
type PromptKind ¶
type PromptKind uint8
PromptKind is what a prompt wants from the user.
const ( // PromptSecret is echo-off input (password, PIN). PromptSecret PromptKind = iota // PromptVisible is echo-on input (username, OTP). PromptVisible // PromptInfo is informational text; no answer. PromptInfo // PromptError is error text; no answer. PromptError )
Prompt kinds.
type Refusal ¶
type Refusal uint8
Refusal is why a login was turned down, for a login screen to word. The zero value claims nothing, so a failure nobody classified never reads as a wrong password.
const ( RefusalUnknown Refusal = iota // RefusalCredentials: a wrong password or an unknown user, one // refusal so a login screen does not reveal which accounts exist. RefusalCredentials // RefusalExpired: the account or its password expired. RefusalExpired // RefusalTooManyAttempts: a module gave up after repeated failures. RefusalTooManyAttempts // RefusalDenied: the account may not log in, whatever its password. RefusalDenied )
Refusals.
type RefusedError ¶
type RefusedError struct {
Call, Code string
}
RefusedError is PAM turning a login down: the call that refused it and the code it returned. Its text is what greetd's protocol carries.
func (*RefusedError) Error ¶
func (e *RefusedError) Error() string
func (*RefusedError) Refusal ¶
func (e *RefusedError) Refusal() Refusal
Refusal classifies the code; a code outside pamCodes is unknown.
type Session ¶
type Session struct {
Cmd, Env []string
}
Session is the command and the environment a login starts.
type Start ¶
type Start struct {
Session func() Session
Before func()
}
Start is what a successful login does: Session, read at start_session, says what it starts, and Before runs between the authentication and start_session.
type Verified ¶
type Verified struct {
// contains filtered or unexported fields
}
Verified is what follows a verified password: the keyring, the vault. It runs behind the success rather than before it, since a keyring deriving its key must not keep the screen locked, and whoever ends the process waits for it, or the keyring would never hear of the password.
func NewVerified ¶
NewVerified is what follows a verified password: each of hooks in turn, then unlocking the session keyring. Each borrows the password until it returns.