--- title: "Repository Server" linkTitle: "Repository Server" toc_hide: true --- By default, every user of Kopia repository directly connects to an underlying storage using read-write access. If the users who share repository don't completely trust each other, some malicious actors can delete repository data structures causing data loss for others. Repository Server allows an instance of kopia to proxy access to the underlying storage and has Kopia clients proxy all access through it, only requiring username and password to talk to server without any knowledge of repository storage credentials. In repository server mode, each user is limited to seeing their own snapshots and policy manifest without being able to access those from another user account. >NOTE: Only snapshot and policy manifests are access-controlled, not the underlying contents. If two users shared the same file, it will be backed using exactly the same content IDs. The consequence of this is that if a third user can guess the content ID of files in the repository, they will be able to access the files. Because content IDs are one-way salted hashes of contents, in principle it should be impossible to guess content ID without possessing original content. ## Starting Repository Server Repository Server should be started on a dedicated server in LAN, such that all clients can directly connect to it. Before we can start repository server, we must first create a list of usernames and passwords that will be allowed access. ## Configuring Allowed Users Starting in Kopia v0.8, allowed repository users can be configured using `kopia server user` commands. Each user is identified by its lowercase `username@hostname` where hostname by default is the name of the computer the client is connecting from (without domain name suffix). To add a user: ```shell $ kopia server user add myuser@mylaptop Enter new password for user myuser@mylaptop: Re-enter new password for verification: Updated user credentials will take effect in 5-10 minutes or when the server is restarted. To refresh credentials in a running server use 'kopia server refresh' command. ``` Other commands are also available: * `kopia server user list` - lists user accounts * `kopia server user set` - changes password * `kopia server user delete` - deletes user account >__Prior to Kopia v0.8__, the user list must be put in a text file formatted using the [htpasswd](https://httpd.apache.org/docs/2.4/programs/htpasswd.html) utility from Apache. This method is still supported in v0.8, but it's recommended to use `kopia server user` to manage users instead. > To create password file for two users: > ```shell > $ htpasswd -c password.txt user1@host1 > New password: > Re-type new password: > Adding password for user user1@host1 > > $ htpasswd password.txt user2@host1 > New password: > Re-type new password: > Adding password for user user2@host1 > ``` ### Auto-Generated TLS Certificate To start repository server with auto-generated TLS certificate for the first time: ```shell kopia server start \ --tls-generate-cert \ --tls-cert-file ~/my.cert \ --tls-key-file ~/my.key \ --address 0.0.0.0:51515 \ --server-control-username control \ --server-control-password PASSWORD_HERE ``` This will generate TLS certificate and key files and store them in the provided paths (`~/my.cert` and `~/my.key` respectively). It will also print certificate SHA256 fingerprint, which will be used later: ```shell SERVER CERT SHA256: 48537cce585fed39fb26c639eb8ef38143592ba4b4e7677a84a31916398d40f7 ``` Note that when starting the server again the `--tls-generate-cert` must be omitted, otherwise the server will fail to start. >__Prior to Kopia v0.8,__ the command line for `kopia server start` also needs `--htpasswd-file ~/password.txt` ### Custom TLS Certificates If a user has obtained custom certificate (for example from LetsEncrypt or another CA), using it is simply a matter of providing PEM-formatted certificate and key files on server startup. To get SHA256 certificate of existing file use: ```shell $ openssl x509 -in ~/my.cert -noout -fingerprint -sha256 | sed 's/://g' | cut -f 2 -d = 48537CCE585FED39FB26C639EB8EF38143592BA4B4E7677A84A31916398D40F7 ``` ### On Client Computer Assuming we're on another machine running as `user1@host1`, we can now run the following command to connect to the repository (notice we're using fingerprint obtained before without `:` separators) ```shell kopia repository connect server --url https://
:51515 \ --server-cert-fingerprint 48537cce585fed39fb26c639eb8ef38143592ba4b4e7677a84a31916398d40f7 ``` Once connected, all snapshot and policy `kopia` commands should work for the current user, but low-level commands such as `repo status` will fail: ```shell $ kopia repository status kopia: error: operation supported only on direct repository, try --help ``` You can override username and hostname with this command : ```shell $ kopia repo connect server --url=http://11.222.111.222:51515 --override-username=johndoe --override-hostname=my-laptop ``` ## Server Access Control (ACL) Kopia server will check permissions when users try to access contents and manifests based on rules we call ACLs (access control list). >__Prior to Kopia v0.8,__ the rules were non-configurable and each user could only read and write their own snapshot manifests. Starting in Kopia v0.8 the ACLs can be controlled by using `kopia server acl` commands. If no ACLs are explicitly defined, Kopia will use a set of built-in access control rules, which grants all authenticated users identified by `username@hostname` ability to: * read and write policies for `username@hostname` and `username@hostname:/path`, * read and write snapshots for `username@hostname:/path`, * read `global` policy, * read `host`-level policies for their own `hostname`, * read and write `user`-level policies for their own `username@hostname`, * read and write their own `user` account `username@hostname` (to be able to change password), * read objects if they know their object IDs * write new `content` to the repository ### Access control for individual files or directories Kopia does not currently perform access control checks to verify that a user trying to access file or directory by object ID is the original owner of the file (because of Kopia's deduplication, two different users who have the same file will get the same object ID when snapshotting it). This means that any user who knows of a valid object ID will get be able to restore its contents (by `kopia restore