Skip to content

fix(secrets): keep no device token in a plain file in the Flatpak unless the user asks - #260

Merged
bketelsen merged 1 commit into
mainfrom
fix/secrets-no-file-fallback-in-flatpak
Nov 22, 2026
Merged

bketelsen merged 1 commit into
mainfrom
fix/secrets-no-file-fallback-in-flatpak

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Summary

Fixes #249. When no Secret Service answered on the session bus, secrets.Open returned the file store (secrets.json in notesd's data directory) and only logged a warning. ADR-0016, ADR-0031 and the README say the token goes to the keyring unless FROSTNOTES_SECRETS=file is set. On such a desktop the pairing probe passed on the file, and the user was not told.

The new ADR-0045 decides it the way Frostmail's ADR-0046 does, so the suite's apps behave alike:

  • In the Flatpak (config.InFlatpak), with FROSTNOTES_SECRETS unset and no Secret Service, notesd keeps no plain file. It still starts and serves notes. Its secret store fails every Get, Set and Delete with an error that wraps ErrNoKeyring and names flatpak override --user --env=FROSTNOTES_SECRETS=file org.frostyard.Frostnotes.
    • The store never answers ErrNotFound, which sync reads as a revoked token. A device paired on the old fallback keeps its pairing, and sync reports the error with the hint.
    • The pairing probe fails first, so sync.pair answers "this device cannot keep a hub token: …" with the hint, before the hub hears of the device.
    • A secrets.json that is already there stays untouched. When a Secret Service answers on a later start, its tokens move in, as before.
  • Outside the Flatpak (a source build, the .deb, a hub host), the fallback to the 0600 file stays, with its warning.
  • FROSTNOTES_SECRETS=file still picks the file in both cases.

Code:

  • secrets.Options{NoFallback, Hint}, with HostOptions(), FlatpakOptions() and OptionsFor(inFlatpak).
  • Open(ctx, file, log, opts).
  • An unexported noKeyring store.
  • ErrNoKeyring now reads "no keyring can keep the token". Its 3 existing uses (no default collection) add the hint for where the process runs.
  • cmd/notesd passes OptionsFor(config.InFlatpak(os.Getenv)).

Docs: ADR-0045; the status lines of ADR-0016 and ADR-0031 say they are amended by it; the README's Remove section; docs/design/sync.md and overview.md; and the comment of packaging/flatpak/smoke-test.sh. The smoke test runs as the Flatpak with no session bus and pairs nothing, so it still passes.

Closes #249

Risk paths

risk:high: this PR touches internal/secrets/open.go, secretservice.go, secretservice_test.go and the new options.go, options_test.go and nokeyring.go. All are matched by internal/secrets/** (L1). Why it is safe:

  • The change only removes a fallback, and only in the Flatpak. No path now writes a token anywhere it could not before.
  • The Secret Service path is unchanged apart from the hint in an error message.
  • The host fallback and FROSTNOTES_SECRETS=file behave as before. TestOpenPicksAndMigrates still holds them.
  • The no-keyring store never reads or writes the file and never answers ErrNotFound, so no pairing is dropped and no token is lost. TestOpenInTheFlatpakKeepsNoFile checks all 3 operations and that the file's bytes are unchanged, then checks that the token moves into the Secret Service once one answers. It fails without the change.
  • TestOpenInTheFlatpakAllowsExplicitFile and TestOptionsFor cover the override and the choice of options.

packaging/flatpak/smoke-test.sh changes only in a comment and is not in the risk list.

Checks

  • make verify (with BASE=origin/main): passed locally.
  • go test ./internal/secrets/ ./internal/syncer/ ./cmd/...: passed. TestOpenInTheFlatpakKeepsNoFile failed with the NoFallback check removed.

…ess the user asks (#249)

When no Secret Service answered, secrets.Open fell back to secrets.json with only a log line, while ADR-0016, ADR-0031 and the README say the token goes to the keyring unless FROSTNOTES_SECRETS=file is set; the pairing probe then passed on the file and the user was not told. ADR-0045 settles it as Frostmail's ADR-0046 does: in the Flatpak, notesd keeps no plain file, and its store fails every Get, Set and Delete with an error that wraps ErrNoKeyring (never ErrNotFound, which sync reads as a revoked token) and names the flatpak override; the pairing probe fails first. Outside the Flatpak the fallback stays, with its warning. A secrets.json already there stays untouched until a Secret Service answers, then moves in as before. secrets.Options (NoFallback, Hint) and OptionsFor(config.InFlatpak) pick the behavior; TestOpenInTheFlatpakKeepsNoFile fails without it.
@github-actions github-actions Bot added level:L1 Read every line risk:high Touches a path in .github/risk-paths.json labels Nov 22, 2026
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 22, 2026
@bketelsen
bketelsen merged commit 0fba851 into main Nov 22, 2026
11 checks passed
@bketelsen
bketelsen deleted the fix/secrets-no-file-fallback-in-flatpak branch November 22, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L1 Read every line ready-for-human Reviewed, CI green: ready for Brian to review and merge risk:high Touches a path in .github/risk-paths.json

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sweep: notesd keeps device tokens in a plain file when no Secret Service answers, but ADR-0016, ADR-0031 and the README say the keyring

2 participants