Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if storage should be updated during invalidation #28059

Merged
merged 11 commits into from
Aug 22, 2024
3 changes: 3 additions & 0 deletions changelog/28059.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
command: The `vault secrets move` and `vault auth move` command will no longer attempt to write to storage on performance standby nodes.
```
18 changes: 10 additions & 8 deletions vault/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,17 @@ func (c *Core) remountCredential(ctx context.Context, src, dst namespace.MountPa
srcMatch.Path = strings.TrimPrefix(dst.MountPath, credentialRoutePrefix)

// Update the mount table
if err := c.persistAuth(ctx, c.auth, &srcMatch.Local); err != nil {
srcMatch.Path = srcPath
srcMatch.Tainted = true
c.authLock.Unlock()
if err == logical.ErrReadOnly && c.perfStandby {
return err
}
if updateStorage {
if err := c.persistAuth(ctx, c.auth, &srcMatch.Local); err != nil {
srcMatch.Path = srcPath
srcMatch.Tainted = true
c.authLock.Unlock()
if err == logical.ErrReadOnly && c.perfStandby {
return err
}

return fmt.Errorf("failed to update auth table with error %+v", err)
return fmt.Errorf("failed to update auth table with error %+v", err)
}
}

// Remount the backend, setting the existing route entry
Expand Down
18 changes: 10 additions & 8 deletions vault/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,15 +1189,17 @@ func (c *Core) remountSecretsEngine(ctx context.Context, src, dst namespace.Moun
srcMatch.Path = dst.MountPath

// Update the mount table
if err := c.persistMounts(ctx, c.mounts, &srcMatch.Local); err != nil {
srcMatch.Path = srcPath
srcMatch.Tainted = true
c.mountsLock.Unlock()
if err == logical.ErrReadOnly && c.perfStandby {
return err
}
if updateStorage {
if err := c.persistMounts(ctx, c.mounts, &srcMatch.Local); err != nil {
srcMatch.Path = srcPath
srcMatch.Tainted = true
c.mountsLock.Unlock()
if err == logical.ErrReadOnly && c.perfStandby {
return err
}

return fmt.Errorf("failed to update mount table with error %+v", err)
return fmt.Errorf("failed to update mount table with error %+v", err)
}
}

// Remount the backend
Expand Down
17 changes: 17 additions & 0 deletions vault/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,23 @@ func GenerateRandBytes(length int) ([]byte, error) {
return buf, nil
}

func TestWaitPerfStandby(t testing.TB, core *Core) {
t.Helper()
start := time.Now()
var perfStandby bool
for time.Now().Sub(start) < 30*time.Second {
perfStandby = core.PerfStandby()

if perfStandby {
break
}
}
if !perfStandby {
err := errors.New("core not in perf standby mode")
t.Fatal(err)
}
}

func TestWaitActive(t testing.TB, core *Core) {
t.Helper()
if err := TestWaitActiveWithError(core); err != nil {
Expand Down
Loading