feat(auth): the door that can delegate no longer needs a person's session
`/mcp` — `email_send`, `slack_post`, `delegate` — authenticated with `authenticate`, which accepts only `full`. Nothing hands it a token today, so this cost nothing yet; the moment something did, the only credential that worked would have been an owner's session, held by an agent runtime. `SCOPE_AGENT_DOOR` is that credential's narrow form. `full` still works, so the UI and every human caller are unaffected, and the route now names what it accepts rather than accepting everything by default. The test that matters is not that each scope opens its own route: it is that holding one grants nothing the other has. Both tokens live where an agent can read them. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
f52cff3e04
commit
22eeaa6f15
@@ -168,6 +168,54 @@ async fn a_scoped_token_is_refused_by_every_unscoped_caller() {
|
||||
assert_eq!(ok.user_id, user.id);
|
||||
}
|
||||
|
||||
/// The two narrow scopes must not substitute for each other.
|
||||
///
|
||||
/// They protect different things — one reads the skills catalogue, the other
|
||||
/// operates the §15 door that can `delegate`. Both tokens live where an agent
|
||||
/// can read them, so the whole value of having two constants is that holding
|
||||
/// one grants nothing the other has.
|
||||
#[tokio::test]
|
||||
async fn one_narrow_scope_does_not_open_the_other() {
|
||||
let pool = cm_testkit::test_pool().await;
|
||||
let (_ws, user) = seeded(&pool).await;
|
||||
let auth = AuthService::new(pool);
|
||||
|
||||
let skills = auth
|
||||
.mint_scoped(user.id, cm_auth::SCOPE_SKILLS_READ, time::Duration::hours(1))
|
||||
.await
|
||||
.unwrap();
|
||||
let door = auth
|
||||
.mint_scoped(user.id, cm_auth::SCOPE_AGENT_DOOR, time::Duration::hours(1))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
matches!(
|
||||
auth.authenticate_scoped(&skills, cm_auth::SCOPE_AGENT_DOOR).await,
|
||||
Err(AuthError::Unauthenticated)
|
||||
),
|
||||
"a skills token must not reach the door — the door can `delegate`"
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
auth.authenticate_scoped(&door, cm_auth::SCOPE_SKILLS_READ).await,
|
||||
Err(AuthError::Unauthenticated)
|
||||
),
|
||||
"and a door token must not read the catalogue"
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
auth.authenticate(&door).await,
|
||||
Err(AuthError::Unauthenticated)
|
||||
),
|
||||
"nor authenticate an ordinary API call"
|
||||
);
|
||||
assert!(auth
|
||||
.authenticate_scoped(&door, cm_auth::SCOPE_AGENT_DOOR)
|
||||
.await
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
/// A person's session keeps working everywhere, including the scoped route.
|
||||
#[tokio::test]
|
||||
async fn a_full_session_still_satisfies_a_scoped_route() {
|
||||
|
||||
Reference in New Issue
Block a user