Skip to content

Private registry auth#2339

Merged
samalba merged 7 commits intomoby:masterfrom
shin-:private_reg_auth
Dec 3, 2013
Merged

Private registry auth#2339
samalba merged 7 commits intomoby:masterfrom
shin-:private_reg_auth

Conversation

@shin-
Copy link
Contributor

@shin- shin- commented Oct 22, 2013

This enables people to put nginx or apache with basic auth in front of their private registry and still be able to push and pull images.

Only allowed over HTTPS for now.

server.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Index Server address be hard coded here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always been for search, except for the fact that it was buried inside registry.go before. Since the private registry doesn't support any kind of search (at least at the moment), I think it makes sense that we do it this way.

@lukewpatterson
Copy link

This is great -- I've been waiting for this capability for the past couple of months.

Currently, my CI server pushes to my private registry as part of the deployment process, but since I have no way of protecting with auth, I have a few hoops:

  • hide my registry behind firewall
  • set up, tear down an SSH tunnel around my push and pull
  • edit my CI-server's and consumers' hosts file to trick push and pull into using my tunneled port

+1 for the capability allowed by this PR

backflips

@shin-
Copy link
Contributor Author

shin- commented Oct 23, 2013

@lukewpatterson Thanks for the feedback -- does the https requirement work for you? I was thinking of maybe adding a --force-auth parameter if you want to use basic auth over HTTP connections (mostly for testing/development purposes). I'm interested to hear about real life use cases there, and how I can make your life easier. :)

@lukewpatterson
Copy link

Hey @shin- , I like the development/testing option of HTTP w/ auth. I'd picture it as more of a --allow-auth-http process than a --force-auth ("allow" rather than "force"), but either wording works for me.

One big thing that would help me is a complete, minimal nginx.conf example file to accompany the feature. I've been following progress on this topic - and occasionally see references to people declaring success with basic auth - but I can never reproduce success with the information I can glean from the various threads. I want to believe it can work :)

server.go Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samalba This is the part I mentioned to you, and I think this is the cause of the bug we've been observing with the nova integration.

@samalba
Copy link
Contributor

samalba commented Oct 23, 2013

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shin- If you are passing the request as a pointer why are you also returning it and using the result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed convenient. Do you think it's too confusing? We can certainly do without.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the result as the return value would make me believe that my original request is unmodified but that is not the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@allardhoeve
Copy link

Hey @shin-, thanks for the work. I'm curious on how to compile the program to try it. I haven't found any instructions so far on how to build Docker.

Any hints?

@crosbymichael
Copy link
Contributor

@shin- This needs to be rebased.

@vieux
Copy link
Contributor

vieux commented Nov 1, 2013

ping @shin-

@shin-
Copy link
Contributor Author

shin- commented Nov 4, 2013

Done!

@dvoet
Copy link

dvoet commented Nov 5, 2013

I tried to get this working and ran into problems with the login function. It seems that Login in auth/auth.go does not handle a 401 response correctly. I added the following code which gets the job done but may not be what you want in the end:

@@ -224,6 +224,26 @@ func Login(authConfig *AuthConfig, factory *utils.HTTPRequestFactory) (string, e
            } else {
                    return "", fmt.Errorf("Registration: %s", reqBody)
            }
+  } else if reqStatusCode == 401 {
+    req, err := factory.NewRequest("GET", serverAddress+"users/", nil)
+    req.SetBasicAuth(authConfig.Username, authConfig.Password)
+    resp, err := client.Do(req)
+    if err != nil {
+      return "", err
+    }
+    defer resp.Body.Close()
+    body, err := ioutil.ReadAll(resp.Body)
+    if err != nil {
+      return "", err
+    }
+    if resp.StatusCode == 200 {
+      status = "Login Succeeded"
+    } else if resp.StatusCode == 401 {
+      return "", fmt.Errorf("Wrong login/password, please try again")
+    } else {
+      return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body,
+        resp.StatusCode, resp.Header)
+    }
    } else {
            return "", fmt.Errorf("Unexpected status code [%d] : %s", reqStatusCode, reqBody)
    }

@shin-
Copy link
Contributor Author

shin- commented Nov 5, 2013

Thanks @dvoet, that might be an oversight on my part, I'll take a look asap.

@shin-
Copy link
Contributor Author

shin- commented Nov 6, 2013

@dvoet : Oh hey, I just had an epiphany today about this. Of course, the /v1/users/ endpoints need to be whitelisted for this to work, otherwise you're asking someone to be logged in before you're letting them log in...

@dvoet
Copy link

dvoet commented Nov 6, 2013

@shin- But if it is white listed I don't think authentication will happen on a login call and the credentials will not be verified. If they get set incorrectly in the auth config it will lead to 401 error down the line. The normal basic auth pattern is a challenge/response which is what I was trying to accomplish.

@dvoet
Copy link

dvoet commented Nov 6, 2013

the URL called in pingRegistryEndpoint needs to be whitelisted

@shin-
Copy link
Contributor Author

shin- commented Nov 7, 2013

I see what you mean! I'll integrate your patch. Thanks!

@shin-
Copy link
Contributor Author

shin- commented Nov 7, 2013

Integrated @dvoet 's patch. Thanks! Also rebased all the changes. Can you guys take another look? :)

@vieux
Copy link
Contributor

vieux commented Nov 11, 2013

@dvoet @allardhoeve is this working for you ?

@dvoet
Copy link

dvoet commented Nov 12, 2013

yes

@shin-
Copy link
Contributor Author

shin- commented Nov 13, 2013

@crosbymichael @vieux Are we ready to merge this? If there's any outstanding issue I'm available to sort it out. :)

@vieux
Copy link
Contributor

vieux commented Nov 13, 2013

@crosbymichael @creack I must say I wasn't able to get it working, probably my nginx config...

Let's say I don't have access to the index.docker.io. Hoe do I create my login/passwd ?

@shin-
Copy link
Contributor Author

shin- commented Nov 13, 2013

Login/passwords aren't created dynamically, they're in the nginx/apache2/etc. config.

@vieux
Copy link
Contributor

vieux commented Nov 13, 2013

Yes, on the docker cli size I meant.

On Wed, Nov 13, 2013 at 11:28 AM, Joffrey F [email protected]:

Login/passwords aren't created dynamically, they're in the
nginx/apache2/etc. config.


Reply to this email directly or view it on GitHubhttps://github.com//pull/2339#issuecomment-28425540
.

Victor VIEUX
http://vvieux.com

@shin-
Copy link
Contributor Author

shin- commented Nov 13, 2013

docker login had been updated a while ago to accept an optional server parameter, so you can for example type docker login my.registry.io and it will create an entry in .dockercfg for that particular server.

@lucas-clemente
Copy link

Works without issues, here's my working nginx config: https://gist.github.com/lucas-clemente/7518350

In config.yml i have

standalone: true
disable_token_auth: true

Looking forward to seeing this merged!

@vieux
Copy link
Contributor

vieux commented Nov 25, 2013

to be well tested

@samalba
Copy link
Contributor

samalba commented Nov 25, 2013

Good point :-)

Can all people asking for it spend some time testing and provide some feedback?

@dvoet
Copy link

dvoet commented Nov 26, 2013

I have used the login, push and pull commands successfully.

@crosbymichael
Copy link
Contributor

ping @shin-

This needs to be rebased

shin- added 7 commits December 3, 2013 16:24
RequestFactory is no longer a singleton (can be different for different instances of Registry)
Registry now has an indexEndpoint member
Registry methods that needed the indexEndpoint parameter no longer do so
Registry methods will only use token auth where applicable if basic auth is not enabled.
@shin-
Copy link
Contributor Author

shin- commented Dec 3, 2013

Rebased!
cc @crosbymichael

@ross-w
Copy link

ross-w commented Dec 3, 2013

Can confirm re based version does exactly what it says on the tin

Will +1 again for merging

samalba added a commit that referenced this pull request Dec 3, 2013
@samalba samalba merged commit 258d707 into moby:master Dec 3, 2013
@dvoet
Copy link

dvoet commented Dec 4, 2013

sweet! thanks guys.

@lmars
Copy link
Contributor

lmars commented Dec 5, 2013

@shin- great work! I'm having some trouble though because this line in the registry code is blowing up because the auth header is Basic rather than Token, any thoughts?

@ross-w
Copy link

ross-w commented Dec 10, 2013

@lmars Unsetting the Authorization header in the web server worked for me, eg for nginx:

proxy_set_header Authorization "";

@coderlol
Copy link

Anyone with the final nginx conf that will work for SSL and basic auth ?
Btw, should one use "docker login myregistry.myco.com:443" or "docker login myregistry.myco.com" ?

@shin-
Copy link
Contributor Author

shin- commented Dec 30, 2013

@coderlol Sample Nginx conf can be found here
You don't need to include the port.

@aluedeke
Copy link

aluedeke commented Jan 5, 2014

@shin- the file you pointed works fine but has no basic auth support. any example with basic auth? if i add

auth_basic            "Restricted";
auth_basic_user_file  /docker-registry/.htpasswd;

to my config nothing i only get HTTP 500 responses from registry

@shin-
Copy link
Contributor Author

shin- commented Jan 6, 2014

@farahfa
Copy link

farahfa commented Jul 8, 2016

Was the use of basic auth over HTTP connections ever been implemented (some thing like --allow-auth-http or --force-auth; mentioned here and here)?

A real life scenario for this would be trying to deploy a docker image to multiple VMs in a private network which this same network contains a private Docker registry.

@cpuguy83
Copy link
Member

cpuguy83 commented Jul 8, 2016

@farahfa Docker will refuse to send credentials over plain text connections.

thaJeztah added a commit to thaJeztah/docker that referenced this pull request Nov 7, 2019
full diff: moby/libnetwork@0025177...90afbb0

includes:

- docker/libnetwork#/2459 Fix Error Check in NewNetwork
- docker/libnetwork#/2466 Revert "Merge pull request moby#2339 from phyber/iptables-check"
    - reverts docker/libnetwork#/2339 controller: Check if IPTables is enabled for arrangeUserFilterRule
    - re-opens moby/libnetwork#2158 dockerd when run with --iptables=false modifies iptables by adding DOCKER-USER
    - re-opens moby#35777 With iptables=false dockerd still creates DOCKER-USER chain and rules
    - re-opens docker/for-linux#136 dockerd --iptables=false adds DOCKER-USER chain and modify FORWARD chain anyway

Signed-off-by: Sebastiaan van Stijn <[email protected]>
cpuguy83 pushed a commit to cpuguy83/docker that referenced this pull request May 25, 2021
controller: Check if IPTables is enabled for arrangeUserFilterRule
cpuguy83 pushed a commit to cpuguy83/docker that referenced this pull request May 25, 2021
This reverts commit 8d76333, reversing
changes made to bdd0b7b.

Signed-off-by: Arko Dasgupta <[email protected]>
cpuguy83 pushed a commit to cpuguy83/docker that referenced this pull request May 25, 2021
Revert "Merge pull request moby#2339 from phyber/iptables-check"
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

Successfully merging this pull request may close these issues.