Skip to content

Commit

Permalink
Fix places where we fail to propagate storage errors like ErrReadOnly (
Browse files Browse the repository at this point in the history
  • Loading branch information
banks authored May 1, 2024
1 parent cb36fba commit 2593136
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion builtin/logical/pki/cert_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func fetchCertBySerial(sc *storageContext, prefix, serial string) (*logical.Stor
certCounter := sc.Backend.GetCertificateCounter()
certsCounted := certCounter.IsInitialized()
if err = sc.Storage.Put(sc.Context, certEntry); err != nil {
return nil, errutil.InternalError{Err: fmt.Sprintf("error saving certificate with serial %s to new location", serial)}
return nil, errutil.InternalError{Err: fmt.Sprintf("error saving certificate with serial %s to new location: %s", serial, err)}
}
if err = sc.Storage.Delete(sc.Context, legacyPath); err != nil {
// If we fail here, we have an extra (copy) of a cert in storage, add to metrics:
Expand Down
2 changes: 1 addition & 1 deletion vault/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (c *Core) disableAudit(ctx context.Context, path string, updateStorage bool
if updateStorage {
// Update the audit table
if err := c.persistAudit(ctx, newTable, entry.Local); err != nil {
return existed, errors.New("failed to update audit table")
return existed, fmt.Errorf("failed to update audit table: %w: %w", audit.ErrInternal, err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions vault/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (c *Core) enableCredentialInternal(ctx context.Context, entry *MountEntry,
if err == logical.ErrReadOnly && c.perfStandby {
return err
}
return errors.New("failed to update auth table")
return fmt.Errorf("failed to update auth table: %w", err)
}
}

Expand Down Expand Up @@ -406,7 +406,7 @@ func (c *Core) removeCredEntry(ctx context.Context, path string, updateStorage b
return err
}

return errors.New("failed to update auth table")
return fmt.Errorf("failed to update auth table: %w", err)
}
}

Expand Down Expand Up @@ -563,7 +563,7 @@ func (c *Core) taintCredEntry(ctx context.Context, nsID, path string, updateStor
if err == logical.ErrReadOnly && c.perfStandby {
return err
}
return errors.New("failed to update auth table")
return fmt.Errorf("failed to update auth table: %w", err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ func NewCore(conf *CoreConfig) (*Core, error) {
if c.recoveryMode {
checkResult, err := c.checkForSealMigration(context.Background(), conf.UnwrapSeal)
if err != nil {
return nil, fmt.Errorf("error checking if a seal migration is needed")
return nil, fmt.Errorf("error checking if a seal migration is needed: %w", err)
}
if conf.UnwrapSeal != nil || checkResult == sealMigrationCheckAdjust {
return nil, errors.New("cannot run in recovery mode when a seal migration is needed")
Expand Down Expand Up @@ -2324,7 +2324,7 @@ func (c *Core) sealInternalWithOptions(grabStateLock, keepHALock, performCleanup

if err := c.preSeal(); err != nil {
c.logger.Error("pre-seal teardown failed", "error", err)
return fmt.Errorf("internal error")
return fmt.Errorf("internal error: %w", err)
}
} else {
// If we are keeping the lock we already have the state write lock
Expand Down
2 changes: 1 addition & 1 deletion vault/logical_system_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (b *SystemBackend) tuneMountTTLs(ctx context.Context, path string, me *Moun
if err != nil {
me.Config.MaxLeaseTTL = origMax
me.Config.DefaultLeaseTTL = origDefault
return fmt.Errorf("failed to update mount table, rolling back TTL changes")
return fmt.Errorf("failed to update mount table, rolling back TTL changes: %w", err)
}
if b.Core.logger.IsInfo() {
b.Core.logger.Info("mount tuning of leases successful", "path", path)
Expand Down
2 changes: 1 addition & 1 deletion vault/login_mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ ECONFIG_LOOP:
// i.e. is it the req's ns or an ancestor of req's ns?
eConfigNS, err := c.NamespaceByID(ctx, eConfig.NamespaceID)
if err != nil {
return nil, fmt.Errorf("failed to find the MFAEnforcementConfig namespace")
return nil, fmt.Errorf("failed to find the MFAEnforcementConfig namespace: %w", err)
}

if eConfig == nil || eConfigNS == nil || (eConfigNS.ID != ns.ID && !ns.HasParent(eConfigNS)) {
Expand Down

0 comments on commit 2593136

Please sign in to comment.