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

[Bug]: OIDC does not work with sovereign clouds. Client/azure.go is missing environment variable in func oidcAuth #743

Open
1 task done
DE-Wizard opened this issue May 16, 2024 · 5 comments · May be fixed by #766
Open
1 task done
Labels
bug Something isn't working needs:triage stale

Comments

@DE-Wizard
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Affected Resource(s)

internal/clients/azure.go ProviderConfig

Resource MRs required to reproduce the bug

--- apiVersion: azure.upbound.io/v1beta1 kind: ProviderConfig metadata: name: default spec: credentials: source: OIDCTokenFile msiEndpoint: https://login.microsoftonline.us/<mytenant>/v2.0/.well-known/openid-configuration oidcTokenFilePath: /var/run/secrets/azure/tokens/azure-identity-token environment: usgovernment subscriptionID: <mysubscription> tenantID: <mytenant> clientID: <myclient>

Steps to Reproduce

I have tried using the OIDC token provided by Azure Workload Identity.

What happened?

My resource-group import failed and the provider-family-azure put out a log saying AADSTS900382: Confidential Client is not supported in Cross Cloud request. I looked at the code and I noticed that in the func oidcAuth section that it was missing the if statement to check the environment to use the right endpoint as you are already doing in func spAuth and func msiAuth.

Relevant Error Output Snippet

2024-05-16T00:06:56Z	DEBUG	provider-azure	Connecting to the service provider	{"uid": "0bbb7209-6f70-426a-a874-887e24cf4f45", "name": "rg-mgmt-cluster", "gvk": "azure.upbound.io/v1beta1, Kind=ResourceGroup"}
2024-05-16T00:06:57Z	DEBUG	provider-azure	Cannot connect to provider	{"controller": "managed/azure.upbound.io/v1beta1, kind=resourcegroup", "request": {"name":"rg-mgmt-cluster"}, "uid": "0bbb7209-6f70-426a-a874-887e24cf4f45", "version": "4061648", "external-name": "rg-mgmt-cluster", "error": "cannot initialize the Terraform plugin SDK async external client: cannot get terraform setup: failed to configure the no-fork Azure client: failed to configure the provider: [{0 building account: could not acquire access token to parse claims: clientCredentialsToken: received HTTP status 400 with response: {\"error\":\"invalid_request\",\"error_description\":\"AADSTS900382: Confidential Client is not supported in Cross Cloud request. Trace ID: a183dc20-c730-41db-87dd-39f532600e00 Correlation ID: 1653a396-4a20-4790-8558-26bf6be7b9bd Timestamp: 2024-05-16 00:06:56Z\",\"error_codes\":[900382],\"timestamp\":\"2024-05-16 00:06:56Z\",\"trace_id\":\"a183dc20-c730-41db-87dd-39f532600e00\",\"correlation_id\":\"1653a396-4a20-4790-8558-26bf6be7b9bd\"}  []}]", "errorVerbose": "failed to configure the provider: [{0 building account: could not acquire access token to parse claims: clientCredentialsToken: received HTTP status 400 with response: {\"error\":\"invalid_request\",\"error_description\":\"AADSTS900382: Confidential Client is not supported in Cross Cloud request. Trace ID: a183dc20-c730-41db-87dd-39f532600e00 Correlation ID: 1653a396-4a20-4790-8558-26bf6be7b9bd Timestamp: 2024-05-16 00:06:56Z\",\"error_codes\":[900382],\"timestamp\":\"2024-05-16 00:06:56Z\",\"trace_id\":\"a183dc20-c730-41db-87dd-39f532600e00\",\"correlation_id\":\"1653a396-4a20-4790-8558-26bf6be7b9bd\"}  []}]\ngit.luolix.top/upbound/provider-azure/internal/clients.configureNoForkAzureClient\n\tgit.luolix.top/upbound/provider-azure/internal/clients/azure.go:125\nmain.main.TerraformSetupBuilder.func11\n\tgit.luolix.top/upbound/provider-azure/internal/clients/azure.go:116\ngit.luolix.top/crossplane/upjet/pkg/controller.(*TerraformPluginSDKConnector).Connect\n\tgit.luolix.top/crossplane/upjet@v1.3.0/pkg/controller/external_tfpluginsdk.go:231\ngit.luolix.top/crossplane/upjet/pkg/controller.(*TerraformPluginSDKAsyncConnector).Connect\n\tgit.luolix.top/crossplane/upjet@v1.3.0/pkg/controller/external_async_tfpluginsdk.go:55\ngit.luolix.top/crossplane/crossplane-runtime/pkg/reconciler/managed.(*NopDisconnecter).Connect\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/reconciler/managed/reconciler.go:246\ngit.luolix.top/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/reconciler/managed/reconciler.go:892\ngit.luolix.top/crossplane/crossplane-runtime/pkg/ratelimiter.(*Reconciler).Reconcile\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/ratelimiter/reconciler.go:54\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:119\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:316\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:227\nruntime.goexit\n\truntime/asm_amd64.s:1650\nfailed to configure the no-fork Azure client\nmain.main.TerraformSetupBuilder.func11\n\tgit.luolix.top/upbound/provider-azure/internal/clients/azure.go:116\ngit.luolix.top/crossplane/upjet/pkg/controller.(*TerraformPluginSDKConnector).Connect\n\tgit.luolix.top/crossplane/upjet@v1.3.0/pkg/controller/external_tfpluginsdk.go:231\ngit.luolix.top/crossplane/upjet/pkg/controller.(*TerraformPluginSDKAsyncConnector).Connect\n\tgit.luolix.top/crossplane/upjet@v1.3.0/pkg/controller/external_async_tfpluginsdk.go:55\ngit.luolix.top/crossplane/crossplane-runtime/pkg/reconciler/managed.(*NopDisconnecter).Connect\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/reconciler/managed/reconciler.go:246\ngit.luolix.top/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/reconciler/managed/reconciler.go:892\ngit.luolix.top/crossplane/crossplane-runtime/pkg/ratelimiter.(*Reconciler).Reconcile\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/ratelimiter/reconciler.go:54\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:119\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:316\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:227\nruntime.goexit\n\truntime/asm_amd64.s:1650\ncannot get terraform setup\ngit.luolix.top/crossplane/upjet/pkg/controller.(*TerraformPluginSDKConnector).Connect\n\tgit.luolix.top/crossplane/upjet@v1.3.0/pkg/controller/external_tfpluginsdk.go:234\ngit.luolix.top/crossplane/upjet/pkg/controller.(*TerraformPluginSDKAsyncConnector).Connect\n\tgit.luolix.top/crossplane/upjet@v1.3.0/pkg/controller/external_async_tfpluginsdk.go:55\ngit.luolix.top/crossplane/crossplane-runtime/pkg/reconciler/managed.(*NopDisconnecter).Connect\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/reconciler/managed/reconciler.go:246\ngit.luolix.top/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/reconciler/managed/reconciler.go:892\ngit.luolix.top/crossplane/crossplane-runtime/pkg/ratelimiter.(*Reconciler).Reconcile\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/ratelimiter/reconciler.go:54\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:119\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:316\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:227\nruntime.goexit\n\truntime/asm_amd64.s:1650\ncannot initialize the Terraform plugin SDK async external client\ngit.luolix.top/crossplane/upjet/pkg/controller.(*TerraformPluginSDKAsyncConnector).Connect\n\tgit.luolix.top/crossplane/upjet@v1.3.0/pkg/controller/external_async_tfpluginsdk.go:57\ngit.luolix.top/crossplane/crossplane-runtime/pkg/reconciler/managed.(*NopDisconnecter).Connect\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/reconciler/managed/reconciler.go:246\ngit.luolix.top/crossplane/crossplane-runtime/pkg/reconciler/managed.(*Reconciler).Reconcile\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/reconciler/managed/reconciler.go:892\ngit.luolix.top/crossplane/crossplane-runtime/pkg/ratelimiter.(*Reconciler).Reconcile\n\tgit.luolix.top/crossplane/crossplane-runtime@v1.16.0-rc.1.0.20240424114634-8641eb2ba384/pkg/ratelimiter/reconciler.go:54\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:119\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:316\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\tsigs.k8s.io/controller-runtime@v0.17.3/pkg/internal/controller/controller.go:227\nruntime.goexit\n\truntime/asm_amd64.s:1650"}

