2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-04-24 19:15:50 +00:00
|
|
|
package awsauth
|
2016-04-06 00:42:26 +00:00
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2016-04-06 00:42:26 +00:00
|
|
|
"crypto/x509"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/pem"
|
|
|
|
"fmt"
|
2016-10-04 00:25:07 +00:00
|
|
|
"strings"
|
2016-04-06 00:42:26 +00:00
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2016-04-06 00:42:26 +00:00
|
|
|
)
|
|
|
|
|
2016-04-13 23:01:06 +00:00
|
|
|
// pathListCertificates creates a path that enables listing of all
|
|
|
|
// the AWS public certificates registered with Vault.
|
2019-07-31 23:11:35 +00:00
|
|
|
func (b *backend) pathListCertificates() *framework.Path {
|
2016-04-13 23:01:06 +00:00
|
|
|
return &framework.Path{
|
|
|
|
Pattern: "config/certificates/?",
|
|
|
|
|
2023-04-06 15:08:30 +00:00
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
|
|
OperationPrefix: operationPrefixAWS,
|
|
|
|
OperationSuffix: "certificate-configurations",
|
|
|
|
},
|
|
|
|
|
2019-07-31 23:11:35 +00:00
|
|
|
Operations: map[logical.Operation]framework.OperationHandler{
|
|
|
|
logical.ListOperation: &framework.PathOperation{
|
|
|
|
Callback: b.pathCertificatesList,
|
|
|
|
},
|
2016-04-13 23:01:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathListCertificatesHelpSyn,
|
|
|
|
HelpDescription: pathListCertificatesHelpDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 23:11:35 +00:00
|
|
|
func (b *backend) pathConfigCertificate() *framework.Path {
|
2016-04-06 00:42:26 +00:00
|
|
|
return &framework.Path{
|
2016-04-13 23:01:06 +00:00
|
|
|
Pattern: "config/certificate/" + framework.GenericNameRegex("cert_name"),
|
2023-04-06 15:08:30 +00:00
|
|
|
|
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
|
|
OperationPrefix: operationPrefixAWS,
|
|
|
|
},
|
|
|
|
|
2016-04-06 00:42:26 +00:00
|
|
|
Fields: map[string]*framework.FieldSchema{
|
2016-10-04 00:25:07 +00:00
|
|
|
"cert_name": {
|
2016-04-13 23:01:06 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "Name of the certificate.",
|
|
|
|
},
|
2016-10-04 00:25:07 +00:00
|
|
|
"aws_public_cert": {
|
2016-04-06 00:42:26 +00:00
|
|
|
Type: framework.TypeString,
|
2017-09-27 00:28:52 +00:00
|
|
|
Description: "Base64 encoded AWS Public cert required to verify PKCS7 signature of the EC2 instance metadata.",
|
2016-04-06 00:42:26 +00:00
|
|
|
},
|
2016-10-04 00:25:07 +00:00
|
|
|
"type": {
|
2016-10-04 18:57:04 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Default: "pkcs7",
|
2016-10-04 00:29:35 +00:00
|
|
|
Description: `
|
|
|
|
Takes the value of either "pkcs7" or "identity", indicating the type of
|
|
|
|
document which can be verified using the given certificate. The reason is that
|
|
|
|
the PKCS#7 document will have a DSA digest and the identity signature will have
|
|
|
|
an RSA signature, and accordingly the public certificates to verify those also
|
2016-10-04 18:57:04 +00:00
|
|
|
vary. Defaults to "pkcs7".`,
|
2016-10-04 00:25:07 +00:00
|
|
|
},
|
2016-04-06 00:42:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
ExistenceCheck: b.pathConfigCertificateExistenceCheck,
|
|
|
|
|
2019-07-31 23:11:35 +00:00
|
|
|
Operations: map[logical.Operation]framework.OperationHandler{
|
|
|
|
logical.CreateOperation: &framework.PathOperation{
|
|
|
|
Callback: b.pathConfigCertificateCreateUpdate,
|
2023-04-06 15:08:30 +00:00
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
|
|
OperationVerb: "configure",
|
|
|
|
OperationSuffix: "certificate",
|
|
|
|
},
|
2019-07-31 23:11:35 +00:00
|
|
|
},
|
|
|
|
logical.UpdateOperation: &framework.PathOperation{
|
|
|
|
Callback: b.pathConfigCertificateCreateUpdate,
|
2023-04-06 15:08:30 +00:00
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
|
|
OperationVerb: "configure",
|
|
|
|
OperationSuffix: "certificate",
|
|
|
|
},
|
2019-07-31 23:11:35 +00:00
|
|
|
},
|
|
|
|
logical.ReadOperation: &framework.PathOperation{
|
|
|
|
Callback: b.pathConfigCertificateRead,
|
2023-04-06 15:08:30 +00:00
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
|
|
OperationSuffix: "certificate-configuration",
|
|
|
|
},
|
2019-07-31 23:11:35 +00:00
|
|
|
},
|
|
|
|
logical.DeleteOperation: &framework.PathOperation{
|
|
|
|
Callback: b.pathConfigCertificateDelete,
|
2023-04-06 15:08:30 +00:00
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
|
|
OperationSuffix: "certificate-configuration",
|
|
|
|
},
|
2019-07-31 23:11:35 +00:00
|
|
|
},
|
2016-04-06 00:42:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathConfigCertificateSyn,
|
|
|
|
HelpDescription: pathConfigCertificateDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Establishes dichotomy of request operation between CreateOperation and UpdateOperation.
|
|
|
|
// Returning 'true' forces an UpdateOperation, CreateOperation otherwise.
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathConfigCertificateExistenceCheck(ctx context.Context, req *logical.Request, data *framework.FieldData) (bool, error) {
|
2016-04-13 23:01:06 +00:00
|
|
|
certName := data.Get("cert_name").(string)
|
|
|
|
if certName == "" {
|
|
|
|
return false, fmt.Errorf("missing cert_name")
|
|
|
|
}
|
2016-05-05 18:12:22 +00:00
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
entry, err := b.lockedAWSPublicCertificateEntry(ctx, req.Storage, certName)
|
2016-04-06 00:42:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return entry != nil, nil
|
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// pathCertificatesList is used to list all the AWS public certificates registered with Vault
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathCertificatesList(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
2016-04-19 19:32:15 +00:00
|
|
|
b.configMutex.RLock()
|
|
|
|
defer b.configMutex.RUnlock()
|
2016-05-03 16:14:07 +00:00
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
certs, err := req.Storage.List(ctx, "config/certificate/")
|
2016-04-13 23:01:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return logical.ListResponse(certs), nil
|
|
|
|
}
|
|
|
|
|
2022-06-01 17:26:17 +00:00
|
|
|
// Decodes the PEM encoded certificate and parses it into a x509 cert
|
2016-04-06 00:42:26 +00:00
|
|
|
func decodePEMAndParseCertificate(certificate string) (*x509.Certificate, error) {
|
2016-10-04 00:25:07 +00:00
|
|
|
// Decode the PEM block and error out if a block is not detected in the first attempt
|
2016-04-06 00:42:26 +00:00
|
|
|
decodedPublicCert, rest := pem.Decode([]byte(certificate))
|
|
|
|
if len(rest) != 0 {
|
2016-05-05 15:22:36 +00:00
|
|
|
return nil, fmt.Errorf("invalid certificate; should be one PEM block only")
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// Check if the certificate can be parsed
|
2016-04-06 00:42:26 +00:00
|
|
|
publicCert, err := x509.ParseCertificate(decodedPublicCert.Bytes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if publicCert == nil {
|
|
|
|
return nil, fmt.Errorf("invalid certificate; failed to parse certificate")
|
|
|
|
}
|
|
|
|
return publicCert, nil
|
|
|
|
}
|
|
|
|
|
2016-04-13 23:01:06 +00:00
|
|
|
// awsPublicCertificates returns a slice of all the parsed AWS public
|
2022-06-01 17:26:17 +00:00
|
|
|
// certificates, which are used to verify either the identity, RSA 2048
|
|
|
|
// or the PKCS7 signatures of the instance identity documents. This method will
|
2016-10-03 22:06:28 +00:00
|
|
|
// append the certificates registered using `config/certificate/<cert_name>`
|
2022-06-01 17:26:17 +00:00
|
|
|
// endpoint, along with the default certificates in the backend.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) awsPublicCertificates(ctx context.Context, s logical.Storage, isPkcs bool) ([]*x509.Certificate, error) {
|
2016-05-05 18:12:22 +00:00
|
|
|
// Lock at beginning and use internal method so that we are consistent as
|
|
|
|
// we iterate through
|
|
|
|
b.configMutex.RLock()
|
|
|
|
defer b.configMutex.RUnlock()
|
|
|
|
|
2022-06-01 17:26:17 +00:00
|
|
|
certs := make([]*x509.Certificate, len(defaultCertificates))
|
|
|
|
copy(certs, defaultCertificates)
|
2016-04-13 23:01:06 +00:00
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// Get the list of all the registered certificates
|
2018-01-19 06:44:44 +00:00
|
|
|
registeredCerts, err := s.List(ctx, "config/certificate/")
|
2016-04-28 02:25:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-04-13 23:01:06 +00:00
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// Iterate through each certificate, parse and append it to a slice
|
2016-04-13 23:01:06 +00:00
|
|
|
for _, cert := range registeredCerts {
|
2018-01-19 06:44:44 +00:00
|
|
|
certEntry, err := b.nonLockedAWSPublicCertificateEntry(ctx, s, cert)
|
2016-04-13 23:01:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if certEntry == nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, fmt.Errorf("certificate storage has a nil entry under the name: %q", cert)
|
2016-04-13 23:01:06 +00:00
|
|
|
}
|
2016-10-04 00:29:35 +00:00
|
|
|
// Append relevant certificates only
|
|
|
|
if (isPkcs && certEntry.Type == "pkcs7") ||
|
|
|
|
(!isPkcs && certEntry.Type == "identity") {
|
|
|
|
decodedCert, err := decodePEMAndParseCertificate(certEntry.AWSPublicCert)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
certs = append(certs, decodedCert)
|
2016-04-13 23:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return certs, nil
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// lockedSetAWSPublicCertificateEntry is used to store the AWS public key in
|
|
|
|
// the storage. This method acquires lock before creating or updating a storage
|
|
|
|
// entry.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) lockedSetAWSPublicCertificateEntry(ctx context.Context, s logical.Storage, certName string, certEntry *awsPublicCert) error {
|
2016-10-04 00:25:07 +00:00
|
|
|
if certName == "" {
|
|
|
|
return fmt.Errorf("missing certificate name")
|
|
|
|
}
|
|
|
|
|
|
|
|
if certEntry == nil {
|
|
|
|
return fmt.Errorf("nil AWS public key certificate")
|
|
|
|
}
|
|
|
|
|
|
|
|
b.configMutex.Lock()
|
|
|
|
defer b.configMutex.Unlock()
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
return b.nonLockedSetAWSPublicCertificateEntry(ctx, s, certName, certEntry)
|
2016-10-04 00:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nonLockedSetAWSPublicCertificateEntry is used to store the AWS public key in
|
|
|
|
// the storage. This method does not acquire lock before reading the storage.
|
|
|
|
// If locking is desired, use lockedSetAWSPublicCertificateEntry instead.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) nonLockedSetAWSPublicCertificateEntry(ctx context.Context, s logical.Storage, certName string, certEntry *awsPublicCert) error {
|
2016-10-04 00:25:07 +00:00
|
|
|
if certName == "" {
|
|
|
|
return fmt.Errorf("missing certificate name")
|
|
|
|
}
|
|
|
|
|
|
|
|
if certEntry == nil {
|
|
|
|
return fmt.Errorf("nil AWS public key certificate")
|
|
|
|
}
|
|
|
|
|
|
|
|
entry, err := logical.StorageEntryJSON("config/certificate/"+certName, certEntry)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
return fmt.Errorf("failed to create storage entry for AWS public key certificate")
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
return s.Put(ctx, entry)
|
2016-10-04 00:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// lockedAWSPublicCertificateEntry is used to get the configured AWS Public Key
|
|
|
|
// that is used to verify the PKCS#7 signature of the instance identity
|
|
|
|
// document.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) lockedAWSPublicCertificateEntry(ctx context.Context, s logical.Storage, certName string) (*awsPublicCert, error) {
|
2016-04-19 19:32:15 +00:00
|
|
|
b.configMutex.RLock()
|
|
|
|
defer b.configMutex.RUnlock()
|
2016-05-03 16:14:07 +00:00
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
return b.nonLockedAWSPublicCertificateEntry(ctx, s, certName)
|
2016-05-05 18:12:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// nonLockedAWSPublicCertificateEntry reads the certificate information from
|
|
|
|
// the storage. This method does not acquire lock before reading the storage.
|
|
|
|
// If locking is desired, use lockedAWSPublicCertificateEntry instead.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) nonLockedAWSPublicCertificateEntry(ctx context.Context, s logical.Storage, certName string) (*awsPublicCert, error) {
|
|
|
|
entry, err := s.Get(ctx, "config/certificate/"+certName)
|
2016-04-06 00:42:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2016-10-04 00:25:07 +00:00
|
|
|
var certEntry awsPublicCert
|
|
|
|
if err := entry.DecodeJSON(&certEntry); err != nil {
|
2016-04-06 00:42:26 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2016-10-04 00:25:07 +00:00
|
|
|
|
|
|
|
// Handle upgrade for certificate type
|
|
|
|
persistNeeded := false
|
|
|
|
if certEntry.Type == "" {
|
|
|
|
certEntry.Type = "pkcs7"
|
|
|
|
persistNeeded = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if persistNeeded {
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := b.nonLockedSetAWSPublicCertificateEntry(ctx, s, certName, &certEntry); err != nil {
|
2016-10-04 00:25:07 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &certEntry, nil
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// pathConfigCertificateDelete is used to delete the previously configured AWS
|
|
|
|
// Public Key that is used to verify the PKCS#7 signature of the instance
|
|
|
|
// identity document.
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathConfigCertificateDelete(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
2016-04-27 03:40:11 +00:00
|
|
|
b.configMutex.Lock()
|
|
|
|
defer b.configMutex.Unlock()
|
2016-04-28 04:35:49 +00:00
|
|
|
|
2016-04-13 23:01:06 +00:00
|
|
|
certName := data.Get("cert_name").(string)
|
|
|
|
if certName == "" {
|
|
|
|
return logical.ErrorResponse("missing cert_name"), nil
|
|
|
|
}
|
2016-04-28 04:35:49 +00:00
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
return nil, req.Storage.Delete(ctx, "config/certificate/"+certName)
|
2016-04-13 23:01:06 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// pathConfigCertificateRead is used to view the configured AWS Public Key that
|
|
|
|
// is used to verify the PKCS#7 signature of the instance identity document.
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathConfigCertificateRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
2016-04-13 23:01:06 +00:00
|
|
|
certName := data.Get("cert_name").(string)
|
|
|
|
if certName == "" {
|
|
|
|
return logical.ErrorResponse("missing cert_name"), nil
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
certificateEntry, err := b.lockedAWSPublicCertificateEntry(ctx, req.Storage, certName)
|
2016-04-06 00:42:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if certificateEntry == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &logical.Response{
|
2018-01-19 06:44:44 +00:00
|
|
|
Data: map[string]interface{}{
|
|
|
|
"aws_public_cert": certificateEntry.AWSPublicCert,
|
|
|
|
"type": certificateEntry.Type,
|
|
|
|
},
|
2016-04-06 00:42:26 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// pathConfigCertificateCreateUpdate is used to register an AWS Public Key that
|
|
|
|
// is used to verify the PKCS#7 signature of the instance identity document.
|
2018-01-08 18:31:38 +00:00
|
|
|
func (b *backend) pathConfigCertificateCreateUpdate(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
2016-04-13 23:01:06 +00:00
|
|
|
certName := data.Get("cert_name").(string)
|
|
|
|
if certName == "" {
|
2016-10-04 00:25:07 +00:00
|
|
|
return logical.ErrorResponse("missing certificate name"), nil
|
|
|
|
}
|
|
|
|
|
2016-05-05 18:12:22 +00:00
|
|
|
b.configMutex.Lock()
|
|
|
|
defer b.configMutex.Unlock()
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// Check if there is already a certificate entry registered
|
2018-01-19 06:44:44 +00:00
|
|
|
certEntry, err := b.nonLockedAWSPublicCertificateEntry(ctx, req.Storage, certName)
|
2016-04-06 00:42:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if certEntry == nil {
|
|
|
|
certEntry = &awsPublicCert{}
|
|
|
|
}
|
|
|
|
|
2016-10-04 18:57:04 +00:00
|
|
|
// Check if type information is provided
|
|
|
|
certTypeRaw, ok := data.GetOk("type")
|
|
|
|
if ok {
|
|
|
|
certEntry.Type = strings.ToLower(certTypeRaw.(string))
|
|
|
|
} else if req.Operation == logical.CreateOperation {
|
|
|
|
certEntry.Type = data.Get("type").(string)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch certEntry.Type {
|
|
|
|
case "pkcs7":
|
|
|
|
case "identity":
|
|
|
|
default:
|
|
|
|
return logical.ErrorResponse(fmt.Sprintf("invalid certificate type %q", certEntry.Type)), nil
|
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// Check if the value is provided by the client
|
2016-05-05 15:36:28 +00:00
|
|
|
certStrData, ok := data.GetOk("aws_public_cert")
|
2016-04-06 00:42:26 +00:00
|
|
|
if ok {
|
2016-05-05 15:36:28 +00:00
|
|
|
if certBytes, err := base64.StdEncoding.DecodeString(certStrData.(string)); err == nil {
|
|
|
|
certEntry.AWSPublicCert = string(certBytes)
|
|
|
|
} else {
|
2016-05-05 16:44:40 +00:00
|
|
|
certEntry.AWSPublicCert = certStrData.(string)
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
2016-04-13 23:01:06 +00:00
|
|
|
} else {
|
|
|
|
// aws_public_cert should be supplied for both create and update operations.
|
|
|
|
// If it is not provided, throw an error.
|
|
|
|
return logical.ErrorResponse("missing aws_public_cert"), nil
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// If explicitly set to empty string, error out
|
2016-04-06 00:42:26 +00:00
|
|
|
if certEntry.AWSPublicCert == "" {
|
2016-04-13 23:01:06 +00:00
|
|
|
return logical.ErrorResponse("invalid aws_public_cert"), nil
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// Verify the certificate by decoding it and parsing it
|
2016-04-06 00:42:26 +00:00
|
|
|
publicCert, err := decodePEMAndParseCertificate(certEntry.AWSPublicCert)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if publicCert == nil {
|
|
|
|
return logical.ErrorResponse("invalid certificate; failed to decode and parse certificate"), nil
|
|
|
|
}
|
|
|
|
|
2016-10-04 00:25:07 +00:00
|
|
|
// If none of the checks fail, save the provided certificate
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := b.nonLockedSetAWSPublicCertificateEntry(ctx, req.Storage, certName, certEntry); err != nil {
|
2016-04-06 00:42:26 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Struct awsPublicCert holds the AWS Public Key that is used to verify the PKCS#7 signature
|
2018-03-20 18:54:10 +00:00
|
|
|
// of the instance identity document.
|
2016-04-06 00:42:26 +00:00
|
|
|
type awsPublicCert struct {
|
2018-02-27 20:27:49 +00:00
|
|
|
AWSPublicCert string `json:"aws_public_cert"`
|
|
|
|
Type string `json:"type"`
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const pathConfigCertificateSyn = `
|
2018-03-20 18:54:10 +00:00
|
|
|
Adds the AWS Public Key that is used to verify the PKCS#7 signature of the identity document.
|
2016-04-06 00:42:26 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
const pathConfigCertificateDesc = `
|
2016-04-28 02:25:15 +00:00
|
|
|
AWS Public Key which is used to verify the PKCS#7 signature of the identity document,
|
2016-05-12 11:19:29 +00:00
|
|
|
varies by region. The public key(s) can be found in AWS EC2 instance metadata documentation.
|
2016-04-28 02:25:15 +00:00
|
|
|
The default key that is used to verify the signature is the one that is applicable for
|
|
|
|
following regions: US East (N. Virginia), US West (Oregon), US West (N. California),
|
|
|
|
EU (Ireland), EU (Frankfurt), Asia Pacific (Tokyo), Asia Pacific (Seoul), Asia Pacific (Singapore),
|
2016-04-06 00:42:26 +00:00
|
|
|
Asia Pacific (Sydney), and South America (Sao Paulo).
|
2016-04-28 02:25:15 +00:00
|
|
|
|
2016-05-12 11:19:29 +00:00
|
|
|
If the instances belongs to region other than the above, the public key(s) for the
|
|
|
|
corresponding regions should be registered using this endpoint. PKCS#7 is verified
|
|
|
|
using a collection of certificates containing the default certificate and all the
|
|
|
|
certificates that are registered using this endpoint.
|
2016-04-06 00:42:26 +00:00
|
|
|
`
|
2021-04-08 16:43:39 +00:00
|
|
|
|
2016-04-13 23:01:06 +00:00
|
|
|
const pathListCertificatesHelpSyn = `
|
2016-05-12 11:19:29 +00:00
|
|
|
Lists all the AWS public certificates that are registered with the backend.
|
2016-04-13 23:01:06 +00:00
|
|
|
`
|
2021-04-08 16:43:39 +00:00
|
|
|
|
2016-04-13 23:01:06 +00:00
|
|
|
const pathListCertificatesHelpDesc = `
|
|
|
|
Certificates will be listed by their respective names that were used during registration.
|
|
|
|
`
|