Design: preserve complete keyring state across daemon restarts
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- linux, rust
调研方向
先从 issue 中描述的 daemon 初始化和 D-Bus 名称获取入口开始,然后检查 UnlockedKeyring 的解锁和密码轮换路径。第一个聚焦的变更应在服务获取之前建立初始化;只有在完整的重启状态、验证、恢复和 logout 边界契约都已实现并经过测试后,更广泛的工作才算完成。
由索引模型根据 Issue 内容生成。
描述
Problem
I hit a lifecycle gap while using oo7 with PAM.
PAM unlocked the Login collection, and oo7-daemon-login delivered the
password through its sealed memfd. Later, a package update restarted
oo7-daemon without ending the desktop session. The helper had already exited,
and no systemd credential was configured, so the new daemon loaded the
collection locked. The user had not logged out or requested Lock().
I previously suggested retaining the helper memfd in systemd's file descriptor
store in #506.
After reviewing the wider lifecycle, I no longer think oo7 should retain the raw
login password for the whole session. The fdstore still looks like a suitable
optional transport, but it should carry keyring-specific restart state instead.
Proposed ownership
Credential acquisition should remain outside oo7. PAM, the desktop,
credentiald, or another provider supplies a secret or key. oo7 validates it,
unlocks its own keyrings, and retains only the state needed to resume those
keyrings after its process restarts.
The split would be:
- The file backend owns validated key-based unlocking and should retain derived
keys rather than source passwords. - The server owns a versioned snapshot of persistent keyring and lock state.
- An optional Linux/systemd backend carries that snapshot through the service
fdstore. - Desktop and distro integration owns the logout boundary.
Non-systemd behavior should remain unchanged.
First release contract
I think the first release advertising restart continuity should implement the
complete state model rather than a Login-only or collection-only subset:
- Every persistent encrypted and unencrypted file keyring is represented.
- Collection and per-item lock state is restored exactly.
- The raw PAM or prompt password is discarded after key derivation.
- Graceful and crash-triggered daemon restarts restore state.
- Explicit locks remain effective after restart.
- Malformed, stale, mismatched, or oversized state fails locked without partial
restoration. - Single-keyring and multi-keyring password changes have crash-consistent
recovery. - Restoration finishes before
org.freedesktop.secretsis acquired. - An explicit stop, logout, user-manager exit, or reboot discards state.
The work can still land as small preparatory PRs. The shipped service should not
enable continuity until the complete contract is tested.
Key-based file API
UnlockedKeyring currently retains the source Secret and derives its Key
lazily. I propose deriving the key during unlock and retaining only the key.
The narrow API needed for this is:
LockedKeyring::unlock(secret), which derives a key and delegates to a
validated key path.- An
unlock_with_key(key)path for restart restoration. - An
UnlockedKeyringthat contains the derived key, not the source password. - Password rotation that derives the replacement key and drops the source
password before returning.
This follows the direction discussed in
#506,
where callers may provide either a secret or an already-derived key.
For non-empty keyrings, restart restoration should authenticate every encrypted
item with the supplied key. Empty keyrings have no encrypted content to test,
so their restart entry must instead be bound to the exact keyring file.
Restart state
A snapshot would describe the complete persistent keyring inventory:
RestartState {
version
generation
keyrings: [
{
canonical relative file identity
exact file digest
format version
collection lock state
derived key or explicit unencrypted state
locked item indexes
}
]
}
Item indexes are safe only when bound to the digest of the exact keyring file.
If the file is unchanged, item order is deterministic. This preserves item lock
state without requiring an on-disk item-ID migration.
The parser should bound the total size and counts, reject unknown versions,
duplicates, invalid key lengths, path traversal, truncation, trailing data, and
stale file digests, and apply restoration all-or-nothing.
The snapshot must not contain passwords, temporary session-keyring data, D-Bus
sessions, client state, or absolute paths.
State updates
The server should rebuild the complete snapshot after successful durable
changes:
- Collection and item lock or unlock.
- Persistent collection creation or deletion.
- Completed migration.
- Persistent item writes or deletion.
- Password rotation.
Failed operations must leave the previous snapshot unchanged. Locking one
collection must not discard continuity for unrelated collections.
Optional systemd transport
On systemd systems, the server could serialize the snapshot into a bounded,
sealed memfd and submit it with FDSTORE=1.
The unit would eventually add:
NotifyAccess=main
FileDescriptorStoreMax=2
FileDescriptorStorePreserve=restart
Two transient slots avoid a loss window while replacing state:
- Publish generation
N+1under a generation-specificFDNAME. - Call
sd_notify_barrier()to confirm receipt. - Remove generation
N. - Return to one descriptor at steady state.
If a crash leaves two generations, oo7 can try newest to oldest and select the
newest one matching the current keyring files.
At startup, oo7 should consume descriptors using
sd_listen_fds_with_names(true) semantics, validate and restore them, register
all service objects and aliases, and only then acquire
org.freedesktop.secrets.
Type=dbus can remain. Fdstore notifications only require access to
NOTIFY_SOCKET.
With FileDescriptorStorePreserve=restart, systemd preserves state for an
explicit restart or automatic crash restart and discards it after a full stop.
Password changes
A single-keyring password change should stage re-encryption separately and
replace the live object only after the new file is durable.
A PAM password change may affect several keyrings. Updating them sequentially
can leave a permanent old/new mixture after a crash. I think this needs a
narrow rotation journal:
- Prepare and fsync every replacement file.
- Write and fsync a journal containing paths and old/new file digests, but no
passwords or keys. - Commit the journal.
- Rename every prepared file into place.
- Publish restart state with the new keys and original lock states.
- Remove the journal after all files and restart state are committed.
Before journal commit, recovery keeps all keyrings on the old password. After
journal commit, recovery rolls all of them forward. A reboot without fdstore
would finish the disk transaction but start encrypted keyrings locked.
Logout boundary
Restart continuity must not extend beyond the desktop session. A desktop that
treats logout as the end of the unlock lifetime should bind oo7 to its graphical
session, for example with:
PartOf=graphical-session.target
Logout also needs to wait for that target to stop when the user manager remains
alive because lingering is enabled. I see this as desktop/distro policy rather
than portable oo7 core behavior.
Suggested implementation sequence
I would keep this reviewable with at most one small PR open from this series at
a time:
- Delay D-Bus name acquisition until initialization is complete.
- Derive keys eagerly and remove retained passwords from
UnlockedKeyring. - Drain and zeroize PAM secrets after processing and startup replay.
- Finish durable atomic keyring replacement, including directory fsync and
temporary-file cleanup. - Make single-keyring password rotation transactional.
- Agree on and implement the bounded restart-state format.
- Add validated key-based restore.
- Capture and restore complete state from bytes without systemd.
- Keep that state synchronized after successful mutations.
- Add the optional systemd fdstore transport.
- Add crash recovery for multi-keyring password rotation.
- Add the release-level restart and fault-injection matrix.
- Enable fdstore in the shipped unit.
The early PRs are useful correctness and security improvements on their own and
would not add dormant fdstore scaffolding.
Questions
- Does oo7 owning derived restart state fit the intended boundary, while the
desktop continues to own credential acquisition? - Is a complete file-bound snapshot an acceptable way to preserve exact item
lock state without changing the keyring file format? - Does an optional systemd-specific server path fit oo7's portability goals?
- Is the proposed first-release contract the right point at which to enable the
unit settings?
If this direction is acceptable, I can start with the D-Bus readiness change
and keep the implementation to one focused PR at a time.
- 主要语言
- Rust
- 星标
- 481
- 派生
- 62
- 平均合并
- 9 小时 51 分钟
- 30 天内合并 PR
- 55
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
linux-credentials/oo7 的其他 Issue
-
NoNewPrivileges blocks CAP_IPC_LOCK for oo7-daemon可能重新可做 关联的 PR 已关闭且未合并。 未关闭server
难度 2/5 1-3 小时 新手友好度 67/100
linux-credentials/oo7#645 · 4 条评论 ·
维护者通常 1 天内回复
-
server
难度 4/5 3-5 天 新手友好度 48/100
linux-credentials/oo7#685 · 4 条评论 ·
维护者通常 1 天内回复
-
question server
难度 5/5 一周以上 新手友好度 20/100
linux-credentials/oo7#642 · 8 条评论 ·
维护者通常 1 天内回复
-
question server
难度 4/5 3-5 天 新手友好度 45/100
linux-credentials/oo7#614 · 1 条评论 ·
维护者通常 1 天内回复
-
question server
难度 3/5 半天 新手友好度 35/100
linux-credentials/oo7#603 · 1 条评论 ·
维护者通常 1 天内回复
查看 linux-credentials/oo7 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
-
needs triage
难度 2/5 1-3 小时 新手友好度 76/100
pbakaus/impeccable#1620 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
swc-project/swc-next-issues#533 ·
-
bug
难度 2/5 1-3 小时 新手友好度 77/100
nautechsystems/nautilus_trader#5718 ·
维护者通常 1 天内回复
-
`luvus --remote` cannot start on a host whose login shell is Nushell可能已有人在做 @schlich 今天认领。 未关闭status: needs triage
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 4 天内回复