Skip to content

Commit 8925259

Browse files
hoexterglasntiennae
authored
fix: provide a sensible example for a privateca Root CA example (#631)
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]> Co-authored-by: Katie McLaughlin <[email protected]> Co-authored-by: Jennifer Davis <[email protected]>
1 parent 0addd92 commit 8925259

File tree

2 files changed

+27
-51
lines changed
  • privateca
    • certificate_authority_basic
    • certificate_authority_subordinate

2 files changed

+27
-51
lines changed

privateca/certificate_authority_basic/main.tf

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,41 @@
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 {
28-
organization = "HashiCorp"
29+
organization = "ACME"
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
5745
}
5846
}
5947
}
6048
}
61-
lifetime = "86400s"
6249
key_spec {
6350
algorithm = "RSA_PKCS1_4096_SHA256"
6451
}
52+
// valid for 10 years
53+
lifetime = "${10 * 365 * 24 * 3600}s"
6554
}
6655
# [END privateca_create_ca]

privateca/certificate_authority_subordinate/main.tf

Lines changed: 13 additions & 26 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"
@@ -24,12 +26,9 @@ resource "google_privateca_certificate_authority" "root_ca" {
2426
config {
2527
subject_config {
2628
subject {
27-
organization = "HashiCorp"
29+
organization = "ACME"
2830
common_name = "my-certificate-authority"
2931
}
30-
subject_alt_name {
31-
dns_names = ["hashicorp.com"]
32-
}
3332
}
3433
x509_config {
3534
ca_options {
@@ -43,20 +42,21 @@ resource "google_privateca_certificate_authority" "root_ca" {
4342
crl_sign = true
4443
}
4544
extended_key_usage {
46-
server_auth = false
4745
}
4846
}
4947
}
5048
}
5149
key_spec {
5250
algorithm = "RSA_PKCS1_4096_SHA256"
5351
}
52+
// valid for 10 years
53+
lifetime = "${10 * 365 * 24 * 3600}s"
5454
}
5555

56-
resource "google_privateca_certificate_authority" "default" {
56+
resource "google_privateca_certificate_authority" "sub_ca" {
5757
// This example assumes this pool already exists.
5858
// Pools cannot be deleted in normal test circumstances, so we depend on static pools
59-
pool = "my-pool"
59+
pool = "my-sub-pool"
6060
certificate_authority_id = "my-certificate-authority-sub"
6161
location = "us-central1"
6262
deletion_protection = false # set to true to prevent destruction of the resource
@@ -66,12 +66,9 @@ resource "google_privateca_certificate_authority" "default" {
6666
config {
6767
subject_config {
6868
subject {
69-
organization = "HashiCorp"
69+
organization = "ACME"
7070
common_name = "my-subordinate-authority"
7171
}
72-
subject_alt_name {
73-
dns_names = ["hashicorp.com"]
74-
}
7572
}
7673
x509_config {
7774
ca_options {
@@ -81,28 +78,18 @@ resource "google_privateca_certificate_authority" "default" {
8178
}
8279
key_usage {
8380
base_key_usage {
84-
digital_signature = true
85-
content_commitment = true
86-
key_encipherment = false
87-
data_encipherment = true
88-
key_agreement = true
89-
cert_sign = true
90-
crl_sign = true
91-
decipher_only = true
81+
cert_sign = true
82+
crl_sign = true
9283
}
9384
extended_key_usage {
94-
server_auth = true
95-
client_auth = false
96-
email_protection = true
97-
code_signing = true
98-
time_stamping = true
9985
}
10086
}
10187
}
10288
}
103-
lifetime = "86400s"
89+
// valid for 5 years
90+
lifetime = "${5 * 365 * 24 * 3600}s"
10491
key_spec {
105-
algorithm = "RSA_PKCS1_4096_SHA256"
92+
algorithm = "RSA_PKCS1_2048_SHA256"
10693
}
10794
type = "SUBORDINATE"
10895
}

0 commit comments

Comments
 (0)