Commit Graph

673 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
3a9bafa366 refactor(general): rename repodiag.logWriteSyncer (#4109)
* refactor(general): clarify comments

* refactor(general): rename `repodiag.logWriteSyncer`

This name reflects:
- the function of the struct; and
- the interface it implements (`zapcore.WriteSyncer`)
2024-09-15 09:34:23 -07:00
Julio López
c936075ab0 refactor(general): rename repodiag.BlobWriter (#4110)
This name reflects the function of the struct / type.

The previous name (`Writer`) conveyed that this type
implemented the `Writer` interface / `Write` function,
which it does not.
2024-09-15 09:33:58 -07:00
Julio López
bdbdd404d9 refactor(server): relocate user.getPasswordHashAlgorithm (#4101)
Trivial code movement, no effective code changes.
2024-09-09 17:00:07 -07:00
Jarek Kowalski
ac446a2d16 chore(ci): upgraded linter to 1.60.3 (#4086)
* silenced several 'gosec' findings
2024-09-03 21:29:56 -07:00
Julio López
d37de8316e refactor(general): generalize units package (#4075)
Generalize a couple of functions in the units package using generics.
This allows removing duplicate code and simplifying callers by removing unnecessary integer conversions.

Additional cleanups:

- make "/s" part of the Printf format string ;
- simplify setSizeMBParameter;
- generalize cli.maybeHumanReadable*` helpers;
- remove unneeded receiver in commandRepositorySetParameters helpers.
2024-08-26 17:26:32 -07:00
Julio López
948162dce5 refactor(general): minor miscellaneous cleanups (#4074)
Cleanups:

- use non-format variants of Log/Print with no additional args;
- fold in Fprintf call with no args into the following one;
- add missing arg placeholder in format strings;
- use require.Positive instead of Greater(..., 0);
- rename function to fillWithZeros to avoid collision with builtin clear;
- define type for context key to avoid collisions.
2024-08-25 22:10:46 -07:00
dependabot[bot]
b7074f76bf build(deps): bump github.com/prometheus/client_golang (#4070)
Bumps the telemetry-dependencies group with 1 update in the / directory: [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang).


Updates `github.com/prometheus/client_golang` from 1.19.1 to 1.20.1
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/v1.20.1/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.19.1...v1.20.1)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: telemetry-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-08-24 04:44:35 +00: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
c262998173 chore(general): misc cleanups (#3982)
* chore(general): remove unused `Behavior` type
* chore(test): leverage `testutil.ServerParameters` in server test
2024-07-11 17:18:44 -07:00
Julio López
1f9f9a1846 chore(general): use non-formatting log variants when there is no formatting (#3931)
Use non-formatting logging functions for message without formatting.
For example, `log.Info("message")` instead of `log.Infof("message")`

Configure linter for printf-like functions
2024-06-18 23:13:17 -07:00
Julio López
4786ab3cbb refactor(general): remove no-longer used functions and tests (#3924)
Followup cleanup for #3919

All the changes are in the `epoch` package

Summary:
- Removal of now unused code and tests.
- Refactoring to simplify test and remove a linter annotation.
- Fix a typo
2024-06-18 12:24:56 -07:00
Julio López
2a79224a33 fix(general): relax epoch compaction check for contiguous ranges (#3919)
While the current implementation should not produce non-contiguous
ranges, this invariant check may be too stringent, in particular for
repositories created and mutated by older kopia (client) processes.

For backwards compatibility the check is relaxed to allow operations to
proceed in older repositories.
2024-06-17 16:25:47 -07:00
Julio López
adedd1ea45 fix(general): avoid panic on computing password hash error (#3907)
Rationale: this code path is primarily executed from the server. A
potential error, say from a corrupt, unsupported or otherwise invalid
user profile should not cause the server to panic (and crash).

It is possible for `computePasswordHash` to return an error, not just an
impossibility.

Test refactoring:
- use 'require' in user profile tests;
- move test case to TestBadPasswordHashVersion;
- update comments in test.
2024-06-07 13:00:44 -07:00
Julio López
d9b2aab8b9 fix(general): add parameter to log message (#3904) 2024-06-06 13:44:48 -07:00
Julio López
68ffb41db8 refactor(server): initialize dummy hash with non-zero value (#3892)
Motivation: avoid making accidental decisions based on all-zeros content
in the future.

While the dummy hash is a non-zero-value slice, that is it is non-empty
(thus not nil), it is still the default value produced by
`make([]byte, salt + hashLength)`, and it is possible to accidentally
compare and have a positive match against a newly initialized slice.
2024-06-05 16:46:29 -07:00
Jarek Kowalski
fcb8197f3f chore(ci): upgraded linter to 1.59.0 (#3883) 2024-05-29 20:31:57 -07:00
Julio López
7fd6e5912f chore(cli): cleanup user profile errors (#3889) 2024-05-29 18:02:14 -07:00
Sirish Bathina
05fedcff60 fix(general): change pbkdf2 min salt length to 16 bytes (#3864)
Changing the minimum salt length of Pbkdf2 key derivation
algorithm to the NIST recommended minimum of 16 bytes.

This matches the minimum salt for scrypt-based key derivation.
2024-05-13 15:10:37 -07:00
Mark Severson
3fcdb9b185 refactor(general): avoid using empty master keys (#3835)
Previously, empty master keys were passed to the underlying
cryptographic primitives (HKDF, AEAD, etc.).

While this worked because the authentication mechanisms returned an
error, it's best to avoid passing empty master keys to these primitives
in the first place. This refactor avoids passing empty master keys and
enforces this via an assertion in the key derivation function.
2024-05-01 14:50:01 -07:00
Julio López
ad06bb20b1 refactor(general): remove ability to enable compaction on index load (#3834)
Cleanup.

- Fixes: #3638
- #3639
2024-05-01 14:33:46 -07:00
Julio López
065e0adbfd refactor(general): make key derivers available in tests (#3826)
- Re-introduces the **insecure**, lightweight key deriver for
  testing **only**.
- Makes `scrypt` and `pbkdf2` derivers available in tests as well.
2024-04-30 17:21:11 -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
Julio López
2db8b20ed9 chore(general): rename files for consistency (#3825) 2024-04-26 14:47:36 -07:00
Sirish Bathina
1e98511c2e feat(general): key derivation algorithm for cache encryption (#3799)
Add an option to select the password-based key derivation algorithm
for the local cache encryption key when connecting to a kopia
repository server.
2024-04-25 17:45:12 -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
Julio López
17c3a8d4de refactor(general): include parameters in pbkdf2 instantiation (#3811)
Use `pbkdf2-sha256-600000` as the name to be consistent with the scrypt
instantiation.

The format is `pbkdf2-<hash_type>-<number_of_iterations>`
2024-04-19 15:50:45 -07:00
Julio López
ff9f6a8325 refactor(general): change default number of iterations for PBKDF2 (#3810)
Use the value recommended by NIST
2024-04-19 15:27:38 -07:00
Jarek Kowalski
211e28c98c chore(repository): BREAKING CHANGE remove support for HTTP-based repository API (#3745)
Remove support for HTTP-based repository API
2024-04-17 16:23:58 -07:00
Jarek Kowalski
b55d5b474c refactor(repository): refactored internal index read API to reduce memory allocations (#3754)
* refactor(repository): refactored internal index read API to reduce memory allocations

* fixed stress test flake, improved debuggability

* fixed spurious checklocks failures

* post-merge fixes

* pr feedback
2024-04-12 22:59:11 -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
Jarek Kowalski
123927d573 fix(server): fixed deadlock between server and scheduler during shutdown (#3782) 2024-04-09 22:37:50 -07:00
Jarek Kowalski
09415e0c7d chore(ci): upgraded to go 1.22 (#3746)
Upgrades go to 1.22 and switches to new-style for loops

---------

Co-authored-by: Julio López <1953782+julio-lopez@users.noreply.github.com>
2024-04-08 09:52:47 -07:00
lvyaoting
67f87a5450 chore(general): fix function names in comment (#3786)
Signed-off-by: lvyaoting <lvyaoting@outlook.com>
2024-04-07 21:33:33 -07:00
Christoph Anderson
db5d868b5f feat(ui): Add language support for kopiaUI (#3768)
* Add multi-language support

* Adding a guidline to outline the localisation process.

* Moved doc to separate pr

---------

Co-authored-by: lupusA <lupuapps@gmail.com>
2024-04-06 05:10:11 +00:00
Aaron Alpar
2994179025 comment fixes (#3775) 2024-04-04 13:56:39 -07:00
Matthieu MOREL
5c85ca6bb0 refactor(deps): migrate from go.uber.org/multierr to standard errors (#3761)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-04-01 23:16:20 -07:00
Aaron Alpar
a4260e0185 fix(providers): Reduce memory allocation (gc thrash) (#3695)
Avoid minio allocations by implementing `ReadAt` function.
This change causes Minio libraries to reduce memory allocations.
Specifically, buffer allocations for S3 upload.
Add tests for new functionality.

---------

Co-authored-by: Shikhar Mall <shikhar.mall@veeam.com>
Co-authored-by: Nick <nick@kasten.io>
2024-04-01 15:10:27 -07:00
Julio López
e600c15b6b fix(general): disable writes on index loads (#3646)
Change default 'allowWritesOnIndexLoad' to false when env var is unset
Add TestNoEpochAdvanceOnIndexRead

Ref:
- Followup to #3645
- Avoid index (epoch) cleanup and compaction during index reads #3638
- Make "read" commands/operations really read-only.  #3639
2024-03-31 22:27:49 -07:00
Julio López
522209369c refactor(test): explicitly advance epoch in TestMaybeCompactSingleEpoch_CompactionError (#3755)
Ref:
- #3638
2024-03-27 12:49:53 -07:00
Jarek Kowalski
7278f570e2 chore(ci): upgraded linter to 1.57.1 (#3753) 2024-03-25 22:20:38 -07:00
Julio López
fdb6d3c097 refactor(general): add epoch.Manager.MaybeGenerateRangeCheckpoint (#3727)
* epoch manager: factor out getRangeToCompact
* epoch manager: add epoch.Manager.MaybeGenerateRangeCheckpoint
* test epoch.Manager.MaybeGenerateRangeCheckpoint
2024-03-22 15:29:11 -07:00
Julio López
f8352275ba refactor(general): add epoch.Manager.CleanupMarkers (#3726)
Includes tests for CleanupMarkers
2024-03-19 18:35:29 -07:00
Julio López
6236ff7fba refactor(general): add epoch.Manager.MaybeCompactSingleEpoch (#3728)
Add:
- epoch.Manager.MaybeCompactSingleEpoch
- getCompactedEpochRange helper
- oldestUncompactedEpoch helper
- TestOldestUncompactedEpoch
- Tests for MaybeCompactSingleEpoch

Ref:
- Subset and dependency of #3651
- Depends on #3735
- Avoid index (epoch) cleanup and compaction during index reads #3638
- Make "read" commands/operations really read-only.  #3639
2024-03-19 17:46:45 -07:00
Julio López
316356a031 refactor(general): closedIntRange (#3735)
Refactoring for the original implementation with intRange and
getKeyRange from closed-open ranges [lo, hi) to closed ranges: [lo, hi].
The primary motivation is for consistency with the implementation
of epoch.RangeMetadata in the same package, and thus avoid
confusion and reduce cognitive load.

Changes:

- adds a getContiguousKeyRange wrapper that checks for contiguity.
- getKeyRange simply returns a range with minimum and maximum
  values for the keys in the map.
- changes the range implementation from closed-open ranges [lo, hi)
   to closed ranges: [lo, hi] where both lo and hi are included in the range.
- Additional unit tests are included.
- renames intRange to closedIntRange to reflect new functionality.

Ref:
- Follow up refactor(general): add epoch.getKeyRange helper #3721
- Needed for refactor(general): add epoch.Manager.MaybeCompactSingleEpoch #3728
- Avoid index (epoch) cleanup and compaction during index reads #3638
2024-03-18 22:58:16 -07:00
Sirish Bathina
4ea6cf98d1 update min salt size to 16 (#3732) 2024-03-13 15:02:33 -07:00
Nick
8647f71299 fix(cli): Output error msg returned by API server payload when possible (#3724)
Updates unit test expected error output
2024-03-13 18:29:50 +00:00
Sirish Bathina
ddcdfdb55a changes for switching key derivation (#3725) 2024-03-13 00:34:46 +00:00
Julio López
4a06623eb6 refactor(general): add clarification comment (#3723)
Followup to #3721

Co-authored-by: Nick <nick@kasten.io>
2024-03-12 11:52:25 -07:00
Julio López
e143c71e6d refactor(general): add epoch.getKeyRange helper (#3721)
Extracted from #3651.

Thanks to @plar and @redgoat650 for the suggestions.

Ref:

- #3603
- #3645
- #3638
- #3639
2024-03-12 11:05:50 -07:00