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

Add option to set certificate in-memory #6831

Merged
merged 3 commits into from
Dec 19, 2019
Merged

Conversation

michelvocks
Copy link
Contributor

This PR adds the option to set an in-memory certificate to the client instead of requiring the certificate to be stored on disk in a file.

@notnoop I saw some weird changes in the vendor.json file. I couldn't find any information regarding the tool used to vendor imports so I used govendor. I this still accurate?

@notnoop
Copy link
Contributor

notnoop commented Dec 13, 2019

Thanks @michelvocks . We use vendorfmt (invoked by make vendorfmt) to make vendor file more diff friendly.

I would love some motivation here and the trade-off of having file vs env-var for tls configuration? Operators can always dump cert to a file prior to starting nomad; but setting it through env-var makes it harder to reload tls configuration.

Also, it'll be nice to treat client key/cert in mutual tls setting consistently. Should we have env-vars for these as well? Though I feel a bit odd about having private key being an env var. We had a security vulnerability CVE-2019-14802 because nomad env-var processes were accidentally made available to tasks in that's fixed in #6055 .

@michelvocks
Copy link
Contributor Author

Hi @notnoop!

Thanks for the feedback!
I've applied vendorfmt to make the change more diff friendly.

I would love some motivation here and the trade-off of having file vs env-var for tls configuration? Operators can always dump cert to a file prior to starting nomad; but setting it through env-var makes it harder to reload tls configuration.

I agree. A certificate env-var for Nomad is not necessarily important (that is why I removed it from the PR) for me. What actually interests me is to set the client certificate via the client SDK directly in-memory without the requirement to dump the certificate to disk.

That would allow me to implement hashicorp/vault#5619. Since we are using the Nomad client SDK in Vault to communicate with external Nomad instances, we can use this feature to allow Vault operators to define multiple client certificates per Nomad instance.

Cheers,
Michel

Copy link
Contributor

@endocrimes endocrimes left a comment

Choose a reason for hiding this comment

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

As an option for using the Nomad SDK this LGTM 👍

Might want to also update api/go.{mod,sum} to pull the correct version of go-rootcerts.

@michelvocks
Copy link
Contributor Author

Hi @endocrimes!

Good catch! I've updated the go modules files.

Cheers,
Michel

Copy link
Contributor

@notnoop notnoop left a comment

Choose a reason for hiding this comment

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

Thanks for the context! Indeed, having those flags in /api package is great. Minor comment about naming, but not critical.

api/api.go Outdated
@@ -178,6 +178,10 @@ type TLSConfig struct {
// the Nomad server SSL certificate.
CAPath string

// CAInMemCert is the PEM-encoded CA cert to use to verify the Nomad server
// SSL certificate.
CAInMemCert []byte
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel a tad uneasy about InMem as a public field to indicate that this is the raw cert bytes. I'd probably consider using something with bytes, raw, or even Pem, e.g. CACertPEM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I changed it to CACertPEM. What do you think?

// CAInMemCert is the PEM-encoded CA cert to use to verify the Nomad server
// SSL certificate.
CAInMemCert []byte

// ClientCert is the path to the certificate for Nomad communication
ClientCert string
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably should expose a raw field for ClientCert and ClientKey values. I can follow up with that as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I added both.

Copy link
Contributor

@notnoop notnoop left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks! This is a good improvement - merging momentarily.

@notnoop notnoop merged commit 792fe74 into master Dec 19, 2019
@notnoop notnoop deleted the add_inmemory_certificate branch December 19, 2019 13:54
@michelvocks
Copy link
Contributor Author

Thanks a lot for your support @notnoop & @endocrimes!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants