Commit Graph

311 Commits

Author SHA1 Message Date
Jarek Kowalski
ddd267accc crypto: deprecated crypto algorithms and replaced with better alternatives
New ciphers are using authenticated encryption with associated data
(AEAD) and per-content key derived using HMAC-SHA256:

* AES256-GCM-HMAC-SHA256
* CHACHA20-POLY1305-HMAC-SHA256

They support content IDs of arbitrary length and are quite fast:

On my 2019 MBP:

- BLAKE2B-256 + AES256-GCM-HMAC-SHA256 - 648.7 MiB / second
- BLAKE2B-256 + CHACHA20-POLY1305-HMAC-SHA256 - 597.1 MiB / second
- HMAC-SHA256 + AES256-GCM-HMAC-SHA256 351 MiB / second
- HMAC-SHA256 + CHACHA20-POLY1305-HMAC-SHA256 316.2 MiB / second

Previous ciphers had several subtle issues:

* SALSA20 encryption, used weak nonce (64 bit prefix of content ID),
  which means that for any two contents, whose IDs that have the same
  64-bit prefix, their plaintext can be decoded from the ciphertext
  alone.

* AES-{128,192,256}-CTR were not authenticated, so we were
  required to hash plaintext after decryption to validate. This is not
  recommended due to possibility of subtle timing attacks if an attacker
  controls the ciphertext.

* SALSA20-HMAC was only validating checksum and not that the ciphertext
  was for the correct content ID.

New repositories cannot be created using deprecated ciphers, but they
will still be supported for existing repositories, until at least 0.6.0.

The users are encouraged to migrate to one of new ciphers when 0.5.0 is
out.
2020-02-29 20:50:50 -08:00
Jarek Kowalski
d181403284 crypto: refactored encryption, hashing and splitter into separate packages (#274)
Added some tests, deleted XSALSA20 which never worked E2E
2020-02-27 12:36:49 -08:00
Jarek Kowalski
765bff8e0b cli: restored snapshot create --hostname and --username flags 2020-02-25 20:40:23 -08:00
Jarek Kowalski
e3854f7773 BREAKING: changed how hostname/username are handled
The hostname/username are now persisted when connecting to repository
in a local config file.

This prevents weird behavior changes when hostname is suddenly changed,
such as when moving between networks.

repo.Repository will now expose Hostname/Username properties which
are always guarnateed to be set, and are used throughout.

Removed --hostname/--username overrides when taking snapshot et.al.
2020-02-25 20:40:23 -08:00
Jarek Kowalski
c8fcae93aa logging: refactored logging
This is mostly mechanical and changes how loggers are instantiated.

Logger is now associated with a context, passed around all methods,
(most methods had ctx, but had to add it in a few missing places).

By default Kopia does not produce any logs, but it can be overridden,
either locally for a nested context, by calling

ctx = logging.WithLogger(ctx, newLoggerFunc)

To override logs globally, call logging.SetDefaultLogger(newLoggerFunc)

This refactoring allowed removing dependency from Kopia repo
and go-logging library (the CLI still uses it, though).

It is now also possible to have all test methods emit logs using
t.Logf() so that they show up in failure reports, which should make
debugging of test failures suck less.
2020-02-25 17:24:44 -08:00
Prasad Ghangal
c682fffdf2 Support for Azure blob storage (#271)
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
2020-02-25 16:32:26 -08:00
Jarek Kowalski
897483299f Kopia UI & CLI: support for progress indicator (#268)
Percentage based on last-known snapshot size

* server: exposed last completed snapshot size in the API
* cli: added support for progress indicator (percentage based on last-known snapshot size)
* htmlui: added progress indicator in the UI (percentage based on last-known snapshot size)
2020-02-24 17:55:02 -08:00
Jarek Kowalski
f8006f8ce0 cli: removed flags for configuring global policy on repository creation 2020-02-18 12:21:11 -08:00
Jarek Kowalski
a21da7b960 cli: fixed double-close of repository during 'server start' 2020-02-16 22:43:36 -08:00
Jarek Kowalski
0f79279f5e server: added support for new verbs in the API
/api/v1/repo/create
/api/v1/repo/connect
/api/v1/repo/disconnect

Refactored server code and fixed a number of outstanding robustness
issues. Tweaked the API responses a bit to make more sense when consumed
by the UI.
2020-02-13 17:23:50 -08:00
Prasad Ghangal
1c3858a906 Add AWS Session Token support to Kopia
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
2020-02-12 08:19:24 -08:00
Jarek Kowalski
a8503a007c server: allow starting server on randomly-allocated port by specifing port 0 (#224)
allow starting server on randomly-allocated port by specifing port 0
2020-02-11 17:08:50 -08:00
Jarek Kowalski
862fc69bff cli: marked --ignore-{file,dir}-errors as enums, so that CLI parser enforces correct values 2020-02-11 06:41:20 -08:00
Nick
162db3e861 [minor] Fix error handling policy print (#221)
Fixes print for error handling policy. Previously was printing
pointer address, now dereference pointer to print boolean itself.
Nil check in case the caller passes a policy with nil. In that
case print "false" which is the behavior in uploader for nil
pointer.
2020-02-10 20:22:55 -08:00
Jarek Kowalski
4736e9037e revamped progress output and cleaned up logging
See https://asciinema.org/a/ykx6uzEhKY3451fWEnX9nm9uo
2020-02-10 19:08:35 -08:00
Nick
1a24c34df8 Ignore read errors based on policy settings (#207)
* Ignore read errors based on policy settings

Added an error handling policy section. Can independently control error handling for directory and file read errors, toggle-able from the `policy set` command to either "true", "false", or "inherit". If any read error is hit, the error handling will check the effective policy on whether to ignore it or not. Currently there is no differentiation between read error types, though in the future we may want to add the `errors.Is(err, os.ErrPermission)` conditional.

Fix was implemented such that the policy ignores read errors ONLY on child entries of the source. So a snapshot will still fail if the source root directory itself can't be read, but you can ignore the error if a file or a subdirectory in the snapshot source root can't be read. I did this to address some otherwise strange behavior where you would successfully snapshot (because you ignored the error), but couldn't restore that snapshot because nothing really happened during the operation.
2020-02-10 17:35:53 -08:00
Jarek Kowalski
edca1733b6 repo: moved password persistence to repository layer 2020-02-09 20:55:07 -08:00
Julio Lopez
4625e5ba9e Remove content.CompactOptions.MinSmallBlobs
Use MaxSmallBlobs instead. MaxSmallBlobs was not being really used.
Replaced uses of MinSmallBlobs with MaxSmallBlobs and removed
MinSmallBlobs
2020-02-06 21:51:51 -08:00
Jarek Kowalski
0a42ceab27 gcs: added --embed-credentials options which persists --credentials-file as part of Kopia configuration 2020-02-04 22:35:26 -08:00
Jarek Kowalski
9680dc376b cli: improvements for 'kopia server' and client
Those will make it possible to securely host 'kopia server' embedded
in a desktop app that runs in the background and can access UI.

- added support for using and generating TLS certificates
- added /api/v1/shutdown API to remotely trigger server shutdown
- added support for automatically shutting down server if no requests
  arrive in certain amount of time
- added support for generating and printing random password to STDERR

TLS supports 3 modes:

1. serve TLS using externally-provided cert/key PEM files
2. generate & write PEM files, then serve TLS using them
3. generate and use emphemeral cert/key (prints SHA256 fingerprint)
2020-01-24 17:25:45 -08:00
Nick
3913241159 [Trivial] Fix command description for blob delete
Fix probable copy paste error on "blob delete" subcommand from
the "blob show" description.
2020-01-20 21:28:44 -08:00
Jarek Kowalski
644ef93d45 s3: added optional --region parameter
Fixes #168
2020-01-09 16:37:36 -08:00
Jarek Kowalski
ac70a38101 lint: upgraded to 1.22.2 and make lint issues a build failure
fixed or silenced linter warnings, mostly due to magic numeric constants
2020-01-03 16:39:30 -08:00
Julio Lopez
ac6e84107e Add CopyOptions and copier structs 2020-01-02 13:49:28 -08:00
Julio Lopez
20b896da18 Add restore command flags 2020-01-02 13:49:28 -08:00
Julio Lopez
c03a143ae9 Fix flag description 2020-01-02 09:50:45 -08:00
Julio Lopez
194680adfc Refactor: relocate user/host helpers to userhost.go 2019-12-18 23:11:38 -08:00
Julio Lopez
0b7f30b6b4 rename cli/snapshot_utils.go -> cli/userhost.go 2019-12-18 23:11:38 -08:00
Julio Lopez
c8360ce6ca cleanup: fix linter errors
```
make lint
kopia/tools/.tools/bin/golangci-lint --deadline 180s run | tee .linterr.txt
cli/command_snapshot_delete.go:5: File is not `goimports`-ed with -local github.com/kopia/kopia (goimports)

tests/end_to_end_test/end_to_end_test.go:303: Function 'TestSnapshotDelete' is too long (187 > 100) (funlen)
func TestSnapshotDelete(t *testing.T) {
tests/end_to_end_test/end_to_end_test.go:306:2: only one cuddle assignment allowed before range statement (wsl)
	for _, tc := range []struct {
	^
tests/end_to_end_test/end_to_end_test.go:517:4: only one cuddle assignment allowed before if statement (wsl)
			if expectDeleteSucceeds {
			^
tests/end_to_end_test/end_to_end_test.go:537:2: assignments should only be cuddled with other assignments (wsl)
	line := lines[0]
	^
tests/end_to_end_test/end_to_end_test.go:542:2: only one cuddle assignment allowed before if statement (wsl)
	if typeVal != "policy" {
	^
tests/end_to_end_test/end_to_end_test.go:558:2: assignments should only be cuddled with other assignments (wsl)
	restoreDir := filepath.Join(e.dataDir, "restored")
	^
tests/end_to_end_test/end_to_end_test.go:568:2: if statements should only be cuddled with assignments (wsl)
	if got, want := len(si[0].snapshots), 1; got != want {
	^
tests/end_to_end_test/end_to_end_test.go:571:2: assignments should only be cuddled with other assignments (wsl)
	snapID := si[0].snapshots[0].snapshotID
	^
tests/end_to_end_test/end_to_end_test.go:604:2: if statements should only be cuddled with assignments (wsl)
	if len(fileInfo) != 0 {
	^
cli/command_snapshot_delete.go:25:2: only one cuddle assignment allowed before if statement (wsl)
	if err != nil {
	^
cli/command_snapshot_delete.go:36:3: if statements should only be cuddled with assignments (wsl)
		if labels["username"] != getUserName() {
		^
```
2019-12-18 18:17:15 -08:00
Jarek Kowalski
d9d4804dcb server: handle known UI routes specially by serving root index file 2019-12-14 13:10:32 -08:00
Nick
3f721aaf01 Snapshot restore command
Snapshot restore will take a snapshot ID and restore the
associated snapshot to the target path.
- Looks up the manifest with the snapshot ID
- Gets the snapshot root entry
- Copies the snapshot from the root entry to the target path

Because it uses the parent manifest with the copied permissions,
the restored directory will have the permissions of the original
source directory.
2019-12-13 06:18:50 -08:00
Nick
ae3d5610bf Dedicated snapshot delete command to delete by snap ID (#8)
Implemented snapshot delete command. Behaves similarly to manifest rm, but with extra verification steps. 
- Checks that the referenced manifest is of type "snapshot"
- Checks that the ID points to a snapshot, checks that the host name, user name, and path provided by flag or defaults match the source of the snapshot ID. Command will fail if they do not match, except if given --unsafe-ignore-source, which will bypass the associated safety requirement and delete anyway.

Added end to end tests for input combinations, restore in conjunction with delete, and trying to snapshot delete a manifest by ID of a non-snapshot manifest.
2019-12-12 18:02:48 -08:00
Jarek Kowalski
2ba4e83cef moved all compression to separate package and sanitized identifiers 2019-12-10 23:25:28 -08:00
Jarek Kowalski
8ab93e0e2f addressed PR comments 2019-12-10 23:25:28 -08:00
Jarek Kowalski
c057e17379 compression: added support for min/max file sizes eligible for compression 2019-12-10 23:25:28 -08:00
Jarek Kowalski
cfa2eea1e1 object: stop verifying object length in VerifyObject
With compression, the decompressed object length is
not known until we read the content.
2019-12-10 23:25:28 -08:00
Jarek Kowalski
a97b89662d policy: added compression policy 2019-12-10 23:25:28 -08:00
Jarek Kowalski
5ae2da4aea cli: added benchmark compression 2019-12-10 23:25:28 -08:00
Julio Lopez
cb850bc1ff Reformat help message constant to pacify lll linter 2019-12-10 22:22:32 -08:00
Julio Lopez
d3f324f59b Add diff.compareEntry helper to compare attribute entries
- Use it to compare the entry attributes for all entry types.
  Allows comparing differences in file attributes among the
  contents of two directories. This is useful for verifying
  restored contents in end-to-end tests.

- Print message about modified entries only when both entries
  are files and they are being compared.
2019-12-10 22:22:32 -08:00
Pavan Navarathna
fb57e828ad Restore command
Behavior:

- Creates top directory on restore
- Fails when target directories or files already exist
- Allows restoring to local root directory
- Restores of file attributes => mod time, mode, owner info
- Only a directory can be specified as a parameter

Not implemented:

- Restoring attributes of the top folder
- Restoring symlinks
- Restoring a single file
2019-12-10 22:22:32 -08:00
Julio Lopez
887a9180fa Trivial: fix imports grouping 2019-12-10 22:22:32 -08:00
Jarek Kowalski
f6d59608ab upload: require *policy.Tree for each upload 2019-12-07 14:24:57 -08:00
Jarek Kowalski
b68ef7d781 refactored policy types and policy.Getter 2019-12-06 23:53:22 -08:00
Jarek Kowalski
6217df1a87 lint: switched to 1.21 and fixed a ton of whitespace issues discovered
by new wsl linter
2019-11-26 06:49:49 -08:00
Julio Lopez
24f292b719 Cleanup lint: empty lines (via whitespace and wsl linters) 2019-11-22 15:17:40 +09:00
Pavan Navarathna
829742599c [#124] Add optional flags to override hostname and username 2019-11-22 15:15:21 +09:00
Jarek Kowalski
b3e1eab094 server: added --server-username and --server-password to optionally require basic auth for Kopia server 2019-11-20 15:49:40 -08:00
Jarek Kowalski
e8a1eaa9ee htmlui: added experimental HTML-based UI
This is enabled by `kopia server --ui` and can be viewed in a browser
at http://localhost:51515/

Right now it can only list snapshots and policies (barely).
2019-11-20 14:41:38 -08:00
Julio Lopez
91508dac46 Move 'snapshot gc' functionality to gc package
Motivation:
Allow generalizing TreeWalker. See follow-up commit.

Changes:
* [x] Refactoring, no functional changes.
2019-11-06 17:34:28 -08:00