Commit Graph

464 Commits

Author SHA1 Message Date
Jarek Kowalski
f5eb12e8b7 content: introduced content.Crypter (#1112) 2021-06-01 20:12:34 -07:00
Jarek Kowalski
6811f1fae1 cli: optimized 'kopia index recover' by leveraging partial read and parallelism (#1094) 2021-05-23 22:18:31 -07:00
Jarek Kowalski
e15a79474c azure: added support for using SAS Tokens instead of storage keys (#1093)
Fixes #1071
2021-05-22 12:43:55 -07:00
Jarek Kowalski
76490dc361 sftp: ensure key file and known hosts are absolute paths (#1092)
Fixes #1089
2021-05-22 11:17:22 -07:00
Jarek Kowalski
40510c043d Support for content-level compression (#1076)
* cli: added a flag to create repository with v2 index features

* content: plumb through compression.ID parameter to content.Manager.WriteContent()

* content: expose content.Manager.SupportsContentCompression

This allows object manager to decide whether to create compressed object
or let the content manager do it.

* object: if compression is requested and the repo supports it, pass compression ID to the content manager

* cli: show compression status in 'repository status'

* cli: output compression information in 'content list' and 'content stats'

* content: compression and decompression support

* content: unit tests for compression

* object: compression tests

* testing: added integration tests against v2 index

* testing: run all e2e tests with and without content-level compression

* htmlui: added UI for specifying index format on creation

* cli: additional tests for 'content ls' and 'content stats'

* applied pr suggestions
2021-05-22 05:35:27 -07:00
Jarek Kowalski
99b7a6e5d2 unrelated cleanups from PR #1076 (#1091)
* cli: fixed progress estimate for 'snapshot verify'

* content: prevent multiple close of shared content manager

* content: test cleanup
2021-05-21 23:59:14 -07:00
Jarek Kowalski
5179ad2cd2 cli: test + misc improvements (#1083)
* cli: Added --max-examples-per-bucket flag to 'kopia snapshot estimate'

Added and cleaned up a bunch of unit tests.

Fixes #1054

* cli: misc tests to increase code coverage of the cli package

* ci: move code coverage run into separate GH job
2021-05-17 21:47:11 -07:00
Jarek Kowalski
38d01d4c4d compression: added 'lz4' and 'deflate' methods (#1077)
* compression: add mapping from HeaderID to Name

* compression: minor refactoring

* compression: added 'lz4' based on 'github.com/pierrec/lz4'

* compression: added 'deflate' support

* cli: 'kopia benchmark compression' improvements
2021-05-16 14:42:56 -07:00
Jarek Kowalski
30ca3e2e6c Upgraded linter to 1.40.1 (#1072)
* tools: upgraded linter to 1.40.1

* lint: fixed nolintlint vionlations

* lint: disabled tagliatele linter

* lint: fixed remaining warnings
2021-05-15 12:12:34 -07:00
Jarek Kowalski
fcd507a56d Refactored most of the CLI tests to run in-process as opposed to using sub-processes (#1059)
* cli: fixed remaining testability indirections for output and logging

* cli: added cli.RunSubcommand() which is used in testing to execute a subcommand in the same process

* tests: refactored most e2e tests to invoke kopia subcommands in-process

* Makefile: enable code coverage for cli/ and internal/

* testing: pass 'testing' tag to unit tests which uses much faster (insecure) password hashing scheme

* Makefile: push coverage from PRs again

* tests: disable buffer management to reduce memory usage on ARM

* cli: fixed misaligned atomic field on ARMHF

also temporarily fixed statup-time benign race condition when setting
default on the timeZone variable, which is the last global variable.
2021-05-11 22:26:28 -07:00
Jarek Kowalski
41931f21ce repo: refactored password persistence (#1065)
* introduced passwordpersist package which has password persistence
  strategies (keyring, file, none, multiple) with possibility of adding
  more in the future.
* moved all password persistence logic out of 'repo'
* removed global variable repo.EnableKeyRing
2021-05-11 21:53:36 -07:00
Jarek Kowalski
8a2167784d cli: final steps to remove last global variables for password and globalPasswordFromToken (#1056)
* cli: removed globalPassword variable

* cli: remove globalPasswordFromToken variable
2021-05-07 12:43:47 -07: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
Josef Vogt
a56e099f2a Benchmark: Remove superfluous = in printout (#1043) 2021-05-01 11:20:50 -07:00
Sirish Bathina
dd41296f2a Tagging of kopia snapshots and listing of snapshots by tag (#1030) 2021-04-30 06:16:19 -07:00
Jarek Kowalski
df430371b9 Refactored content.Info to be an interface and switched index parsing to be lazy (#1008) 2021-04-27 05:53:52 -07:00
Jarek Kowalski
2062c07259 mechanical field renames (#988)
* content: mechanical rename content.Info.Length -> content.Info.PackedLength
* server: renamed grpc API ContentInfo.length->packed_length (non-breaking)
2021-04-16 22:42:32 -07:00
Julio López
0d12cdc541 cleanup a few nits (#980)
* nit: remove unneeded assignment

* nit: remove unnecessary parameter from optionsFromFlags

Rename function as well.
Remove `opts` parameter since it was always nil.

* nit: remove unused opts parameter from openRepository

* cleanup: remove redundant translateError

* cleanup remove unused blob/providers package
2021-04-13 08:01:29 -07:00
Jarek Kowalski
50fac71a32 cli: fixed password prompt on Windows (#960)
Verified manually.
2021-04-11 09:23:15 -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
4638a6a966 switched progress tracking and ETA computation to time.Now() as it causes fake clock time to run too fast (#953)
* logging: use clock.Now instead of time.Now
* timetrack: centralized computing ETAs for various tasks using real clock (time.Now)
2021-04-08 22:52:35 -07:00
Julio López
81a2783d1f cli: consistent naming for delete command and aliases (#951) 2021-04-06 18:58:10 -07:00
Jarek Kowalski
f8ba160f23 site: updated docs in preparation for 0.8.0-beta4 release 2021-04-02 22:18:44 -07:00
Jarek Kowalski
d07eb9f300 cli: added --safety=full|none flag to maintenance commands (#912)
* cli: added --safety=full|none flag to maintenance commands

This allows selection between safe, high-latency maintenance parameters
which allow concurrent access (`full`) or low-latency which may be
unsafe in certain situations when concurrent Kopia processes are
running.

This is a breaking change for advanced CLI commands, where it removes
timing parameters and replaces them with single `--safety` option.

* 'blob gc'
* 'content rewrite'
* 'snapshot gc'

* pr renames

* maintenance: fixed computation of safe time for --safety=none

* maintenance: improved logging for blob gc

* maintenance: do not rewrite truly short, densely packed packs

* mechanical: pass eventual consistency settle time via CompactOptions

* maintenance: add option to disable eventual consistency time buffers with --safety=none

* maintenance: trigger flush at the end of snapshot gc

* maintenance: reload indexes after compaction that drops deleted entries, this allows single-pass maintenance with --safety=none to delete all unused blobs

* testing: allow debugging of integration tests inside VSCode

* testing: added end-to-end maintenance test that verifies that full maintenance with --safety=none removes all data
2021-04-02 21:56:01 -07:00
Jarek Kowalski
9a128ffb9f filesystem: support ~ in repository path, require absolute paths (#922)
Fixes #918
2021-04-02 21:55:24 -07:00
Jarek Kowalski
74833cefcb cli: added standard --json flags to several commands (#910)
* cli: added standard --json flags to several commands

Fixes #272

* Update flag description

Co-authored-by: Julio López <julio+gh@kasten.io>
2021-03-25 17:55:18 -07:00
Jarek Kowalski
e88107bb42 Terminal password prompt - switched to golang.org/x/term (#898)
* cli: switched to golang.org/x/term when asking for password, this is compatible with distroless

* go.mod: upgraded some dependencies due to broken mac test build
2021-03-19 22:10:43 -07:00
Jarek Kowalski
3a94c16678 Dockerfile: switched to distroless, specified defaults environment variables for containerized kopia (#897)
* Dockerfile: specified reasonable defaults options for containerized kopia

* addressed pr comments, switched to gcr.io/distroless/static:nonroot

distroless has no executable code, so this requires KOPIA_PASSWORD
to always be provided via env, b/c distroless does not have
/bin/stty to disable TTY echo (we should not require that, BTW)

* site: added docker image documentation
2021-03-19 21:54:48 -07:00
Jarek Kowalski
cbcd59f18e Added repository user authorization support + server flag refactoring + refresh (#890)
* nit: replaced harcoded string constants with named constants

* acl: added management of ACL entries

* auth: implemented DefaultAuthorizer which uses ACLs if any entries are found in the system and falls back to LegacyAuthorizer if not

* cli: switch to DefaultAuthorizer when starting server

* cli: added ACL management

* server: refactored authenticator + added refresh

Authenticator is now an interface which also supports Refresh.

* authz: refactored authorizer to be an interface + added Refresh()

* server: refresh authentication and authorizer

* e2e tests for ACLs

* server: handling of SIGHUP to refresh authn/authz caches

* server: reorganized flags to specify auth options:

- removed '--allow-repository-users' - it's always on
- one of --without-password, --server-password or --random-password
  can be specified to specify password for the UI user
- htpasswd-file - can be specified to provide password for UI or remote
  users

* cli: moved 'kopia user' to 'kopia server user'

* server: allow all UI actions if no authenticator is set

* acl: removed priority until we have a better understood use case for it

* acl: added validation of allowed labels when adding ACL entries

* site: added docs for ACLs
2021-03-18 23:03:27 -07:00
Jarek Kowalski
7e79553fb2 ui: show the current username@hostname as it is connecting to repository (#886) 2021-03-14 13:13:54 -07:00
Jarek Kowalski
4efb06849e server: ensure we reject access to the UI static files for users other than the UI user (#884)
This is for a scenario where a user provides valid username/password
but such that the username is not authorized to access the UI.

Previously we'd make it look like they got access (because they can
see the UI at leaast partially), but all API calls would fail.

With this change we're failing early with HTTP 403 and pointing the
users at a GH issue explaining what to do.

Fixes #580.
2021-03-13 09:58:27 -08:00
Jarek Kowalski
951d7ce33b maintenance: enable full maintenance by default with 24h interval (#879)
Tweaked default message to print on repository creation.
2021-03-11 21:08:10 -08:00
Jarek Kowalski
132e2eef50 New snapshot UX - streamlined snapshot creation and policy setting (#878)
* uitask: added support for reporting string progress info

* server: report current directory as task progress

* snapshot: created reusable Estimate() method to be used during upload, cli estimate and via API

* cli: switched to snapshotfs.Estimate()

* server: added API to estimate snapshot size

* kopia-ui: fixed directory selector

* htmlui: streamlined new snapshot flow and cleaned up policy setting

See https://youtu.be/8p6csuoB3kg
2021-03-10 23:04:55 -08: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
689ed0a851 server: refactored authentication and authorization (#871)
This formalizes the concept of a 'UI user' which is a local
user that can call APIs the same way that UI does it.

The server will now allow access to:

- UI user (identified using `--server-username` with password specified
  using `--server-password' or `--random-password`)
- remote users with usersnames/passwords specified in `--htpasswd-file`
- remote users defined in the repository using `kopia users add`
  when `--allow-repository-users` is passed.

The UI user only has access to methods specifically designated as such
(normally APIs used by the UI + few special ones such as 'shutdown').

Remote users (identified via `user@host`) don't get access to UI APIs.

There are some APIs that can be accessed by any authenticated
caller (UI or remote):

- /api/v1/flush
- /api/v1/repo/status
- /api/v1/repo/sync
- /api/v1/repo/parameters

To make this easier to understand in code, refactored server handlers
to require specifing what kind of authorization is required
at registration time.
2021-03-08 22:25:22 -08:00
Jarek Kowalski
1f1465f4ba Improvements and cleanups for connecting to kopia server (#870)
* repo: refactored connect code set up cache for server repositories

- improved logic to close the cache on last connection
- preemptively add all contents with a prefix to the cache
- refactored how config is loaded and saved

Now cache dir will be stored as relative and resolved to absolute as
part of loading and saving the file, in all other places cache dir
is expected to be absolute.

* server: removed cache directory from the API and UI

This won't be easily available and does not seem useful to expose
anyway.

* cli: enabled cache commands for server repositories

* cli: added KOPIA_CACHE_DIRECTORY environment variable

This is used on two occassions - when setting up connection (it gets
persisted in the config) and later when opening (to override the
cache location from config). It makes setting up docker container with
mounted cache somewhat easier with one environment variable.

* cli: show cache size for the server cache

* tls: present more helpful error message that includes SHA256 fingerprint of the TLS server on mismatch

* server: return the name of user who attempted to login when authentication fails
2021-03-07 11:25:21 -08:00
Pavan Navarathna
3e76169921 Support for stdin streams (#862)
* Add StreamingFile interface
* unit test for virtualfs
* CLI: Snapshot create support for stdin sources
* Uploader support for fs.StreamingFile
* End to end test for stdin source snapshot
* upload test to improve coverage
2021-03-04 15:34:05 -08:00
Jarek Kowalski
9620b57e35 server: avoid password hashing by using short-lived JWT tokens (#857)
Tokens encode the authenticated user, last for 1 minute and are signed
with HMAC-SHA-256. This improves HTTP server performance by a lot:

BEFORE: 168383 files (6.4 GB) - 3m38s
AFTER: 168383 files (6.4 GB) - 1m37s
2021-03-01 06:17:06 -08:00
Jarek Kowalski
ac9f85967a Added first-class support for fs.ErrorEntry for directory entries that could not be read or are unknown/unsupported (#852)
* policy: added errorHandling.ignoreUnknownTypes flag (defaults to true)

* cli: get/set ignore-unknown-types policy flag

* htmlui: added UI for setting ignore-unknown-types

* htmlui: fixed typo

* fs: return fs.ErrorEntry when a directory entry is not recognized (localfs and repofs)

* upload: explicitly handle unknown entry types by treating them as ignored errors
2021-03-01 06:16:26 -08:00
Jarek Kowalski
d9b58fb6e2 linter: upgraded to 1.37.1 (#846) 2021-02-20 11:34:14 -08:00
Robert Kroeger
113670e576 Working kopia mount on Apple Silicon (#825)
* Working kopia mount on Apple Silicon

Work around upstream issues with MacFuse and bazil.org/fuse on Apple
Silicon Macs by using WebDav on darwin arm64. Provides an (at least
temporary) fix for #811.
2021-02-18 09:13:59 -08:00
Jarek Kowalski
23273af1cd snapshot: reworked error handling and added fail-fast option (#840)
Fixes #690

This is a breaking change for folks who are expecting snapshots to fail
quickly without writing a snapshot manifest in case of an error.

Before this change, any source read failure would cause the entire
snapshot to fail (and not write a snapshot manifest as a result),
unless `ignoreFileErrors` or `ignoreDirectoryErrors` was set.

The new behavior is to continue snapshotting remaining files and
directories (this can be disabled by passing `--fail-fast` flag or
setting `KOPIA_SNAPSHOT_FAIL_FAST=1` environment variable) and defer
returning an error until the very end.

After snapshotting we will always attempt to write the snapshot manifest
(except when the root of the snapshot itself cannot be opened). In case
of a fail-fast error, the manifest will be marked as 'partial' and
the directory tree will contain only partial set of files.

In case of any errors, the manifest (and each directory object) will
list the number if failures and no more than 10 examples of failed
files/directories along with their respective errors.

Once the snapshot is complete we will return non-zero exit code to the
operating system if there were any fatal errors during snapshotting.

With this change we are repurposing `ignoreFileErrors` and
`ignoreDirectoryErrors` to designate some errors as non-fatal.
Non-fatal errors are reported as warnings in the logs and will not
cause a non-zero exit code to be returned.
2021-02-17 10:29:01 -08:00
Jarek Kowalski
c990fc9ec1 cache: streamlined flags and cache handling (#831)
* cache: improved cache cleanup on exit

Ensure we do one full sweep before closing if cache has been modified.

Before we would do periodic sweep every minute which would not kick in
for very short snapshots, which Kopia does very frequently. This leads
to build-up of metadata cache entries (q blobs) that never
get cleaned until some long session.

* caching: streamlined cache handling

- deprecated caching-related flags, now cache is always on or off with
  no way to disable it per invocation.
- reduced default list cache duration from 10min to 30s
- moved blob-list cache to separate subdirectory
- cleaned up cache info output to include blob-list cache parameters
- removed ability to disable cache for per-context (this was only
  used in 'snapshot verify' codepath)
- added ability to partially clear individual caches via CLI
2021-02-16 17:30:49 -08:00
Jarek Kowalski
675bf4e033 Removed manifest manager refresh + server improvements (#835)
* manifest: removed explicit refresh

Instead, content manager is exposing a revision counter that changes
on each mutation or index change. Manifest manager will be invalidated
whenever this is encountered.

* server: refactored initialization API

* server: added unit tests for repository server APIs (HTTP and REST)

* server: ensure we don't upload contents that already exist

This saves bandwidth, since the client can compute hash locally
and ask the server whether the object exists before starting the upload.
2021-02-15 23:55:58 -08:00
Jarek Kowalski
5240f62e47 Auto shutdown fix (#834)
* server: removed auto-shutdown option

* server: added --shutdown-on-stdin which will shutdown server when stdin is closed. used by kopia-ui
2021-02-13 19:49:32 -08:00
Jarek Kowalski
de840547e6 Improved upload reporting (#832)
* blob: refactored upload reporting

Instead of plumbing this through blob storage context, we are passing
and explicit callback that reports uploads as they happen.

* htmlui: improved counter presentation

* nit: added missing UI route which fixes Reload behavior on the Tasks page
2021-02-13 10:51:11 -08:00
Jarek Kowalski
4bf42e337d fix long filenames on Windows (#822)
* windows: fixed handling of long filenames
2021-02-12 09:09:42 -08:00
Pavan Navarathna
c964e244f0 Support for ignoring sources when using snapshot create --all (#804)
* Add manual field to SchedulingPolicy
* CLI: Set and show for policy with manual field
* CLI: Edit policy support for manual field
* Check manual when creating snapshot for all source
* End to end test for snapshot create all
* Add UI option for setting Manual field
2021-02-10 21:59:06 -08:00
Nick
0e1c617045 Fix progress output string format (#828) 2021-02-10 11:18:52 -08:00