-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(jans-cedarling): implement CEDARLING_ID_TOKEN_TRUST_MODE #10585
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed in a7a888e
Strict, | ||
} | ||
|
||
impl FromStr for IdTokenTrustMode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry about that, must've missed it since rustanalyzer isn't complaining. removed in 9e964d4
jwt::{Token, TokenClaimTypeError}, | ||
}; | ||
|
||
pub fn enforce_id_tkn_trust_mode(tokens: &DecodedTokens) -> Result<(), IdTokenTrustModeError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write a small description for at least public functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a docstring that describes what the function does here: 4208d86
jwt::{Token, TokenClaimTypeError}, | ||
}; | ||
|
||
pub fn enforce_id_tkn_trust_mode(tokens: &DecodedTokens) -> Result<(), IdTokenTrustModeError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can have something more descriptive by renaming this function to validate_id_token_trust_mode
, but it's up to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that might be a better name. renamed the function here: ff0c60e
#[derive(Debug, thiserror::Error)] | ||
pub enum IdTokenTrustModeError { | ||
#[error("the access token's `client_id` does not match with the id token's `aud`")] | ||
ClientIdIdTokenAudMismatch, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can rename this one to AccessTokenClientIdMismatch
to avoid some typing error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed here 2195d90
fn get_tkn_claim_as_str( | ||
token: &Token, | ||
claim_name: &str, | ||
) -> Result<Box<str>, IdTokenTrustModeError> { | ||
let claim = token | ||
.get_claim(claim_name) | ||
.ok_or(IdTokenTrustModeError::MissingRequiredClaim( | ||
claim_name.to_string(), | ||
token.kind, | ||
))?; | ||
let claim_str = claim | ||
.as_str() | ||
.map_err(|e| IdTokenTrustModeError::TokenClaimTypeError(token.kind, e))?; | ||
Ok(claim_str.into()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this function by
fn get_tkn_claim_as_str(
token: &Token,
claim_name: &str,
) -> Result<Box<str>, IdTokenTrustModeError> {
token
.get_claim(claim_name)
.ok_or_else(|| IdTokenTrustModeError::MissingRequiredClaim(claim_name.to_string(), token.kind))
.and_then(|claim| claim.as_str()
.map(|s| s.into())
.map_err(|e| IdTokenTrustModeError::TokenClaimTypeError(token.kind, e)))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is less readable... but I think can get used to it so i changed it here fdda12e
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
- rename enforce_id_tkn_trust_mode to validate_id_tkn_trust_mode Signed-off-by: rmarinn <[email protected]>
- rename ClientIdIdTokenAudMismatch to AccessTokenClientIdMismatch Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
Signed-off-by: rmarinn <[email protected]>
Prepare
Description
This PR implements ID token trust mode which can be set via the
CEDARLING_ID_TOKEN_TRUST_MODE
bootstrap property. The trust mode implements additional checks done on the input token's claims. This PR introduces two modes:None
andStrict
(more info below).Target issue
target issue: #10479
closes: #10479
Implementation Details
None
ModeNo additional validations checks on the tokens are implemented.
Strict
Modeid_token.aud
must match theaccess_token.client_id
.sub
must match theid_token.sub
.aud
must match theaccess_token.client_id
.Test and Document the changes
Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with
docs:
to indicate documentation changes or if the below checklist is not selected.