Skip to content

Commit d492ca7

Browse files
hc-github-team-secure-vault-corecipherboy
andauthoredApr 26, 2023
Fix reading issuer's enable_aia_url_templating value (hashicorp#20354) (hashicorp#20358)
* Add enable_aia_url_templating to read issuer This field was elided from read issuer responses, though the value otherwise persisted correctly. * Add comprehensive test for patching issuers * Add changelog entry --------- Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> Co-authored-by: Alexander Scheel <alex.scheel@hashicorp.com>
1 parent 777b996 commit d492ca7

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
 

‎builtin/logical/pki/backend_test.go

+117
Original file line numberDiff line numberDiff line change
@@ -6829,6 +6829,123 @@ func TestProperAuthing(t *testing.T) {
68296829
}
68306830
}
68316831

6832+
func TestPatchIssuer(t *testing.T) {
6833+
t.Parallel()
6834+
6835+
type TestCase struct {
6836+
Field string
6837+
Before interface{}
6838+
Patched interface{}
6839+
}
6840+
testCases := []TestCase{
6841+
{
6842+
Field: "issuer_name",
6843+
Before: "root",
6844+
Patched: "root-new",
6845+
},
6846+
{
6847+
Field: "leaf_not_after_behavior",
6848+
Before: "err",
6849+
Patched: "permit",
6850+
},
6851+
{
6852+
Field: "usage",
6853+
Before: "crl-signing,issuing-certificates,ocsp-signing,read-only",
6854+
Patched: "issuing-certificates,read-only",
6855+
},
6856+
{
6857+
Field: "revocation_signature_algorithm",
6858+
Before: "ECDSAWithSHA256",
6859+
Patched: "ECDSAWithSHA384",
6860+
},
6861+
{
6862+
Field: "issuing_certificates",
6863+
Before: []string{"http://localhost/v1/pki-1/ca"},
6864+
Patched: []string{"http://localhost/v1/pki/ca"},
6865+
},
6866+
{
6867+
Field: "crl_distribution_points",
6868+
Before: []string{"http://localhost/v1/pki-1/crl"},
6869+
Patched: []string{"http://localhost/v1/pki/crl"},
6870+
},
6871+
{
6872+
Field: "ocsp_servers",
6873+
Before: []string{"http://localhost/v1/pki-1/ocsp"},
6874+
Patched: []string{"http://localhost/v1/pki/ocsp"},
6875+
},
6876+
{
6877+
Field: "enable_aia_url_templating",
6878+
Before: false,
6879+
Patched: true,
6880+
},
6881+
{
6882+
Field: "manual_chain",
6883+
Before: []string(nil),
6884+
Patched: []string{"self"},
6885+
},
6886+
}
6887+
6888+
for index, testCase := range testCases {
6889+
t.Logf("index: %v / tc: %v", index, testCase)
6890+
6891+
b, s := CreateBackendWithStorage(t)
6892+
6893+
// 1. Setup root issuer.
6894+
resp, err := CBWrite(b, s, "root/generate/internal", map[string]interface{}{
6895+
"common_name": "Vault Root CA",
6896+
"key_type": "ec",
6897+
"ttl": "7200h",
6898+
"issuer_name": "root",
6899+
})
6900+
requireSuccessNonNilResponse(t, resp, err, "failed generating root issuer")
6901+
id := string(resp.Data["issuer_id"].(issuerID))
6902+
6903+
// 2. Enable Cluster paths
6904+
resp, err = CBWrite(b, s, "config/urls", map[string]interface{}{
6905+
"path": "https://localhost/v1/pki",
6906+
"aia_path": "http://localhost/v1/pki",
6907+
})
6908+
requireSuccessNonNilResponse(t, resp, err, "failed updating AIA config")
6909+
6910+
// 3. Add AIA information
6911+
resp, err = CBPatch(b, s, "issuer/default", map[string]interface{}{
6912+
"issuing_certificates": "http://localhost/v1/pki-1/ca",
6913+
"crl_distribution_points": "http://localhost/v1/pki-1/crl",
6914+
"ocsp_servers": "http://localhost/v1/pki-1/ocsp",
6915+
})
6916+
requireSuccessNonNilResponse(t, resp, err, "failed setting up issuer")
6917+
6918+
// 4. Read the issuer before.
6919+
resp, err = CBRead(b, s, "issuer/default")
6920+
requireSuccessNonNilResponse(t, resp, err, "failed reading root issuer before")
6921+
require.Equal(t, testCase.Before, resp.Data[testCase.Field], "bad expectations")
6922+
6923+
// 5. Perform modification.
6924+
resp, err = CBPatch(b, s, "issuer/default", map[string]interface{}{
6925+
testCase.Field: testCase.Patched,
6926+
})
6927+
requireSuccessNonNilResponse(t, resp, err, "failed patching root issuer")
6928+
6929+
if testCase.Field != "manual_chain" {
6930+
require.Equal(t, testCase.Patched, resp.Data[testCase.Field], "failed persisting value")
6931+
} else {
6932+
// self->id
6933+
require.Equal(t, []string{id}, resp.Data[testCase.Field], "failed persisting value")
6934+
}
6935+
6936+
// 6. Ensure it stuck
6937+
resp, err = CBRead(b, s, "issuer/default")
6938+
requireSuccessNonNilResponse(t, resp, err, "failed reading root issuer after")
6939+
6940+
if testCase.Field != "manual_chain" {
6941+
require.Equal(t, testCase.Patched, resp.Data[testCase.Field])
6942+
} else {
6943+
// self->id
6944+
require.Equal(t, []string{id}, resp.Data[testCase.Field], "failed persisting value")
6945+
}
6946+
}
6947+
}
6948+
68326949
var (
68336950
initTest sync.Once
68346951
rsaCAKey string

‎builtin/logical/pki/path_fetch_issuers.go

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ func respondReadIssuer(issuer *issuerEntry) (*logical.Response, error) {
276276
data["issuing_certificates"] = issuer.AIAURIs.IssuingCertificates
277277
data["crl_distribution_points"] = issuer.AIAURIs.CRLDistributionPoints
278278
data["ocsp_servers"] = issuer.AIAURIs.OCSPServers
279+
data["enable_aia_url_templating"] = issuer.AIAURIs.EnableTemplating
279280
}
280281

281282
response := &logical.Response{

‎changelog/20354.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
secrets/pki: Include per-issuer enable_aia_url_templating in issuer read endpoint.
3+
```

0 commit comments

Comments
 (0)
Please sign in to comment.