-
Notifications
You must be signed in to change notification settings - Fork 263
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
Unable to authenticate to Azure ACR using repository tokens #473
Comments
Hello :) Have you been able to authenticate the o ACR using the AAD Service principal from Kubernetes secret? It works when running inside the container with the |
As explained above, authenticating with service principals works correctly. The topic of this issue is related to ACR repository tokens. |
You're using access keys, not scopes and tokens; can you please remove your comment and create a different issue instead, as it will only bring confusion. |
Agree was thinking of doing that... let me do that in new issue. |
I was able to make #!/bin/sh
# 1. Get AAD Access token
AAD_ACCESS_TOKEN=$(wget --quiet --header="Metadata: true" \
--output-document - \
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/&client_id="$AZURE_CLIENT_ID |
python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])")
# 2. Get refresh token
ACR_REFRESH_TOKEN=$(wget --quiet --header="Content-Type: application/x-www-form-urlencoded" \
--post-data="grant_type=access_token&service=$AZURE_CONTAINER_REGISTRY&tenant=$AZURE_TENANT_ID&access_token=$AAD_ACCESS_TOKEN" \
--output-document - \
https://$AZURE_CONTAINER_REGISTRY/oauth2/exchange |
python3 -c "import sys, json; print(json.load(sys.stdin)['refresh_token'])")
# Script output
echo "00000000-0000-0000-0000-000000000000:$ACR_REFRESH_TOKEN" |
Install azure-cli in Docker image in order to use the `az acr login` command. Can be used with Azure Managed Identities with the following script: ```yaml --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config namespace: argocd data: log.level: debug registries.conf: | registries: - name: acrexample api_url: https://acrexample.azurecr.io/ prefix: acrexample.azurecr.io ping: yes insecure: no credentials: ext:/app/scripts/acr-login.sh credsexpire: 10h --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config-acr namespace: argocd data: acr-login.sh: | #!/bin/sh LOGIN=$(az login --identity) REGISTRY="acrexample" TOKEN=$(az acr login --name $REGISTRY --expose-token --output tsv --query accessToken) echo "00000000-0000-0000-0000-000000000000:$TOKEN" ``` Closes argoproj-labs#550 and argoproj-labs#473
Install azure-cli in Docker image in order to use the `az acr login` command. Can be used with Azure Managed Identities with the following script: ```yaml --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config namespace: argocd data: log.level: debug registries.conf: | registries: - name: acrexample api_url: https://acrexample.azurecr.io/ prefix: acrexample.azurecr.io ping: yes insecure: no credentials: ext:/app/scripts/acr-login.sh credsexpire: 10h --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config-acr namespace: argocd data: acr-login.sh: | #!/bin/sh LOGIN=$(az login --identity) REGISTRY="acrexample" TOKEN=$(az acr login --name $REGISTRY --expose-token --output tsv --query accessToken) echo "00000000-0000-0000-0000-000000000000:$TOKEN" ``` Closes argoproj-labs#550 and argoproj-labs#473 Signed-off-by: Jarvis Yang <[email protected]>
Install azure-cli in Docker image in order to use the `az acr login` command. Can be used with Azure Managed Identities with the following script: ```yaml --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config namespace: argocd data: log.level: debug registries.conf: | registries: - name: acrexample api_url: https://acrexample.azurecr.io/ prefix: acrexample.azurecr.io ping: yes insecure: no credentials: ext:/app/scripts/acr-login.sh credsexpire: 10h --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config-acr namespace: argocd data: acr-login.sh: | #!/bin/sh LOGIN=$(az login --identity) REGISTRY="acrexample" TOKEN=$(az acr login --name $REGISTRY --expose-token --output tsv --query accessToken) echo "00000000-0000-0000-0000-000000000000:$TOKEN" ``` Closes argoproj-labs#550 and argoproj-labs#473 Signed-off-by: Jarvis Yang <[email protected]>
Install azure-cli in Docker image in order to use the `az acr login` command. Can be used with Azure Managed Identities with the following script: ```yaml --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config namespace: argocd data: log.level: debug registries.conf: | registries: - name: acrexample api_url: https://acrexample.azurecr.io/ prefix: acrexample.azurecr.io ping: yes insecure: no credentials: ext:/app/scripts/acr-login.sh credsexpire: 10h --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config-acr namespace: argocd data: acr-login.sh: | #!/bin/sh LOGIN=$(az login --identity) REGISTRY="acrexample" TOKEN=$(az acr login --name $REGISTRY --expose-token --output tsv --query accessToken) echo "00000000-0000-0000-0000-000000000000:$TOKEN" ``` Closes argoproj-labs#550 and argoproj-labs#473
Install azure-cli in Docker image in order to use the `az acr login` command. Can be used with Azure Managed Identities with the following script: ```yaml --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config namespace: argocd data: log.level: debug registries.conf: | registries: - name: acrexample api_url: https://acrexample.azurecr.io/ prefix: acrexample.azurecr.io ping: yes insecure: no credentials: ext:/app/scripts/acr-login.sh credsexpire: 10h --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config-acr namespace: argocd data: acr-login.sh: | #!/bin/sh LOGIN=$(az login --identity) REGISTRY="acrexample" TOKEN=$(az acr login --name $REGISTRY --expose-token --output tsv --query accessToken) echo "00000000-0000-0000-0000-000000000000:$TOKEN" ``` Closes argoproj-labs#550 and argoproj-labs#473 Signed-off-by: Francesc Arbona <[email protected]>
Install azure-cli in Docker image in order to use the `az acr login` command. Can be used with Azure Managed Identities with the following script: ```yaml --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config namespace: argocd data: log.level: debug registries.conf: | registries: - name: acrexample api_url: https://acrexample.azurecr.io/ prefix: acrexample.azurecr.io ping: yes insecure: no credentials: ext:/app/scripts/acr-login.sh credsexpire: 10h --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config-acr namespace: argocd data: acr-login.sh: | #!/bin/sh LOGIN=$(az login --identity) REGISTRY="acrexample" TOKEN=$(az acr login --name $REGISTRY --expose-token --output tsv --query accessToken) echo "00000000-0000-0000-0000-000000000000:$TOKEN" ``` Closes argoproj-labs#550 and argoproj-labs#473 Signed-off-by: Francesc Arbona <[email protected]>
Install azure-cli in Docker image in order to use the `az acr login` command. Can be used with Azure Managed Identities with the following script: ```yaml --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config namespace: argocd data: log.level: debug registries.conf: | registries: - name: acrexample api_url: https://acrexample.azurecr.io/ prefix: acrexample.azurecr.io ping: yes insecure: no credentials: ext:/app/scripts/acr-login.sh credsexpire: 10h --- apiVersion: v1 kind: ConfigMap metadata: name: argocd-image-updater-config-acr namespace: argocd data: acr-login.sh: | #!/bin/sh LOGIN=$(az login --identity) REGISTRY="acrexample" TOKEN=$(az acr login --name $REGISTRY --expose-token --output tsv --query accessToken) echo "00000000-0000-0000-0000-000000000000:$TOKEN" ``` Closes argoproj-labs#550 and argoproj-labs#473 Signed-off-by: Francesc Arbona <[email protected]>
You are probably right. I have modified the script to use workload identities since posting that comment. See below for a script using workload identities. #!/bin/sh
# 1. Get AAD Access token
AAD_ACCESS_TOKEN=$(wget --quiet --header="Content-Type: application/x-www-form-urlencoded" \
--post-data="scope=https%3A%2F%2Fmanagement.azure.com%2F.default&client_id=${AZURE_CLIENT_ID}&client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer&client_assertion=$(cat "${AZURE_FEDERATED_TOKEN_FILE}")&grant_type=client_credentials" \
--output-document - \
"https://login.microsoftonline.com/${AZURE_TENANT_ID}/oauth2/v2.0/token" | python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])")
# 2. Get refresh token
ACR_REFRESH_TOKEN=$(wget --quiet --header="Content-Type: application/x-www-form-urlencoded" \
--post-data="grant_type=access_token&service=$AZURE_CONTAINER_REGISTRY&tenant=$AZURE_TENANT_ID&access_token=$AAD_ACCESS_TOKEN" \
--output-document - \
https://$AZURE_CONTAINER_REGISTRY/oauth2/exchange | python3 -c "import sys, json; print(json.load(sys.stdin)['refresh_token'])")
# Script output
echo "00000000-0000-0000-0000-000000000000:$ACR_REFRESH_TOKEN"
|
Describe the bug
argocd-image-updater fails to retrieve tags when registry authentication is configured to use Azure ACR tokens.
To Reproduce
Version 1: Using the token name and password as credentials
That was my initial attempt:
When I realized it wouldn't work, I attempted it with Service Principal credentials (client id / secret) and it worked fine.
Version 2: Using a credential script to generate an OAuth token using the Docker registry API
Since I could successfully do a simple
docker login
with the token credentials, I assumed that argocd-image-updater did not implement the OAuth flow correctly, I embarked on trying to understand how the Docker Registry API works and I ended up creating the following credentials script (redacted elements have been replaced by meaningful variable names):Expected behavior
Both versions presented above should work fine, as they follow the Docker Registry API and reproducing them manually works fine as well.
Additional context
Logging in to docker using the token credentials directly works fine:
So does listing the tags using a token generated by the registry's token endpoint (using enssentially the same script as the one shown above):
This successful attempt led me to try the credentials script solution... which failed as well. At this point, I'm out of options, which is why I'm creating this issue.
Version
v0.12.0+aee153d
Logs
Version 1
Version 2
Credential script is configured with an annotation at the application level (the logs show that the script gets called as expected).
The text was updated successfully, but these errors were encountered: