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

Allow empty or absent subject block #209

Merged
merged 13 commits into from
May 14, 2022

Conversation

detro
Copy link
Contributor

@detro detro commented May 11, 2022

Closes #61

RFC that motivates fixing this bug: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.6

This affects 2 resources:

  • tls_cert_request
  • tls_self_signed_cert

Caveat

In accordance with RFC 5280, the creation of the certificate will
fail, if the desired certificate is a CA and it has an empty Subject (i.e. no Distinguished Name is provided). Specifically, this part of the RFC:

If the subject is a CA (e.g., the basic constraints extension, as discussed in Section 4.2.1.9, is present and the value of cA is TRUE), then the subject field MUST be populated with a non-empty distinguished name matching the contents of the issuer field in all certificates issued by the subject CA.

Small side improvement

Something that is possible to do with tls_locally_signed_cert, but it's probably undesirable, is to create a certificate using as CA a certificate that, in facts, is not one.

As this if functionally legit, now we will just raise a warning every time a certificate with this "quirk" gets created with this resource.

╷
│ Warning: CA is not a CA
│
│   with tls_locally_signed_cert.test,
│   on main.tf line 24, in resource "tls_locally_signed_cert" "test":
│   24: resource "tls_locally_signed_cert" "test" {
│
│ Certificate provided as Authority does not appear to be as much: the resulting certificate might fail
│ validations
╵

@detro detro requested a review from a team as a code owner May 11, 2022 16:51
Ivan De Marino added 7 commits May 11, 2022 18:25
@detro detro force-pushed the detro/61-allow_empty_or_absent_subject_block branch from 2d74b4c to dcc3328 Compare May 11, 2022 17:25
Copy link
Contributor

@bookshelfdave bookshelfdave left a comment

Choose a reason for hiding this comment

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

lgtm! 👍

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Looks good to me, yay for being more RFC compliant. 🚀 Some small nits for consideration, nothing blocking from me. 😄

Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

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

LGTM

Ivan De Marino added 2 commits May 12, 2022 18:07
….1.2.6

If the certificate we are creating is a CA, subject can't be empty
…ng a CA that is not a CA

The certificate will STILL be created, but the provider should signal that the resulting certificate could fail validation.
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Looks good to me 🚀

@@ -8,6 +8,7 @@ install: build

# See https://golangci-lint.run/
lint:
golangci-lint cache clean
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, I've never needed to run this before. Is there something going on that requires it?

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 haven't experienced this before, but I have had a situation with the unparam linter where it wouldn't pick up an issue until I cleaned the cache.

I might be something that can only happen locally, as the runners on the GH CI are always executed against a fresh environment.

I'm not sure it's necessary, but it did seem to make a difference in spotting this. 🤷

Co-authored-by: Brian Flad <bflad417@gmail.com>
@detro detro merged commit 8e43f9d into main May 14, 2022
@detro detro deleted the detro/61-allow_empty_or_absent_subject_block branch May 14, 2022 08:13
jackivanov pushed a commit to jackivanov/terraform-provider-tls that referenced this pull request Aug 4, 2022
* Update schema to allow `subject` to be optional or empty in `tls_cert_request` and `tls_self_signed_cert`

* Centralised the logic to handle `subject` detection and parsing

The only case to handle are:
1. is absent
2. is empty

in case it appear multiple times instead, we let the schema handle that

* Updated testing

* Regenerated doc

* Linter caught issues

* Updated CHANGELOG

* Tweaking negative tests error regexp to accomodate TF 0.12

* Better follow https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.6

If the certificate we are creating is a CA, subject can't be empty

* Raise a warning when trying to create a `tls_locally_signed_cert` using a CA that is not a CA

The certificate will STILL be created, but the provider should signal that the resulting certificate could fail validation.

* PR review

* Parallelise run for GolangCI-Lint(er)

* Update CHANGELOG: mention warning now raised by `tls_locally_signed_cert` resource when providing a CA that is not a CA

* Apply suggestions from code review

Co-authored-by: Brian Flad <bflad417@gmail.com>

Co-authored-by: Brian Flad <bflad417@gmail.com>
Copy link

I'm going to lock this pull request because it has been closed for 30 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 May 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

subject block required, all fields optional, but cannot pass empty block
4 participants