I created a test cluster exp-aks-02 with the following configuration:
Kubernetes Version: 1.25.6
Authentication and Authorization: Azure AD authentication with Kubernetes RBAC
Network Plugin: Azure CNI
(The cluster does not use the ACR integration.)
I then went ahead and bootstrapped flux, and assigned ACR Pull and Reader permissions to the User Assigned Managed Identity exp-aks-02-agentpool on a ACR instance.
At this point, I expected it to just work, but flux get sources would show this error:
unknown build error: failed to get credential from azure: DefaultAzureCredential: failed to acquire a token.
Attempted credentials:
EnvironmentCredential: missing environment variable AZURE_TENANT_ID
ManagedIdentityCredential: no default identity is assigned to this resource
AzureCLICredential: Azure CLI not found on path
Ideas?
Other Observations
Fetching token by specifying the UAI to use
I followed the thread at #898 and concluded the reason this happens is because I have two UAIs (User Assigned managed Identities) attached to this cluster (exp-aks-02-agentpool and aciconnectorlinux-exp-aks-02).
So I tried patching the flux-system kustomization to add AZURE_CLIENT_ID:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- gotk-components.yaml
- gotk-sync.yaml
labels:
- pairs:
toolkit.fluxcd.io/tenant: sre-team
patches:
- patch: |
- op: add
path: /spec/template/spec/containers/0/args/-
value: --concurrent=20
- op: add
path: /spec/template/spec/containers/0/args/-
value: --requeue-dependency=5s
target:
kind: Deployment
name: "(kustomize-controller|helm-controller|source-controller)"
- patch: |
- op: add
path: /spec/template/spec/containers/0/env/-
value:
name: AZURE_CLIENT_ID
value: --client-id--
target:
kind: Deployment
name: "(helm-controller|source-controller)"
But I now see this error (which almost feels like a bug):
unknown build error: failed to get credential from azure: error exchanging token: failed to decode the response: invalid character '<' looking for beginning of value
However hitting the token API directly works as long as I include the client_id parameter:
$ kubectl exec -it source-controller-59b5c97495-htrtb -n flux-system -- /bin/sh
$ wget -q -O - "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/&client_id=$AZURE_CLIENT_ID" --header "Metadata: true"
{"access_token":"--redacted--","client_id":"--client-id--","expires_in":"84928","expires_on":"1681412609","ext_expires_in":"86399","not_before":"1681325909","resource":"https://management.azure.com/","token_type":"Bearer"}
akv2k8s works ok
I am able to consume secrets from azure keyvault using the akv2k8s project which appears to use the userAssignedIdentityID value from /etc/kubernetes/azure.json:
apiVersion: v1
kind: Namespace
metadata:
name: akv2k8s
labels:
toolkit.fluxcd.io/tenant: sre-team
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: akv2k8s
namespace: akv2k8s
spec:
interval: 60m0s
url: https://charts.spvapi.no
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: akv2k8s
namespace: akv2k8s
spec:
interval: 60m
chart:
spec:
chart: akv2k8s
version: "2.*"
sourceRef:
kind: HelmRepository
name: akv2k8s
interval: 12h
values:
global:
metrics:
enabled: true
---
apiVersion: spv.no/v1alpha1
kind: AzureKeyVaultSecret
metadata:
name: test-credentials
namespace: monitoring
spec:
vault:
name: vault-name
object:
type: multi-key-value-secret
name: test-credentials
contentType: application/x-json
output:
secret:
name: test-credentials
I created a test cluster
exp-aks-02with the following configuration:(The cluster does not use the ACR integration.)
I then went ahead and bootstrapped flux, and assigned ACR Pull and Reader permissions to the User Assigned Managed Identity
exp-aks-02-agentpoolon a ACR instance.At this point, I expected it to just work, but
flux get sourceswould show this error:Ideas?
Other Observations
Fetching token by specifying the UAI to use
I followed the thread at #898 and concluded the reason this happens is because I have two UAIs (User Assigned managed Identities) attached to this cluster (
exp-aks-02-agentpoolandaciconnectorlinux-exp-aks-02).So I tried patching the flux-system kustomization to add
AZURE_CLIENT_ID:But I now see this error (which almost feels like a bug):
However hitting the token API directly works as long as I include the
client_idparameter:akv2k8s works ok
I am able to consume secrets from azure keyvault using the akv2k8s project which appears to use the
userAssignedIdentityIDvalue from/etc/kubernetes/azure.json: