Skip to content

Simplify JWT_ISSUER validation #327

@robrap

Description

@robrap

Ideally we would set `verify_iss' to True on this line:

'verify_iss': False, # TODO (ARCH-204): manually verify until issuer is configured correctly.

This would be in place of the manual verification done across all the JWT_ISSUERS, using this code (which could be removed):

# TODO (ARCH-204): verify issuer manually until it is properly configured.
token_issuer = decoded_token.get('iss')
# .. custom_attribute_name: jwt_auth_issuer
# .. custom_attribute_description: Value set to the JWT auth issuer.
set_custom_attribute('jwt_auth_issuer', token_issuer)
issuer_matched = any(issuer['ISSUER'] == token_issuer for issuer in get_jwt_issuers())
if token_issuer == jwt_issuer['ISSUER']:
# .. custom_attribute_name: jwt_auth_issuer_verification
# .. custom_attribute_description: Depending on issuer verification, the value will
# be one of: matches-first-issuer, matches-later-issuer, or no-match.
set_custom_attribute('jwt_auth_issuer_verification', 'matches-first-issuer')
elif issuer_matched:
set_custom_attribute('jwt_auth_issuer_verification', 'matches-later-issuer')
else:
set_custom_attribute('jwt_auth_issuer_verification', 'no-match')
logger.info('Token decode failed due to mismatched issuer [%s]', token_issuer)
raise jwt.InvalidTokenError('%s is not a valid issuer.' % token_issuer)

Note: this code could be removed once monitoring proves out that jwt_auth_issuer_verification always has a value of matches-first-issuer across services, especially including ecommerce and discovery, which still have add settings.

Note: Last discussed, it seemed to make sense the JWT_ISSUERS would remain a list, just in case we want to expand again in the future for rotating or moving.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions