Skip to content

nbo: read a token_file up front - #304

Open
multivac61 wants to merge 1 commit into
Mic92:mainfrom
multivac61:nbo-token-file
Open

multivac61 wants to merge 1 commit into
Mic92:mainfrom
multivac61:nbo-token-file

Conversation

@multivac61

Copy link
Copy Markdown
Contributor

Adds a token_file host setting for nbo. The file's first line is read when settings load and sent with every request, like a static token or NIXBOT_TOKEN.

Why

Since #282, token_command runs only when a request needs it. Reads go out anonymously, and the token is fetched only after a 401 or 403. The server never answers a private repository that way. An anonymous /api/repos leaves private repositories out of the list, and /api/repos/<repo>/builds returns 404. So with only a token_command, nbo repo list shows no private repositories, and nbo build list or nbo schedule run reports them as not known, even though the token would see them.

A token in a file, such as a secret sops-nix or agenix decrypts to /run/secrets/…, cannot prompt. So it doesn't need #282's laziness, and reading it up front fixes private reads. token_command keeps its lazy behaviour for password managers.

If a token_file can't be read, nbo raises an error naming the path. It doesn't fall back to an anonymous client that quietly sees nothing.

Testing

  • test_settings_token_file covers reading the file, NIXBOT_TOKEN taking precedence, and the error for a missing file. All of test_cli.py passes, and ruff, mypy and nix fmt are clean.
  • Against a live instance with a private repository: token_command = "cat /run/secrets/…" lists no private repositories, while token_file = "/run/secrets/…" lists them and their builds.

🤖 Generated with Claude Code

A token_command runs only when a request needs it, so reads go out
anonymously and retry with the token only on a 401 or 403. The server
answers an anonymous read of a private repository with an empty list or a
404 instead, so with only a token_command `nbo repo list` shows no private
repositories and `nbo build list` reports them missing. A token kept in a
file, such as a secret sops-nix or agenix decrypts, cannot prompt, so
token_file is read up front and sent with every request like a static
token. A token_file that cannot be read is an error rather than an
anonymous client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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