Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions eng/common/TestResources/deploy-test-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ steps:
- template: /eng/common/TestResources/setup-environments.yml

- ${{ if eq('true', parameters.UseFederatedAuth) }}:
- task: AzureCLI@2
Copy link
Member

Choose a reason for hiding this comment

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

Do you know if there is a way to get similar values in the PS context? Also should we make this an opt-in as I'd hate for everyone to have to spend time logging into Az CLI and Az Powershell and not even end up needing these values.

Copy link
Member Author

@benbp benbp Jun 3, 2024

Choose a reason for hiding this comment

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

From what I could tell there is not. It's really unfortunate. Although maybe it's just the addSpnToEnvironment field that's specific to az cli and it's always there for az powershell? I can test.

I agree re: opt-in. I can add the parameter plumbing.

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we call Get-AzAccessToken to get another token to use with az cli?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't find any of the inner source for that call :(

Copy link
Member

Choose a reason for hiding this comment

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

You can definitely get the client id and tenant from https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzurePowerShellV5/InitializeAz.ps1#L121 the question is how do you get a token. I'm guessing we could call Get-AzAccessToken to get one as needed depending on the resource type.

displayName: Set OIDC variables
inputs:
azureSubscription: ${{ parameters.ServiceConnection }}
scriptType: pscore
scriptLocation: inlineScript
addSpnToEnvironment: true
inlineScript: |
Write-Host "##vso[task.setvariable variable=ARM_CLIENT_ID;issecret=true]$($env:servicePrincipalId)"
Write-Host "##vso[task.setvariable variable=ARM_TENANT_ID;issecret=true]$($env:tenantId)"
Write-Host "##vso[task.setvariable variable=ARM_OIDC_TOKEN;issecret=true]$($env:idToken)"
Copy link
Member

Choose a reason for hiding this comment

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

Should this be called OIDC? In other places we are calling it Federated token for example.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was copying this off the task you added. Want me to edit both and normalize?

Copy link
Member

Choose a reason for hiding this comment

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

Which task are you referring to? I don't remember using OIDC naming anywhere.

Copy link
Member Author

@benbp benbp Jun 3, 2024

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

lol... Ok I don't remember why I called it that. What do you think is a good name for this value?

Copy link
Member

Choose a reason for hiding this comment

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

It wasn't an issue with my manual tests running the identity pipeline, and we have a fairly complex arm deployment.

Copy link
Member

Choose a reason for hiding this comment

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

Also, at least in Identity's case, we only need the token in the -pre script, so that is well before the long part of the arm deployment. So perhaps we should document a best practice for deployments that need this, they should az login in a pre script.

Copy link
Member Author

Choose a reason for hiding this comment

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

Even if they az login, the token used for login will still expire right? But maybe similar to what Wes said in the other comment thread we can possibly renew the access token in the deploy script if it becomes a problem for people.

Copy link
Member

Choose a reason for hiding this comment

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

No, the OIDC token is exchanged for a regular access token, and that token would typically be good for at least an hour.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, great then.


- task: AzurePowerShell@5
displayName: Deploy test resources
env:
Expand Down