You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(secret-service): add Linux Secret Service daemon (#3434) - #3607
Implement the org.freedesktop.secrets D-Bus API on top of the gopass store, so desktop applications (Firefox, Chromium, VS Code, Electron apps, NetworkManager, secret-tool, ...) keep their secrets in the same GPG-encrypted, git-backed store as the CLI instead of GNOME Keyring or KDE Wallet.
The feature is Linux-only and pure Go: D-Bus comes from godbus/dbus/v5 and all crypto from the standard library plus golang.org/x/crypto, and the volatile session collection uses golang.org/x/sys/unix. No CGo, no new dependencies.
Also correct ADR A-11, which had several errors: the prior art uses the gopass Go API (not the CLI); the DH key schedule is HKDF-SHA256, not a bare SHA256; item IDs must be hyphen-free to be valid D-Bus path elements; and the volatile session collection plus a metadata cache for SearchItems were missing from the design.
Implemented:
transport sessions "plain" and "dh-ietf1024-sha256-aes128-cbc-pkcs7" (HKDF key derivation, left-padded DH values), unit-tested on all hosts
Service, Collection, Item and Session objects via godbus + prop, with introspection XML
gopass API-backed store with an in-memory item metadata cache so SearchItems does not decrypt the store on every lookup, plus aliases and in-memory lock state
volatile session collection, served from the Linux kernel keyring on a runtime.LockOSThread-pinned thread (in-memory fallback when keyctl is unavailable). Payloads never reach the store, so transient credentials cannot become GPG files or git commits.
CreateItem(replace=true), the item Locked property, and full signal coverage (ItemCreated, ItemChanged, ItemDeleted, CollectionChanged)
CLI: gopass secret-service serve [--replace] [--prefix] [--notify-on-access], status, install and uninstall, plus a non-Linux stub
install/uninstall write a systemd user unit and a D-Bus session activation file below the XDG config/data dirs; reference copies ship in contrib/secret-service/
Store.Aliases and docs/commands/secret-service.md
libsecret compatibility:
libsecret does not call ReadAlias. It derives /org/freedesktop/secrets/aliases/ locally and then calls CreateItem on that path, so secret-tool store failed with UnknownInterface. Export a Collection object at every alias path and emit collection signals from each of them.
D-Bus object path elements may not contain hyphens, so items created out of band by the CLI (e.g. cli-inserted) produced invalid object paths and could not be served. Encode such names as x+hex; names that are already safe and do not start with x stay verbatim, so generated item IDs keep their historic layout.
Tests:
integration tests against a private dbus-daemon covering both transport algorithms, the session collection, install/uninstall and status (tests/secret_service_test.go, tests/secret_service_dh_test.go)
a libsecret interoperability test driving the daemon with secret-tool, which also exercises the DH transport against a real client (tests/secret_service_libsecret_test.go)
unit tests for the vault and session store, the item ID mapping, and the systemd/D-Bus templates, which are asserted byte-identical to contrib/secret-service/
main_test.go: command discovery invoked every command's Action, which started a daemon and claimed org.freedesktop.secrets on the real session bus. Skip long-running commands and correct the asserted command count.
Docs: mark ADR A-11 implemented (and its index entry), and document serve, status, install and uninstall plus the remaining limitations.
Validated with make test, the integration tests above, and linux, windows and darwin builds.
Implement the org.freedesktop.secrets D-Bus API on top of the gopass
store, so desktop applications (Firefox, Chromium, VS Code, Electron
apps, NetworkManager, secret-tool, ...) keep their secrets in the same
GPG-encrypted, git-backed store as the CLI instead of GNOME Keyring or
KDE Wallet.
The feature is Linux-only and pure Go: D-Bus comes from
godbus/dbus/v5 and all crypto from the standard library plus
golang.org/x/crypto, and the volatile session collection uses
golang.org/x/sys/unix. No CGo, no new dependencies.
Also correct ADR A-11, which had several errors: the prior art uses the
gopass Go API (not the CLI); the DH key schedule is HKDF-SHA256, not a
bare SHA256; item IDs must be hyphen-free to be valid D-Bus path
elements; and the volatile `session` collection plus a metadata cache
for SearchItems were missing from the design.
Implemented:
- transport sessions "plain" and
"dh-ietf1024-sha256-aes128-cbc-pkcs7" (HKDF key derivation,
left-padded DH values), unit-tested on all hosts
- Service, Collection, Item and Session objects via godbus + prop,
with introspection XML
- gopass API-backed store with an in-memory item metadata cache so
SearchItems does not decrypt the store on every lookup, plus aliases
and in-memory lock state
- volatile `session` collection, served from the Linux kernel keyring
on a runtime.LockOSThread-pinned thread (in-memory fallback when
keyctl is unavailable). Payloads never reach the store, so transient
credentials cannot become GPG files or git commits.
- CreateItem(replace=true), the item Locked property, and full signal
coverage (ItemCreated, ItemChanged, ItemDeleted, CollectionChanged)
- CLI: `gopass secret-service serve [--replace] [--prefix]
[--notify-on-access]`, `status`, `install` and `uninstall`, plus a
non-Linux stub
- install/uninstall write a systemd user unit and a D-Bus session
activation file below the XDG config/data dirs; reference copies ship
in contrib/secret-service/
- Store.Aliases and docs/commands/secret-service.md
libsecret compatibility:
- libsecret does not call ReadAlias. It derives
/org/freedesktop/secrets/aliases/<alias> locally and then calls
CreateItem on that path, so `secret-tool store` failed with
UnknownInterface. Export a Collection object at every alias path and
emit collection signals from each of them.
- D-Bus object path elements may not contain hyphens, so items created
out of band by the CLI (e.g. `cli-inserted`) produced invalid object
paths and could not be served. Encode such names as `x`+hex; names
that are already safe and do not start with `x` stay verbatim, so
generated item IDs keep their historic layout.
Tests:
- integration tests against a private dbus-daemon covering both
transport algorithms, the session collection, install/uninstall and
status (tests/secret_service_test.go, tests/secret_service_dh_test.go)
- a libsecret interoperability test driving the daemon with secret-tool,
which also exercises the DH transport against a real client
(tests/secret_service_libsecret_test.go)
- unit tests for the vault and session store, the item ID mapping, and
the systemd/D-Bus templates, which are asserted byte-identical to
contrib/secret-service/
main_test.go: command discovery invoked every command's Action, which
started a daemon and claimed org.freedesktop.secrets on the real session
bus. Skip long-running commands and correct the asserted command count.
Docs: mark ADR A-11 implemented (and its index entry), and document
serve, status, install and uninstall plus the remaining limitations.
Validated with make test, the integration tests above, and linux,
windows and darwin builds.
Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
The implementation currently permits store-prefix traversal and locked-secret access, while also mishandling multiline payloads and parts of the D-Bus contract.
Harden the Secret Service daemon and fix several D-Bus contract and
storage issues found in review.
Security and correctness:
- GetSecrets: validate that the collection is path-safe, the decoded
item name is a single non-reserved segment, and the collection is
unlocked before reading, closing a path traversal via encoded
"../../" item IDs and a lock bypass.
- CreateItem(replace=true): require an exact attribute-map match instead
of a subset match, so {service:x} no longer replaces
{service:x,user:a}.
- Store secret payloads binary-safely: keep simple single-line UTF-8
values in the password field (so `gopass show` still prints them) and
base64-encode anything else under _ss_secret; exclude it from the
metadata cache.
- Escape client attributes that use the reserved _ss_ namespace to
_ss_attr_<name> so they cannot overwrite internal metadata.
- Serialize the SetAlias read-modify-write cycle with a dedicated mutex.
- Guard the metadata cache with a generation counter so a stale
in-flight read cannot overwrite a concurrent invalidation.
D-Bus contract:
- OpenSession("plain") now uses an empty string variant for input and
output as required by the spec, and validates the input variant; DH
keeps using a byte array.
- Normalize zero timestamps to 0 instead of wrapping to a huge uint64.
- Advertise Modified with EmitTrue and refresh it after every mutation;
refresh asynchronously from prop.Set callbacks to avoid a deadlock.
Volatile session collection:
- Zero the previous payload when overwriting an in-memory entry.
- Reject LockCollection instead of reporting a lock that never applies.
- Remove every tracked key from the vault on Close.
Tests and docs:
- Add unit tests for the new storage, cache, vault and lock behavior.
- Assert the plain-session string contract in the integration test.
- Skip secret-service.status during command discovery (it connects to
the real session bus).
- Document the storage format in ADR A-11.
fix(secret-service): harden DH, session ownership and signals
Address the second round of review feedback on the D-Bus daemon:
- Validate the client's DH public value: require the exact 128-byte
encoding and 1 < Y < p-1, rejecting degenerate values (0, 1, p-1)
that would yield a publicly known shared secret.
- Bind sessions to the opener's unique bus name and tear them down on
NameOwnerChanged, so a crashed or malicious client cannot leave
unbounded exported objects and AES keys alive. Enforce ownership on
every later session use.
- Emit Service.CollectionChanged on collection label changes and on
Lock/Unlock, matching the signal-coverage contract.
- Allow CreateItem(replace=true) to replace an item with an empty
attribute set instead of creating a duplicate.
- Generation-check the metadata cache fill in GetItem so a concurrent
mutation cannot be overwritten by a stale in-flight read.
- Guard the session collection label with the store mutex to remove a
data race between GetCollection and SetCollectionLabel.
- Narrow the kernel-keyring security claim: payloads still pass through
Go byte slices during D-Bus decode, decryption and AddKey.
Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
Harden the D-Bus daemon and fix correctness issues found in review:
- Sample the DH private exponent uniformly from [2, p-2] instead of
[0, p-1); the latter allows 0, 1 and p-1, which yield a publicly
derivable shared secret.
- Encode attribute values losslessly: base64 values containing a line
break, NUL or the AKV separator so arbitrary D-Bus strings survive
the line-oriented gopass format.
- Export the collection Modified property with change emission and
republish it after a label change.
- Return NoSession for missing, foreign or closed sessions instead of
NotSupported, reserving NotSupported for malformed ciphertext.
- Recreate an alias object when its target collection changes so
/aliases/<name> immediately serves the new collection.
- Reject collection names using the reserved "_" prefix.
- Validate the target collection exists in SetAlias.
- Keep the volatile session collection out of Service.Collections even
when a durable directory of the same name exists.
- Serialize persistence operations against the shared gopass store,
which cannot perform concurrent git add/commit.
- Correct the ADR: golang.org/x/crypto is v0.57.0 and the Linux build
tag covers the D-Bus service files, not the portable crypto package.
Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
Export collection items before publishing their paths
internal/secretservice/collection.go:117
Items discovered while exporting a collection are only converted to paths; their Item objects are never exported. A client that enumerates Collection.Items and calls GetSecret directly will therefore receive UnknownObject unless another call happened to run ensureItem first. Export each item before publishing its path.
Validate object existence when resolving paths
internal/secretservice/service.go:689
This resolver validates only path syntax, not object existence. Lock/Unlock therefore report arbitrary nonexistent collection paths as successfully processed; a nonexistent item path also locks its entire collection. Resolve canonical paths only after GetCollection/GetItem confirms the referenced object exists.
Restrict NameOwnerChanged matches to the bus daemon
internal/secretservice/session.go:55
The signal match does not constrain the sender, so another session-bus peer can emit a forged NameOwnerChanged signal and cause sessions belonging to an arbitrary client to be torn down. Match the bus daemon as the sender in addition to the interface/member/path.
This issue also appears on line 149 of the same file.
Encode arbitrary D-Bus strings losslessly before persisting them in the
line-oriented AKV format. Collection labels, item labels, content types,
attribute names and values, and alias names are now reversibly encoded
(base64 with a marker prefix) when they contain a line break or the ": "
separator, and decoded on read. Values that already start with the base64
marker are encoded too so they cannot be mistaken for encoded data.
Propagate alias-store read errors instead of treating every failure as an
empty map, which previously let a transient decryption or I/O error
overwrite and discard all existing aliases. Only a confirmed not-found
error yields the default map.
Preserve the previous kernel-keyring payload until a replacement succeeds:
KEYCTL_UPDATE replaces the payload atomically, so a failed update no longer
destroys the old secret and leaves metadata for an unreadable item.
Export every collection item before publishing its object path, so a client
that enumerates Collection.Items and then calls GetSecret directly no longer
receives UnknownObject.
Validate object existence when resolving collection, item and alias paths,
so Lock/Unlock no longer report arbitrary nonexistent paths as processed and
a nonexistent item path cannot lock its whole collection.
Restrict the NameOwnerChanged signal match to the bus daemon, so another
session-bus peer cannot forge the signal and tear down an arbitrary client's
sessions.
The test fake store now round-trips through the real AKV parser and returns
store.ErrNotFound, so the lossless-encoding tests exercise serialization.
Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
If persisting the requested alias fails, this method still reports successful collection creation, but ReadAlias and libsecret's /aliases/<name> path will not resolve as requested. Propagate the failure and define rollback/partial-success handling rather than returning a successful result after logging it.
Avoid rewriting unchanged alias secrets
internal/secretservice/store.go:839
Avoid rewriting the alias secret when this call makes no change. ensureDefaultCollection calls SetAlias("default", "default") on every daemon start, and re-encrypting identical plaintext still changes the ciphertext and can create a new git commit on every login/startup.
Keep Modified timestamp stable across reads
internal/secretservice/volatile.go:330
Modified changes on every read, even when the collection has not changed. This also lets the canonical and alias objects expose different timestamps depending on when each was exported. Store a stable modified timestamp and update it only when the session collection is actually mutated.
Serialize item field updates so concurrent property writes cannot lose
data. The Label, Attributes and SetSecret callbacks previously performed a
full read-modify-write of the whole item: a concurrent update to a
different field could be silently reverted by whichever write landed last.
Add SetItemLabel, SetItemAttributes and SetItemSecret to the Store
interface, which update a single field under the store's operation lock,
and use them from the item callbacks. A missing item is still reported as
NoSuchObject while other failures (e.g. a write error) map to NotSupported.
Avoid a cross-object deadlock when a collection label is written through
the canonical object and an alias object concurrently. Each property
callback runs while the prop package holds its own object's lock, so
calling SetMust on another object's properties from within the callback
could block forever. Defer the cross-object sync to a goroutine that runs
after the callback returns, and reload the final stored label so racing
writes cannot publish a stale value.
Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
Serialize refreshes to prevent stale property publication
internal/secretservice/item.go:159
These refresh goroutines are not ordered. With concurrent label/attribute writes, an older refresh can load an earlier snapshot, pause, and publish it after the newer refresh, leaving the exported D-Bus property cache stale even though the store is correct. Serialize refreshes or guard them with a generation so only the newest snapshot is published.
Handle D-Bus replacement permissions correctly
internal/secretservice/service.go:221
REPLACE_EXISTING is conditional: D-Bus only replaces a current owner that requested ALLOW_REPLACEMENT. Consequently this cannot evict “any existing provider” as the CLI/docs promise, and this daemon also omits ALLOW_REPLACEMENT, so a later gopass --replace cannot replace it either. Narrow the user-facing promise to replacement-when-allowed and consider requesting ALLOW_REPLACEMENT for gopass-to-gopass handover.
Propagate alias store errors instead of deleting aliases
internal/secretservice/service.go:259
A transient alias decryption/I/O error is converted into a default-only map. The cleanup loop then unexports every non-default alias, making valid aliases disappear until another sync. Aliases already treats a genuinely missing store as an empty map, so other errors should be propagated here.
Encode aliases whose whitespace would be trimmed
internal/secretservice/store.go:355
Alias keys with leading or trailing whitespace are considered safe here, but AKV parsing applies strings.TrimSpace to keys. For example, aliases "login" and " login" collapse to the same persisted key. Encode names whenever trimming would change them.
Distinguish metadata errors from missing metadata
internal/secretservice/store.go:449
Every metadata read failure is treated as an absent _meta entry. A decryption or I/O failure on an empty collection becomes “collection not found”, after which startup/CreateItem paths may recreate and overwrite its metadata; with items present, the error is silently replaced by fabricated timestamps and labels. Only store.ErrNotFound should trigger the legacy fallback, and callers need a distinct not-found error so they create collections only in that case.
Clear stale lock state when deleting collections
internal/secretservice/store.go:521
Deleting a collection leaves its in-memory lock entry behind. Recreating the same collection name later makes the new collection immediately report Locked=true, even though it has never been locked. Clear s.locked[name] after a successful deletion.
Do not synthesize missing default aliases
internal/secretservice/store.go:875
The unconditional default fallback defeats SetAlias("default", "/"): after the alias is removed, ReadAlias immediately resolves it to default again. It can also return a dead collection path after the default collection is deleted. Treat a missing default alias as unset (or explicitly recreate/protect the default collection), rather than synthesizing a target without checking existence.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement the org.freedesktop.secrets D-Bus API on top of the gopass store, so desktop applications (Firefox, Chromium, VS Code, Electron apps, NetworkManager, secret-tool, ...) keep their secrets in the same GPG-encrypted, git-backed store as the CLI instead of GNOME Keyring or KDE Wallet.
The feature is Linux-only and pure Go: D-Bus comes from godbus/dbus/v5 and all crypto from the standard library plus golang.org/x/crypto, and the volatile session collection uses golang.org/x/sys/unix. No CGo, no new dependencies.
Also correct ADR A-11, which had several errors: the prior art uses the gopass Go API (not the CLI); the DH key schedule is HKDF-SHA256, not a bare SHA256; item IDs must be hyphen-free to be valid D-Bus path elements; and the volatile
sessioncollection plus a metadata cache for SearchItems were missing from the design.Implemented:
sessioncollection, served from the Linux kernel keyring on a runtime.LockOSThread-pinned thread (in-memory fallback when keyctl is unavailable). Payloads never reach the store, so transient credentials cannot become GPG files or git commits.gopass secret-service serve [--replace] [--prefix] [--notify-on-access],status,installanduninstall, plus a non-Linux stublibsecret compatibility:
secret-tool storefailed with UnknownInterface. Export a Collection object at every alias path and emit collection signals from each of them.cli-inserted) produced invalid object paths and could not be served. Encode such names asx+hex; names that are already safe and do not start withxstay verbatim, so generated item IDs keep their historic layout.Tests:
main_test.go: command discovery invoked every command's Action, which started a daemon and claimed org.freedesktop.secrets on the real session bus. Skip long-running commands and correct the asserted command count.
Docs: mark ADR A-11 implemented (and its index entry), and document serve, status, install and uninstall plus the remaining limitations.
Validated with make test, the integration tests above, and linux, windows and darwin builds.