mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 15:43:21 +00:00
Add configurable htpasswd location
This commit is contained in:
parent
cb85fb38c0
commit
3903ed000c
7 changed files with 52 additions and 22 deletions
38
README.md
38
README.md
|
@ -32,23 +32,24 @@ Usage:
|
||||||
rest-server [flags]
|
rest-server [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
--append-only enable append only mode
|
--append-only enable append only mode
|
||||||
--cpu-profile string write CPU profile to file
|
--cpu-profile string write CPU profile to file
|
||||||
--debug output debug messages
|
--debug output debug messages
|
||||||
-h, --help help for rest-server
|
-h, --help help for rest-server
|
||||||
--listen string listen address (default ":8000")
|
--htpasswd-file string location of .htpasswd file (default: "<data directory>/.htpasswd")
|
||||||
--log string log HTTP requests in the combined log format
|
--listen string listen address (default ":8000")
|
||||||
--max-size int the maximum size of the repository in bytes
|
--log filename write HTTP requests in the combined log format to the specified filename
|
||||||
--no-auth disable .htpasswd authentication
|
--max-size int the maximum size of the repository in bytes
|
||||||
--no-verify-upload do not verify the integrity of uploaded data. DO NOT enable unless the rest-server runs on a very low-power device
|
--no-auth disable .htpasswd authentication
|
||||||
--path string data directory (default "/tmp/restic")
|
--no-verify-upload do not verify the integrity of uploaded data. DO NOT enable unless the rest-server runs on a very low-power device
|
||||||
--private-repos users can only access their private repo
|
--path string data directory (default "/tmp/restic")
|
||||||
--prometheus enable Prometheus metrics
|
--private-repos users can only access their private repo
|
||||||
--prometheus-no-auth disable auth for Prometheus /metrics endpoint
|
--prometheus enable Prometheus metrics
|
||||||
--tls turn on TLS support
|
--prometheus-no-auth disable auth for Prometheus /metrics endpoint
|
||||||
--tls-cert string TLS certificate path
|
--tls turn on TLS support
|
||||||
--tls-key string TLS key path
|
--tls-cert string TLS certificate path
|
||||||
-v, --version version for rest-server
|
--tls-key string TLS key path
|
||||||
|
-v, --version version for rest-server
|
||||||
```
|
```
|
||||||
|
|
||||||
By default the server persists backup data in the OS temporary directory (`/tmp/restic` on Linux/BSD and others, in `%TEMP%\\restic` in Windows, etc). **If `rest-server` is launched using the default path, all backups will be lost**. To start the server with a custom persistence directory and with authentication disabled:
|
By default the server persists backup data in the OS temporary directory (`/tmp/restic` on Linux/BSD and others, in `%TEMP%\\restic` in Windows, etc). **If `rest-server` is launched using the default path, all backups will be lost**. To start the server with a custom persistence directory and with authentication disabled:
|
||||||
|
@ -57,7 +58,7 @@ By default the server persists backup data in the OS temporary directory (`/tmp/
|
||||||
rest-server --path /user/home/backup --no-auth
|
rest-server --path /user/home/backup --no-auth
|
||||||
```
|
```
|
||||||
|
|
||||||
To authenticate users (for access to the rest-server), the server supports using a `.htpasswd` file to specify users. You can create such a file at the root of the persistence directory by executing the following command (note that you need the `htpasswd` program from Apache's http-tools). In order to append new user to the file, just omit the `-c` argument. Only bcrypt and SHA encryption methods are supported, so use -B (very secure) or -s (insecure by today's standards) when adding/changing passwords.
|
To authenticate users (for access to the rest-server), the server supports using a `.htpasswd` file to specify users. By default, the server looks for this file at the root of the persistence directory. You can create such a file by executing the following command (note that you need the `htpasswd` program from Apache's http-tools). In order to append new user to the file, just omit the `-c` argument. Only bcrypt and SHA encryption methods are supported, so use -B (very secure) or -s (insecure by today's standards) when adding/changing passwords.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
htpasswd -B -c .htpasswd username
|
htpasswd -B -c .htpasswd username
|
||||||
|
@ -104,6 +105,7 @@ Note that:
|
||||||
|
|
||||||
- **contrary to the defaults** of `rest-server`, the persistent data volume is located to `/data`.
|
- **contrary to the defaults** of `rest-server`, the persistent data volume is located to `/data`.
|
||||||
- By default, the image uses authentication. To turn it off, set environment variable `DISABLE_AUTHENTICATION` to any value.
|
- By default, the image uses authentication. To turn it off, set environment variable `DISABLE_AUTHENTICATION` to any value.
|
||||||
|
- By default, the image loads the `.htpasswd` file from the persistent data volume (i.e. from `/data/.htpasswd`). To change the location of this file, set the environment variable `PASSWORD_FILE` to the path of the `.htpasswd` file.
|
||||||
- It's suggested to set a container name to more easily manage users (`--name` parameter to `docker run`).
|
- It's suggested to set a container name to more easily manage users (`--name` parameter to `docker run`).
|
||||||
- You can set environment variable `OPTIONS` to any extra flags you'd like to pass to rest-server.
|
- You can set environment variable `OPTIONS` to any extra flags you'd like to pass to rest-server.
|
||||||
|
|
||||||
|
|
6
changelog/unreleased/issue-187
Normal file
6
changelog/unreleased/issue-187
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Feature: Allow configurable location for .htpasswd file (in present tense)
|
||||||
|
|
||||||
|
Added the ability for a user to change the location of the .htpasswd file with the --htpasswd-file argument.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/issues/187
|
||||||
|
https://github.com/restic/restic/pull/188
|
|
@ -47,6 +47,7 @@ func init() {
|
||||||
flags.StringVar(&server.TLSCert, "tls-cert", server.TLSCert, "TLS certificate path")
|
flags.StringVar(&server.TLSCert, "tls-cert", server.TLSCert, "TLS certificate path")
|
||||||
flags.StringVar(&server.TLSKey, "tls-key", server.TLSKey, "TLS key path")
|
flags.StringVar(&server.TLSKey, "tls-key", server.TLSKey, "TLS key path")
|
||||||
flags.BoolVar(&server.NoAuth, "no-auth", server.NoAuth, "disable .htpasswd authentication")
|
flags.BoolVar(&server.NoAuth, "no-auth", server.NoAuth, "disable .htpasswd authentication")
|
||||||
|
flags.StringVar(&server.HtpasswdPath, "htpasswd-file", server.HtpasswdPath, "location of .htpasswd file (default: \"<data directory>/.htpasswd)\"")
|
||||||
flags.BoolVar(&server.NoVerifyUpload, "no-verify-upload", server.NoVerifyUpload,
|
flags.BoolVar(&server.NoVerifyUpload, "no-verify-upload", server.NoVerifyUpload,
|
||||||
"do not verify the integrity of uploaded data. DO NOT enable unless the rest-server runs on a very low-power device")
|
"do not verify the integrity of uploaded data. DO NOT enable unless the rest-server runs on a very low-power device")
|
||||||
flags.BoolVar(&server.AppendOnly, "append-only", server.AppendOnly, "enable append only mode")
|
flags.BoolVar(&server.AppendOnly, "append-only", server.AppendOnly, "enable append only mode")
|
||||||
|
|
|
@ -100,6 +100,22 @@ func TestGetHandler(t *testing.T) {
|
||||||
t.Errorf("NoAuth=true: expected no error, got %v", err)
|
t.Errorf("NoAuth=true: expected no error, got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// With NoAuth = true and custom .htpasswd
|
||||||
|
htpFile, err := ioutil.TempFile(dir, "custom")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
err := os.Remove(htpFile.Name())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
_, err = getHandler(&restserver.Server{HtpasswdPath: htpFile.Name()})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("NoAuth=false with custom htpasswd: expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Create .htpasswd
|
// Create .htpasswd
|
||||||
htpasswd := filepath.Join(dir, ".htpasswd")
|
htpasswd := filepath.Join(dir, ".htpasswd")
|
||||||
err = ioutil.WriteFile(htpasswd, []byte(""), 0644)
|
err = ioutil.WriteFile(htpasswd, []byte(""), 0644)
|
||||||
|
|
|
@ -16,4 +16,4 @@ else
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec rest-server --path "$DATA_DIRECTORY" $OPTIONS
|
exec rest-server --path "$DATA_DIRECTORY" --htpasswd-file "$PASSWORD_FILE" $OPTIONS
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
// Server encapsulates the rest-server's settings and repo management logic
|
// Server encapsulates the rest-server's settings and repo management logic
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Path string
|
Path string
|
||||||
|
HtpasswdPath string
|
||||||
Listen string
|
Listen string
|
||||||
Log string
|
Log string
|
||||||
CPUProfile string
|
CPUProfile string
|
||||||
|
|
10
mux.go
10
mux.go
|
@ -60,10 +60,14 @@ func (s *Server) wrapMetricsAuth(f http.HandlerFunc) http.HandlerFunc {
|
||||||
func NewHandler(server *Server) (http.Handler, error) {
|
func NewHandler(server *Server) (http.Handler, error) {
|
||||||
if !server.NoAuth {
|
if !server.NoAuth {
|
||||||
var err error
|
var err error
|
||||||
server.htpasswdFile, err = NewHtpasswdFromFile(filepath.Join(server.Path, ".htpasswd"))
|
if server.HtpasswdPath == "" {
|
||||||
if err != nil {
|
server.HtpasswdPath = filepath.Join(server.Path, ".htpasswd")
|
||||||
return nil, fmt.Errorf("cannot load .htpasswd (use --no-auth to disable): %v", err)
|
|
||||||
}
|
}
|
||||||
|
server.htpasswdFile, err = NewHtpasswdFromFile(server.HtpasswdPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot load %s (use --no-auth to disable): %v", server.HtpasswdPath, err)
|
||||||
|
}
|
||||||
|
log.Printf("Loaded htpasswd file: %s", server.HtpasswdPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
const GiB = 1024 * 1024 * 1024
|
const GiB = 1024 * 1024 * 1024
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue