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

Add a credentials provider for Github Azure OIDC #950

Closed
wants to merge 15 commits into from

Conversation

renaudhartert-db
Copy link
Contributor

@renaudhartert-db renaudhartert-db commented Jun 19, 2024

Note: this PR could not be merged because of its first unverified commit, please see PR #965.

Changes

This PR adds a CredentialsProvider to authenticate with Azure from Github workflows.

The code is inspired by a similar feature already implemented in the Python SDK. It works as follows:

  1. Obtain an ID token from Azure leveraging the env variables ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN as explained here.
  2. Exchange that ID token for an auth token.

Tests

Added a test suite which covers all the added code paths. I've also confirmed in my own Github Action that the code is properly able to authenticate.

Note: I'm not super happy with how errors are compared (i.e. using a prefix) which is a little brittle. A better approach would be to leverage errors.As or errors.Is. However, it is difficult to do that at the moment without adding ad hoc new error types. A longer term solution would probably involve standardizing the package around a set of clearly defined error types shared by all implementations of CredentialsProvider in config. That is out of the scope of this PR though.

  • make test passing
  • make fmt applied
  • relevant integration tests applied

@renaudhartert-db renaudhartert-db changed the title Add a credentials provider for Github Azure OIDC. Add a credentials provider for Github Azure OIDC Jun 19, 2024
@renaudhartert-db renaudhartert-db marked this pull request as ready for review June 28, 2024 20:56
Copy link
Contributor

@mgyucht mgyucht left a comment

Choose a reason for hiding this comment

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

Overall this seems good to me, great test cases as well! One small suggestion for logging when we can't successfully fetch the credential.

I think this is great for now. I'm picturing something in the future that there is a more generalized workflow of:

  1. Discover the current environment the SDK is in (github actions, azure devops, etc).
  2. Fetch the ID token according to the local environment (query the Github endpoint, somehow gather the ID token from Azure DevOps, etc.)
  3. Exchange the ID token for an OAuth token (using Azure EntraID endpoint, using Databricks OAuth API, etc.)

Essentially, we can probably generalize this to support OIDC strategies in the future by decoupling the ID token fetching from the token exchange endpoint. That said, let's not let perfect be the enemy of good, and we can make that change when we do work to support Azure DevOps, for example.

config/auth_azure_github_oidc.go Show resolved Hide resolved
config/auth_azure_github_oidc_test.go Show resolved Hide resolved
config/auth_azure_github_oidc_test.go Outdated Show resolved Hide resolved
@renaudhartert-db
Copy link
Contributor Author

renaudhartert-db commented Jul 5, 2024

Thanks for the review @mgyucht! Please have a look at my answers and feel free to re-open the discussions.

I'm picturing something in the future that there is a more generalized workflow of:

  1. Discover the current environment the SDK is in (github actions, azure devops, etc).
  2. Fetch the ID token according to the local environment (query the Github endpoint, somehow gather the ID token from Azure DevOps, etc.)
  3. Exchange the ID token for an OAuth token (using Azure EntraID endpoint, using Databricks OAuth API, etc.)

Agreed, this is also how I picture the evolution of this package. How to effectively generalize the flow will become clearer as we add OIDC use cases.

@renaudhartert-db renaudhartert-db deleted the rh/azure-github-oidc branch July 5, 2024 12:08
github-merge-queue bot pushed a commit that referenced this pull request Jul 5, 2024
_Note: this PR is a copy of PR #950 which could not be merged because of
some unverified commits. Please check PR #950 for the original review
and comments._

## Changes

This PR adds a `CredentialsProvider` to authenticate with Azure from
Github workflows.

The code is inspired by a similar feature already implemented in the
Python SDK. It works as follows:

1. Obtain an ID token from Azure leveraging the env variables
`ACTIONS_ID_TOKEN_REQUEST_URL` and `ACTIONS_ID_TOKEN_REQUEST_TOKEN` as
[explained
here](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-cloud-providers).
2. Exchange that ID token for an auth token.

## Tests

Added a test suite which covers all the added code paths. I've also
confirmed in my own Github Action that the code is properly able to
authenticate.

Note: I'm not super happy with how errors are compared (i.e. using a
prefix) which is a little brittle. A better approach would be to
leverage `errors.As` or `errors.Is`. However, it is difficult to do that
at the moment without adding ad hoc new error types. A longer term
solution would probably involve standardizing the package around a set
of clearly defined error types shared by all implementations of
`CredentialsProvider` in `config`. That is out of the scope of this PR
though.

- [x] `make test` passing
- [x] `make fmt` applied
- [x] relevant integration tests applied
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.

None yet

2 participants