Closed Schwimo closed 1 year ago
I am currently experimenting with this SDK and Amazon ECR, too. The Amazon Auth token is a bas64 string in format username:password
.
I managed to pass the authorization by using the BasicAuthCredentials
with following code:
var token = Encoding.UTF8.GetString(
Convert.FromBase64String(response.AuthorizationData.FirstOrDefault()?.AuthorizationToken ?? ""));
var partials = token.Split(':');
return new BasicAuthCredentials(StrToSecureString(partials[0]), StrToSecureString(partials[1]));
However, I fail to fetch a list of images from the registry, I get an exception
Docker.DotNet.DockerApiException: "Docker API responded with status code=NotFound, response=404 page not found"
Thanks @Serraniel Didn't think about the base64 string format. Now it works.
As far as I understood, the BasicAuthCredentials are used if your docker engine needs other credentials. They are not used for a container registry. It works with passing the converted token within the auth config.
I did the following:
// Get the ECR authorization token
var getAuthorizationTokenRequest = new GetAuthorizationTokenRequest();
var response = await ecrClient.GetAuthorizationTokenAsync(getAuthorizationTokenRequest);
var base64Token = Convert.FromBase64String(response.AuthorizationData[0].AuthorizationToken);
// The token now contains the login name and the token in this format:
// AWS:Token
var token = Encoding.UTF8.GetString(base64Token);
// That's why we split it here
var partials = token.Split(':');
// Extract the authorization token and registry URL
//var token = response.AuthorizationData[0].AuthorizationToken;
var registryUrl = response.AuthorizationData[0].ProxyEndpoint;
var imagesCreateParameters = new ImagesCreateParameters
{
FromImage = dockerImage + ":latest"
};
var auth = new AuthConfig
{
Username = partials[0],
Password = partials[1],
ServerAddress = registryUrl,
};
await client.Images.CreateImageAsync(imagesCreateParameters, auth, progress);
Output of
dotnet --info
:What version of Docker.DotNet?:
Steps to reproduce the issue:
What actually happened?: I received an token. But the following error occurs:
repository does not exist or may require 'docker login': denied: Your Authorization Token is invalid.
What did you expect to happen?:
Additional information: When I ececute
docker pull image_name
locally from a terminal, it works.