hostauth

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hostauth verifies the host OS's own credentials. The application stores no passwords — every authentication goes through the OS subsystem (Open Directory on macOS, PAM on Linux, SAM on Windows) so the same password that unlocks the machine is what unlocks remote superadmin.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCredentials = errors.New("invalid credentials")

ErrInvalidCredentials is returned when the OS rejects the supplied username/password pair.

View Source
var ErrNotImplemented = errors.New("host auth not implemented on this OS")

ErrNotImplemented is returned by the stub OS implementations until real per-platform authenticators land (Linux PAM and Windows LogonUserW are follow-up tasks; v1 ships macOS only).

Functions

func BareUsername added in v0.5.4

func BareUsername(s string) string

BareUsername strips platform qualifiers from an account name so the same human-typed username works against every OS:

  • "MACHINE\alice" / "DOMAIN\alice" (Windows down-level) → "alice"
  • "alice@example.com" (Windows UPN) → "alice"
  • "alice" (Unix / bare) → "alice"

Unix account names cannot contain '\' or '@' (useradd and macOS both forbid them), and Windows SAM account names forbid both characters too, so stripping at the last '\' / first '@' is unambiguous: any qualifier present is exactly one of the two Windows forms.

func CurrentDisplayName

func CurrentDisplayName() string

CurrentDisplayName returns the GECOS / "full name" of the agent's OS user (e.g. "Alice Smith"). May be empty on stripped-down systems; the portal falls back to the username in that case.

func CurrentUser

func CurrentUser() (string, error)

CurrentUser returns the agent process's own username — used as the canonical "this host's account". The matrix-agent runs as a user-level service, so this is the account the in-process shell will inherit.

func SameUser added in v0.5.4

func SameUser(submitted, canonical string) bool

SameUser reports whether a submitted username refers to the same account as the canonical one, accepting either the exact local form or the bare (unqualified) form, case-insensitively. This is the single equality rule for the "submitted user must be the agent's own OS user" gates (/auth and the SSH PasswordCallback).

On Windows, Go's user.Current().Username is the SAM-compatible "MACHINE\user" — demanding that exact string from an SSH client is hostile (quoting a backslash plus a space), so "user" alone must match too. The match only widens the *comparison*: callers still authenticate the canonical name, so the password remains the gate.

Types

type Authenticator

type Authenticator interface {
	Authenticate(username, password string) error
}

Authenticator verifies a username/password pair against the host OS. Implementations live in per-OS files (hostauth_<goos>.go).

func DefaultAuthenticator

func DefaultAuthenticator() Authenticator

DefaultAuthenticator on Linux uses PAM. The service name defaults to "login" but is overridable with MATRIX_PAM_SERVICE for distros that expose a more specific auth-only stack (e.g. "common-auth", "system-auth"). Build with CGO_ENABLED=1 and libpam-dev installed.

type StubAuth

type StubAuth struct {
	Want map[string]string // username → expected password
}

StubAuth always returns the configured result. Tests inject this so we don't shell out to dscl during unit/integration tests.

func (StubAuth) Authenticate

func (s StubAuth) Authenticate(user, pass string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL