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

fix: provide a sensible example for a privateca Root CA example #631

Merged
merged 7 commits into from
Nov 4, 2024

Conversation

hoexter
Copy link
Contributor

@hoexter hoexter commented Apr 2, 2024

This one looks a lot like someone copied by accident the subordinate example out of certificate_authority_subordinate/main.tf as a root CA. Thus it contains a lot of values set which are outright invalid or not recommend for Root CA certficates if you consider RFC 5280 and CA/B Baseline Requirements as the standard to follow.

Also the subordinate example is a bit odd, e.g. configuring SAN on any kind of CA certificate doesn't make sense. And the resources examples there make use of the same pool name.

I tried to keep the lifetime setting, but set it to 99 years. That is probably a sensible value for a P(rivate)KI setup. For something public 10y or 15y are probably more sensible.

Description

Fixes #630

Note: If you are not associated with Google, open an issue for discussion before submitting a pull request.

Checklist

Readiness

  • [] Yes, merge this PR after it is approved
  • No, don't merge this PR after it is approved

Testing

--> this should get a test run somewhere, right now I don't have a test setup at hand to validate it against the API of the CAS

@hoexter hoexter requested review from a team as code owners April 2, 2024 10:22
email_protection = true
code_signing = true
time_stamping = true
server_auth = false
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for the basic case this should be true; matching up to documentation here https://registry.terraform.io/providers/hashicorp/google/5.24.0/docs/resources/privateca_certificate_authority.

For the subordinate it's false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Plesae don't look at the provider configuration examples, those are equally wrong. Please take a look at either RFCs or the CA/B BR. E.g. here for the EKU values take a look at https://cabforum.org/uploads/CA-Browser-Forum-TLS-BRs-v2.0.2.pdf 7.1.2.1.2 Root CA Extensions -> It's "Extension extKeyUsage" "Presence MUST NOT".
For a subordinate the EKU values are a MUST if it's not empty aka unrestricted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to mention the obvious I'm not a PKIX expert myself, but inside Google you also have wizards like Ryan Sleevi, though trivial stuff like this might be not a good target for a wizard. The people who developed the CAS product should be also fine to consult with for the details.

Copy link

@pmansour pmansour Jul 8, 2024

Choose a reason for hiding this comment

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

Agreed with @hoexter: by default, we probably don't want any EKUs here.

EKUs can appear on a CA, but they have a different meaning there -- specifically, they function to limit the allowed set of EKUs on all intermediate CAs and leaf certificates in that chain. That's probably not something most people want to do at their root-level CA.

Copy link

Choose a reason for hiding this comment

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

Btw, in this case I'd suggest dropping the extended_key_usage { .. } block completely, rather than including it with only false values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the language server tells me that the provider expects the extended_key_usage {} block to be present, maybe it can be empty.

@msampathkumar
Copy link
Contributor

/gcbrun

@Sita04
Copy link

Sita04 commented Jul 5, 2024

@msampathkumar Can you help add @pmansour to the list of reviewers?

Copy link

@pmansour pmansour left a comment

Choose a reason for hiding this comment

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

Great callouts, thanks for helping to fix this! The values in this sample were probably copied over from somewhere without much thought about reasonable defaults. I think the changes here go a long way towards making these more realistic.

- Peter from the CAS eng team

email_protection = true
code_signing = true
time_stamping = true
server_auth = false
Copy link

@pmansour pmansour Jul 8, 2024

Choose a reason for hiding this comment

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

Agreed with @hoexter: by default, we probably don't want any EKUs here.

EKUs can appear on a CA, but they have a different meaning there -- specifically, they function to limit the allowed set of EKUs on all intermediate CAs and leaf certificates in that chain. That's probably not something most people want to do at their root-level CA.

privateca/certificate_authority_basic/main.tf Outdated Show resolved Hide resolved
email_protection = true
code_signing = true
time_stamping = true
server_auth = false
Copy link

Choose a reason for hiding this comment

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

Btw, in this case I'd suggest dropping the extended_key_usage { .. } block completely, rather than including it with only false values.

@@ -27,9 +29,6 @@ resource "google_privateca_certificate_authority" "root_ca" {
organization = "HashiCorp"
common_name = "my-certificate-authority"
}
subject_alt_name {
dns_names = ["hashicorp.com"]
}
}
x509_config {
Copy link

Choose a reason for hiding this comment

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

could you also remove the extended_key_usage { .. } block here as well?

privateca/certificate_authority_subordinate/main.tf Outdated Show resolved Hide resolved
privateca/certificate_authority_subordinate/main.tf Outdated Show resolved Hide resolved
}

