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 Fix OpenAPI spec definitions for PKI EAB APIs into release/1.14.x #21468

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
108 changes: 85 additions & 23 deletions builtin/logical/pki/path_acme_eab.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"
"net/http"
"path"
"strings"
"time"

"github.com/hashicorp/go-uuid"
Expand Down Expand Up @@ -39,20 +41,32 @@ func mustBase64Decode(s string) []byte {
func pathAcmeEabList(b *backend) *framework.Path {
return &framework.Path{
Pattern: "eab/?$",

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixPKI,
},

Fields: map[string]*framework.FieldSchema{},

Fields: map[string]*framework.FieldSchema{},
Operations: map[logical.Operation]framework.OperationHandler{
logical.ListOperation: &framework.PathOperation{
Callback: b.pathAcmeListEab,
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "list-eab-key",
OperationSuffix: "acme",
OperationPrefix: operationPrefixPKI,
OperationVerb: "list-eab-keys",
Description: "List all eab key identifiers yet to be used.",
},
Responses: map[int][]framework.Response{
http.StatusOK: {{
Description: "OK",
Fields: map[string]*framework.FieldSchema{
"keys": {
Type: framework.TypeStringSlice,
Description: `A list of unused eab keys`,
Required: true,
},
"key_info": {
Type: framework.TypeMap,
Description: `EAB details keyed by the eab key id`,
Required: false,
},
},
}},
},
Callback: b.pathAcmeListEab,
},
},

Expand All @@ -69,25 +83,58 @@ func patternAcmeNewEab(b *backend, pattern string) *framework.Path {
fields := map[string]*framework.FieldSchema{}
addFieldsForACMEPath(fields, pattern)

opSuffix := getAcmeOperationSuffix(pattern)

return &framework.Path{
Pattern: pattern,
Fields: fields,

Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{
Callback: b.pathAcmeCreateEab,
ForwardPerformanceSecondary: false,
ForwardPerformanceStandby: true,
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixPKI,
OperationVerb: "generate-eab-key",
OperationSuffix: "acme",
OperationSuffix: opSuffix,
Description: "Generate an ACME EAB token for a directory",
},
Responses: map[int][]framework.Response{
http.StatusOK: {{
Description: "OK",
Fields: map[string]*framework.FieldSchema{
"id": {
Type: framework.TypeString,
Description: `The EAB key identifier`,
Required: true,
},
"key_type": {
Type: framework.TypeString,
Description: `The EAB key type`,
Required: true,
},
"key": {
Type: framework.TypeString,
Description: `The EAB hmac key`,
Required: true,
},
"acme_directory": {
Type: framework.TypeString,
Description: `The ACME directory to which the key belongs`,
Required: true,
},
"created_on": {
Type: framework.TypeTime,
Description: `An RFC3339 formatted date time when the EAB token was created`,
Required: true,
},
},
}},
},
},
},

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixPKI,
},

HelpSynopsis: "Generate external account bindings to be used for ACME",
HelpDescription: `Generate single use id/key pairs to be used for ACME EAB.`,
}
Expand All @@ -97,26 +144,23 @@ func pathAcmeEabDelete(b *backend) *framework.Path {
return &framework.Path{
Pattern: "eab/" + uuidNameRegex("key_id"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixPKI,
},

Fields: map[string]*framework.FieldSchema{
"key_id": {
Type: framework.TypeString,
Description: "EAB key identifier",
Required: true,
},
},

Operations: map[logical.Operation]framework.OperationHandler{
logical.DeleteOperation: &framework.PathOperation{
DisplayAttrs: &framework.DisplayAttributes{
OperationSuffix: "acme-configuration",
},
Callback: b.pathAcmeDeleteEab,
ForwardPerformanceSecondary: false,
ForwardPerformanceStandby: true,
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixPKI,
OperationVerb: "delete-eab-key",
Description: "Delete an unused EAB token",
},
},
},

Expand Down Expand Up @@ -230,3 +274,21 @@ func (b *backend) pathAcmeDeleteEab(ctx context.Context, r *logical.Request, d *
}
return resp, nil
}

// getAcmeOperationSuffix used mainly to compute the OpenAPI spec suffix value to distinguish
// different versions of ACME Vault APIs based on directory paths
func getAcmeOperationSuffix(pattern string) string {
hasRole := strings.Contains(pattern, framework.GenericNameRegex("role"))
hasIssuer := strings.Contains(pattern, framework.GenericNameRegex(issuerRefParam))

switch {
case hasRole && hasIssuer:
return "for-issuer-and-role"
case hasRole:
return "for-role"
case hasIssuer:
return "for-issuer"
default:
return ""
}
}
3 changes: 3 additions & 0 deletions changelog/21458.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
openapi: Fix schema definitions for PKI EAB APIs
```