Skip to content

Conversation

@david-crespo
Copy link
Contributor

@david-crespo david-crespo commented Nov 17, 2025

/// a device token. This is a slightly awkward fit but is included here
/// because we need to use this to clamp the expiration time when device
/// tokens are confirmed using an existing device token.
device_token_expiration: Option<DateTime<Utc>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the sad part. I considered doing a proper scheme: AuthnScheme struct here like AuthnScheme::DeviceToken { time_expires: Option<DateTime<Utc>> } but I think that makes the abstraction-leaking here even worse. We don't want app-layer code to be doing conditional logic based on the authn scheme. Authz policy is generally meant to cover that. The device token confirmation logic in this PR is a special case.

max and the current token's expiration time.",
));
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new validation logic for explicit TTL request

(None, Some(token_exp)) => Some(token_exp),
(None, None) => None,
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new clamping logic for no explicit TTL

// If the user does not request a specific TTL, we do not error out.
// We calculate the token TTL as min(silo max TTL, current token TTL
// if present). Token confirm requests authenticated with a console
// session can get device tokens with TTLs up to the silo max.
Copy link
Contributor Author

@david-crespo david-crespo Nov 18, 2025

Choose a reason for hiding this comment

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

We discussed this clamping logic in chat and decided that while it was more user-friendly to error out when TTL is specified, it is too easy to get the error when not specifying a TTL, so we clamp instead. Users confirming a token through a console session will never hit any of this logic anyway.

Copy link
Member

@pietroalbini pietroalbini left a comment

Choose a reason for hiding this comment

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

Code looks correct to me! Left a minor nit and a few suggestions to improve the tests, but I'm also happy for the test changes to be done in a followup PR if we want to get 17.1 out ASAP.

Comment on lines +401 to +404
SchemeResult::Authenticated(Details {
actor: _,
device_token_expiration: _
})
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
SchemeResult::Authenticated(Details {
actor: _,
device_token_expiration: _
})
SchemeResult::Authenticated(Details { .. })

testctx,
session_auth_response.device_code,
client_id,
AuthnMode::Session(session_token.clone()),
Copy link
Member

Choose a reason for hiding this comment

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

This request doesn't have to be authenticated. I lean slightly towards only authenticating requests that actually need it.

}

#[nexus_test]
async fn test_device_token_cannot_extend_expiration(
Copy link
Member

Choose a reason for hiding this comment

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

In general, can we wrap the three device flow requests into a function? That'd made the test easier to understand (as we'd check whether the flow as a whole passes or fails with some params, instead of a wall of requests).

@david-crespo david-crespo merged commit 3eaaad5 into main Nov 18, 2025
17 checks passed
@david-crespo david-crespo deleted the device-token-clamp branch November 18, 2025 15:35
iliana pushed a commit that referenced this pull request Nov 18, 2025
david-crespo added a commit that referenced this pull request Nov 19, 2025
We wanted to merge #9411 quickly but there was some test cleanup to do.
Claude did a pretty amazing job with the vaguest prompt:

> I want to factor out `test_device_token_cannot_extend_expiration` so
it's more readable
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.

4 participants