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

Backport of VAULT-21435 Use seal wrappers rather than config to determine autoSeal barrier type. into release/1.15.x #24166

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/24165.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
core: Fix an error that resulted in the wrong seal type being returned by sys/seal-status while
Vault is in seal migration mode.
```
12 changes: 7 additions & 5 deletions vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -5001,8 +5001,14 @@ func (core *Core) GetSealStatus(ctx context.Context, lock bool) (*SealStatusResp
return s, nil
}

var sealType string
var recoverySealType string
sealType := sealConfig.Type
if core.SealAccess().RecoveryKeySupported() {
recoverySealType = sealConfig.Type
sealType = core.seal.BarrierSealConfigType().String()
} else {
sealType = sealConfig.Type
}

// Fetch the local cluster name and identifier
var clusterName, clusterID string
Expand All @@ -5016,10 +5022,6 @@ func (core *Core) GetSealStatus(ctx context.Context, lock bool) (*SealStatusResp
}
clusterName = cluster.Name
clusterID = cluster.ID
if core.SealAccess().RecoveryKeySupported() {
recoverySealType = sealType
}
sealType = core.seal.BarrierSealConfigType().String()
}

progress, nonce := core.SecretProgress(lock)
Expand Down
10 changes: 5 additions & 5 deletions vault/seal_autoseal.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func NewAutoSeal(lowLevel seal.Access) *autoSeal {
ret.barrierConfig.Store((*SealConfig)(nil))
ret.recoveryConfig.Store((*SealConfig)(nil))

// See SealConfigType for the rules about computing the type.
if len(lowLevel.GetSealGenerationInfo().Seals) > 1 {
ret.barrierSealConfigType = SealConfigTypeMultiseal
// See SealConfigType for the rules about computing the type. Note that NewAccess guarantees
// that there is at least one wrapper
if wrappers := lowLevel.GetAllSealWrappersByPriority(); len(wrappers) == 1 {
ret.barrierSealConfigType = SealConfigType(wrappers[0].SealConfigType)
} else {
// Note that the Access constructors guarantee that there is at least one KMS config
ret.barrierSealConfigType = SealConfigType(lowLevel.GetSealGenerationInfo().Seals[0].Type)
ret.barrierSealConfigType = SealConfigTypeMultiseal
}

return ret
Expand Down
12 changes: 12 additions & 0 deletions vault/seal_autoseal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"context"
"errors"
"github.com/stretchr/testify/require"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -212,3 +213,14 @@ func TestAutoSeal_HealthCheck(t *testing.T) {
t.Fatal("Expected seals to be healthy")
}
}

func TestAutoSeal_BarrierSealConfigType(t *testing.T) {
singleWrapperAccess, _ := seal.NewToggleableTestSeal(&seal.TestSealOpts{WrapperCount: 1})
multipleWrapperAccess, _ := seal.NewToggleableTestSeal(&seal.TestSealOpts{WrapperCount: 2})

require.Equalf(t, singleWrapperAccess.GetAllSealWrappersByPriority()[0].SealConfigType, NewAutoSeal(singleWrapperAccess).BarrierSealConfigType().String(),
"autoseals that have a single seal wrapper report that wrapper's as the barrier seal type")

require.Equalf(t, SealConfigTypeMultiseal, NewAutoSeal(multipleWrapperAccess).BarrierSealConfigType(),
"autoseals that have a multiple seal wrappers report the barrier seal type as Multiseal")
}