Skip to content
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

Use client id from trusted issuer in oidc token verifier. #12530

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dekiel
Copy link
Contributor

@dekiel dekiel commented Jan 9, 2025

Description

Changed OIDC token verifier behaviour to read a client id from trusted issuer map. At present the tools reads a client id from command line flag. This approach will not work with more than one client applications. Each client application should provide it's own client id in a oidc token audience claim. This is to prevent hijacking a token from other application in the same oidc token provider and leveraging a hijacked permissions. With client id provided as flag we would have to know the valid expected client id before running the tool.

The PR propose to define valid client id in Issuer. After reading an issuer from token and matching it with trusted issuers, we can set correct expected client id and run oidc token verification against uniq client id/audience value.

Changes proposed in this pull request:

  • Added ClientID field to the Issuer struct and defined current default value for github.com an github.tools.sap oidc providers.
  • Refactored NewVerifierConfig function.
    It's a TokenProcessor method now and does not expect a clientID string as argument. Moved function implementation closer to the TokenProcessor implementation to maintain consistency.
    The clientID value is read from trusted issuer in TokenProcessor instance.
    Moved a test for empty client id scenario to the unit tests file because to client id provided by TokenProcessor can't be modified outside a package.
    Added more expectations in test for providing a valid default verifier config scenario.
  • Refactored NewTokenProcessor function.
    It does not expect a VerifierConfig as argument anymore. The config is expected to be created after creating a TokenProcessor instance, because a TokenProcessor provides an expected client id value.
    The function verifies if matched trusted issuer has non empty ClientID value.
  • Removed verifierConfig field from TokenProcessor. The value is used only to create a token verifier instance which happens outside a TokenProcessor scope.
  • Refactored main function.
    Swapped order of creating a VerifierConfig and TokenProcessor instances. A TokenProcessor must be created first in order to provide a trusted issuer with expected client id value.
    Removed unused client-id command line flag and options field.
  • Housekeeping changes.
    Added more debug logs.
    Removed trusted workflows command line flag and options field.
    Aligned tests to the changes.
    Regenerated mocks to align with changes.

dekiel added 3 commits January 9, 2025 14:19
…his allow creating a config with different expected client id values, based on detected issuer in provided oidc token. Each client specific for oidc provider and application must use uniq audience value.
@dekiel dekiel requested review from neighbors-dev-bot and a team as code owners January 9, 2025 14:11
@kyma-bot kyma-bot added cla: yes Indicates the PR's author has signed the CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 9, 2025
@Sawthis Sawthis requested review from akiioto and szumejker January 10, 2025 07:18
pkg/oidc/oidc.go Show resolved Hide resolved
… validating and setting trusted issuer.

The issuer validation code is now a method on issuer type.
@kyma-bot kyma-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 10, 2025
@dekiel dekiel requested a review from akiioto January 10, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indicates the PR's author has signed the CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants