Repository password change support (#1197)

* repo: added 'enable password change' flag (defaults to true for new repositories), which prevents embedding replicas of kopia.repository in pack blobs

* cli: added 'repo change-password' which can change the password of a connected repository

* repo: nit - renamed variables and functions dealing with key derivation

* repo: fixed cache validation HMAC secret to use stored HMAC secret instead of password-derived one

* cli: added test for repo change-password

* repo: negative cases for attempting to change password in an old repository

* Update cli/command_repository_change_password.go

Co-authored-by: Julio Lopez <julio+gh@kasten.io>

Co-authored-by: Julio Lopez <julio+gh@kasten.io>
This commit is contained in:
Jarek KowalskiandJulio Lopez authored and GitHub committed 2021-07-17 07:58:02 -07:00
1 parent f15c76ef6e
commit 730ba7b94a
20 files changed
+292 -60

No files matched your search

+18 -11
View File
@@ -17,13 +17,15 @@
"github.com/kopia/kopia/repo/object"
)
const masterPassword = "foobarbazfoobarbaz"
const defaultPassword = "foobarbazfoobarbaz"
// Environment encapsulates details of a test environment.
type Environment struct {
Repository repo.Repository
RepositoryWriter repo.DirectRepositoryWriter
Password string
configDir string
storageDir string
connected bool
@@ -46,9 +48,10 @@ func (e *Environment) setup(t *testing.T, opts ...Options) *Environment {
opt := &repo.NewRepositoryOptions{
BlockFormat: content.FormattingOptions{
HMACSecret: []byte{},
Hash: "HMAC-SHA256",
Encryption: encryption.DefaultAlgorithm,
HMACSecret: []byte{},
Hash: "HMAC-SHA256",
Encryption: encryption.DefaultAlgorithm,
EnablePasswordChange: true,
},
ObjectFormat: object.Format{
Splitter: "FIXED-1M",
@@ -72,17 +75,21 @@ func (e *Environment) setup(t *testing.T, opts ...Options) *Environment {
t.Fatalf("err: %v", err)
}
if err = repo.Initialize(ctx, st, opt, masterPassword); err != nil {
if e.Password == "" {
e.Password = defaultPassword
}
if err = repo.Initialize(ctx, st, opt, e.Password); err != nil {
t.Fatalf("err: %v", err)
}
if err = repo.Connect(ctx, e.ConfigFile(), st, masterPassword, nil); err != nil {
if err = repo.Connect(ctx, e.ConfigFile(), st, e.Password, nil); err != nil {
t.Fatalf("can't connect: %v", err)
}
e.connected = true
rep, err := repo.Open(ctx, e.ConfigFile(), masterPassword, openOpt)
rep, err := repo.Open(ctx, e.ConfigFile(), e.Password, openOpt)
if err != nil {
t.Fatalf("can't open: %v", err)
}
@@ -135,7 +142,7 @@ func (e *Environment) MustReopen(t *testing.T, openOpts ...func(*repo.Options))
t.Fatalf("close error: %v", err)
}
rep, err := repo.Open(ctx, e.ConfigFile(), masterPassword, repoOptions(openOpts))
rep, err := repo.Open(ctx, e.ConfigFile(), e.Password, repoOptions(openOpts))
if err != nil {
t.Fatalf("err: %v", err)
}
@@ -154,7 +161,7 @@ func (e *Environment) MustOpenAnother(t *testing.T) repo.RepositoryWriter {
ctx := testlogging.Context(t)
rep2, err := repo.Open(ctx, e.ConfigFile(), masterPassword, &repo.Options{})
rep2, err := repo.Open(ctx, e.ConfigFile(), e.Password, &repo.Options{})
if err != nil {
t.Fatalf("err: %v", err)
}
@@ -192,11 +199,11 @@ func (e *Environment) MustConnectOpenAnother(t *testing.T, openOpts ...func(*rep
},
}
if err = repo.Connect(ctx, config, st, masterPassword, connOpts); err != nil {
if err = repo.Connect(ctx, config, st, e.Password, connOpts); err != nil {
t.Fatal("can't connect:", err)
}
rep, err := repo.Open(ctx, e.ConfigFile(), masterPassword, repoOptions(openOpts))
rep, err := repo.Open(ctx, e.ConfigFile(), e.Password, repoOptions(openOpts))
if err != nil {
t.Fatal("can't open:", err)
}
+1 -1
View File
@@ -19,7 +19,7 @@ func TestTimeFuncWiring(t *testing.T) {
ft := faketime.NewTimeAdvance(time.Date(2018, time.February, 6, 0, 0, 0, 0, time.UTC), 0)
// Re open with injected time
rep, err := repo.Open(ctx, env.RepositoryWriter.ConfigFilename(), masterPassword, &repo.Options{TimeNowFunc: ft.NowFunc()})
rep, err := repo.Open(ctx, env.RepositoryWriter.ConfigFilename(), env.Password, &repo.Options{TimeNowFunc: ft.NowFunc()})
if err != nil {
t.Fatal("Failed to open repo:", err)
}