Add issuer reference info on JSON endpoint (#18482)

* Add issuer reference info on JSON endpoint

This endpoint is unauthenticated and shouldn't contain sensitive
information. However, listing the issuers (LIST /issuers) already
returns both the issuer ID and the issuer name (if any) so this
information is safe to return here.

When fetching /pki/issuer/default/json, it would be nice to know exactly
which issuer ID and name it corresponds to, without having to fetch the
authenticated endpoint as well.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add changelog entry

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
This commit is contained in:
Alexander Scheel 2022-12-19 16:39:01 -05:00 committed by GitHub
parent f86eaf2f98
commit 3ccbddab0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -304,6 +304,14 @@ func runSteps(t *testing.T, rootB, intB *backend, client *api.Client, rootName,
if path == "issuer/default/json" { if path == "issuer/default/json" {
// Preserves the new line. // Preserves the new line.
expected += "\n" expected += "\n"
_, present := resp.Data["issuer_id"]
if !present {
t.Fatalf("expected issuer/default/json to include issuer_id")
}
_, present = resp.Data["issuer_name"]
if !present {
t.Fatalf("expected issuer/default/json to include issuer_name")
}
} }
if diff := deep.Equal(resp.Data["certificate"].(string), expected); diff != nil { if diff := deep.Equal(resp.Data["certificate"].(string), expected); diff != nil {
t.Fatal(diff) t.Fatal(diff)

View File

@ -841,6 +841,8 @@ func (b *backend) pathGetRawIssuer(ctx context.Context, req *logical.Request, da
Data: map[string]interface{}{ Data: map[string]interface{}{
"certificate": string(certificate), "certificate": string(certificate),
"ca_chain": issuer.CAChain, "ca_chain": issuer.CAChain,
"issuer_id": issuer.ID,
"issuer_name": issuer.Name,
}, },
}, nil }, nil
} }

3
changelog/18482.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
secrets/pki: Return issuer_id and issuer_name on /issuer/:issuer_ref/json endpoint.
```