Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/registry-notary-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,8 @@ pub struct EvidenceAuditEvent {
pub occurred_at: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub principal_id_hash: Option<Hashed<PrincipalIdentifier>>,
#[serde(default)]
pub scopes_used: Vec<String>,
pub decision: String,
pub method: String,
pub path: String,
Expand Down Expand Up @@ -2267,6 +2269,7 @@ mod tests {
event_id: "01HX".to_string(),
occurred_at: "2026-05-25T00:00:00Z".to_string(),
principal_id_hash: Some(Hashed::from_hash("hmac-sha256:principal")),
scopes_used: vec!["self_attestation".to_string()],
decision: "denied".to_string(),
method: "POST".to_string(),
path: "/v1/evaluations".to_string(),
Expand Down Expand Up @@ -2349,6 +2352,7 @@ mod tests {
json!("person_is_alive_sd_jwt")
);
assert_eq!(value["principal_id_hash"], json!("hmac-sha256:principal"));
assert_eq!(value["scopes_used"], json!(["self_attestation"]));
assert_eq!(
value["source_sidecar_config_hashes"],
json!(["sha256:2222222222222222222222222222222222222222222222222222222222222222"])
Expand All @@ -2373,6 +2377,7 @@ mod tests {
let decoded: EvidenceAuditEvent =
serde_json::from_value(value).expect("audit event deserializes");
assert_eq!(decoded.event_id, event.event_id);
assert_eq!(decoded.scopes_used, vec!["self_attestation"]);
assert_eq!(decoded.access_mode, Some(AccessMode::SelfAttestation));
assert_eq!(
decoded.denial_code,
Expand Down Expand Up @@ -2427,6 +2432,7 @@ mod tests {
assert!(decoded.verification_id.is_none());
assert!(decoded.claim_hash.is_none());
assert!(decoded.purposes.is_none());
assert!(decoded.scopes_used.is_empty());
assert!(decoded.row_count.is_none());
assert!(decoded.error_code.is_none());
assert!(decoded.access_mode.is_none());
Expand Down
1 change: 1 addition & 0 deletions crates/registry-notary-server/benches/json_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn build_audit_event() -> EvidenceAuditEvent {
principal_id_hash: Some(Hashed::<PrincipalIdentifier>::from_hash(
"hmac-sha256:client-bench-001",
)),
scopes_used: vec!["farmer_registry:evidence_verification".to_string()],
decision: "allow".to_string(),
method: "POST".to_string(),
path: "/v1/evaluations".to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/registry-notary-server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,7 @@ fn config_apply_intent_audit_event(audit: ConfigAuditEvent) -> EvidenceAuditEven
event_id: Ulid::new().to_string(),
occurred_at,
principal_id_hash: None,
scopes_used: Vec::new(),
decision: "accepted".to_string(),
method: "BACKGROUND".to_string(),
path: "/__events/admin.config_apply.intent".to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/registry-notary-server/src/federation/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub(super) fn federation_audit_event(
event_id: Ulid::new().to_string(),
occurred_at,
principal_id_hash: None,
scopes_used: Vec::new(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Record federated source scopes in audits

For successful /federation/v1/evaluations calls, the handler builds an EvidencePrincipal from peer.config.source_scopes and uses those scopes to evaluate and return claim results, but this audit constructor always emits an empty scopes_used list. That makes every successful federated evaluation look unscoped in the audit trail even though source scopes were exercised, undermining the required reconstruction of which permission authorized the claim result.

Useful? React with 👍 / 👎.

decision: audit.decision,
method: "POST".to_string(),
path: "/federation/v1/evaluations".to_string(),
Expand Down
3 changes: 3 additions & 0 deletions crates/registry-notary-server/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3291,6 +3291,7 @@ pub(crate) fn pre_auth_audit_event(
event_id: Ulid::new().to_string(),
occurred_at,
principal_id_hash: fields.principal_id_hash,
scopes_used: Vec::new(),
decision: decision.to_string(),
method: method.to_string(),
path: path.to_string(),
Expand Down Expand Up @@ -4629,6 +4630,7 @@ fn build_audit_event(
principal_id_hash: principal.map(|principal| {
Hashed::<PrincipalIdentifier>::from_hash(hasher.hash(&principal.principal_id))
}),
scopes_used: principal.map_or_else(Vec::new, |principal| principal.scopes.clone()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Record only checked request scopes

When a credential or OIDC token carries extra scopes beyond the one this route actually checks, this copies every granted scope into scopes_used, including unrelated scopes on successes and denials. For example, claim access is checked against per-claim required scopes and OID4VCI issuance checks the credential-configuration scope, so auditing the whole principal scope set can overstate which permission authorized returned data; record the checked/required scopes for the request instead of the full token/API-key scope list.

Useful? React with 👍 / 👎.

decision,
method: method.to_string(),
path: path.to_string(),
Expand Down Expand Up @@ -7993,6 +7995,7 @@ credential_profiles:
event_id: "01HX0000000000000000000000".to_string(),
occurred_at: "2026-05-22T00:00:00Z".to_string(),
principal_id_hash: Some(Hashed::from_hash("sha256:caseworker")),
scopes_used: vec!["registry_notary:admin".to_string()],
decision: "allowed".to_string(),
method: "GET".to_string(),
path: "/v1/claims".to_string(),
Expand Down
11 changes: 11 additions & 0 deletions crates/registry-notary-server/tests/standalone_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8195,6 +8195,15 @@ async fn oidc_mode_verifies_token_from_fixture_idp() {
assert!(envelopes
.iter()
.all(|envelope| envelope.record.get("principal_id").is_none()));
let claims_audit = envelopes
.iter()
.map(|envelope| &envelope.record)
.find(|record| record["path"] == json!("/v1/claims") && record["status"] == json!(200))
.expect("claims audit record exists");
assert_eq!(
claims_audit["scopes_used"],
json!(["farmer_registry:evidence_verification"])
);
assert!(!audit.contains(&token));

idp.stop().await;
Expand Down Expand Up @@ -8427,6 +8436,7 @@ async fn oidc_self_attestation_evaluates_renders_and_audits_access_mode() {
.starts_with("hmac-sha256:"));
assert!(evaluate_audit.get("principal_id").is_none());
assert!(evaluate_audit.get("principal_id_hash").is_some());
assert_eq!(evaluate_audit["scopes_used"], json!(["self_attestation"]));

let render_audit = records
.iter()
Expand All @@ -8437,6 +8447,7 @@ async fn oidc_self_attestation_evaluates_renders_and_audits_access_mode() {
})
.expect("render audit record exists");
assert_eq!(render_audit["access_mode"], json!("self_attestation"));
assert_eq!(render_audit["scopes_used"], json!(["self_attestation"]));
assert_eq!(
render_audit["purposes"],
json!(["citizen_self_attestation"])
Expand Down
Loading