Skip to content

Commit

Permalink
Add readonly and htpasswd configuration flags (#2879)
Browse files Browse the repository at this point in the history
* Add readonly and htpasswd flags support for Kopia

Signed-off-by: Pavel Larkin <pavel.larkin@veeam.com>

* Add tests for flags

---------

Signed-off-by: Pavel Larkin <pavel.larkin@veeam.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
plar and mergify[bot] committed May 13, 2024
1 parent 67696b0 commit 190f57b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/kopia/command/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const (
userPasswordFlag = "--user-password"
enablePprof = "--enable-pprof"
metricsListerAddress = "--metrics-listen-addr"
htpasswdFilePath = "--htpasswd-file"

// Repository specific
repositorySubCommand = "repository"
Expand Down Expand Up @@ -121,4 +122,7 @@ const (

// DefaultLogDirectory is the directory where kopia log file is created
DefaultLogDirectory = "/tmp/kopia-log"

// DefaultHtpasswdFilePath is the path to the generated htpasswd file
DefaultHtpasswdFilePath = "/tmp/kopia-htpasswd"
)
11 changes: 11 additions & 0 deletions pkg/kopia/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type ServerStartCommandArgs struct {
TLSKeyFile string
ServerUsername string
ServerPassword string
HtpasswdFilePath string
ReadOnly bool
AutoGenerateCert bool
Background bool
EnablePprof bool
Expand All @@ -43,12 +45,21 @@ func ServerStart(cmdArgs ServerStartCommandArgs) []string {
args = args.AppendLoggableKV(addressFlag, cmdArgs.ServerAddress)
args = args.AppendLoggableKV(tlsCertFilePath, cmdArgs.TLSCertFile)
args = args.AppendLoggableKV(tlsKeyFilePath, cmdArgs.TLSKeyFile)

if cmdArgs.HtpasswdFilePath != "" {
args = args.AppendLoggableKV(htpasswdFilePath, cmdArgs.HtpasswdFilePath)
}

args = args.AppendLoggableKV(serverUsernameFlag, cmdArgs.ServerUsername)
args = args.AppendRedactedKV(serverPasswordFlag, cmdArgs.ServerPassword)

args = args.AppendLoggableKV(serverControlUsernameFlag, cmdArgs.ServerUsername)
args = args.AppendRedactedKV(serverControlPasswordFlag, cmdArgs.ServerPassword)

if cmdArgs.ReadOnly {
args = args.AppendLoggable(readOnlyFlag)
}

if cmdArgs.EnablePprof {
args = args.AppendLoggable(enablePprof)
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/kopia/command/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ func (kServer *KopiaServerTestSuite) TestServerCommands(c *C) {
},
expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password > /dev/null 2>&1 &",
},
{
f: func() []string {
args := ServerStartCommandArgs{
CommandArgs: commandArgs,
ServerAddress: "a-server-address",
TLSCertFile: "/path/to/cert/tls.crt",
TLSKeyFile: "/path/to/key/tls.key",
ServerUsername: "a-username@a-hostname",
ServerPassword: "a-user-password",
AutoGenerateCert: false,
Background: true,
ReadOnly: true,
HtpasswdFilePath: "/path/htpasswd",
}
return ServerStart(args)
},
expectedLog: "bash -o errexit -c kopia --log-level=error --config-file=path/kopia.config --log-dir=cache/log server start --address=a-server-address --tls-cert-file=/path/to/cert/tls.crt --tls-key-file=/path/to/key/tls.key --htpasswd-file=/path/htpasswd --server-username=a-username@a-hostname --server-password=a-user-password --server-control-username=a-username@a-hostname --server-control-password=a-user-password --readonly > /dev/null 2>&1 &",
},
{
f: func() []string {
args := ServerStatusCommandArgs{
Expand Down

0 comments on commit 190f57b

Please sign in to comment.