Skip to content

Commit b9deb5d

Browse files
authored
feat(sys/seal-status): send both barrier and recovery seal types (#1638)
* feat(sys/seal-status): send both barrier and recovery seal types Signed-off-by: Pascal Reeb <pascal.reeb@secretz.io> * chore: add changelog Signed-off-by: Pascal Reeb <pascal.reeb@secretz.io> * fix: typo Signed-off-by: Pascal Reeb <pascal.reeb@secretz.io> * chore: update test Signed-off-by: Pascal Reeb <pascal.reeb@secretz.io> * chore: add feedback from satoqz Signed-off-by: Pascal Reeb <pascal.reeb@secretz.io> --------- Signed-off-by: Pascal Reeb <pascal.reeb@secretz.io>
1 parent 8550404 commit b9deb5d

File tree

6 files changed

+103
-83
lines changed

6 files changed

+103
-83
lines changed

api/sys_seal.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,22 @@ func sealStatusRequestWithContext(ctx context.Context, c *Sys, r *Request) (*Sea
9696
}
9797

9898
type SealStatusResponse struct {
99-
Type string `json:"type"`
100-
Initialized bool `json:"initialized"`
101-
Sealed bool `json:"sealed"`
102-
T int `json:"t"`
103-
N int `json:"n"`
104-
Progress int `json:"progress"`
105-
Nonce string `json:"nonce"`
106-
Version string `json:"version"`
107-
BuildDate string `json:"build_date"`
108-
Migration bool `json:"migration"`
109-
ClusterName string `json:"cluster_name,omitempty"`
110-
ClusterID string `json:"cluster_id,omitempty"`
111-
RecoverySeal bool `json:"recovery_seal"`
112-
StorageType string `json:"storage_type,omitempty"`
113-
Warnings []string `json:"warnings,omitempty"`
99+
Type string `json:"type"`
100+
Initialized bool `json:"initialized"`
101+
Sealed bool `json:"sealed"`
102+
T int `json:"t"`
103+
N int `json:"n"`
104+
Progress int `json:"progress"`
105+
Nonce string `json:"nonce"`
106+
Version string `json:"version"`
107+
BuildDate string `json:"build_date"`
108+
Migration bool `json:"migration"`
109+
ClusterName string `json:"cluster_name,omitempty"`
110+
ClusterID string `json:"cluster_id,omitempty"`
111+
RecoverySeal bool `json:"recovery_seal"`
112+
RecoverySealType string `json:"recovery_seal_type,omitempty"`
113+
StorageType string `json:"storage_type,omitempty"`
114+
Warnings []string `json:"warnings,omitempty"`
114115
}
115116

116117
type UnsealOpts struct {

changelog/1638.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
core: sys/seal-status: endpoint now always returns the barrier seal type, explicitly adds recovery seal type
3+
```

command/format.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,16 @@ func (t TableFormatter) Output(ui cli.Ui, secret *api.Secret, data interface{})
290290
func (t TableFormatter) OutputSealStatusStruct(ui cli.Ui, secret *api.Secret, data interface{}) error {
291291
var status SealStatusOutput = data.(SealStatusOutput)
292292
var sealPrefix string
293+
294+
out := []string{}
295+
out = append(out, "Key | Value")
296+
out = append(out, fmt.Sprintf("Seal Type | %s", status.Type))
297+
293298
if status.RecoverySeal {
294299
sealPrefix = "Recovery "
300+
out = append(out, fmt.Sprintf("Recovery Seal Type | %s", status.RecoverySealType))
295301
}
296302

297-
out := []string{}
298-
out = append(out, "Key | Value")
299-
out = append(out, fmt.Sprintf("%sSeal Type | %s", sealPrefix, status.Type))
300303
out = append(out, fmt.Sprintf("Initialized | %t", status.Initialized))
301304
out = append(out, fmt.Sprintf("Sealed | %t", status.Sealed))
302305
out = append(out, fmt.Sprintf("Total %sShares | %d", sealPrefix, status.N))

command/format_test.go

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func TestStatusFormat(t *testing.T) {
108108

109109
expectedOutputString := `Key Value
110110
--- -----
111+
Seal Type type
111112
Recovery Seal Type type
112113
Initialized true
113114
Sealed true
@@ -140,6 +141,7 @@ Warnings [warning]`
140141

141142
expectedOutputString = `Key Value
142143
--- -----
144+
Seal Type type
143145
Recovery Seal Type type
144146
Initialized true
145147
Sealed true
@@ -167,21 +169,22 @@ func getMockStatusData(emptyFields bool) SealStatusOutput {
167169
var sealStatusResponseMock api.SealStatusResponse
168170
if !emptyFields {
169171
sealStatusResponseMock = api.SealStatusResponse{
170-
Type: "type",
171-
Initialized: true,
172-
Sealed: true,
173-
T: 1,
174-
N: 2,
175-
Progress: 3,
176-
Nonce: "nonce",
177-
Version: "version",
178-
BuildDate: "build date",
179-
Migration: true,
180-
ClusterName: "cluster name",
181-
ClusterID: "cluster id",
182-
RecoverySeal: true,
183-
StorageType: "storage type",
184-
Warnings: []string{"warning"},
172+
Type: "type",
173+
RecoverySealType: "type",
174+
Initialized: true,
175+
Sealed: true,
176+
T: 1,
177+
N: 2,
178+
Progress: 3,
179+
Nonce: "nonce",
180+
Version: "version",
181+
BuildDate: "build date",
182+
Migration: true,
183+
ClusterName: "cluster name",
184+
ClusterID: "cluster id",
185+
RecoverySeal: true,
186+
StorageType: "storage type",
187+
Warnings: []string{"warning"},
185188
}
186189

187190
// must initialize this struct without explicit field names due to embedding
@@ -200,20 +203,21 @@ func getMockStatusData(emptyFields bool) SealStatusOutput {
200203
}
201204
} else {
202205
sealStatusResponseMock = api.SealStatusResponse{
203-
Type: "type",
204-
Initialized: true,
205-
Sealed: true,
206-
T: 1,
207-
N: 2,
208-
Progress: 3,
209-
Nonce: "nonce",
210-
Version: "version",
211-
BuildDate: "build date",
212-
Migration: true,
213-
ClusterName: "",
214-
ClusterID: "",
215-
RecoverySeal: true,
216-
StorageType: "",
206+
Type: "type",
207+
RecoverySealType: "type",
208+
Initialized: true,
209+
Sealed: true,
210+
T: 1,
211+
N: 2,
212+
Progress: 3,
213+
Nonce: "nonce",
214+
Version: "version",
215+
BuildDate: "build date",
216+
Migration: true,
217+
ClusterName: "",
218+
ClusterID: "",
219+
RecoverySeal: true,
220+
StorageType: "",
217221
}
218222

219223
// must initialize this struct without explicit field names due to embedding

vault/logical_system.go

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4508,21 +4508,22 @@ func (b *SystemBackend) pathInternalOpenAPI(ctx context.Context, req *logical.Re
45084508
}
45094509

45104510
type SealStatusResponse struct {
4511-
Type string `json:"type"`
4512-
Initialized bool `json:"initialized"`
4513-
Sealed bool `json:"sealed"`
4514-
T int `json:"t"`
4515-
N int `json:"n"`
4516-
Progress int `json:"progress"`
4517-
Nonce string `json:"nonce"`
4518-
Version string `json:"version"`
4519-
BuildDate string `json:"build_date"`
4520-
Migration bool `json:"migration"`
4521-
ClusterName string `json:"cluster_name,omitempty"`
4522-
ClusterID string `json:"cluster_id,omitempty"`
4523-
RecoverySeal bool `json:"recovery_seal"`
4524-
StorageType string `json:"storage_type,omitempty"`
4525-
Warnings []string `json:"warnings,omitempty"`
4511+
Type string `json:"type"`
4512+
Initialized bool `json:"initialized"`
4513+
Sealed bool `json:"sealed"`
4514+
T int `json:"t"`
4515+
N int `json:"n"`
4516+
Progress int `json:"progress"`
4517+
Nonce string `json:"nonce"`
4518+
Version string `json:"version"`
4519+
BuildDate string `json:"build_date"`
4520+
Migration bool `json:"migration"`
4521+
ClusterName string `json:"cluster_name,omitempty"`
4522+
ClusterID string `json:"cluster_id,omitempty"`
4523+
RecoverySeal bool `json:"recovery_seal"`
4524+
RecoverySealType string `json:"recovery_seal_type,omitempty"`
4525+
StorageType string `json:"storage_type,omitempty"`
4526+
Warnings []string `json:"warnings,omitempty"`
45264527
}
45274528

45284529
func (core *Core) GetSealStatus(ctx context.Context, lock bool) (*SealStatusResponse, error) {
@@ -4534,8 +4535,10 @@ func (core *Core) GetSealStatus(ctx context.Context, lock bool) (*SealStatusResp
45344535
}
45354536

45364537
var sealConfig *SealConfig
4538+
var recoveryType string
45374539
if core.SealAccess().RecoveryKeySupported() {
45384540
sealConfig, err = core.SealAccess().RecoveryConfig(ctx)
4541+
recoveryType = core.SealAccess().RecoveryType()
45394542
} else {
45404543
sealConfig, err = core.SealAccess().BarrierConfig(ctx)
45414544
}
@@ -4545,13 +4548,14 @@ func (core *Core) GetSealStatus(ctx context.Context, lock bool) (*SealStatusResp
45454548

45464549
if sealConfig == nil {
45474550
s := &SealStatusResponse{
4548-
Type: core.SealAccess().BarrierType().String(),
4549-
Initialized: initialized,
4550-
Sealed: true,
4551-
RecoverySeal: core.SealAccess().RecoveryKeySupported(),
4552-
StorageType: core.StorageType(),
4553-
Version: version.GetVersion().VersionNumber(),
4554-
BuildDate: version.BuildDate,
4551+
Type: core.SealAccess().BarrierType().String(),
4552+
Initialized: initialized,
4553+
Sealed: true,
4554+
RecoverySeal: core.SealAccess().RecoveryKeySupported(),
4555+
RecoverySealType: recoveryType,
4556+
StorageType: core.StorageType(),
4557+
Version: version.GetVersion().VersionNumber(),
4558+
BuildDate: version.BuildDate,
45554559
}
45564560

45574561
return s, nil
@@ -4574,20 +4578,21 @@ func (core *Core) GetSealStatus(ctx context.Context, lock bool) (*SealStatusResp
45744578
progress, nonce := core.SecretProgress(lock)
45754579

45764580
s := &SealStatusResponse{
4577-
Type: sealConfig.Type,
4578-
Initialized: initialized,
4579-
Sealed: sealed,
4580-
T: sealConfig.SecretThreshold,
4581-
N: sealConfig.SecretShares,
4582-
Progress: progress,
4583-
Nonce: nonce,
4584-
Version: version.GetVersion().VersionNumber(),
4585-
BuildDate: version.BuildDate,
4586-
Migration: core.IsInSealMigrationMode(lock) && !core.IsSealMigrated(lock),
4587-
ClusterName: clusterName,
4588-
ClusterID: clusterID,
4589-
RecoverySeal: core.SealAccess().RecoveryKeySupported(),
4590-
StorageType: core.StorageType(),
4581+
Type: core.SealAccess().BarrierType().String(),
4582+
Initialized: initialized,
4583+
Sealed: sealed,
4584+
T: sealConfig.SecretThreshold,
4585+
N: sealConfig.SecretShares,
4586+
Progress: progress,
4587+
Nonce: nonce,
4588+
Version: version.GetVersion().VersionNumber(),
4589+
BuildDate: version.BuildDate,
4590+
Migration: core.IsInSealMigrationMode(lock) && !core.IsSealMigrated(lock),
4591+
ClusterName: clusterName,
4592+
ClusterID: clusterID,
4593+
RecoverySeal: core.SealAccess().RecoveryKeySupported(),
4594+
RecoverySealType: recoveryType,
4595+
StorageType: core.StorageType(),
45914596
}
45924597

45934598
return s, nil

vault/seal_access.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (s *SealAccess) RecoveryKeySupported() bool {
3838
return s.seal.RecoveryKeySupported()
3939
}
4040

41+
func (s *SealAccess) RecoveryType() string {
42+
return s.seal.RecoveryType()
43+
}
44+
4145
func (s *SealAccess) RecoveryConfig(ctx context.Context) (*SealConfig, error) {
4246
return s.seal.RecoveryConfig(ctx)
4347
}

0 commit comments

Comments
 (0)