Coder Social home page Coder Social logo

Comments (20)

kaleming avatar kaleming commented on May 3, 2024 5

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.

from dockerswarm.rocks.

coltonbh avatar coltonbh commented on May 3, 2024 1

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.

from dockerswarm.rocks.

coltonbh avatar coltonbh commented on May 3, 2024 1

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?

from dockerswarm.rocks.

coltonbh avatar coltonbh commented on May 3, 2024 1

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

from dockerswarm.rocks.

mehdihz avatar mehdihz commented on May 3, 2024 1

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 ...

from dockerswarm.rocks.

kaleming avatar kaleming commented on May 3, 2024

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) ?

from dockerswarm.rocks.

coltonbh avatar coltonbh commented on May 3, 2024

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.

from dockerswarm.rocks.

kaleming avatar kaleming commented on May 3, 2024

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

from dockerswarm.rocks.

coltonbh avatar coltonbh commented on May 3, 2024

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

from dockerswarm.rocks.

kaleming avatar kaleming commented on May 3, 2024

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.

from dockerswarm.rocks.

kaleming avatar kaleming commented on May 3, 2024

Unfortunately I still get the same - 401 Unauthorized message.

from dockerswarm.rocks.

coltonbh avatar coltonbh commented on May 3, 2024

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...

from dockerswarm.rocks.

kaleming avatar kaleming commented on May 3, 2024

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.

from dockerswarm.rocks.

coltonbh avatar coltonbh commented on May 3, 2024

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

from dockerswarm.rocks.

daniel-butler avatar daniel-butler commented on May 3, 2024

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

from dockerswarm.rocks.

claudiopastorini avatar claudiopastorini commented on May 3, 2024

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)

from dockerswarm.rocks.

ccrvlh avatar ccrvlh commented on May 3, 2024

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

from dockerswarm.rocks.

kielerrr avatar kielerrr commented on May 3, 2024

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)

from dockerswarm.rocks.

tiangolo avatar tiangolo commented on May 3, 2024

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/ 🥲

from dockerswarm.rocks.

github-actions avatar github-actions commented on May 3, 2024

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

from dockerswarm.rocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.