resource "google_privateca_certificate_authority" "default" {
// This example assumes this pool already exists.
// Pools cannot be deleted in normal test circumstances, so we depend on static pools
pool = "my-pool"
pool = "my-sub-pool"
certificate_authority_id = "my-certificate-authority-sub"
location = "us-central1"
deletion_protection = false # set to true to prevent destruction of the resource
Copy link

Choose a reason for hiding this comment

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

(sorry for the misplaced comment -- I can't figure out how to comment on the actual lines I want to mention, which weren't modified here)

Could you also make the following changes for the sub CA:

  • Remove the subject_alt_name
  • Get rid of all base_key_usage values except for cert_sign and crl_sign.
  • Get rid of the extended_key_usage block entirely
  • Update the lifetime from 1 day (86400s) to 5 years ("{5 * 365 * 24 * 3600}")
  • Update the signing key algorithm to use RSA_PKCS1_2048_SHA256 (more efficient for use in a sub CA)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, also took the freedom to replace HashiCorp with ACME
eku block is empty, someone has to check what the provider actually makes out of 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.

This one looks a lot like someone copied by accident the subordinate
example out of `certificate_authority_subordinate/main.tf` as a root
CA. Thus it contains a lot of values set which are outright invalid
or not recommend for Root CA certficates if you consider RFC 5280
and CA/B Baseline Requirements as the standard to follow.

Also the subordinate example is a bit odd, e.g. configuring SAN
on any kind of CA certificate doesn't make sense. And the resources
examples there make use of the same pool name.

Align the lifetime to some practical values, 10years for a Root CA
and 5years for a subordinate.

Signed-off-by: Sven Höxter <[email protected]>
@hoexter hoexter force-pushed the fix-root-ca-sample branch from 1697025 to bdda738 Compare July 9, 2024 08:02
@hoexter hoexter requested a review from pmansour July 9, 2024 11:28
@msampathkumar
Copy link
Contributor

This PR has been inactive for two months. If this inactivity continues for another two weeks, I will close the request.

@hoexter hoexter requested a review from iennae October 7, 2024 07:49
@hoexter
Copy link
Contributor Author

hoexter commented Oct 7, 2024

@msampathkumar I updated the PR long ago with the proposed changes by @pmansour. Thus it's just waiting for a review by you/your team. :)

@glasnt
Copy link
Contributor

glasnt commented Oct 10, 2024

/gcbrun

glasnt added a commit that referenced this pull request Oct 10, 2024
@glasnt glasnt mentioned this pull request Oct 10, 2024
2 tasks
iennae pushed a commit that referenced this pull request Oct 14, 2024
* fix: add my-sub-pool to support #631

* update resource alias
@iennae
Copy link
Contributor

iennae commented Oct 14, 2024

/gcbrun

@glasnt
Copy link
Contributor

glasnt commented Oct 14, 2024

The tests here now pass with #748 merged, but I am not knowledgeable enough in this specific area to review this PR. @iennae are you able to review?

@hoexter
Copy link
Contributor Author

hoexter commented Oct 23, 2024

Can I do anything else to help you to review this PR and get it a state you can merge?

@glasnt
Copy link
Contributor

glasnt commented Oct 23, 2024

/gcbrun

@glasnt glasnt enabled auto-merge (squash) November 4, 2024 04:19
@glasnt
Copy link
Contributor

glasnt commented Nov 4, 2024

I haven't been able to find a subject matter expert on this, but looking at the changes made, it seems reasonable. I'm not an expert on RFC5280, but removing some of the extra fields appears to match what modules do (e.g.. csa-certificate-authority-service)

@glasnt
Copy link
Contributor

glasnt commented Nov 4, 2024

/gcbrun

@glasnt glasnt merged commit 8925259 into terraform-google-modules:main Nov 4, 2024
5 checks passed
hoexter added a commit to hoexter/magic-modules that referenced this pull request Nov 6, 2024
…alues

Some of the properties configured here are either wrong or at least
not very sensible on root certificates / subordinates.

A similar set of fixes got applied to terraform documentation samples
in terraform-google-modules/terraform-docs-samples#631

Signed-off-by: Sven Hoexter <[email protected]>
hoexter added a commit to hoexter/magic-modules that referenced this pull request Nov 6, 2024
…alues

Some of the properties configured here are either wrong or at least
not very sensible on root certificates / subordinates.

A similar set of fixes got applied to terraform documentation samples
in terraform-google-modules/terraform-docs-samples#631

Signed-off-by: Sven Hoexter <[email protected]>
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.

privateca root ca example is invalid for a standard compliant root ca
6 participants