-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
[Enhancement]: Support identitytoken based authentication (OAuth2) #841
Comments
Created PR #842 as a proposed fix. |
May I ask in which CI environment you are running? |
GitHub. |
Why don't you use the Docker login action? |
AFAIK, when having the Docker Registry in Azure, the way to login is with |
We can try the Docker login action. We are currently doing it like this in the GitHub workflow:
I would guess that the Docker login action simply conflates the two so we would end up with the same |
Yes, you right. Doing like this in a GitHub Workflow will not work - name: 'Azure CLI login'
uses: azure/login@v1
with:
...
- name: 'ACR login'
run: az acr login --name ${{ vars.ACR_NAME }} but this will: - name: Login to ACR
uses: docker/login-action@v2
with:
registry: ${{ vars.ACR_NAME }}
username: ${{ secrets.AZURE_CLIENT_ID }}
password: ${{ secrets.AZURE_CLIENT_SECRET }} So basically, it really needs to be username/password authentication in order for testcontainers-dotnet to understand it. Since the change is so trivial (see the PR) and since I think testcontainers-dotnet should have the goal of supporting the same authentication that Docker CLI does, then I think the PR is still worthwhile. But thanks, @HofmeisterAn , the |
The issue is that I am unsure whether the configuration you provided above is correct or not. It does not seem right to me. In my understanding, |
Well, the config I've provided works with the Docker CLI. From what I can tell from the Docker CLI source code, is that their AuthConfig object will be populated with all fields found in the config file (so including the This is what I believe the Docker CLI sends to the endpoint with my example: {
"username": "00000000-0000-0000-0000-000000000000",
"serveraddress": "...",
"identitytoken": "gwHEWT356ASfg....eUWR"
} (the password - as derived from the So, yes, slightly different than my PR where it would be sending solely this to the endpoint: {
"identitytoken": "gwHEWT356ASfg....eUWR"
} For Azure Container Registry at least, both forms seem to work. But the way the Docker CLI does it should probably be the benchmark. I've looked at testcontainers-java. Crucial points are here and here. My conclusion is that the underlying Docker library, docker-java, is prepared for it, but testcontainers-java never populates the identitytoken field. So similar situation to testcontainers-dotnet. Therefore, @HofmeisterAn, I think you are right when you say that other libraries might also fail on the config I've provided. But the Docker CLI doesn't and that is the important thing. I'll update the PR to mimic more precisely what the Docker CLI does. |
In Testcontainers for Go, when autodiscovering the docker auth configs, we leverage a library to read from the credential helpers, and in there, the identity token takes precedence when present (see https://github.com/cpuguy83/dockercfg/blob/main/auth.go#L66-L68 and https://github.com/testcontainers/testcontainers-go/blob/main/docker_auth.go#L53). |
Considering @mdelapenya's response, I think we can add another provider to testcontainers-dotnet/src/Testcontainers/Builders/DockerRegistryAuthenticationProvider.cs Lines 96 to 99 in 7a5cc2e
Somehow, my assumption was resolving the identity token goes always through the credential helpers and I was wondering e.g. why Java does not handle it (AFAIK). Not a proper solution, but you can mimic the credential helper in the meantime too. Something we do in our tests too. |
I did some tests last week which are related to this. But, azure was not in that test GCP
AWS
and what I can see in both cases by executing |
@eddumelendez you're using a credential helper. This issue is explicit for an environment without credential helper. Which stores the identity token in the Docker config. |
@HofmeisterAn : Regarding creating a new Provider class vs amending the existing provider ( |
We are still experiencing this issue with version 3.5.0 and are transforming the docker auth config via the following script locally as a workaround. It would be nice if the Testcontainers library could support the identitytoken natively. #!/bin/sh -e
test -n "${ACR_NAME}" || ( echo "ACR_NAME is not defined!" && false )
test -n "${ARM_SUBSCRIPTION_ID}" || ( echo "ARM_SUBSCRIPTION_ID is not defined!" && false )
az acr login --name "${ACR_NAME}" --subscription "${ARM_SUBSCRIPTION_ID}"
TOKEN=$(jq -r ".auths[\"${ACR_NAME}.azurecr.io\"].identitytoken" ~/.docker/config.json)
DOCKER_CONFIG=$(cat ~/.docker/config.json | jq "del(.auths[\"${ACR_NAME}.azurecr.io\"].identitytoken)")
AUTH=$(echo -n "00000000-0000-0000-0000-000000000000:${TOKEN}" | base64 --wrap=0 -)
DOCKER_CONFIG=$(echo "${DOCKER_CONFIG}" | jq ".auths[\"${ACR_NAME}.azurecr.io\"].auth = \"${AUTH}\"")
echo "${DOCKER_CONFIG}" > ~/.docker/config.json
jq . ~/.docker/config.json
|
There was a pull request (#842) some time ago. I think we can merge it once we add the missing test. |
Running into the same issue currently and wondering if anyone has a source for this comment from op:
There's a similar thread over on Docker.DotNet about the same issue: |
Problem
Some containers registries use OAuth2 protocol for authentication. For example Azure Container Registry.
After obtaining such credentials, Docker's
config.json
file look something like this:This is a use-case which testcontainers-dotnet cannot handle at the moment.
With the above, testcontainers-dotnet will produce the following exception:
This is because testcontainers-dotnet completely ignores the
identitytoken
. It solely looks at theauth
value and attempts to extract username/password from that. In the above case the username is00000000-0000-0000-0000-000000000000
and the password is empty string. It will use those values for authentication which will of course fail.Note: The above config file works with the Docker CLI, but doesn't work with testcontainers-dotnet.
Solution
Use the
identitytoken
value if present. Only try to extract username/password from theauth
property if theidentitytoken
is not present.See https://docs.docker.com/engine/api/v1.42/#section/Authentication
The fix is trivial as Docker.DotNet library has full support for this use-case.
Benefit
Support for Azure Container Registry.
(especially from a CI pipeline)
Alternatives
No known workarounds.
It would actually work as-is if the CI pipeline had a credstore available, because testcontainers-dotnet actually already support this use-case with identitytoken. However, CI workflows typically do not have such facility available, hence the
docker login
command will put the identitytoken directly in the config file.Would you like to help contributing this enhancement?
Yes
The text was updated successfully, but these errors were encountered: