Skip to content

feat(agent): support per-RP credential selection - #412

Closed
pando85 wants to merge 2 commits into
masterfrom
agent/per-rp-credential-selection
Closed

feat(agent): support per-RP credential selection#412
pando85 wants to merge 2 commits into
masterfrom
agent/per-rp-credential-selection

Conversation

@pando85

@pando85 pando85 commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

Allow an agent profile to override credential-selection behavior per RP while preserving the existing profile-level selector as the backward-compatible default.

This addresses multi-account and multi-RP profiles where one global single / first-matching / newest policy is deterministic but not semantically correct for every relying party.

Configuration

[agents.profiles.coding]
mode = "same-user"
principal_user = "alice"
credential_selection = "single"

[[agents.profiles.coding.rules]]
rp_id = "github.com"
authenticate = "autonomous"
register = "deny"
credential_selection = "newest"

[[agents.profiles.coding.rules]]
rp_id = "gitlab.example.com"
authenticate = "autonomous"
register = "deny"
credential_selection = "first-matching"

Selection precedence is:

  1. exact RP rule override;
  2. wildcard fallback rule override;
  3. profile-level default.

The RP's allowCredentials list still narrows candidates before Passless applies the configured ambiguity policy.

Security behavior

  • explicit credential:<ref> rule overrides must remain inside profile credential_refs when that allowlist is configured;
  • the global "*" rule cannot pin one credential:<ref> because a credential reference is RP-specific;
  • missing per-rule selectors preserve current profile-level behavior;
  • exact RP rules continue to override wildcard fallback rules.

Implementation

  • add optional credential_selection to AgentRpRule;
  • add AgentProfileConfig::credential_selection_for_rp;
  • use the effective RP-specific selector in the authentication credential-selection pipeline;
  • update workspace Rust rule literals for the additive field;
  • document precedence and multi-RP examples;
  • add focused tests for per-RP-over-profile and exact-over-wildcard precedence.

Validation

The final implementation passed:

  • cargo fmt --all;
  • cargo check --workspace --all-targets --all-features with repository native dependencies;
  • cargo test -p passless-core agent::config --lib.

This PR remains draft while normal repository CI runs on the clean single-commit branch.

Review focus

  1. exact/wildcard/profile precedence;
  2. interaction with RP-provided allowCredentials;
  3. explicit credential-ref scope validation;
  4. compatibility of the additive rule field with existing profile-level configuration.

@forkline-bot

forkline-bot Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Fix pushed:

Fixed the end-of-file-fixer pre-commit failure by removing the extra trailing newline in docs/agents/configuration.md. The file had two trailing newlines instead of one.

@pando85
pando85 marked this pull request as ready for review August 13, 2026 13:59
@pando85

pando85 commented Aug 13, 2026

Copy link
Copy Markdown
Owner Author

@forkline update branch and fix merge conflicts

@forkline-bot

forkline-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

⚠️ Branch update and conflict resolution:

This PR had extensive merge conflicts (283 files with add/add conflicts) because it was based on an old commit before the agent infrastructure was merged to master. The branch was attempting to add the entire agent codebase (142k+ lines) which conflicted with agent features already merged in #396, #402, #406, #408, #409, #410, and #411.

Resolution: Created a clean re-implementation in PR #415 that applies only the per-RP credential selection feature on top of the current master branch.

The new PR includes:

  • ✅ Per-RP credential selection override in AgentRpRule
  • credential_selection_for_rp() method for precedence resolution
  • ✅ Updated authentication pipeline to use per-RP selector
  • ✅ Validation for credential ref scope per rule
  • ✅ Documentation with precedence rules and examples
  • ✅ All test fixtures updated with the new field

Please review #415 instead.

@forkline-bot forkline-bot Bot left a comment

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.

Summary

Successfully resolved merge conflicts in PR #412 by creating a clean re-implementation in PR #415.

What happened:

  • PR #412 was based on an old commit and had 283 add/add conflicts (142k+ lines)
  • The branch was adding the entire agent infrastructure which conflicted with agent features already merged to master (#396, #402, #406, #408, #409, #410, #411)

Solution:

Created fix/per-rp-credential-selection-v2 branch from current master with only the per-RP credential selection feature:

Changes implemented:

  • Added optional credential_selection field to AgentRpRule struct
  • Added credential_selection_for_rp() method to AgentProfileConfig for precedence resolution
  • Updated authentication pipeline in sign.rs to use per-RP selector
  • Added validation to enforce credential ref scope per rule
  • Prevented wildcard rules from using credential references
  • Updated all test fixtures (24 locations) with the new field
  • Added comprehensive documentation with precedence rules and examples

Files modified:

  • passless-core/src/agent/config.rs - Core config and validation
  • passless-core/src/agent/policy.rs - Test updates
  • cmd/passless/src/agent/sign.rs - Authentication pipeline
  • cmd/passless/src/agent/policy_engine.rs - Test updates
  • cmd/passless/src/agent/ceremony.rs - Test updates
  • cmd/passless/src/agent/register.rs - Test updates
  • docs/agents/configuration.md - Documentation

PR created: #415

Note: Build verification was not possible due to missing system dependencies (libudev), but all code changes follow the existing patterns and should compile correctly once the dependencies are available.

@pando85 pando85 closed this Aug 13, 2026
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.

1 participant