To validate an OIDC token and integrate it with AWS IAM for role assumption, follow these steps:
-
Retrieve JWK:
- Fetch the JSON Web Key (JWK) from
jwks_uriusing thekidfrom the token's header. This can be done by making a GET request to the URL retrieved from the OpenID Connect configuration.
- Fetch the JSON Web Key (JWK) from
-
Verify JWT Signature:
- Use the retrieved JWK to verify the signature of the JWT. This ensures the token is legitimate and secure.
-
Extract Claims:
- Decode the JWT to extract the payload, which includes claims such as
iss,aud,sub,exp, etc.
- Decode the JWT to extract the payload, which includes claims such as
-
Validate Claims:
- Ensure the audience (
aud) matcheshttps://epycbyte.com/[TEAM_SLUG]. - Confirm the subject (
sub) aligns withowner:[TEAM_SLUG]:project:[PROJECT_NAME]:environment:[ENVIRONMENT].
- Ensure the audience (
-
Check Expiration:
- Convert the
expclaim from seconds since epoch to a human-readable format to determine the token's validity period.
- Convert the
-
Integrate with AWS IAM:
- Structure an IAM policy document with conditions that check the validated claims.
- Use these policies in AWS IAM roles to control access based on the token's attributes.
-
Handle Errors and Expiration:
- Implement mechanisms to handle invalid or expired tokens, such as returning appropriate HTTP errors or denying access if necessary.
-
Test and Monitor:
- Test the setup with actual tokens to ensure correct behavior.
- Continuously monitor for issues like token expiration or configuration changes that might affect access control.