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

Format certificates properly (rfc7468) with a trailing new line #10411

Merged
merged 39 commits into from
Jul 1, 2021

Conversation

dhiaayachi
Copy link
Collaborator

@dhiaayachi dhiaayachi commented Jun 16, 2021

Fix #8178
When receiving a certificate from a certificate provider (ie: vault or consul it self) the certificate is not sanitized for trailing new lines, when we return the certificate in a response to v1/connect/ca/roots we concatenate the certificates without taking into account if it have the right newline or not.

This PR is to:

  • sanitize the certificates before we store them in memory
  • format the certificate (with the intermediates) correctly on the v1/connect/ca/roots api call

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 16, 2021 18:50 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 16, 2021 18:50 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 16, 2021 19:29 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 16, 2021 19:29 Inactive
@dhiaayachi dhiaayachi added the theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies label Jun 16, 2021
@dhiaayachi dhiaayachi requested review from a team and removed request for a team June 16, 2021 19:42
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

I only had a quick look, but similar to my comment in #10411 I thought we would want to be adding a newline when missing, not removing them.

I think enforcing that in the providers (what you have done here), is a good place to do so. Enforcing the correct format before before we store it. That way we don't have to change the certs when we send them out, because we always know we've stored them in the correct format with necessary newlines.

@vercel vercel bot temporarily deployed to Preview – consul June 21, 2021 15:24 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 21, 2021 15:24 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 21, 2021 15:43 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 21, 2021 15:43 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 21, 2021 16:13 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 21, 2021 16:13 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 21, 2021 16:14 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 21, 2021 16:14 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 22, 2021 19:36 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 22, 2021 19:36 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 30, 2021 19:28 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 30, 2021 19:28 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 30, 2021 19:30 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 30, 2021 19:30 Inactive
@vercel vercel bot temporarily deployed to Preview – consul June 30, 2021 19:37 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging June 30, 2021 19:37 Inactive
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Nice, LGTM!

VaultProvider.SignIntermediate and VaultProvider.CrossSignCA seem like they return certs from the Vault API response. Do those two calls need the trailing newline added as well?

agent/connect/ca/testing.go Show resolved Hide resolved
agent/consul/state/connect_ca_test.go Outdated Show resolved Hide resolved
agent/consul/server_connect.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging July 1, 2021 00:23 Inactive
@vercel vercel bot temporarily deployed to Preview – consul July 1, 2021 00:23 Inactive
@vercel vercel bot temporarily deployed to Preview – consul July 1, 2021 00:34 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging July 1, 2021 00:34 Inactive
@dhiaayachi dhiaayachi changed the title Format rootCA trailing new line properly for v1/connect/ca/roots Format certificates properly (rfc7468) with a trailing new line Jul 1, 2021
@dhiaayachi dhiaayachi merged commit 9b45107 into main Jul 1, 2021
@dhiaayachi dhiaayachi deleted the malformed_ca_carriage branch July 1, 2021 00:48
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/402278.

@hc-github-team-consul-core
Copy link
Collaborator

🍒✅ Cherry pick of commit 9b45107 onto release/1.10.x succeeded!

hc-github-team-consul-core pushed a commit that referenced this pull request Jul 1, 2021
* trim carriage return from certificates when inserting rootCA in the inMemDB

* format rootCA properly when returning the CA on the connect CA endpoint

* Fix linter warnings

* Fix providers to trim certs before returning it

* trim newlines on write when possible

* add changelog

* make sure all provider return a trailing newline after the root and intermediate certs

* Fix endpoint to return trailing new line

* Fix failing test with vault provider

* make test more robust

* make sure all provider return a trailing newline after the leaf certs

* Check for suffix before removing newline and use function

* Add comment to consul provider

* Update change log

Co-authored-by: R.B. Boyer <[email protected]>

* fix typo

* simplify code callflow

Co-authored-by: R.B. Boyer <[email protected]>

* extract requireNewLine as shared func

* remove dependency to testify in testing file

* remove extra newline in vault provider

* Add cert newline fix to envoy xds

* remove new line from mock provider

* Remove adding a new line from provider and fix it when the cert is read

* Add a comment to explain the fix

* Add missing for leaf certs

* fix missing new line

* fix missing new line in leaf certs

* remove extra new line in test

* updage changelog

Co-authored-by: Daniel Nephin <[email protected]>

* fix in vault provider and when reading cache (RPC call)

* fix AWS provider

* fix failing test in the provider

* remove comments and empty lines

* add check for empty cert in test

* fix linter warnings

* add new line for leaf and private key

* use string concat instead of Sprintf

* fix new lines for leaf signing

* preallocate slice and remove append

* Add new line to `SignIntermediate` and `CrossSignCA`

Co-authored-by: R.B. Boyer <[email protected]>
Co-authored-by: Daniel Nephin <[email protected]>
@hc-github-team-consul-core
Copy link
Collaborator

🍒❌ Cherry pick of commit 9b45107 onto release/1.9.x failed! Build Log

@hc-github-team-consul-core
Copy link
Collaborator

🍒❌ Cherry pick of commit 9b45107 onto release/1.8.x failed! Build Log

dhiaayachi added a commit that referenced this pull request Jul 6, 2021
* trim carriage return from certificates when inserting rootCA in the inMemDB

* format rootCA properly when returning the CA on the connect CA endpoint

* Fix linter warnings

* Fix providers to trim certs before returning it

* trim newlines on write when possible

* add changelog

* make sure all provider return a trailing newline after the root and intermediate certs

* Fix endpoint to return trailing new line

* Fix failing test with vault provider

* make test more robust

* make sure all provider return a trailing newline after the leaf certs

* Check for suffix before removing newline and use function

* Add comment to consul provider

* Update change log

Co-authored-by: R.B. Boyer <[email protected]>

* fix typo

* simplify code callflow

Co-authored-by: R.B. Boyer <[email protected]>

* extract requireNewLine as shared func

* remove dependency to testify in testing file

* remove extra newline in vault provider

* Add cert newline fix to envoy xds

* remove new line from mock provider

* Remove adding a new line from provider and fix it when the cert is read

* Add a comment to explain the fix

* Add missing for leaf certs

* fix missing new line

* fix missing new line in leaf certs

* remove extra new line in test

* updage changelog

Co-authored-by: Daniel Nephin <[email protected]>

* fix in vault provider and when reading cache (RPC call)

* fix AWS provider

* fix failing test in the provider

* remove comments and empty lines

* add check for empty cert in test

* fix linter warnings

* add new line for leaf and private key

* use string concat instead of Sprintf

* fix new lines for leaf signing

* preallocate slice and remove append

* Add new line to `SignIntermediate` and `CrossSignCA`

Co-authored-by: R.B. Boyer <[email protected]>
Co-authored-by: Daniel Nephin <[email protected]>
dhiaayachi added a commit that referenced this pull request Jul 6, 2021
* trim carriage return from certificates when inserting rootCA in the inMemDB

* format rootCA properly when returning the CA on the connect CA endpoint

* Fix linter warnings

* Fix providers to trim certs before returning it

* trim newlines on write when possible

* add changelog

* make sure all provider return a trailing newline after the root and intermediate certs

* Fix endpoint to return trailing new line

* Fix failing test with vault provider

* make test more robust

* make sure all provider return a trailing newline after the leaf certs

* Check for suffix before removing newline and use function

* Add comment to consul provider

* Update change log

Co-authored-by: R.B. Boyer <[email protected]>

* fix typo

* simplify code callflow

Co-authored-by: R.B. Boyer <[email protected]>

* extract requireNewLine as shared func

* remove dependency to testify in testing file

* remove extra newline in vault provider

* Add cert newline fix to envoy xds

* remove new line from mock provider

* Remove adding a new line from provider and fix it when the cert is read

* Add a comment to explain the fix

* Add missing for leaf certs

* fix missing new line

* fix missing new line in leaf certs

* remove extra new line in test

* updage changelog

Co-authored-by: Daniel Nephin <[email protected]>

* fix in vault provider and when reading cache (RPC call)

* fix AWS provider

* fix failing test in the provider

* remove comments and empty lines

* add check for empty cert in test

* fix linter warnings

* add new line for leaf and private key

* use string concat instead of Sprintf

* fix new lines for leaf signing

* preallocate slice and remove append

* Add new line to `SignIntermediate` and `CrossSignCA`

Co-authored-by: R.B. Boyer <[email protected]>
Co-authored-by: Daniel Nephin <[email protected]>
dhiaayachi added a commit that referenced this pull request Jul 6, 2021
…) (#10555)

* trim carriage return from certificates when inserting rootCA in the inMemDB

* format rootCA properly when returning the CA on the connect CA endpoint

* Fix linter warnings

* Fix providers to trim certs before returning it

* trim newlines on write when possible

* add changelog

* make sure all provider return a trailing newline after the root and intermediate certs

* Fix endpoint to return trailing new line

* Fix failing test with vault provider

* make test more robust

* make sure all provider return a trailing newline after the leaf certs

* Check for suffix before removing newline and use function

* Add comment to consul provider

* Update change log

Co-authored-by: R.B. Boyer <[email protected]>

* fix typo

* simplify code callflow

Co-authored-by: R.B. Boyer <[email protected]>

* extract requireNewLine as shared func

* remove dependency to testify in testing file

* remove extra newline in vault provider

* Add cert newline fix to envoy xds

* remove new line from mock provider

* Remove adding a new line from provider and fix it when the cert is read

* Add a comment to explain the fix

* Add missing for leaf certs

* fix missing new line

* fix missing new line in leaf certs

* remove extra new line in test

* updage changelog

Co-authored-by: Daniel Nephin <[email protected]>

* fix in vault provider and when reading cache (RPC call)

* fix AWS provider

* fix failing test in the provider

* remove comments and empty lines

* add check for empty cert in test

* fix linter warnings

* add new line for leaf and private key

* use string concat instead of Sprintf

* fix new lines for leaf signing

* preallocate slice and remove append

* Add new line to `SignIntermediate` and `CrossSignCA`

Co-authored-by: R.B. Boyer <[email protected]>
Co-authored-by: Daniel Nephin <[email protected]>

Co-authored-by: R.B. Boyer <[email protected]>
Co-authored-by: Daniel Nephin <[email protected]>
dhiaayachi added a commit that referenced this pull request Jul 6, 2021
…) (#10556)

* Format certificates properly (rfc7468) with a trailing new line (#10411)

* trim carriage return from certificates when inserting rootCA in the inMemDB

* format rootCA properly when returning the CA on the connect CA endpoint

* Fix linter warnings

* Fix providers to trim certs before returning it

* trim newlines on write when possible

* add changelog

* make sure all provider return a trailing newline after the root and intermediate certs

* Fix endpoint to return trailing new line

* Fix failing test with vault provider

* make test more robust

* make sure all provider return a trailing newline after the leaf certs

* Check for suffix before removing newline and use function

* Add comment to consul provider

* Update change log

Co-authored-by: R.B. Boyer <[email protected]>

* fix typo

* simplify code callflow

Co-authored-by: R.B. Boyer <[email protected]>

* extract requireNewLine as shared func

* remove dependency to testify in testing file

* remove extra newline in vault provider

* Add cert newline fix to envoy xds

* remove new line from mock provider

* Remove adding a new line from provider and fix it when the cert is read

* Add a comment to explain the fix

* Add missing for leaf certs

* fix missing new line

* fix missing new line in leaf certs

* remove extra new line in test

* updage changelog

Co-authored-by: Daniel Nephin <[email protected]>

* fix in vault provider and when reading cache (RPC call)

* fix AWS provider

* fix failing test in the provider

* remove comments and empty lines

* add check for empty cert in test

* fix linter warnings

* add new line for leaf and private key

* use string concat instead of Sprintf

* fix new lines for leaf signing

* preallocate slice and remove append

* Add new line to `SignIntermediate` and `CrossSignCA`

Co-authored-by: R.B. Boyer <[email protected]>
Co-authored-by: Daniel Nephin <[email protected]>

* fix compilation error

* fix failing test

Co-authored-by: R.B. Boyer <[email protected]>
Co-authored-by: Daniel Nephin <[email protected]>
@acpana acpana mentioned this pull request Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/v1/agent/connect/ca/leaf/web endpoint returns CertPEM without a trailing newline when using vault ca provider
4 participants