Skip to content

Commit ec4e7a0

Browse files
committed
fix: provide a sensible example for a privateca Root CA example
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. Signed-off-by: Sven Höxter <[email protected]>
1 parent ad0ed50 commit ec4e7a0

File tree

2 files changed

+19
-28
lines changed
  • privateca
    • certificate_authority_basic
    • certificate_authority_subordinate

2 files changed

+19
-28
lines changed

privateca/certificate_authority_basic/main.tf

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,42 @@
1515
*/
1616

1717
# [START privateca_create_ca]
18-
resource "google_privateca_certificate_authority" "default" {
18+
resource "google_privateca_certificate_authority" "root_ca" {
1919
// This example assumes this pool already exists.
2020
// Pools cannot be deleted in normal test circumstances, so we depend on static pools
21-
pool = "my-pool"
22-
certificate_authority_id = "my-certificate-authority-hashicorp"
23-
location = "us-central1"
24-
deletion_protection = false # set to true to prevent destruction of the resource
21+
pool = "my-pool"
22+
certificate_authority_id = "my-certificate-authority-root"
23+
location = "us-central1"
24+
deletion_protection = false # set to true to prevent destruction of the resource
25+
ignore_active_certificates_on_deletion = true
2526
config {
2627
subject_config {
2728
subject {
2829
organization = "HashiCorp"
2930
common_name = "my-certificate-authority"
3031
}
31-
subject_alt_name {
32-
dns_names = ["hashicorp.com"]
33-
}
3432
}
3533
x509_config {
3634
ca_options {
37-
is_ca = true
38-
max_issuer_path_length = 10
35+
# is_ca *MUST* be true for certificate authorities
36+
is_ca = true
3937
}
4038
key_usage {
4139
base_key_usage {
42-
digital_signature = true
43-
content_commitment = true
44-
key_encipherment = false
45-
data_encipherment = true
46-
key_agreement = true
47-
cert_sign = true
48-
crl_sign = true
49-
decipher_only = true
40+
# cert_sign and crl_sign *MUST* be true for certificate authorities
41+
cert_sign = true
42+
crl_sign = true
5043
}
5144
extended_key_usage {
52-
server_auth = true
53-
client_auth = false
54-
email_protection = true
55-
code_signing = true
56-
time_stamping = true
45+
server_auth = false
5746
}
5847
}
5948
}
6049
}
61-
lifetime = "86400s"
6250
key_spec {
6351
algorithm = "RSA_PKCS1_4096_SHA256"
6452
}
53+
// Root CA should be valid indefinetly e.g. 99 years
54+
lifetime = "${99 * 365 * 24 * 3600}s"
6555
}
6656
# [END privateca_create_ca]

privateca/certificate_authority_subordinate/main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
# [START privateca_create_subordinateca]
1818
resource "google_privateca_certificate_authority" "root_ca" {
19+
// This example assumes this pool already exists.
20+
// Pools cannot be deleted in normal test circumstances, so we depend on static pools
1921
pool = "my-pool"
2022
certificate_authority_id = "my-certificate-authority-root"
2123
location = "us-central1"
@@ -27,9 +29,6 @@ resource "google_privateca_certificate_authority" "root_ca" {
2729
organization = "HashiCorp"
2830
common_name = "my-certificate-authority"
2931
}
30-
subject_alt_name {
31-
dns_names = ["hashicorp.com"]
32-
}
3332
}
3433
x509_config {
3534
ca_options {
@@ -51,12 +50,14 @@ resource "google_privateca_certificate_authority" "root_ca" {
5150
key_spec {
5251
algorithm = "RSA_PKCS1_4096_SHA256"
5352
}
53+
// Root CA should be valid indefinetly e.g. 99 years
54+
lifetime = "${99 * 365 * 24 * 3600}s"
5455
}
5556

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

0 commit comments

Comments
 (0)