Crossplane Version

1.15.2

Provider Version

1.1.0

Kubernetes Version

1.28.9

Kubernetes Distribution

AKS US Gov GCC-High

Additional Info

func oidcAuth should look like this: (see added if statement just before return nil)
`func oidcAuth(pc *v1beta1.ProviderConfig, ps *terraform.Setup) error {
if pc.Spec.SubscriptionID == nil || len(*pc.Spec.SubscriptionID) == 0 {
return errors.New(errSubscriptionIDNotSet)
}
if pc.Spec.TenantID == nil || len(*pc.Spec.TenantID) == 0 {
return errors.New(errTenantIDNotSet)
}
if pc.Spec.ClientID == nil || len(*pc.Spec.ClientID) == 0 {
return errors.New(errClientIDNotSet)
}
// OIDC Token File Path defaults to a projected-volume path mounted in the pod running in the AKS cluster, when workload identity is enabled on the pod.
ps.Configuration[keyOidcTokenFilePath] = defaultOidcTokenFilePath
if pc.Spec.OidcTokenFilePath != nil {
ps.Configuration[keyOidcTokenFilePath] = *pc.Spec.OidcTokenFilePath
}
ps.Configuration[keySubscriptionID] = *pc.Spec.SubscriptionID
ps.Configuration[keyTenantID] = *pc.Spec.TenantID
ps.Configuration[keyClientID] = *pc.Spec.ClientID
ps.Configuration[keyUseOIDC] = "true"
if pc.Spec.Environment != nil {
ps.Configuration[keyEnvironment] = *pc.Spec.Environment
}
return nil

}`

Because of environment restrictions I have an issue trying to test this minor change and I also cannot GPG sign my commits from my work system. Even if I make the change and sign it from my personal computer I don't have a good way to test. This should be a non-breaking change as the constructs are already there.

@DE-Wizard DE-Wizard added bug Something isn't working needs:triage labels May 16, 2024
@waterfoul
Copy link

Did that fix work for you? I tried it and it didn't fix the issue

@waterfoul
Copy link

Hmmm, looking at the provider that should work....

@DE-Wizard
Copy link
Author

DE-Wizard commented Jun 12, 2024 via email

@waterfoul
Copy link

Looks like my first attempt didn't apply correctly. The fix works

@waterfoul waterfoul linked a pull request Jun 13, 2024 that will close this issue
3 tasks
Copy link

This provider repo does not have enough maintainers to address every issue. Since there has been no activity in the last 90 days it is now marked as stale. It will be closed in 14 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

@github-actions github-actions bot added the stale label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants