Skip to content

Add postil login and logout device-authorization flow - #126

Merged
morgaesis merged 1 commit into
mainfrom
cli-login
Jul 30, 2026
Merged

Add postil login and logout device-authorization flow#126
morgaesis merged 1 commit into
mainfrom
cli-login

Conversation

@morgaesis

Copy link
Copy Markdown
Contributor

postil login authorizes a device against the control plane and stores a short-lived credential, so a first-time user can review without obtaining a model provider key first. The credential lives in the user config directory at mode 0600 under a 0700 directory, written to its final mode at creation rather than adjusted afterwards, and it acts as a fallback behind the four existing key environment variables so an explicit key still wins. An expired credential produces one instruction to log in again rather than a provider authentication error, and postil doctor reports whether a credential is present and when it expires. The token never appears in output.

Implements the CLI half of hosted-inference login against the gateway
contract: postil login opens a device-authorization flow (RFC 8628-style),
polls for approval, and stores the resulting token at
${XDG_CONFIG_HOME:-~/.config}/postil/credentials.json. postil logout revokes
it server-side and always removes the local file, even when that call fails.

The stored token is a fallback in api key resolution, used only when none of
POSTIL_API_KEY/OPENROUTER_API_KEY/MODEL_API_KEY/LLM_API_KEY is set; when used,
its apiBase and model apply unless POSTIL_API_BASE/REVIEW_MODEL override them.
This is applied even when the credential is expired (routing information
only, not a secret) so require_model and postil doctor can still run and
report the expiry with one actionable "run postil login again" message
instead of a generic missing-model or upstream auth error. The precedence is
documented alongside the existing config.rs precedence comment and in
docs/configuration.md.

The credentials file and its containing directory get their final
permission bits (0600 / 0700) set at creation via OpenOptionsExt/
DirBuilderExt, matching the existing atomic-write pattern used for other
private receipt files in this codebase, so there is no window where the
token is briefly world-readable, and writes are never followed by a
separate chmod.
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​dirs@​6.0.09910093100100
Addedcargo/​time@​0.3.5410010093100100

View full report

@morgaesis
morgaesis merged commit 6471668 into main Jul 30, 2026
10 checks passed
@morgaesis
morgaesis deleted the cli-login branch July 30, 2026 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant