-
Notifications
You must be signed in to change notification settings - Fork 52
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
auth: Support AzureDevOps Pipeline OIDC auth (similar to Github OIDC auth) #1139
base: main
Are you sure you want to change the base?
Conversation
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 looking really good. I appreciate the environment variable names will be defined in the provider, but thinking ahead, I suggest they match what has been implemented for azapi
, so that from a usability perspective customers only need to set one env var.
This is what the azapi
env vars look like:
- task: AzureCLI@2
displayName: Acc Tests with OIDC Azure Pipeline
inputs:
azureSubscription: 'azapi-oidc-test' // Azure Service Connection ID
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$env:ARM_TENANT_ID = $env:tenantId
$env:ARM_CLIENT_ID = $env:servicePrincipalId
$env:ARM_OIDC_REQUEST_TOKEN = "$(System.AccessToken)"
$env:ARM_OIDC_AZURE_SERVICE_CONNECTION_ID = "azapi-oidc-test"
$env:ARM_USE_OIDC = 'true'
terraform plan
addSpnToEnvironment: true
You'll also notice that the TOKEN REQUEST URI is not specified here. That is because the azure go sdk handles finding that. I think we could do the same here?
@jaredfholgate Good spots! The namings of the env vars will be defined in the provider, instead of the go-azure-sdk, which is slightly different than how Azure track2 SDK does. Since you can already see that the github oidc implementation in this SDK didn't auto-discover those env vars, but prefer an explicit definition by the users: // IdTokenRequestUrl is the URL for the OIDC provider from which to request an ID token.
// Usually exposed via the ACTIONS_ID_TOKEN_REQUEST_URL environment variable when running in GitHub Actions
IdTokenRequestUrl string Followings are only defined in the test files: GitHubToken = os.Getenv("ACTIONS_ID_TOKEN_REQUEST_TOKEN")
GitHubTokenURL = os.Getenv("ACTIONS_ID_TOKEN_REQUEST_URL")
ADOPipelineToken = os.Getenv("SYSTEM_ACCESSTOKEN")
ADOPipelineTokenURL = os.Getenv("SYSTEM_OIDCREQUESTURI")
ADOServiceConnectionId = os.Getenv("ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID") When this PR get merged and we integrate this feature into the |
Just to be clear, will the provider look up the Or are you expecting the user to explicitly pass that url? It seems unnecessary to add that requirement given it is not required for Apologies if I am missing something. |
@jaredfholgate The library won't auto-detect those environment variables by naming convention, as it has been like this for the github case, so I won't break this convention by recognizing ADO env vars. On the other hand, the provider will detect those env vars, including |
This enables users who intend to use ADO OIDC while enbaled both won't end up using Github OIDC auth and fail. This can work since ADO OIDC has one more condition (i.e. the service connection ID) than Github OIDC.
Got it, thanks. Just wanted to ensure the experience for each provider is the same. I'm really pleased this is getting implemented it will make a huge difference for our customers. |
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.
Thanks @magodo - This looks good to me. Just one comment to be mindful of as we carry this forward into the provider(s).
As mentioned offline, due to the nature of this change and some logistical factors the team has, I'm going to have to hold off merging this for the time being, but we'll get it in so we can progress it and make it available asap.
Thanks again.
OIDCRequestToken = anyOfEnvVar("ACTIONS_ID_TOKEN_REQUEST_TOKEN", "SYSTEM_ACCESSTOKEN") | ||
OIDCRequestURL = anyOfEnvVar("ACTIONS_ID_TOKEN_REQUEST_URL", "SYSTEM_OIDCREQUESTURI") |
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.
Assuming we take a similar approach when plugging this into the provider, we're going to need to be careful not to make assumptions about which value the user intends to be consumed of these two if both exist on the host.
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.
In case either of these have both env vars available,do you think it makes sense to just error out?
Cc @ms-henglu for azapi.
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 suspect that we should document the priority of selection in the provider configuration documentation and leave it to the user? There may be cases where users need/want to have both in their environment?
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.
Sure, we'll need to document the environment variable selection order for the users and let them make the call. Whilst, I don't know if there is a case that both environment variables will be available.
This PR adds support for Azure DevOps Pipeline OIDC authentication, similar to the existing Github OIDC authentication.
Currently users are able to use OIDC token under ADO pipeline to exchange for an ARM access token, assuming the OIDC token is from the
AzureCLI
task or other tasks that support OIDC. The problem of this auth way is when the arm access token expires, there is no way to refresh and get a new one OIDC token.This PR makes the provider get a OIDC token by itself, via the OIDC request token + request URL + ADO service connection (properly configured).
With this, the users will be able to use 3 flavors of OIDC auths:
Test
I used the following pipeline definition to run the acctest:
Following is the screenshot of the result:
References
Update [Jan.10]
I've added more tests at the
client
(ACC) andauth
(UT) packages. Meanwhile, I've updated theauth/README.md
file. Besides, I've adjusted the order of ADO and Github OIDC in theNewAuthorizerFromCredentials
function, which enables users who intend to use ADO OIDC while enbaled both won't end up using Github OIDC auth and fail. This can work since ADO OIDC has one more condition (i.e. the service connection ID) than Github OIDC.Tests
Github Action
ADO