Skip to content

server: Add a storage adapter for V1 keyrings - #711

Open
BrandoDev wants to merge 2 commits into
linux-credentials:mainfrom
BrandoDev:server/v1-storage-adapter
Open

BrandoDev wants to merge 2 commits into
linux-credentials:mainfrom
BrandoDev:server/v1-storage-adapter

Conversation

@BrandoDev

@BrandoDev BrandoDev commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

This is the first step of #642. Daemon collections now use a private storage adapter backed by the existing libsecret-compatible V1 keyring. The daemon still serves the same Secret Service API, opens existing files in place and writes new collections in V1.

The commits can be reviewed in order.

  1. Move subset and exact attribute matching behind a query prepared once per search. The D-Bus collection can request either match without handling the V1 file key. Cached records handle write-through replacement and lock transitions. Only encrypted V0 placeholders convert search attributes to MD5 digests.
  2. Use the adapter for live collections, item operations and password changes. Discovery, creation and legacy migration all return the daemon keyring accepted by the collection constructor.

The final tree passes the daemon suite with default features (165 tests) and with OpenSSL and default features disabled (164 tests), the workspace formatting check and daemon Clippy with default features. The unencrypted collection tests exercise Secret Service lookup before and after unlock and reopen a newly created file with the V1 reader.

@BrandoDev
BrandoDev marked this pull request as ready for review November 21, 2026 18:50

@bilelmoussaoui bilelmoussaoui left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a proper review, but I think we should still split this into smaller PRs.

Having a wrapper Record/Keyring, make sense. Although i am not sure if that is better than having say, a trait that defines what is a Collection, and what is an Item inside of it.

Then most of the v1 file item level APIs would become trait implementation for v1 "backend". Not sure how doable but might be interesting to give it a shot.

Comment thread server/src/storage.rs Resolved
Comment thread server/src/migration.rs Resolved
Comment thread server/src/collection/mod.rs Resolved
Comment thread server/src/collection/mod.rs Resolved
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

📊 Code Coverage Report

Metric Value
Current PR Coverage 88.58%
Main Branch Coverage 88.31%
Coverage Change 📈 +0.27%

Coverage report generated by cargo-tarpaulin

@BrandoDev BrandoDev closed this Nov 21, 2026
@BrandoDev BrandoDev reopened this Nov 21, 2026
@BrandoDev

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @bilelmoussaoui. I agree it would be easier to review this in smaller PRs. I’d start with the partial-unlock fix and its regression test. That fix stands on its own. If the daemon can’t unlock one item, the collection and its other items should stay locked.

For the storage work, I’d then try a small V1 implementation with a collection trait and an associated item type implementing an item trait. One concrete question is whether the D-Bus item can read and update a record without reaching through the wrapper to get a file::UnlockedItem. That would give us a small patch to evaluate together before changing discovery and migration.

Would you be happy with that split and with trying the trait design in the second PR? I’d like to confirm the direction with you before reorganizing this one.

@bilelmoussaoui

Copy link
Copy Markdown
Collaborator

Sounds good to me to split the fix into a separate issue.

D-Bus searches need subset matches and CreateItem needs exact matches for replacement. Let the collection request either operation without fetching and passing around a V1 file key. Both paths still acquire the key once per query.

Keep the V0 digest conversion with the records that need it. Only encrypted legacy placeholders use it, and they share the converted attributes across a search. Dispatch records from both discovery paths and keep cached replacements in sync with successful file writes.
Have discovery, creation and migration return the daemon keyring directly so Collection::new can accept the same type at every call site. Route password changes and item operations through that adapter while retaining the atomic lock transition from main.

Exercise Secret Service lookup on a locked, unencrypted V1 file and after unlock, and reopen a newly created collection with the V1 reader.
@BrandoDev
BrandoDev force-pushed the server/v1-storage-adapter branch from 01c2056 to e43c63c Compare November 23, 2026 16:13
Comment thread server/src/storage.rs
@@ -0,0 +1,282 @@
//! File-backed storage used by daemon collections.

use std::{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split the Keyring & record types into separate files.

Comment thread server/src/storage.rs
data_dir: &Path,
name: &str,
secret: Option<Secret>,
) -> Result<Self, file::Error> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, I would create a new error type for the server as other implementations might not use file::Error specific errors ?

Comment thread server/src/storage.rs

pub async fn query<'a>(
&self,
attributes: &'a HashMap<String, String>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use impl AsAttributes.

Comment thread server/src/storage.rs
exact: bool,
) -> Result<ItemQuery<'a>, oo7::crypto::Error> {
match self {
Self::V1(keyring) => ItemQuery::new(keyring, attributes, exact).await,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still not sure what is the usefulness of ItemQuery, maybe do that in a separate PR/commit?

Comment thread server/src/storage.rs
}
}

fn unlocked_v1(&self) -> Result<&file::UnlockedKeyring, file::Error> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is leaking v1/v0 details into something that is meant to be generic. If we were to have a generic implementation, it should cover both Locked/Unlocked keyring, same for records.

Comment thread server/src/storage.rs
/// The cached storage record for a registered D-Bus item.
pub(crate) struct Record {
item: file::Item,
v0_placeholder: bool,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing, we shouldn't leak v0 details here.

Comment thread server/src/storage.rs
}

impl Keyring {
pub async fn open(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would keep the open_at name.

.await?;

let items = unlocked.search_items(&[("created", "unenc-test")]).await?;
let persisted = UnlockedKeyring::load(unlocked.path().unwrap(), None).await?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the point in reloading the keyring here?

"Should be locked initially"
);

// Locked V1 items in an unencrypted keyring carry plaintext attributes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like an unrelated change?

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.

2 participants