Skip to content

Commit

Permalink
Detect Vault 1.11+ import, update default issuer
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
  • Loading branch information
cipherboy committed Nov 3, 2022
1 parent 617a5f2 commit eeed745
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion agent/connect/ca/provider_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,34 @@ func (v *VaultProvider) GenerateIntermediate() (string, error) {
}

// Set the intermediate backend to use the new certificate.
_, err = v.writeNamespaced(v.config.IntermediatePKINamespace, v.config.IntermediatePKIPath+"intermediate/set-signed", map[string]interface{}{
importResp, err := v.writeNamespaced(v.config.IntermediatePKINamespace, v.config.IntermediatePKIPath+"intermediate/set-signed", map[string]interface{}{
"certificate": intermediate.Data["certificate"],
})
if err != nil {
return "", err
}

if importResp != nil {
// Assume we're on Vault 1.11+. We'll assume we only have one issuer
// with a key.
mapping := importResp.Data["mapping"].(map[string]string)
var intermediateId string
for issuer, key := range mapping {
if key != "" {
intermediateId = issuer
break
}
}

// Now post it to the default issuer.
_, err = v.writeNamespaced(v.config.IntermediatePKINamespace, v.config.IntermediatePKIPath+"config/issuers", map[string]interface{}{
"default": intermediateId,
})
if err != nil {
return "", err
}
}

return v.ActiveIntermediate()
}

Expand Down

0 comments on commit eeed745

Please sign in to comment.