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

Add basic auth support for web backend #677

Merged
merged 1 commit into from
Sep 19, 2016
Merged

Conversation

SantoDE
Copy link
Collaborator

@SantoDE SantoDE commented Sep 14, 2016

Hey there,

this PR enables traefik to protect the web backend per basic auth. All you need to do, is at these lines to your traefik.toml

[web.auth.basic] users = ["traefik:$apr1$8EvWcwpO$RaRFXvDJk6LGQ5tM04RRd0"]

so it looks like:

[web]
address = ":8000"
    [web.auth.basic]
    users = ["traefik:$apr1$8EvWcwpO$RaRFXvDJk6LGQ5tM04RRd0"]

Feedback welcome! :)

@SantoDE
Copy link
Collaborator Author

SantoDE commented Sep 15, 2016

Needs a proper rebase. I failed while trying to get this up. Maybe @emilevauge or @jangie can help me get this up properly :)

@SantoDE
Copy link
Collaborator Author

SantoDE commented Sep 15, 2016

Rebase done. All good from my side now. Waiting for you :)

@SantoDE
Copy link
Collaborator Author

SantoDE commented Sep 15, 2016

Rebased again

@emilevauge
Copy link
Member

Fixes #296

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

Hi @SantoDE, thanks for your contribution :)

I have 2 comments. Could you add more explanations to the documentation you have already done in traefik.sample.toml, and add a digest section? You can copy paste (with adaptation) docs from entrypoints authentication:

# To enable basic auth on an entrypoint
# with 2 user/pass: test:test and test2:test2
# Passwords can be encoded in MD5, SHA1 and BCrypt: you can use htpasswd to generate those ones
# [entryPoints]
#   [entryPoints.http]
#   address = ":80"
#   [entryPoints.http.auth.basic]
#   users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
#
# To enable digest auth on an entrypoint
# with 2 user/realm/pass: test:traefik:test and test2:traefik:test2
# You can use htdigest to generate those ones
# [entryPoints]
#   [entryPoints.http]
#   address = ":80"
#   [entryPoints.http.auth.basic]
#   users = ["test:traefik:a2688e031edb4be6a3797f3882655c05 ", "test2:traefik:518845800f9e2bfb1f1f740ec24f074e"]

Could you also add a section in the documentation web site: https://github.com/containous/traefik/blob/master/docs/toml.md ?

Thanks :)

@SantoDE
Copy link
Collaborator Author

SantoDE commented Sep 16, 2016

Hey @emilevauge ,

thanks for your Feedback. I implemented the requested changes. Hope all is good!

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

One last fix!

@@ -411,6 +411,18 @@ address = ":8080"
#
# Optional
# ReadOnly = false
#
# To enable basic auth on an entrypoint
Copy link
Member

@emilevauge emilevauge Sep 16, 2016

Choose a reason for hiding this comment

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

on an entrypoint -> on the webui

# Passwords can be encoded in MD5, SHA1 and BCrypt: you can use htpasswd to generate those ones
# [web.auth.basic]
# users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
# To enable digest auth on an entrypoint
Copy link
Member

Choose a reason for hiding this comment

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

on an entrypoint -> on the webui

@@ -221,6 +221,17 @@
# Optional
# ReadOnly = false

# To enable basic auth on an entrypoint
Copy link
Member

Choose a reason for hiding this comment

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

on an entrypoint -> on the webui

# Passwords can be encoded in MD5, SHA1 and BCrypt: you can use htpasswd to generate those ones
# [web.auth.basic]
# users = ["test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"]
# To enable digest auth on an entrypoint
Copy link
Member

Choose a reason for hiding this comment

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

on an entrypoint -> on the webui

@SantoDE
Copy link
Collaborator Author

SantoDE commented Sep 16, 2016

done and rebased to squash the changes :) @emilevauge

Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

ping @containous/traefik

Copy link

@cocap10 cocap10 left a comment

Choose a reason for hiding this comment

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

Custom parser missing ?

@@ -28,6 +30,7 @@ type WebProvider struct {
KeyFile string `description:"SSL certificate"`
ReadOnly bool `description:"Enable read only API"`
server *Server
Auth *types.Auth `description:"Auth Crendetials for Web Point"`
Copy link

@cocap10 cocap10 Sep 18, 2016

Choose a reason for hiding this comment

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

Maybe an issue with the StructTag here.
A flag will be created because of the description StructTag.
But I think a custom parser is missing on type.Auth

And Træfik will probably run into an error if the flag --web.auth is called.

Maybe we should remove the StructTag and assuming that TOML file is the only way to use this feat ?
WDYT @emilevauge ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like I missed that. I guess, removing it and assume TOML file is the only way is fine. Thanks for pointing that out!

However, let's wait for @emilevauge :)

Copy link
Member

Choose a reason for hiding this comment

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

@cocap10 great catch !
Indeed, it sounds OK to assume that TOML will be used to configure authentication users.
Let's remove the struct tag for now :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done and rebased @emilevauge @cocap10 . Thanks for your Feedback 👍 :)

implemented requested changes

fix docs

remove struct tag
@errm
Copy link
Contributor

errm commented Sep 19, 2016

On the face of it this looks good to me.

I am slightly wary of the fact that we now have code to handle basic auth in 2 places.

Not sure if we could DRY this up a bit, or even if that is desirable....

@emilevauge
Copy link
Member

emilevauge commented Sep 19, 2016

I am slightly wary of the fact that we now have code to handle basic auth in 2 places.

As the authentication mechanism takes place in middlewares/authenticator.go, I think we can live with that for now :)

@holms
Copy link

holms commented Sep 6, 2017

How this can be done from docker-compose? There's no way in swarm you can mount files locally, unless making your own Dockerfile.

@holms
Copy link

holms commented Sep 6, 2017 via email

@SantoDE
Copy link
Collaborator Author

SantoDE commented Sep 6, 2017

@holms I guess best way is to mount a traefik.toml inside a volume to your traefik container and set the configuration in that toml

@holms
Copy link

holms commented Sep 6, 2017 via email

@gentunian
Copy link

gentunian commented Nov 17, 2017

@holms you should restrict with constraints where should traefik be placed. Something like:

deploy:
  placement:
    constraints: [node.role == manager]

@raarts
Copy link

raarts commented Jan 15, 2018

@holms, now there's docker configs, or you can use the local-persist driver as a global service, maybe in combination with placement constraints.

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

Successfully merging this pull request may close these issues.

8 participants