Commit Graph

399 Commits

Author SHA1 Message Date
Jarek Kowalski
b60cac4860 fix(cli): fixed v0.18.0 failures using v0.17.0-generated config (#4255)
This was caused by the client using key derivation algorithm
from a config file (which did not have it when it was generated
using old version of Kopia).

Fixes #4254
2024-11-17 10:15:00 -08:00
Jarek Kowalski
eb1cf64c27 chore(ci): upgraded linter to 1.62.0 (#4250) 2024-11-16 07:16:50 -08:00
Jarek Kowalski
32b9b43a4a fix(ci): fix kopia-ui-test race (#4251)
* fix(test): fix kopia-ui-test race

* fix htmlui_e2e_test
2024-11-15 23:40:36 -08:00
Julio López
ccc84fb00d test(cli): prefer require in cli_test_env (#4200)
Facilitates troubleshooting test failures.
2024-10-25 13:21:59 -07:00
Julio López
eb2ea5dddd test(server): speedup cert key generation in server tests (#4166)
Use shorter key size to speed up cert generation in TestServerStartInsecure.

Refactor: add const for default server-control username.
2024-10-10 10:22:34 -07:00
Jarek Kowalski
c0bd372d29 feat(cli): support for defining notification profiles and templates via CLI (#4034)
* feat(cli): support for defining notification profiles via CLI

Profile management:

```
$ kopia notification profile configure email \
    --profile-name=X \
    --smtp-server=smtp.gmail.com \
    --smtp-port=587 \
    --smtp-username=X \
    --smtp-password=X \
    --mail-from=X \
    --mail-to=X \
    --format=html|txt \
    [--send-test-notification]

$ kopia notification profile configure pushover --profile-name=X \
    --user-key=X \
    --app-token=X \
    --format=html|txt \
    [--send-test-notification]

$ kopia notification profile configure webhook --profile-name=X \
    --endpooint=http://some-address:port/path \
    --method=POST|PUT \
    --format=html|txt \
    [--send-test-notification]

$ kopia notification profile test --profile-name=X

$ kopia notification profile delete --profile-name=X

$ kopia notification profile list
```

Template management:

```
$ kopia notification template show X

$ kopia notification template set X \
   --from-stdin | --from-file=X | --editor

$ kopia notification template remove X

$ kopia notification template list

```

Implements #1958

* additional refactoring for testability, various naming tweaks
2024-10-06 16:28:39 +00:00
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
5dbc8a478a refactor(general): minor cleanups (#4003)
Followups to #3655

* wrap fs.Reader
* nit: remove unnecessary intermediate variable
* nit: rename local variable
* cleanup: move restore.Progress interface to cli pkg
* move cliRestoreProgress to a separate file
* refactor(general): replace switch with if/else for clarity
  Removes a tautology for `err == nil`, which was guaranteed
  to be true in the second case statement for the switch.
  Replacing the switch statement with and if/else block is clearer.
* initialize restoreProgress in restore command
* fix: use error.Wrapf with format string and args


Simplify SetCounters signature:

Pass arguments in a `restore.Stats` struct.
  `SetCounters(s restore.Stats)`
Simplifies call sites and implementation.
In this case it makes sense to pass all the values
using the restore.Stats struct as it simplifies
the calls.
However, this pattern should be avoided in general
as it essentially makes all the arguments "optional".
This makes it easy to miss setting a value and simply
passing 0 (the default value), thus it becomes error
prone.
In this particular case, the struct is being passed
through verbatim, thus eliminating the risk of
missing a value, at least in the current state of
the code.
2024-08-27 09:42:58 -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
chaitalisg
b3e088d66a test(general): log dir paths and size in robustness tests (#3973)
Log the paths and the sizes for the cache directories in
multi-client robustness jobs.
2024-07-19 22:58:23 -07:00
Julio López
b980d11c42 refactor(general): setCacheSizeHardLimit helper in robustness (#3990) 2024-07-18 23:59:58 -07:00
chaitalisg
b0814ee3ff fix(test): allow delete random snapshot action (#3987)
Addresses failure introduced in #3963

Change: allow `delete-random-snapID` action in the function `tryDeleteAction`.
Test: Manual local run was successful.
2024-07-16 13:25:24 -07:00
chaitalisg
de298566ea test(general): add delete random snapshot action to robustness tests (#3963)
---------
Co-authored-by: Julio López <1953782+julio-lopez@users.noreply.github.com>
2024-07-15 19:35:25 -07:00
chaitalisg
00495c73ea test(general): set cache size limits for the repository under test used in robustness tests (#3945)
The robustness tests set soft limits for content cache size
and metadata cache size. This PR adds the hard limits for
both the caches, thus reducing the memory required to
run the robustness tests for long term.
2024-07-15 14:06:36 -07:00
chaitalisg
2ec9bbe43c test(general): set cache size limits for metadata repo (#3952)
The soft limits are set for content cache and metadata cache.
This may cause the cache to bloat beyond expectations.
Setting hard limits for the size would keep the cache bloat in
check, thus reducing the memory needed to required to run
the robustness tests over a long time.

---------

Co-authored-by: Julio López <1953782+julio-lopez@users.noreply.github.com>
2024-07-15 13:50:55 -07:00
Julio López
ae9f1c734b fix(server): ensure repo disconnection on server start exit (#3980)
Ensure repository disconnection at the end of the `server start` CLI command.
This was caught as a result of fixing the test below.

Fix `TestServerStartInsecure`:
Remove `--password=xxx` parameter, which causes a server start failure
due to incorrect repo password, and not for the case being checked,
which is the lack of the `--insecure` parameter.

Update test comments accordingly.
2024-07-11 18:51:12 -07:00
chaitalisg
3801e59475 test(general): run maintenance action in robustness (#3927)
Adds the maintenance action to multi-client robustness jobs.
The robustness jobs do not run a maintenance action until now.
---------
Co-authored-by: Julio López <1953782+julio-lopez@users.noreply.github.com>
2024-07-03 20:34:50 -07:00
chaitalisg
e7aa37cce3 test(general): ignore dir not found error during delete action in robustness tests (#3944)
The robustness tests perform delete actions on random subdirectories and
files. If the actions encounter `directory not found` error, the framework 
returns a `no-op` error. 

This change ignores the `no-op` errors specifically for "delete" actions.
This change will reduce the failure frequency when a delete actions on the
source directory result in a no-op.
2024-06-28 16:33:16 -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
chaitalisg
7514a3563f test(general): reduce the file write weight (#3929)
The robustness test `TestRandomizedSmall` generate file action gets
picked up four to eight times more frequently than the other actions.
This PR reduces the frequency of the file generation action so that the
test is more representative of the user workflow.
2024-06-18 13:59:48 -07:00
chaitalisg
4f09136c0c test(general): add delete actions to robustness suite (#3879)
The robustness framework runs do not cover delete actions at the moment. 

This change adds the following actions to the robustness jobs
- delete random subdirectories
- delete contents of directories
2024-06-17 12:20:25 -07:00
Jarek Kowalski
fcb8197f3f chore(ci): upgraded linter to 1.59.0 (#3883) 2024-05-29 20:31:57 -07:00
Eugene Sumin
2b92388286 refactor(general): Increase restore progress granularity (#3655)
When restoring huge file(s), the progress reporting is done in a bit
weird way:

```
kopia_test % kopia snapshot restore ka2084d263182164b6cf3456668e6b6da /Users/eugen.sumin/kopia_test/2
Restoring to local filesystem (/Users/eugen.sumin/kopia_test/2) with parallelism=8...
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.6 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.6 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.6 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.5 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.5 MB/s (100.0%) remaining 0s.
Processed 6 (5.4 GB) of 5 (5.4 GB) 1.5 MB/s (100.0%) remaining 0s.
Restored 5 files, 1 directories and 0 symbolic links (5.4 GB).
```
In fact, the amount of restored data is dumped when particular file
completely restored.

This PR contains the least invasive change, which allows us to see
progress update while file is downloaded from object storage.
```
Restoring to local filesystem (/Users/eugen.sumin/kopia_test/55) with parallelism=8...
Processed 2 (3.1 MB) of 5 (1.8 GB).
Processed 4 (459.6 MB) of 5 (1.8 GB) 270.3 MB/s (25.2%) remaining 4s.
Processed 4 (468.7 MB) of 5 (1.8 GB) 269 MB/s (25.7%) remaining 4s.
Processed 4 (741.6 MB) of 5 (1.8 GB) 269 MB/s (40.6%) remaining 3s.
Processed 4 (1.1 GB) of 5 (1.8 GB) 280 MB/s (57.6%) remaining 2s.
Processed 5 (1.4 GB) of 5 (1.8 GB) 291.1 MB/s (75.2%) remaining 1s.
Processed 5 (1.4 GB) of 5 (1.8 GB) 289.8 MB/s (75.6%) remaining 1s.
Processed 5 (1.6 GB) of 5 (1.8 GB) 270.2 MB/s (85.3%) remaining 0s.
Processed 5 (1.7 GB) of 5 (1.8 GB) 256.3 MB/s (95.0%) remaining 0s.
Processed 6 (1.8 GB) of 5 (1.8 GB) 251 MB/s (100.0%) remaining 0s.
Processed 6 (1.8 GB) of 5 (1.8 GB) 251 MB/s (100.0%) remaining 0s.
Restored 5 files, 1 directories and 0 symbolic links (1.8 GB).
```

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2024-05-10 09:47:13 -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
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
c71f57d83c feat(general): allow setting key derivation algorithm for format blob (#3779)
Adds support to set the algorithm to derive the key used to encrypt
the repository format blob.
2024-04-24 14:07:19 -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
coderwander
f125f09ddc chore: fix some typos in comments (#3805)
Signed-off-by: coderwander <770732124@qq.com>
2024-04-16 14:48:03 -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
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
NickIAm
3da0473219 fix(cli): restore objects with I prefix fails (#3062)
* Fix restoring objects with I prefix
set default of snapshot-time to 'latest' as noted in the help output

* Change test of restore to check it works without a time given
This is because --snapshot-time defaults to "latest" now.
2024-03-26 21:03:46 -07:00
Nick
8c081add53 chore(server): Disable legacy API by default (#3730) 2024-03-13 11:11:09 -07:00
Jarek Kowalski
fb8d9c3bf8 chore(deps): removed direct deprecated protobuf dependency (#3720) 2024-03-11 21:47:14 -07:00
Jarek Kowalski
29cd545c33 chore(ci): upgrade linter to 1.56.2 (#3714) 2024-03-09 10:39:11 -08:00
chaitalisg
c07fb8b14f test(general): Increase timeout to check for generated TLS cert (#3696)
* add debug messages

* increase wait time for tls cert

* add error messages for easier debugging

* Update tests/tools/kopiarunner/kopia_snapshotter.go

Co-authored-by: Nick <nick@kasten.io>

* add comment

---------

Co-authored-by: Nick <nick@kasten.io>
2024-03-05 22:54:39 +00:00
Aaron Alpar
769d5f3a50 fix(ci): fix shadow-copy test (#3629)
Followup for #3624
Fixes #3628

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2024-02-06 20:51:55 -08:00
Maxim Khitrov
f62ef51700 feat(snapshots): Implement volume shadow copy support on Windows (#3543)
* Implement volume shadow copy support on Windows

* Update go-vss version

* Fix unused variables

* Rename upload_actions*.go files

* Move vss settings to a separate policy section

* Handle existing shadow copy root

* Fix tests

* Fix lint issues

* Add cli policy test

* Add OS snapshot integration test

* Add GitHub Actions VSS test

* Fix "Incorrect function" error for root VSS snapshots

* Rename err to finalErr in createOSSnapshot

* Add OSSnapshotMode test

* Do not modify paths starting with \\?\ on Windows

* Allow warning messages in logfile tests

* Fix ignorefs not wrapping OS snapshot directory

* Retry VSS creation if another op was in progress

---------

Co-authored-by: Jarek Kowalski <jaak@jkowalski.net>
2024-02-03 21:44:41 -08:00
Jarek Kowalski
3fed193051 fix(ci): fixed HTMLUI E2E test by switching to macOS runner (#3613)
* fix(test): fixed HTMLUI E2E test

* switched runner to macOS
2024-02-03 15:41:25 -08:00
Jarek Kowalski
a8e4d50600 build(deps): upgraded linter to v1.55.2, fixed warnings (#3611)
* build(deps): upgraded linter to v1.55.2, fixed warnings

* removed unsafe hacks with better equivalents

* test fixes
2024-02-02 23:34:34 -08:00
Julio Lopez
c56d330383 feat(cli): handle SIGTERM (#3562)
* refactor(test): allow signaling sub-process from testenv.CLIExeRunner
* test(cli): add test for handling SIGTERM
* feat(general): catch and process SIGTERM for termination
* refactor(cli): rename function cli.App.onTerminate
  Renames function from onCtrlC to a more generic onTerminate
2024-01-11 18:02:31 -08:00
Julio Lopez
ef803b2185 nit: simplify block (#3528)
Fix typo as well

Followup to #3462
2023-12-19 14:01:54 -08:00
Aaron Alpar
f3a621dbf8 bug(test): Fixup error output when server startup fails in robustness test (#3462)
* add logging to failed server start

* fixup for lint
2023-11-22 22:24:17 +00:00
Jarek Kowalski
3eff91a49b fix(ui): Fixing colors in dark theme (#3392)
* fix(ui): Fixing colors in dark theme

* fixed test

* pickup latest htmluibuild
2023-10-17 22:33:54 -07:00
Jarek Kowalski
7ee30b76bb fix(repository): fixed handling of content.Info (#3356)
* fix(repository): fixed handling of content.Info

Previously content.Info was an interface which was implemented by:

* index.InfoStruct
* index.indexEntryInfoV1
* index.indexEntryInfoV2

The last 2 implementations were relying on memory-mapped files
which in rare cases could be closed while Kopia was still processing
them leading to #2599.

This changes fixes the bug and strictly separates content.Info (which
is now always a struct) from the other two (which were renamed as
index.InfoReader and only used inside repo/content/...).

In addition to being safer, this _should_ reduce memory allocations.

* reduce the size of content.Info with proper alignment.

* pr feedback

* renamed index.InfoStruct to index.Info
2023-10-14 10:34:15 -07:00
PhracturedBlue
0f608ff18c test(cli): Attempt to fix socket-activated tests (#3318) 2023-09-18 21:47:39 -07:00
Jarek Kowalski
af1550ad81 feat(server): reduce server refreshes of the repository (#3265)
* feat(server): reduce server refreshes of the repository

Previously each source would refresh itself from the repository
very frequently to determine the upcoming snapshot time. This change
refactors source manager so it does not own the repository connection
on its own but instead delegates all policy reads through the server.

Also introduces a new server scheduler that is responsible for
centrally managing the snapshot schedule and triggering snapshots
when they are due.

* Update cli/command_server_start.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* Update internal/server/server.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* Update internal/server/server_maintenance.go

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>

* pr feedback

---------

Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
2023-09-15 12:08:35 -07:00
Jarek Kowalski
044db7593b feat(repository): apply retention policies server-side (#3249)
* feat(repository): apply retention policies server-side

This allows append-only snapshots where the client can never delete
arbitrary manifests and policies are maintained on the server.

The client only needs permissions to create snapshots in a given, which
automatically gives them permission to invoke the server-side method
for their own snapshots only.

* Update cli/command_acl_add.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/api_manifest.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/api_manifest.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

* Update internal/server/grpc_session.go

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>

---------

Co-authored-by: Guillaume <Gui13@users.noreply.github.com>
2023-09-02 18:23:21 -07:00
Julio Lopez
1320f0c8e8 chore(general): remove unnecessary //nolint directives (#3256) 2023-08-29 12:40:40 -07:00