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

Add "plumbing" for surfacing warnings, and warning overwriting ttl #17073

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
146 changes: 74 additions & 72 deletions builtin/logical/pki/cert_util.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions builtin/logical/pki/cert_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestPki_MultipleOUs(t *testing.T) {
OU: []string{"Z", "E", "V"},
},
}
cb, err := generateCreationBundle(&b, input, nil, nil)
cb, _, err := generateCreationBundle(&b, input, nil, nil)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestPki_PermitFQDNs(t *testing.T) {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
cb, err := generateCreationBundle(&b, testCase.input, nil, nil)
cb, _, err := generateCreationBundle(&b, testCase.input, nil, nil)
if err != nil {
t.Fatalf("Error: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion builtin/logical/pki/path_intermediate.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (b *backend) pathGenerateIntermediate(ctx context.Context, req *logical.Req
req: req,
apiData: data,
}
parsedBundle, err := generateIntermediateCSR(sc, input, b.Backend.GetRandomReader())
parsedBundle, warnings, err := generateIntermediateCSR(sc, input, b.Backend.GetRandomReader())
if err != nil {
switch err.(type) {
case errutil.UserError:
Expand Down Expand Up @@ -161,6 +161,8 @@ func (b *backend) pathGenerateIntermediate(ctx context.Context, req *logical.Req
}
resp.Data["key_id"] = myKey.ID

resp = addWarnings(resp, warnings)

return resp, nil
}

Expand Down
7 changes: 5 additions & 2 deletions builtin/logical/pki/path_issue_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,11 @@ func (b *backend) pathIssueSignCert(ctx context.Context, req *logical.Request, d
}
var parsedBundle *certutil.ParsedCertBundle
var err error
var warnings []string
if useCSR {
parsedBundle, err = signCert(b, input, signingBundle, false, useCSRValues)
parsedBundle, warnings, err = signCert(b, input, signingBundle, false, useCSRValues)
} else {
parsedBundle, err = generateCert(sc, input, signingBundle, false, rand.Reader)
parsedBundle, warnings, err = generateCert(sc, input, signingBundle, false, rand.Reader)
}
if err != nil {
switch err.(type) {
Expand Down Expand Up @@ -426,6 +427,8 @@ func (b *backend) pathIssueSignCert(ctx context.Context, req *logical.Request, d
}
}

resp = addWarnings(resp, warnings)

return resp, nil
}

Expand Down
8 changes: 6 additions & 2 deletions builtin/logical/pki/path_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (b *backend) pathCAGenerateRoot(ctx context.Context, req *logical.Request,
apiData: data,
role: role,
}
parsedBundle, err := generateCert(sc, input, nil, true, b.Backend.GetRandomReader())
parsedBundle, warnings, err := generateCert(sc, input, nil, true, b.Backend.GetRandomReader())
if err != nil {
switch err.(type) {
case errutil.UserError:
Expand Down Expand Up @@ -275,6 +275,8 @@ func (b *backend) pathCAGenerateRoot(ctx context.Context, req *logical.Request,
resp.AddWarning("Max path length of the generated certificate is zero. This certificate cannot be used to issue intermediate CA certificates.")
}

resp = addWarnings(resp, warnings)

return resp, nil
}

Expand Down Expand Up @@ -355,7 +357,7 @@ func (b *backend) pathIssuerSignIntermediate(ctx context.Context, req *logical.R
apiData: data,
role: role,
}
parsedBundle, err := signCert(b, input, signingBundle, true, useCSRValues)
parsedBundle, warnings, err := signCert(b, input, signingBundle, true, useCSRValues)
if err != nil {
switch err.(type) {
case errutil.UserError:
Expand Down Expand Up @@ -451,6 +453,8 @@ func (b *backend) pathIssuerSignIntermediate(ctx context.Context, req *logical.R
resp.AddWarning("Max path length of the signed certificate is zero. This certificate cannot be used to issue intermediate CA certificates.")
}

resp = addWarnings(resp, warnings)

return resp, nil
}

Expand Down
2 changes: 1 addition & 1 deletion builtin/logical/pki/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func genCertBundle(t *testing.T, b *backend, s logical.Storage) *certutil.CertBu
apiData: apiData,
role: role,
}
parsedCertBundle, err := generateCert(sc, input, nil, true, b.GetRandomReader())
parsedCertBundle, _, err := generateCert(sc, input, nil, true, b.GetRandomReader())

require.NoError(t, err)
certBundle, err := parsedCertBundle.ToCertBundle()
Expand Down
9 changes: 9 additions & 0 deletions builtin/logical/pki/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,12 @@ func (sc *storageContext) isIfModifiedSinceBeforeLastModified(helper *IfModified

return false, nil
}

func addWarnings(resp *logical.Response, warnings []string) *logical.Response {
if warnings != nil && len(warnings) > 0 {
for _, warning := range warnings {
resp.AddWarning(warning)
}
}
return resp
}
3 changes: 3 additions & 0 deletions changelog/17073.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
secrets/pki: Add a warning to any successful response when the requested TTL is overwritten by MaxTTL
```