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

Docker Compose Template for Traefik Has Issues #59

Closed
coltonbh opened this issue Sep 17, 2020 · 20 comments
Closed

Docker Compose Template for Traefik Has Issues #59

coltonbh opened this issue Sep 17, 2020 · 20 comments
Labels

Comments

@coltonbh
Copy link

Great website, tutorial etc...! Thank you for providing this.

I'd like to document my issues using the guide for setting up Traefik at https://dockerswarm.rocks/traefik/ to try and help others...

Deploying the template exactly as described and having followed all the steps:

- invalid interpolation format for services.traefik.deploy.labels.[]: "required variable HASHED_PASSWORD is missing a value: Variable not set". You may need to escape any $ with another $.

According to this stack overflow answer, extended shell-style features, such as ${VARIABLE-default} and ${VARIABLE/foo/bar}, are not supported. So I changed the ${HASHED_PASSWORD?Variable not set} and other related values containing the ?Variable not set addendum to ${HASHED_PASSWORD}.

Next issue: Cannot login--incorrect password.

For those running ubuntu they may find that export USERNAME=admin doesn't do anything--their $USERNAME will still be ubuntu. It took me forever to find out why my login never worked! So log in with username ubuntu and the password they set.

Perhaps updating the docs would be helpful? I'm happy to make a PR and update, but I wanted to check here first to make sure I wasn't missing something elementary before suggesting changes. Thank you again for the great tutorial!

@coltonbh
Copy link
Author

And of course after painstakingly figuring out all these details, then reproducing it from the start the above seems incorrect! The ${VARIABLE?Variable not set} notation seems to work just fine. I think I somehow failed to correctly set my environment variables thereby creating the initial error?? 🤦🏼‍♂️

However, the note about export USERNAME=admin not changing the $USERNAME on ubuntu may be worth adding--I think that was at the root of all the bizarre paths I went down trying to debug.

@kaleming
Copy link

kaleming commented Oct 5, 2020

I got the same error.

I followed your steps and it solved the first issue. However I still can't log in (401 Unauthorized).

I have tried using my user and password without success.

Which password did work for you (with ubuntu username) ?

@coltonbh
Copy link
Author

coltonbh commented Oct 5, 2020

The password set in the $PASSWORD variable did work for me once I used the ubuntu username instead of what I had set in $USERNAME.

@kaleming
Copy link

kaleming commented Oct 5, 2020

In my case, it doesn't work using the password I set in the $PASSWORD. How did you find out ubuntu as $USERNAME ?

@coltonbh
Copy link
Author

coltonbh commented Oct 5, 2020

echo $USERNAME is always ubuntu regardless what I set using export USERNAME=my_own_name

@kaleming
Copy link

kaleming commented Oct 5, 2020

In my case both echo $USERNAME and echo $PASSWORD seems correct, but I still get:

"GET / HTTP/2.0" 401

I have tried to write the credetials directly on yml file:

traefik.http.middlewares.admin-auth.basicauth.users=example:password

I have also tried placing hash instead: example:$apr1$nyeKGV3t$Qj1EEOqrS1wKoURU6CPCU/
generated using htpasswd -nb example "password"

But no success either.

@coltonbh
Copy link
Author

coltonbh commented Oct 5, 2020

I believe you may need to add an additional $ to your credentials if placed directly in the file, you also want to remove the double quotes from your password--those are being included.

So try:
`❯ htpasswd -nb example password

example:$apr1$BVhy2emr$PRkqFeoHHQbIQtE5McvOc0`

Then place the following in your yaml file:
example:$$apr1$$BVhy2emr$$PRkqFeoHHQbIQtE5McvOc0

Any luck?

@kaleming
Copy link

kaleming commented Oct 6, 2020

Unfortunately I still get the same - 401 Unauthorized message.

@kaleming
Copy link

kaleming commented Oct 6, 2020

Hi @coltonbh,

After some hours, it worked doing the following:

1- To create user:password pair, it's possible to use this command:
echo $(htpasswd -nb user password) | sed -e s/\\$/\\$\\$/g

2- Add quotes in this line:
-"traefik.http.middlewares.testauth.basicauth.users=example:$$apr1$$BVhy2emr$$PRkqFeoHHQbIQtE5McvOc0"

Thanks to point out this issue.

@coltonbh
Copy link
Author

coltonbh commented Oct 6, 2020

@kaleming congrats! I figured it was something small like that. Nice sleuthing.

@coltonbh
Copy link
Author

You know what, @kaleming I set up a new swarm yesterday and had the exact same issue again--traefik always gave me 401 responses with the variable defined USERNAME and PASSWORD so I had to do exactly what you did with the "" and the hard coded line. Not sure why this is...

@kaleming
Copy link

Hi @coltonbh, I'm glad this approach worked for you too.
I didn't have time to go further into this issue, I am not sure why either.

@coltonbh
Copy link
Author

Yeah I'm curious what the issue with using the environment variables in the main example. I can't figure it out...

@daniel-butler
Copy link

daniel-butler commented Oct 20, 2020

Are you setting the $HASHED_PASSWORD As specified here?

export HASHED_PASSWORD=$(openssl passwd -apr1 $PASSWORD)
(Optional): Alternatively, if you don't want to put the password in an environment variable, you could type it interactively, e.g.:

$ export HASHED_PASSWORD=$(openssl passwd -apr1)
Password: $ enter your password here
Verifying - Password: $ re enter your password here

@claudiopastorini
Copy link

Using @coltonbh suggestion:

So I changed the ${HASHED_PASSWORD?Variable not set} and other related values containing the ?Variable not set addendum to ${HASHED_PASSWORD}.

Works like a charm in my case.

I do not really understand if the problem is related to the template file or to a bug in docker-compose (it is documented here).

I share my current environment:

  • Ubuntu 18.04.5 LTS
  • Docker version 19.03.11, build dd360c7 (snap version)

@mehdihz
Copy link

mehdihz commented Dec 22, 2020

My problem was caused because of sudo
For docker usage, I used the command with sudo so enivornment variables not shared.

In this case, just share current environments using -E argument
sudo docker -E stack deploy ...

@ccrvlh
Copy link

ccrvlh commented Jan 16, 2021

Try changing the template from $ to $$ (Ubuntu 20.04)

@kielerrr
Copy link

I had this issue on Windows. I thought it was a problem with variable expansion as well, but I was wrong. I set a few env variables the .toml was looking for and it fixed the issue.
For some reason the .env file isn't being picked up or used. Therefore, all env variables were empty.
I made a quick gist to turn the .env file into 'set name=value' notation windows wants.
I pasted the output in the terminal and everything worked. Attaching gist below.

# run in dir with a .env file. prints text block to paste into cmd to load env variables

import os
import re

with open('.env', 'r', encoding='utf-8') as fs:
    env_vars = fs.read().splitlines()
    good_pairs = []
    [good_pairs.append(f'set {var_pair}') for var_pair in env_vars if not re.findall('^ ?#', var_pair) and var_pair != '']
    # [os.system(f'set {var_pair}') for var_pair in env_vars if not re.findall('^ ?#', var_pair) and var_pair != '']

print(good_pairs)
for pair in good_pairs:
    print(pair)
    # os.system(pair)

@tiangolo
Copy link
Owner

Thanks for the patience! And thanks for the notes. Maybe if someone wants to update the examples to use something different than USERNAME I would take that PR.

Nevertheless, I should let you know, I had to deprecate this website and ideas, I would no longer recommend Docker Swarm Mode for new projects: https://dockerswarm.rocks/swarm-or-kubernetes/ 🥲

Copy link

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

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

No branches or pull requests

8 participants