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

Configurable default user & password #919

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

viktorerlingsson
Copy link
Member

WHAT is this pull request doing?

Makes it possible to configure default user and password. Takes a hashed value for password.

Also adds api endpoint /api/auth/hash_password/:password and lavinmqctl command lavinmqctl hash_password password to hash passwords.

Also changes guest-only-loopback to default-user-only-loopback, since the default user no longer has to be guest.

Fixes #877

Configuration

Values can be configured by environment variables, in the config file or by command line arguments.
Env

LAVINMQ_DEFAULT_USER=USER
LAVINMQ_DEFAULT_PASSWORD=PASSWORD

Config file

[main]
default_user=USER
default_password=PASSWORD

Command line
--default-user=USER --default-password=PASSWORD

HOW can this pull request be tested?

Run specs.

@viktorerlingsson viktorerlingsson requested a review from a team as a code owner January 22, 2025 10:46
@@ -118,8 +121,8 @@ module LavinMQ
p.on("-h", "--help", "Show this help") { puts p; exit 0 }
p.on("-v", "--version", "Show version") { puts LavinMQ::VERSION; exit 0 }
p.on("--build-info", "Show build information") { puts LavinMQ::BUILD_INFO; exit 0 }
p.on("--guest-only-loopback=BOOL", "Limit guest user to only connect from loopback address") do |v|
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how much this is used but this is considered breaking change.
If we keep the other flag and add this new we get around it

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. Maybe we should just keep the guest_only_loopback name instead of changing it. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

One way to handle changes is to add the new flag and keep the old, the old still works but logs a deprecation warning and then we remove it next major release

@@ -119,6 +119,13 @@ module LavinMQ
end
context
end

put "/api/auth/hash_password/:password" do |context, params|
Copy link
Member

Choose a reason for hiding this comment

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

Whats this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we use a hashed password I think there should be an easy way to generate that hash. I've taken some inspiration from https://www.rabbitmq.com/docs/passwords#computing-password-hash

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I think it's better to send the password in body, since it's a PUT, URLs tends to show up in logs.

Like so: curl -d my_strong_password -XPUT http://localhost:15672/api/auth/hash_password

yes, it's a different API but maybe better? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, yeah that should be a little safer. Maybe we can support both ways? Password in the URL for compatibility, but we recommend/document sending password as body?

Copy link
Member

Choose a reason for hiding this comment

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

Agree. Lets add that the endpoint with password in body as well. But I can open another issue for that and we can put that in a separate PR

Copy link
Member

Choose a reason for hiding this comment

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

If we want to achive compatibility, it should be GET, not PUT?

I think this could be a thing where we intentionally does not aim for compatibility, as @snichme states, web server logs will contain the plain text password.

@viktorerlingsson viktorerlingsson force-pushed the configurable-default-user branch from edb8be9 to e29b981 Compare February 21, 2025 09:17
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.

Default User and Password from Environment
4 participants