Skip to content

Conversation

@julio-lopez
Copy link
Collaborator

@julio-lopez julio-lopez commented Jul 11, 2024

Objectives:

  • Facilitate the generation of valid password hashes that can be used with the server user --user-password CLI command.
  • Encapsulate implementation details of password hashing in the user package.

Adds a new server user hash-password CLI command to generate the hash from a supplied password.

Modifies the server user set/add --user-password-hash CLI command to accept the password hash generated using the hash-password command.

Adds GetNewProfile(ctx, rep, username) helper to move implementation details to the user package.

Includes CLI and unit tests.

Cleans up and removes unused functions.

@codecov
Copy link

codecov bot commented Jul 11, 2024

Codecov Report

Attention: Patch coverage is 70.27027% with 33 lines in your changes missing coverage. Please review.

Project coverage is 77.19%. Comparing base (cb455c6) to head (6b36d55).
Report is 189 commits behind head on master.

Files Patch % Lines
cli/command_user_add_set.go 33.33% 12 Missing ⚠️
internal/user/hash_password.go 72.41% 4 Missing and 4 partials ⚠️
cli/command_user_hash_password.go 56.25% 5 Missing and 2 partials ⚠️
internal/user/user_manager.go 75.00% 2 Missing and 2 partials ⚠️
internal/user/user_profile.go 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3974      +/-   ##
==========================================
+ Coverage   75.86%   77.19%   +1.32%     
==========================================
  Files         470      483      +13     
  Lines       37301    28848    -8453     
==========================================
- Hits        28299    22269    -6030     
+ Misses       7071     4674    -2397     
+ Partials     1931     1905      -26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@julio-lopez julio-lopez requested a review from plar July 11, 2024 14:08
@julio-lopez julio-lopez changed the title feat(cli) add server user set-password-hash command feat(cli): add server user set-password-hash command Jul 11, 2024
@julio-lopez julio-lopez marked this pull request as ready for review July 11, 2024 17:44
@julio-lopez julio-lopez enabled auto-merge (squash) July 11, 2024 19:21
Copy link
Contributor

@redgoat650 redgoat650 left a comment

Choose a reason for hiding this comment

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

A few nits, but looks good overall

var ErrUserNotFound = errors.New("user not found")

// ErrUserAlreadyExists indicates that a user already exist in the system when attempting to create a new one.
var ErrUserAlreadyExists = errors.New("user already exists found")
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this meant to be just "user already exists"?
("already exists found" sounds kinda weird)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeap, probably edit error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

or "found an already existing user" 😄 (JK, "user already exists" it is)

Comment on lines +42 to +43
// create a new user with and set the password using the password hash
e.RunAndExpectSuccess(t, "server", "users", "add", userFull, "--user-password-hash", passwordHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to test server users set also? Perhaps we can update the password hash and show fail/success when the same user connects with old/new passwords?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good suggestion.
Let me try, although it may require restarting the server or forcing/waiting for a refresh.

Copy link
Collaborator Author

@julio-lopez julio-lopez Jul 12, 2024

Choose a reason for hiding this comment

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

@redgoat650 PTAL.
I added a success case after changing the user password (via a hash).

I'll owe the failure cases, those surfaced a minor issue with a resource not being released when the client command fails to execute. It may be similar to the issue in #3980 but on the client side. 3980 is on the server side, it was surfaced when fixing a test.
I'll address the "resource leakage" issue separately, and then I'll update this test, probably in a separate PR.

Includes tests for `user.HashPassword`
Test rountrip with `decodeHashedPassword`
Test `user.passwordHash.validate()`
…-hash'

CLI test for `server user hash-password` and
`server user add/set --user-password-hash`
This helper encapsulates how a user profile is initialized.
This way, internals of the user package do not need to be exposed.
Removes unused:
- `user.DefaultPasswordHashingAlgorithm` const
- `user.PasswordHashingAlgorithms()` helper
Extends the test to change the user password hash and connect to
the server with the new password.
@julio-lopez julio-lopez requested a review from redgoat650 July 12, 2024 01:19
Copy link
Contributor

@redgoat650 redgoat650 left a comment

Choose a reason for hiding this comment

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

Thanks @julio-lopez, +1 from me

@julio-lopez
Copy link
Collaborator Author

@bathina2 FYI

@jkowalski
Copy link
Contributor

:shipit:

@julio-lopez julio-lopez merged commit 9c5fc84 into kopia:master Jul 12, 2024
@julio-lopez julio-lopez deleted the feat/gen-pw-hash branch July 12, 2024 02:29
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.

3 participants