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

Fix reading issuer's enable_aia_url_templating value #20354

Merged
merged 4 commits into from
Apr 25, 2023
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
117 changes: 117 additions & 0 deletions builtin/logical/pki/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6919,6 +6919,123 @@ func TestProperAuthing(t *testing.T) {
}
}

func TestPatchIssuer(t *testing.T) {
t.Parallel()

type TestCase struct {
Field string
Before interface{}
Patched interface{}
}
testCases := []TestCase{
{
Field: "issuer_name",
Before: "root",
Patched: "root-new",
},
{
Field: "leaf_not_after_behavior",
Before: "err",
Patched: "permit",
},
{
Field: "usage",
Before: "crl-signing,issuing-certificates,ocsp-signing,read-only",
Patched: "issuing-certificates,read-only",
},
{
Field: "revocation_signature_algorithm",
Before: "ECDSAWithSHA256",
Patched: "ECDSAWithSHA384",
},
{
Field: "issuing_certificates",
Before: []string{"http://localhost/v1/pki-1/ca"},
Patched: []string{"http://localhost/v1/pki/ca"},
},
{
Field: "crl_distribution_points",
Before: []string{"http://localhost/v1/pki-1/crl"},
Patched: []string{"http://localhost/v1/pki/crl"},
},
{
Field: "ocsp_servers",
Before: []string{"http://localhost/v1/pki-1/ocsp"},
Patched: []string{"http://localhost/v1/pki/ocsp"},
},
{
Field: "enable_aia_url_templating",
Before: false,
Patched: true,
},
{
Field: "manual_chain",
Before: []string(nil),
Patched: []string{"self"},
},
}

for index, testCase := range testCases {
t.Logf("index: %v / tc: %v", index, testCase)

b, s := CreateBackendWithStorage(t)

// 1. Setup root issuer.
resp, err := CBWrite(b, s, "root/generate/internal", map[string]interface{}{
"common_name": "Vault Root CA",
"key_type": "ec",
"ttl": "7200h",
"issuer_name": "root",
})
requireSuccessNonNilResponse(t, resp, err, "failed generating root issuer")
id := string(resp.Data["issuer_id"].(issuerID))

// 2. Enable Cluster paths
resp, err = CBWrite(b, s, "config/urls", map[string]interface{}{
"path": "https://localhost/v1/pki",
"aia_path": "http://localhost/v1/pki",
})
requireSuccessNonNilResponse(t, resp, err, "failed updating AIA config")

// 3. Add AIA information
resp, err = CBPatch(b, s, "issuer/default", map[string]interface{}{
"issuing_certificates": "http://localhost/v1/pki-1/ca",
"crl_distribution_points": "http://localhost/v1/pki-1/crl",
"ocsp_servers": "http://localhost/v1/pki-1/ocsp",
})
requireSuccessNonNilResponse(t, resp, err, "failed setting up issuer")

// 4. Read the issuer before.
resp, err = CBRead(b, s, "issuer/default")
requireSuccessNonNilResponse(t, resp, err, "failed reading root issuer before")
require.Equal(t, testCase.Before, resp.Data[testCase.Field], "bad expectations")

// 5. Perform modification.
resp, err = CBPatch(b, s, "issuer/default", map[string]interface{}{
testCase.Field: testCase.Patched,
})
requireSuccessNonNilResponse(t, resp, err, "failed patching root issuer")

if testCase.Field != "manual_chain" {
require.Equal(t, testCase.Patched, resp.Data[testCase.Field], "failed persisting value")
} else {
// self->id
require.Equal(t, []string{id}, resp.Data[testCase.Field], "failed persisting value")
}

// 6. Ensure it stuck
resp, err = CBRead(b, s, "issuer/default")
requireSuccessNonNilResponse(t, resp, err, "failed reading root issuer after")

if testCase.Field != "manual_chain" {
require.Equal(t, testCase.Patched, resp.Data[testCase.Field])
} else {
// self->id
require.Equal(t, []string{id}, resp.Data[testCase.Field], "failed persisting value")
}
}
}

var (
initTest sync.Once
rsaCAKey string
Expand Down
6 changes: 6 additions & 0 deletions builtin/logical/pki/path_fetch_issuers.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ to be set on all PR secondary clusters.`,
Description: `OSCP Servers`,
Required: false,
},
"enable_aia_url_templating": {
Type: framework.TypeBool,
Description: `Whether or not templating is enabled for AIA fields`,
Required: false,
},
},
}},
}
Expand Down Expand Up @@ -458,6 +463,7 @@ func respondReadIssuer(issuer *issuerEntry) (*logical.Response, error) {
data["issuing_certificates"] = issuer.AIAURIs.IssuingCertificates
data["crl_distribution_points"] = issuer.AIAURIs.CRLDistributionPoints
data["ocsp_servers"] = issuer.AIAURIs.OCSPServers
data["enable_aia_url_templating"] = issuer.AIAURIs.EnableTemplating
}

response := &logical.Response{
Expand Down
3 changes: 3 additions & 0 deletions changelog/20354.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
secrets/pki: Include per-issuer enable_aia_url_templating in issuer read endpoint.
```