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

🐛 Fix credentials when using a helper that returns a token #1734

Merged
merged 2 commits into from Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -251,10 +251,16 @@ private AuthConfig runCredentialProvider(String hostName, String helperOrStoreNa
final JsonNode helperResponse = OBJECT_MAPPER.readTree(data);
log.debug("Credential helper/store provided auth config for: {}", hostName);

return new AuthConfig()
.withRegistryAddress(helperResponse.at("/ServerURL").asText())
.withUsername(helperResponse.at("/Username").asText())
.withPassword(helperResponse.at("/Secret").asText());
final String username = helperResponse.at("/Username").asText();
final String password = helperResponse.at("/Secret").asText();
if ("<token>".equals(username)) {
return new AuthConfig().withIdentityToken(password);
} else {
return new AuthConfig()
.withRegistryAddress(helperResponse.at("/ServerURL").asText())
.withUsername(username)
.withPassword(password);
}
}

private String getCredentialProgramName(String credHelper) {
Expand Down
Expand Up @@ -69,6 +69,15 @@ public void lookupAuthConfigUsingHelper() throws URISyntaxException {
assertEquals("Correct secret is obtained from a credential store", "secret", authConfig.getPassword());
}

@Test
public void lookupAuthConfigUsingHelperWithToken() throws URISyntaxException {
final RegistryAuthLocator authLocator = createTestAuthLocator("config-with-helper-using-token.json");

final AuthConfig authConfig = authLocator.lookupAuthConfig(new DockerImageName("registrytoken.example.com/org/repo"), new AuthConfig());

assertEquals("Correct identitytoken is obtained from a credential store", "secret", authConfig.getIdentitytoken());
}

@Test
public void lookupUsingHelperEmptyAuth() throws URISyntaxException {
final RegistryAuthLocator authLocator = createTestAuthLocator("config-empty-auth-with-helper.json");
Expand Down
@@ -0,0 +1,11 @@
{
"auths": {
"registrytoken.example.com": {}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/18.03.0-ce (darwin)"
},
"credHelpers": {
"registrytoken.example.com": "fake"
}
}
23 changes: 18 additions & 5 deletions core/src/test/resources/auth-config/docker-credential-fake
Expand Up @@ -15,8 +15,21 @@ if [[ $inputLine == "https://not.a.real.registry/url" ]]; then
exit 1
fi

echo '{' \
' "ServerURL": "url",' \
' "Username": "username",' \
' "Secret": "secret"' \
'}'
if [[ $inputLine == "registry.example.com" ]]; then
echo '{' \
' "ServerURL": "url",' \
' "Username": "username",' \
' "Secret": "secret"' \
'}'
exit 0
fi
if [[ $inputLine == "registrytoken.example.com" ]]; then
echo '{' \
' "ServerURL": "url",' \
' "Username": "<token>",' \
' "Secret": "secret"' \
'}'
exit 0
fi

exit 1
23 changes: 18 additions & 5 deletions core/src/test/resources/auth-config/win/docker-credential-fake.bat
Expand Up @@ -14,8 +14,21 @@ if "%inputLine%" == "https://not.a.real.registry/url" (
exit 1
)

echo {
echo "ServerURL": "url",
echo "Username": "username",
echo "Secret": "secret"
echo }
if "%inputLine%" == "registry.example.com" (
echo {
echo "ServerURL": "url",
echo "Username": "username",
echo "Secret": "secret"
echo }
exit 0
)
if "%inputLine%" == "registrytoken.example.com" (
echo {
echo "ServerURL": "url",
echo "Username": "<token>",
echo "Secret": "secret"
echo }
exit 0
)

exit 1