Skip to content

Commit

Permalink
connect/ca: require new vault mount points when updating the key type…
Browse files Browse the repository at this point in the history
…/bits for the vault connect CA provider

progress on #9572
  • Loading branch information
rboyer committed Jul 13, 2021
1 parent dc15e5e commit 64a7048
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion agent/connect/ca/provider_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (v *VaultProvider) GenerateRoot() error {
}

// Set up the root PKI backend if necessary.
_, err := v.ActiveRoot()
rootPEM, err := v.ActiveRoot()
switch err {
case ErrBackendNotMounted:
err := v.client.Sys().Mount(v.config.RootPKIPath, &vaultapi.MountInput{
Expand Down Expand Up @@ -197,6 +197,31 @@ func (v *VaultProvider) GenerateRoot() error {
if err != nil {
return err
}

if rootPEM != "" {
rootCert, err := connect.ParseCert(rootPEM)
if err != nil {
return err
}

// Vault PKI doesn't allow in-place cert/key regeneration. That
// means if you need to change either the key type or key bits then
// you also need to provide new mount points.
// https://www.vaultproject.io/api-docs/secret/pki#generate-root
//
// A separate bug in vault likely also requires that you use the
// ForceWithoutCrossSigning option when changing key types.
foundKeyType, foundKeyBits, err := connect.KeyInfoFromCert(rootCert)
if err != nil {
return err
}
if v.config.PrivateKeyType != foundKeyType {
return fmt.Errorf("cannot update the PrivateKeyType field without choosing a new PKI mount for the root CA")
}
if v.config.PrivateKeyBits != foundKeyBits {
return fmt.Errorf("cannot update the PrivateKeyBits field without choosing a new PKI mount for the root CA")
}
}
}

return nil
Expand Down

0 comments on commit 64a7048

Please sign in to comment.