Skip to content

feat: Automatic delegation sessions#527

Draft
adamspofford-dfinity wants to merge 7 commits intomainfrom
spofford/sudo-mode
Draft

feat: Automatic delegation sessions#527
adamspofford-dfinity wants to merge 7 commits intomainfrom
spofford/sudo-mode

Conversation

@adamspofford-dfinity
Copy link
Copy Markdown
Contributor

Password-protected identities will generate 'session' delegations by default so you don't have to keep entering your password.

  • This happens by default whenever you use your password with an identity-based command
  • This can be explicitly triggered with icp identity login

A user setting configures the session duration, with five more minutes tacked on to account for clock drift, or can disable the automatic form of this feature.

Only keyring storage is used, since plaintext would not be secure enough for automation. Keyring errors are not an error in the automatic path; it just uses the identity normally.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds automatic, cached “session delegation” support for password-protected PEM identities so users don’t need to re-enter passwords on every identity-based command, with an explicit icp identity login flow and a configurable session duration.

Changes:

  • Introduces PEM session delegation caching (key in keyring + delegation chain on disk) and reuses it on subsequent loads.
  • Adds icp settings session-length to configure/disable automatic session caching, and makes icp identity login public with PEM support.
  • Updates CLI docs, changelog, and adds integration tests covering automatic + explicit session creation.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
docs/reference/cli.md Documents icp identity login and icp settings session-length.
crates/icp/src/settings.rs Adds session_length setting (minutes) with default and serde handling.
crates/icp/src/identity/mod.rs Passes session duration into identity loader; makes password func clonable via Arc.
crates/icp/src/identity/key.rs Implements session delegation load/create/store + best-effort migration/cleanup on rename/delete.
crates/icp/src/context/mod.rs Stores password_func on Context for reuse by commands.
crates/icp/src/context/init.rs Wires password func + session duration into Context/identity loader.
crates/icp-cli/tests/identity_tests.rs Adds end-to-end tests for session reuse and explicit login behavior.
crates/icp-cli/src/main.rs Loads settings to compute default session duration and passes it into context init.
crates/icp-cli/src/commands/settings.rs Adds settings session-length subcommand and value parsing/printing.
crates/icp-cli/src/commands/identity/mod.rs Exposes identity login (removes hidden flag).
crates/icp-cli/src/commands/identity/login.rs Extends identity login to support PEM sessions + duration behavior.
CHANGELOG.md Notes the new password-prompt reduction behavior for password identities.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/icp-cli/src/commands/identity/login.rs Outdated
Comment thread crates/icp/src/identity/key.rs
Comment thread crates/icp/src/identity/key.rs Outdated
Comment thread docs/reference/cli.md Outdated
Comment thread crates/icp-cli/src/main.rs Outdated
Comment thread crates/icp-cli/src/commands/identity/login.rs Outdated
Base automatically changed from spofford/delegation-swap to main April 23, 2026 15:23
@adamspofford-dfinity adamspofford-dfinity marked this pull request as ready for review April 23, 2026 15:25
@adamspofford-dfinity adamspofford-dfinity requested a review from a team as a code owner April 23, 2026 15:25
Comment thread CHANGELOG.md Outdated
Comment thread crates/icp-cli/src/commands/settings.rs Outdated

#[derive(Debug, Args)]
struct SessionLengthArgs {
/// Set to `<N>m` (e.g. `5m`) or `disabled`. If omitted, prints the current value.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Inconsistent suffix support with icp identity login --duration. Would be nice to support identical syntax

Comment thread crates/icp/src/identity/key.rs Outdated
Comment on lines +215 to +216
&& let Ok(delegated) =
create_pem_session_and_build_identity(dirs, name, &*identity, duration)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you think it could be appropriate to log errors in --verbose mode? I imagine without some form of logging errors it will be very hard to debug any issues with sessions

///
/// Returns `None` on any failure (missing, expired, or keyring unavailable) so the
/// caller falls back to normal PEM loading.
fn try_load_pem_session(dirs: LRead<&IdentityPaths>, name: &str) -> Option<Arc<dyn Identity>> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here w.r.t. logging

let contents = fs::read(&old_path).context(CopyKeyFileSnafu)?;
fs::write(&new_path, &contents).context(CopyKeyFileSnafu)?;

// Best-effort: migrate any cached session delegation.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would add a test to show that it can work, even if it's ok if it doesn't

@adamspofford-dfinity adamspofford-dfinity enabled auto-merge (squash) April 24, 2026 15:33
@raymondk raymondk disabled auto-merge April 24, 2026 15:39
@raymondk raymondk marked this pull request as draft April 24, 2026 15:40
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.

3 participants