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

feat: add pkiSign function to use vault pki sign api endpoint #1905

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

n-marton
Copy link
Contributor

@n-marton n-marton commented Apr 3, 2024

This pull requests intends to add a function to leverage the sign api endpoint in vault pki.

This can be really useful if one plans to use a large number of certificates with low TTL, where the usage of the issue endpoint can cause high load on the vault servers. By using the sign endpoint one can shift the heaviest part of the problem (the private key generation), from server side to client side.

@n-marton n-marton force-pushed the feat/add-pkisign branch 2 times, most recently from bc92044 to 395376a Compare June 17, 2024 07:25
@eduardolmedeiros
Copy link

hey guys, any chance to have a look on that?
appreciate.

@alexandrenas
Copy link

Hello team, could please someone have a look? It will be nice to have it soon. Thanks in advance!

Co-authored-by: Amir Aslamov <[email protected]>
@n-marton n-marton requested a review from a team as a code owner February 13, 2025 15:57
n-marton and others added 5 commits February 13, 2025 16:57
@aslamovamir
Copy link

Hi @n-marton , thanks a lot for opening the PR and your contribution. Your changes look great! I left some feedback. Also, we need unit tests added in here to ensure your new functions are covered in unit tests (to test they work in different use cases and edge cases and in case someone changes it in the future, unit tests catch errors): https://github.com/hashicorp/consul-template/blob/main/template/funcs_test.go

@n-marton
Copy link
Contributor Author

Hi @n-marton , thanks a lot for opening the PR and your contribution. Your changes look great! I left some feedback. Also, we need unit tests added in here to ensure your new functions are covered in unit tests (to test they work in different use cases and edge cases and in case someone changes it in the future, unit tests catch errors): https://github.com/hashicorp/consul-template/blob/main/template/funcs_test.go

hey @aslamovamir

thanks for getting back on this MR, I haven't wrote a test there because the cert issue func also did not have one, in fact that part is kind lacking heavily all together, however I am happy to write one for my new func, IF that is the only one thing we miss to merge this feature

@aslamovamir
Copy link

Hi @n-marton , thanks a lot for opening the PR and your contribution. Your changes look great! I left some feedback. Also, we need unit tests added in here to ensure your new functions are covered in unit tests (to test they work in different use cases and edge cases and in case someone changes it in the future, unit tests catch errors): https://github.com/hashicorp/consul-template/blob/main/template/funcs_test.go

hey @aslamovamir

thanks for getting back on this MR, I haven't wrote a test there because the cert issue func also did not have one, in fact that part is kind lacking heavily all together, however I am happy to write one for my new func, IF that is the only one thing we miss to merge this feature

Hi @n-marton, yup I see - I honestly am not part of the codeowners for this repo or never contributed to it so did not know other functions also lack unit tests here. But would be great to have it written for yours if thats okay. All the rest looks good to me in your PR and can approve it once we have unit test coverage.

Copy link

@victorr victorr left a comment

Choose a reason for hiding this comment

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

This is a wonderful PR, thank you so much for your contribution, it should prove very useful.

I have added some comments for your consideration. The most important one is about supporting alt_names. Please also consider addressing the other comments, or at least mentioning in the documentation the the defaults you have used for the signature algorithms.

I am not one of the code owners for this project, but we should have someone from the right team to review the PR soon.

}
// if we passed use_csr_sans, that means serverside will expect the subject alternate names from the csr
// so besides adding that param to the csr template, we also remove it from the map we pass later
if useCSRSans {
Copy link

Choose a reason for hiding this comment

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

The role's use_csr_sans overrides not only parameters uri_sans and ip_sans, but also alt_names.

It would be wonderful if you could add the names inalt_names to the CSR. The names have to be sorted into email addresses and DNS names, you can see how Vault does that here:

https://github.com/hashicorp/vault/blob/a401afe8249e901a9fe6e95b4bb9bbb5b4f8e3e3/builtin/logical/pki/issuing/issue_common.go#L162-L186

return nil, err
}
privateKey = key
csrTemplate.SignatureAlgorithm = x509.SHA512WithRSA
Copy link

Choose a reason for hiding this comment

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

What about looking for a signature_bits parameter to set the signature algorithm? Please consider it, as well as use_pss parameter for the RSA case.

https://github.com/hashicorp/vault/blob/371ffc4bd47a70c09e6b5c59cdd659ec09b719fa/sdk/helper/certutil/helpers.go#L1297-L1309

TTL, which can put a high load on the Vault servers.

The templating behavior is the same as in `pkiCert`, with a few special attributes.
You also need to pass `key_type=rsa|ec|ed25519` in alignment with your
Copy link

Choose a reason for hiding this comment

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

Please mention key_bits here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants