-
Notifications
You must be signed in to change notification settings - Fork 344
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
feat: crypt hasher #2788
feat: crypt hasher #2788
Conversation
2aeaedc
to
1a139d1
Compare
LGTM, but actually I would like to bring up why we actually even need to hash the password? What is the goal? I guess protection of the password, but I am not sure if it is not overkill? This just seems to me like a bad UX... |
I don't remember the exact reason (except not having plain text passwords) but the reasoning was given by @janos in one of the comments here: #2400 |
Yes, as @notanatol said more details are in the previous pr comments, but basic the reason is the same as passwords are not stored in plain text in databases in common web applications. Or, why web servers like apache2 and nginx are doing the same for basic auth configurations. Apache2 and nginx are very popular web servers. |
7ad7a0a
to
3f4b5a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@notanatol since we are using viper-cobra wouldn't it make more sense to use the existing infrastructure to ship the new command?
Also, since you're de-facto creating a new binary here, it will not be built nor shipped by default, which means that we're gonna have to have separate artifacts on releases for this. This involves a lot of changes to the release process and I'm not sure this is entirely necessary or desirable (we were already burnt by maintaining these sort of extra util in the past).
So I wonder whether it would not make sense to pack this as a subcommand in bee
. Ideally we would not have this sort of stuff in bee, not sure why this cannot be a command as part of swarm-cli
. @agazso input please?
I agree that creating a new binary can make things cumbersome. Alternatively it makes sense to add this functionality to |
OK so in this case I'm going to split this PR in two - one with the fixes (HTTP codes) requested by @AuHau and another one with the embedded hasher. Then we'll have all the time we need to make a decision if we want this hasher in the binary or a separate js tool. |
Maybe it will be worth considering just using something existing as |
Oh, I haven't noticed that it is a standalone command. I originally envisioned it as Although I would strongly suggest incorporating this functionality directly into Also, I am not in favor of outsourcing this to |
@AuHau I moved it to be a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the usual naming nitpicking :)
I guess here we are not 100% agreeing (which is fine). IMO it is not in |
Ups sorry 😅 Mis-click 🙈 |
And ad @acud: |
cmd/bee/cmd/bcrypt.go
Outdated
return errors.New("failed to generate password hash") | ||
} | ||
|
||
fmt.Println(string(hashed)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be aware that you're print not just the actual string here, but also a line feed. It would be good to check that it doesn't make some cli checks fail as a result (e.g. if the hashed password is stored in a file then simply bee bcrypt --check playtextpass | diff hash_pass -
to see that they match)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it works:
$> go run $(pwd)/cmd/bee bcrypt super$ecret > plaintext
$> go run $(pwd)/cmd/bee bcrypt --check super$ecret `cat plaintext`
OK: password hash matches provided plain text
but I will remove the new line just in case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they will always pass in this case, because the command generated both outputs (hence both have exactly the same characters, line feed included) :)
$> go run $(pwd)/cmd/bee bcrypt --check super$ecret `go run $(pwd)/cmd/bee bcrypt super$ecret`
OK: password hash matches provided plain text |
Checklist
Description
We now return
403 Forbidden
in only one case - when the provided token is valid but does not have sufficient privileges to access the requested resource.All the other cases will result in a
401 Unauthorized
return code.Added a new command
bcrypt
that can generate a bcrypt hash for a given plain text password. The returned value can be used foradmin-password
configuration parameter. The tool can also validate that the provided hash matches a plain text password (using the--check
option). Note: when checking the hash please make sure to quote it, the shell does not take kindly to the dollar signs in the hash text.Motivation and context
The bcrypt command is a handy offline alternative to https://bcrypt-generator.com/
Usage
This change is