Commit Graph

14 Commits

Author SHA1 Message Date
Julio López
961a39039b refactor(general): use errors.New where appropriate (#4160)
Replaces 'errors.Errorf\("([^"]+)"\)' => 'errors.New("\1")'
2024-10-05 19:05:00 -07:00
Julio López
9c5fc842a1 feat(cli): add server user set-password-hash command (#3974)
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.
2024-07-11 19:29:06 -07:00
Julio López
ca1962f6e4 refactor(general): user password hashing and key derivation helpers (#3821)
Code movement and simplification, no functional changes.

Objectives:
- Allow callers specifying the needed key (or hash) size, instead of
hard-coding it in the registered PBK derivers. Conceptually, the caller
needs to specify the key size, since that is a requirement of the
(encryption) algorithm being used in the caller. Now, the code changes
here do not result in any functional changes since the key size is
always 32 bytes.
- Remove a global definition for the default PB key deriver to use.
Instead, each of the 3 use case sets the default value.

Changes:
- `crypto.DeriveKeyFromPassword` now takes a key size.
- Adds new constants for the key sizes at the callers.
- Removes the global `crypto.MasterKeySize` const.
- Removes the global `crypto.DefaultKeyDerivationAlgorithm` const.
- Adds const for the default derivation algorithms for each use case.
- Adds a const for the salt length in the `internal/user` package, to ensure
  the same salt length is used in both hash versions.
- Unexports various functions, variables and constants in the `internal/crypto`
  & `internal/user` packages.
- Renames various constants for consistency.
- Removes unused functions and symbols.
- Renames files to be consistent and better reflect the structure of the code.
- Adds a couple of tests to ensure the const values are in sync and supported.
- Fixes a couple of typos

Followups to:
- #3725
- #3770
- #3779
- #3799
- #3816

The individual commits show the code transformations to simplify the
review of the changes.
2024-04-26 23:30:56 -07:00
Sirish Bathina
02463ab118 feat(general): user profile hashing version to algorithm translation (#3816)
Reverts to using the `PasswordHashVersion` in the user profile.
Adds a simple mechanism for translating between password hash
version and the corresponding password hashing algorithm (key
derivation algorithm).
2024-04-24 17:50:26 -07:00
Sirish Bathina
0dad3edd72 fix(cli): user add set user-password-hashing-algorithm cli option (#3815)
Updates the `user-password-hashing-algorithm` option to be
hidden and note that it is an experimental setting.
2024-04-23 17:24:01 -07:00
Sirish Bathina
5fa39fe5eb feat(general): User_profile_add_set cli changes (#3770)
* User profile add set cli changes

* Add additional test

* get salt length from key deriver

* Fixes for failing tests

* after shikhars review

* lint fixes
2024-04-10 17:56:13 -07:00
Sirish Bathina
ddcdfdb55a changes for switching key derivation (#3725) 2024-03-13 00:34:46 +00:00
Jarek Kowalski
6fa50640f4 build(deps): manual upgrade to github.com/alecthomas/kingpin/v2 (#2804)
also upgraded github.com/klauspost/reedsolomon to latest non-retracted version
go mod tidy
2023-03-11 06:28:05 -08:00
Jarek Kowalski
a461d767f7 cli: plumbed through 'textOutput' which controls stdout/stderr writers (#1053)
This is mostly for testability.
2021-05-06 20:26:35 -07:00
Jarek Kowalski
d2288c443f cli: major refactoring (#1046)
cli: major refactoring of how CLI commands are registered

The goal is to eliminate flags as global variables to allow for better
testing. Each command and subcommand and most sets of flags are now
their own struct with 'setup()' methods that attached the flags or
subcommand to the provided parent.

This change is 94.3% mechanical, but is fully organic and hand-made.

* introduced cli.appServices interface which provides the environment in which commands run
* remove auto-maintenance global flag
* removed globals in memory_tracking.go
* removed globals from cli_progress.go
* removed globals from the update_check.go
* moved configPath into TheApp
* removed remaining globals from config.go
* refactored logfile to get rid of global variables
* removed 'app' global variable
* linter fixes
* fixed password_*.go build
* fixed BSD build
2021-05-03 10:28:00 -07:00
Jarek Kowalski
f4347886b8 logging: simplified log levels (#954)
Removed Warning, Notify and Fatal:

* `Warning` => `Error` or `Info`
* `Notify` => `Info`
* `Fatal` was never used.

Note that --log-level=warning is still supported for backwards
compatibility, but it is the same as --log-level=error.

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-04-09 07:27:35 -07:00
Jarek Kowalski
59eea8b011 user: validate that usernames in repository are all-lowercase formatted as user@hostname (#873)
* user: validate that usernames in repository are all-lowercase and user@hostname-without-domain
* user: relaxed validation to allow -, _ and . in username and hostname
2021-03-09 14:27:48 -08:00
Jarek Kowalski
d9b58fb6e2 linter: upgraded to 1.37.1 (#846) 2021-02-20 11:34:14 -08:00
Jarek Kowalski
5d07237156 Added support for user authentication using user profiles stored in the repository (#809)
* user: added user profile (username&password for authentication) and CRUD methods
* manifest: helpers for disambiguating manifest entries
* authn: added repository-based user authenticator
* cli: added commands to manipulate user accounts and passwords
* cli: added --allow-repository-users option to 'server start'
* Update cli/command_user_info.go

Co-authored-by: Julio López <julio+gh@kasten.io>
* Always return false when the user is not found.
2021-02-03 22:04:05 -08:00