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

OAuth2 flow fails against docker trusted registry (missing client_id) #1545

Closed
apwil opened this issue Mar 11, 2019 · 5 comments
Closed

OAuth2 flow fails against docker trusted registry (missing client_id) #1545

apwil opened this issue Mar 11, 2019 · 5 comments
Assignees
Milestone

Comments

@apwil
Copy link

apwil commented Mar 11, 2019

Description of the issue:

When pulling/pushing to a docker trusted registry, authentication fails with error:
400 Bad Request {"details":"invalid client ID"}

Docker registry (DTR) requires a client_id parameter to be passed with the refresh_token when making a login request.

From
https://docs.docker.com/registry/spec/auth/oauth/

client_id
(REQUIRED) String identifying the client. This client_id does not need to be registered with the authorization server but should be set to a meaningful value in order to allow auditing keys created by unregistered clients. Accepted syntax is defined in RFC6749 Appendix A.1

Expected behavior:
It should be possible to pull a base image from an internal docker registry (DTR) using OAuth2 authentication flow.

Steps to reproduce:

docker-credential-wincred list
{"internalregistry":"\u003ctoken\u003e"}
  • Run mvn jib:dockerBuild
    Build fails with error:
    Unauthorized for internalregistry/base/custom-base-image: 400 Bad Request
    [ERROR] {"details":"invalid client ID"}

Environment:
jib-maven-plugin 1.0.2
maven 3.5.0
jdk 1.8.0_131

jib-maven-plugin Configuration:

<from>
   <image>internalregistry/base/custom-base-image</image>
</from>

Log output:
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:1.0.2:dockerBuild (default-cli) on project my-project Build to Docker daemon failed, perhaps you should set a credential helper name with the configuration '' or set credentials for 'internalregistry' in your Maven settings: Unauthorized for internalregistry/base/custom-base-image: 400 Bad Request
[ERROR] {"details":"invalid client ID"}

@apwil
Copy link
Author

apwil commented Mar 11, 2019

Note that the following fix:

@@ -269,7 +269,7 @@ public class RegistryAuthenticator {
     String serviceScope = getServiceScopeRequestParameters(scope);
     return isOAuth2Auth()
         ? serviceScope
-            + "&grant_type=refresh_token&refresh_token="
+            + "&client_id=jib&grant_type=refresh_token&refresh_token="
             // If OAuth2, credential.getPassword() is a refresh token.
             + Verify.verifyNotNull(credential).getPassword()
         : serviceScope;

Fixes this issue for me, but I imagine it might cause problems with other OAuth2 endpoints. Does anyone know if ACR (for example) will be affected by a dummy client_id in the request?

@chanseokoh
Copy link
Member

Aha! Thanks @apwil for the detailed information and a pointer for a potential fix.

Since the spec says client_id is required, I think Jib should provide it in principle. The spec says the client doesn't have to registered with the auth server. Sounds like it can be an arbitrary (meaningful) value for auditing purposes, so hopefully ACR won't be affected. @andxu it'd be nice if you can confirm if passing client_id=jib works with ACR.

@andxu
Copy link
Contributor

andxu commented Mar 12, 2019

@chanseokoh I have tested your PR over ACR, it passes.

@apwil
Copy link
Author

apwil commented Mar 12, 2019

Thanks @chanseokoh for the very quick turnaround of this issue!
I see that it is targeted for 1.1.0 - would it be possibly to have it in a 1.0.3 release given that it completes the work done in #1490 ?

@chanseokoh
Copy link
Member

@apwil Jib 1.1.0 with the fix released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants