-
Notifications
You must be signed in to change notification settings - Fork 52
Description
Hi, as the title says, I'm currently trying to setup Workload Identity Federation (WIF) in my Azure DevOps Pipeline in order to move away from long lived service account keys that I currently supply with the STACKIT_SERVICE_ACCOUNT_KEY environment variable.
I followed the guide here and opted for the method with the STACKIT_SERVICE_ACCOUNT_EMAIL and STACKIT_USE_OIDC environment variables but after the setup, I'm getting this error:
╷
│ Error: Error configuring provider
│
│ with provider["registry.opentofu.org/stackitcloud/stackit"],
│ on providers.tf line 1, in provider "stackit":
│ 1: provider "stackit" {
│
│ Setting up authentication: configuring no auth client: error initializing
│ client: error reading federated token file - open
│ /var/run/secrets/stackit.cloud/serviceaccount/token: no such file or
│ directory
╵
Side note: The error messages are kind of cryptic. For example, in my first pipeline run, I forgot to set the mail properly and got this error.
╷
│ Error: Error configuring provider
│
│ with provider["registry.opentofu.org/stackitcloud/stackit"],
│ on providers.tf line 1, in provider "stackit":
│ 1: provider "stackit" {
│
│ Setting up authentication: configuring no auth client: error initializing
│ client: client ID cannot be empty
╵
Side note no.2: Something I noticed is that the provider has no authentication fall-through mechanic when supplying STACKIT_USE_OIDC. If this fails, there is no attempt to check the service account key methods.
Back to the first error. I'm not sure if I correctly set up Federated Identity Providers in the stackit portal. When adding a new provider, the form has one entry by default:
aud → equals → sts.accounts.stackit.cloud
It was not clear to me whether I should keep it or not and just added the other entry:
aud->equals->api://AzureADTokenExchange
Resulting in having both entries. For testing, I removed the stackit one but that resulted in the same error.
The second part that I might have misconfigured is the sub entry. In the docs it says:
Using a hypothetical pipeline named terraform-ado-oidc inside the project '[https://myorg.azure.com/project-abc`](https://myorg.azure.com/project-abc%60) as example ....
....
sub->equals->p://myorg/project-abc/terraform-ado-oidc # This is the pipeline where the process is running
I assume, myorg is the part after https://dev.azure.com/ and before the next '/' from $(System.CollectionUri) or $(System.TeamFoundationCollectionUri).
I assume, project-abc is $(System.TeamProject). In practice, when using a normal git repo url as example https://dev.azure.com/<myorg>/<project-abc>/_git/<repo-name>
In theory, there is also $(System.TeamProjectId).
But for the pipeline name, terraform-ado-oidc in the example, this is not obvious. I can have two pipelines with the same name under different folders in Azure DevOps. They are under different paths but have the same name.
Both of the return cluster, when printing $(Build.DefinitionName) in them.
That's why I think it is imprecise to tell the users to use the pipeline name. I can differentiate them via their ID $(System.DefinitionId) when printing it in the pipeline or in the url (definitionId=012345), when on the pipeline runs page. Further details can be queried under https://dev.azure.com/<orgname>/<projectname>/_apis/pipelines/<DefinitionId>?api-version=7.1. In that response, there is also the folder attribute. In my case above, \\k8s and for the other one \\test.
I tried changing the pipeline name in the sub assertion to the $(System.DefinitionId) value but I still get the same error.
I also tried:
sub->equals->p://<myorg>/<myproject>/\\test\cluster
but that also didn't work.
Can you help me?