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

Refactor raw PKI fetch endpoints #14813

Closed
wants to merge 1 commit into from

Conversation

cipherboy
Copy link
Contributor

Various endpoints (/ca, /crl, /ca_chain, /certs) all use the same core
handling logic with a complicated per-path detection logic of which to
return. Refactor out the common response formatting code, but let each
API handler be distinct to provide the right storage reference.

This refactors just the raw path (/ca, /crl, /ca_chain, and
/cert/*/raw{,/pem}).

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


This should be rebased and merged after #14767 probably. We'll want a second version for the non-raw endpoints, but this at least takes a step in the right direction.

Copy link
Contributor

@kitography kitography left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have comments, but this is 100% better than what it was, so whatever.

builtin/logical/pki/path_fetch.go Outdated Show resolved Hide resolved
// Returns the CA chain
func pathFetchCAChain(b *backend) *framework.Path {
return &framework.Path{
Pattern: `(cert/)?ca_chain`,
Pattern: `cert/ca_chain`,

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathFetchRead,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one in particular not using a helper? I'm not sure why the serial is still set in the switch case statement there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was only handling the non-JSON ("raw") responses in this PR. :-) This endpoint (cert/ca_chain) returns a JSON blob, so I didn't touch it on this first pass.

builtin/logical/pki/path_fetch.go Show resolved Hide resolved
builtin/logical/pki/path_fetch.go Show resolved Hide resolved
builtin/logical/pki/path_fetch.go Show resolved Hide resolved
@@ -315,6 +333,79 @@ reply:
return
}

func (b *backend) readCertByAlias(ctx context.Context, req *logical.Request, alias string) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to duplicate what is already in pathFetchRead: is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; if we later refactor the JSON endpoints, we'll refactor pathFetchRead and likely use this logic instead of the logic already in it.

I didn't really see value in updating pathFetchRead to take out this piece of logic (avoiding the duplication) for the time being, since the bigger refactor of JSON endpoints would probably impact how we structure it anyways.

That's my 2c. at any rate.

builtin/logical/pki/path_fetch.go Show resolved Hide resolved
Various endpoints (/ca, /crl, /ca_chain, /certs) all use the same core
handling logic with a complicated per-path detection logic of which to
return. Refactor out the common response formatting code, but let each
API handler be distinct to provide the right storage reference.

This refactors just the raw path (/ca, /crl, /ca_chain, and
/cert/*/raw{,/pem}).

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
@cipherboy cipherboy force-pushed the cipherboy-refactor-raw-reading branch from 58d5b41 to 1d06b27 Compare April 4, 2022 14:36
@vercel vercel bot temporarily deployed to Preview – vault-storybook April 4, 2022 14:36 Inactive
@vercel vercel bot temporarily deployed to Preview – vault April 4, 2022 14:36 Inactive
@cipherboy cipherboy marked this pull request as draft April 5, 2022 18:16
@cipherboy
Copy link
Contributor Author

This approach won't work, because the Framework logic doesn't understand paths created this way. Closing this.

@cipherboy cipherboy closed this Apr 8, 2022
@cipherboy cipherboy deleted the cipherboy-refactor-raw-reading branch May 17, 2022 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants