Creating certificate authorities
This topic describes how to create certificate authorities (CAs) in a CA pool.
Before you begin
Make sure you have the CA Service Operation Manager (
roles/privateca.caManager
) or the CA Service Admin (roles/privateca.admin
) IAM role. For information about granting an IAM to a principal, see Grant a single role.Create a CA pool by following the instructions in Creating CA pools.
Deciding the CA's settings
You cannot change some CA settings after creating the CA. Some of these settings are specific to Certificate Authority Service, while other settings are inherently immutable to CAs, because they appear in the CA's own certificate. For example, the CA type (root or subordinate) is a permanent setting.
For more information, see Permanent CA settings.
Creating a root CA
A root CA has a self-signed certificate that you must distribute to the trust stores of your clients. The root CA's certificate is at the top of the certificate chain. No other CA can revoke the CA certificate. The CRL of the root CA applies only to the other certificates the root CA issued, but not to itself.
Console
To create a root CA, do the following.
Go to the Certificate Authority Service page in the Google Cloud console.
Click the CA manager tab.
Click Create CA.
Select CA type
To configure the permanent settings of the CA, such as tier, location, lifetime, and the operational state at creation, do the following:
- Select Root CA.
- In the Valid for field, enter the duration for which you want the certificates issued by the CA certificate to be valid.
- Optional: Choose a tier for the CA. For more information, see Workload-optimized tiers.
- Click Region and in the list, select the location where you want to create the CA. We recommend creating the CA geographically near your application's clients. For more information, see Choosing the best location.
Optional: Select the operational state of the CA to be created in.
Optional: Click Certificate profile. In the list, select the certificate profile that matches the type of certificates you want the CA to issue.
Click Next.
- In the Organization (O) field, enter the name of your company.
- Optional: In the Organization unit (OU) field, enter the company subdivision or business unit.
- Optional: In the Country name field, enter a two letter country code.
- Optional: In the State or province name field, enter the name of your state.
- Optional: In the Locality name field, enter the name of your city.
- In the CA common name (CN) field, enter the CA name.
- In the Pool ID field, enter the CA pool name. You cannot change the CA pool after creating the CA.
- Click Next.
- Choose the key algorithm that best meets your needs. For information about deciding the suitable key algorithm, see Choosing a key algorithm.
- Click Next.
The following steps are optional. If you skip these steps, the default settings apply.
- Choose whether you want to use a Google-managed or a self-managed Cloud Storage bucket.
- Choose whether you want to disable the publication of certificate revocation lists (CRLs) and CA certificates to the Cloud Storage bucket.
- Click Next.
If you don't select a self-managed Cloud Storage bucket, CA Service creates a Google-managed bucket in the same location as the CA.
The publication of CRL and CA certificate on a Cloud Storage bucket is enabled by default. To disable these settings, click the toggles.
The following steps are optional.
If you want to add labels to the CA, do the following:
- Click Add item.
- In the Key 1 field, enter the label key.
- In the Value 1 field, enter the label value.
- If you want to add another label, click Add item. Then, add the label key and value as mentioned in steps 2 and 3.
- Click Next.
Carefully review all the settings, then click Create to create the CA.
gcloud
To create a CA pool, run the following command:
gcloud privateca pools create POOL_ID
Replace POOL_ID with the name of the CA pool.
For more information, see Creating a CA pool.
For more information about this
gcloud
command, see gcloud privateca pools create.Create a new root CA in the CA pool you created.
gcloud privateca roots create ROOT_CA_ID --pool=POOL_ID \ --key-algorithm=KEY_ALGORITHM \ --subject="CN=my-ca, O=Test LLC"
Replace the following:
- ROOT_CA_ID: The name of the CA.
- POOL_ID: The name of the CA pool.
- KEY_ALGORITHM: The algorithm to use for creating a
Cloud KMS key. This flag is optional. If you don't include
this flag, the key algorithm defaults to
rsa-pkcs1-4096-sha256
. For more information, see --key-algorithm flag.
By default, the CA is created in the
STAGED
state. To enable a CA by default, include the--auto-enable
flag.If you want to use a customer-managed Cloud Storage bucket for publishing CA certificates and CRLs, add
--bucket bucket-name
to the command. Replace bucket-name with the name of the Cloud Storage bucket.To see the exhaustive list of settings, run the following command:
gcloud privateca roots create --help
REST API
Create a root CA.
HTTP method and URL:
POST https://privateca.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/caPools/POOL_ID/certificateAuthorities?certificate_authority_id=ROOT_CA_ID
Request JSON body:
{ "type": "SELF_SIGNED", "lifetime": { "seconds": 315576000, "nanos": 0 }, "config": { "subject_config": { "subject": { "organization": "ORGANIZATION_NAME", "common_name": "COMMON_NAME" } }, "x509_config":{ "ca_options":{ "is_ca":true }, "key_usage":{ "base_key_usage":{ "cert_sign":true, "crl_sign":true } } } }, "key_spec":{ "algorithm":"RSA_PKCS1_4096_SHA256" } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID", "metadata": {...}, "done": false }
Poll the operation until it has completed.
HTTP method and URL:
GET https://privateca.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID", "metadata": {...}, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.security.privateca.v1.CertificateAuthority", "name": "...", } }
Code samples
Java
Python
Terraform
To create a root CA using a Google-managed key, use the following sample configuration:
To create a root CA using a self-managed key, use the following sample configuration:
After you have verified that the CA works as expected, you can enable it to start issuing load-balanced certificates for the CA pool. For more information, see Enabling a CA.
Testing a CA
To verify that a CA is able to issue certificates, request a certificate from
the associated CA pool and explicitly mention the name of the CA you want to
test using the --ca
flag.
You can use the following methods to request a certificate from a CA pool:
- Have CA Service create a private or public key for you.
- Generate your own private or public key and submit a Certificate Signing Request (CSR).
It is easier to use an auto-generated private key or public key to request a certificate from a CA in a CA pool. This section provides information on testing a CA using that method.
To use an auto-generated private key or public key to request a certificate
from a CA in a CA pool, run the following gcloud
command:
gcloud privateca certificates create \
--issuer-pool=POOL_ID \
--ca=ROOT_CA_ID \
--generate-key \
--key-output-file=KEY_FILENAME \
--cert-output-file=CERT_FILENAME \
--dns-san=DNS_NAME
Replace the following:
- POOL_ID: The name of the CA pool.
- ROOT_CA_ID: The unique identifier of the CA that you want to test.
- KEY_FILENAME: The file where the generated key is written in PEM format.
- CERT_FILENAME: The file where the resulting PEM-encoded certificate chain file is written. The order of the certificate chain is from leaf to root.
DNS_NAME: One or more comma-separated DNS Subject Alternative Names (SANs).
The
--generate-key
flag generates a new RSA-2048 private key on your machine.
To use a Certificate Signing Request (CSR) to request a certificate from a CA in a CA pool, or for more information about requesting certificates, see Requesting certificates.
Enabling a root CA
gcloud
To enable a root CA, run the following gcloud
command:
gcloud privateca roots enable ROOT_CA_ID --pool=POOL_ID
Replace the following:
- ROOT_CA_ID: The name of the CA.
- POOL_ID: The name of the CA pool.
REST API
Enable the CA to issue certificates from the CA pool.
HTTP method and URL:
POST https://privateca.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/caPools/POOL_ID/certificateAuthorities/ROOT_CA_ID:enable
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID", "metadata": {...}, "done": false }
Poll the operation until it has completed.
HTTP method and URL:
GET https://privateca.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID", "metadata": {...}, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.security.privateca.v1.CertificateAuthority", "name": "...", } }
Creating a subordinate CA
Subordinate CAs are easier to revoke and rotate than root CAs. If you have multiple certificate issuance scenarios, you can create a subordinate CA for each of those scenarios. Adding multiple subordinate CAs in a CA pool helps you achieve better load-balancing of certificate requests and a higher total effective QPS.
To create a subordinate CA, do the following:
Console
Go to the Certificate Authority Service page in the Google Cloud console.
Click CA manager.
Click Create CA.
Select CA type
- Click Subordinate CA.
- Click Root CA is in Google Cloud.
- In the Valid for field, enter the duration for which you want the CA certificate to be valid.
- Optional: Choose the tier for the CA. The default tier is Enterprise. For more information, see Workload-optimized tiers.
- Click Region to select a location for the CA. For more information, see Locations.
- Optional: Under Initialized state, select the state the CA must be in at creation.
- Optional: Under Set up an issuance scenario, click Certificate profile and select the certificate profile that best suits your requirements from the list. For more information, see Certificate profiles.
- Click Next.
- In the Organization (O) field, enter the name of your company.
- Optional: In the Organization unit (OU) field, enter the company subdivision or business unit.
- Optional: In the Country name field, enter a two letter country code.
- Optional: In the State or province name field, enter the name of your state.
- Optional: In the Locality name field, enter the name of your city.
- In the CA common name (CN) field, enter the CA name.
- In the Pool ID field, enter the CA pool name. You cannot change the CA pool after creating the CA.
- Click Next.
- Choose the key algorithm that best meets your needs. For information about deciding the suitable key algorithm, see Choosing a key algorithm.
- Click Next.
The following steps are optional. If you skip these steps, the default settings apply.
- Choose whether you want to use a Google-managed or a self-managed Cloud Storage bucket.
- Choose whether you want to disable the publication of certificate revocation lists (CRLs) and CA certificates to the Cloud Storage bucket.
- Click Next.
If you don't select a self-managed Cloud Storage bucket, CA Service creates a Google-managed bucket in the same location as the CA.
The publication of CRL and CA certificate on a Cloud Storage bucket is enabled by default. To disable these settings, click the toggles.
The following steps are optional.
If you want to add labels to the CA, do the following:
- Click Add item.
- In the Key 1 field, enter the label key.
- In the Value 1 field, enter the label value.
- If you want to add another label, click Add item. Then, add the label key and value as mentioned in steps 2 and 3.
- Click Next.
Carefully review all the settings, then click Create to create the CA.
gcloud
Create a CA pool for the subordinate CA:
gcloud privateca pools create SUBORDINATE_POOL_ID
Replace SUBORDINATE_POOL_ID with the name of the CA pool.
For more information about creating CA pools, see Creating a CA pool.
For more information about the
gcloud privateca pools create
command, see gcloud privateca pools create.Create a subordinate CA in the created CA pool.
gcloud privateca subordinates create SUBORDINATE_CA_ID \ --pool=SUBORDINATE_POOL_ID \ --issuer-pool=POOL_ID \ --key-algorithm="ec-p256-sha256" \ --subject="CN=Example Server TLS CA, O=Example LLC"
The following statement is returned when the subordinate CA is created.
Created Certificate Authority [projects/my-project-pki/locations/us-west1/caPools/SUBORDINATE_POOL_ID/certificateAuthorities/SUBORDINATE_CA_ID].
To see an exhaustive list of settings, run the following
gcloud
command:gcloud privateca subordinates create --help
The command returns examples to create a subordinate CA whose issuer is either located on CA Service or located elsewhere.
Terraform
Creating a subordinate CA from an external CA
Creating a subordinate CA from an external CA is a three-step process. The first step is to create a CSR for this CA and download the CSR. Once you have the CSR, it needs to be signed by your external CA (specific instructions depend on your setup). Finally, you can use either the gcloud CLI command-line tool or the Google Cloud console to upload the signed PEM certificate chain. For more details, see the following example.
Step 1: Create a CSR
Console
Visit the Security > Certificate Authority Service menu in Google Cloud console.
Click the CA manager tab.
Click Create CA.
Select CA type:
- Click Subordinate CA.
- In the Valid for field, enter the duration for which you want the certificates issued by the CA certificate to be valid.
- Click Root CA is external.
- Pick one of the available options for the CA Tier. For more information, see Workload-optimized tiers.
- Under Regionalization, select a CA location from the list.
- Click Next.
- In the Organization (O) field, enter the name of your company.
- Optional: In the Organization unit (OU) field, enter the company subdivision or business unit.
- Optional: In the Country name field, enter a two letter country code.
- Optional: In the State or province name field, enter the name of your state.
- Optional: In the Locality name field, enter the name of your city.
- In the CA common name (CN) field, enter the CA name.
- In the Pool ID field, enter the CA pool name. You cannot change the CA pool after creating the CA.
- Click Next.
- Choose the key algorithm that best meets your needs. For information about deciding the suitable key algorithm, see Choosing a key algorithm.
- Click Next.
The following steps are optional. If you skip these steps, the default settings apply.
- Choose whether you want to use a Google-managed or a self-managed Cloud Storage bucket.
- Choose whether you want to disable the publication of certificate revocation lists (CRLs) and CA certificates to the Cloud Storage bucket.
- Click Next.
If you don't select a self-managed Cloud Storage bucket, CA Service creates a Google-managed bucket in the same location as the CA.
The publication of CRL and CA certificate on a Cloud Storage bucket is enabled by default. To disable these settings, click the toggles.
The following steps are optional.
If you want to add labels to the CA, do the following:
- Click Add item.
- In the Key 1 field, enter the label key.
- In the Value 1 field, enter the label value.
- If you want to add another label, click Add item. Then, add the label key and value as mentioned in steps 2 and 3.
- Click Next.
Carefully review all the settings, then click Create to create the CA.
Download the CSR
- On the Certificate authority page, select the CA you want to activate.
- Click Activate.
In the dialog that opens, click
Download CSR.
gcloud
To create a CA pool for the subordinate CA, run the following command. For more information, see Creating a CA pool.
gcloud privateca pools create SUBORDINATE_POOL_ID
Replace SUBORDINATE_POOL_ID with the name of the CA pool.
To create a subordinate CA in the created CA pool, run the following
gcloud
command. Thegcloud
command also creates a CSR and saves it to FILE_NAME file.gcloud privateca subordinates create SUBORDINATE_CA_ID \ --pool=SUBORDINATE_POOL_ID \ --create-csr --csr-output-file=FILE_NAME \ --key-algorithm="ec-p256-sha256" \ --subject="CN=Example Server TLS CA, O=Example LLC"
Replace the following:
- SUBORDINATE_CA_ID: The unique identifier of the subordinate CA.
- SUBORDINATE_POOL_ID: The name of the CA pool.
- FILE_NAME: The name of the file where the PEM-encoded CSR is written.
--key-algorithm
flag takes the cryptographic algorithm that you want to use for creating a managed Cloud HSM key for the CA.--subject
flag takes the X.501 name of the certificate subject.For more information about the
gcloud privateca subordinates create
command, see gcloud privateca subordinates create.
The following statement is returned when the CSR is created:
Created Certificate Authority [projects/my-project-pki/locations/us-west1/caPools/SUBORDINATE_POOL_ID/certificateAuthorities/SUBORDINATE_CA_ID] and saved CSR to FILE_NAME.
To see the exhaustive list of available settings, run the following command:
gcloud privateca subordinates create --help
If you lose the CSR, you can download it again using the following command:
gcloud privateca subordinates get-csr SUBORDINATE_CA_ID \
--pool=SUBORDINATE_POOL_ID
Step 2: Sign the CSR
Pass the generated CSR file from step 1 to the member of your organization responsible for certificate issuance, and request that they sign it. The specific steps depend on your organization's setup.
You can experiment with a simple root CA using the
following openssl
commands:
Shell
Configure settings for the new root CA.
cat > root.conf <<- EOM
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
prompt = no
[ req_distinguished_name ]
commonName = Sample Root
[ v3_ca ]
subjectKeyIdentifier=hash
basicConstraints=critical, CA:true
EOM
Create the new root CA.
openssl req -x509 -new -nodes -config root.conf -keyout rootCA.key \
-days 3000 -out rootCA.crt -batch
Configure the extensions that must be added to the new subordinate CA certificate.
cat > extensions.conf <<- EOM
basicConstraints=critical,CA:TRUE,pathlen:0
keyUsage=critical,keyCertSign,cRLSign
extendedKeyUsage=critical,serverAuth
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
EOM
Sign the subordinate CA's CSR with this root.
openssl x509 -req -in FILE_NAME -CA rootCA.crt -CAkey rootCA.key \
-CAcreateserial -out subordinate.crt -days 1095 -sha256 -extfile extensions.conf
Concatenate the entire certificate chain into a single file.
cat subordinate.crt > chain.crt
cat rootCA.crt >> chain.crt
Step 3: Upload the signed certificate
To activate a subordinate CA using a signed certificate, do the following:
Console
Go to the Certificate Authority Service page in the Google Cloud console.
Click the CA manager tab.
Under Certificate authorities, choose the CA you created in Step 1: Create CSR.
Click
Activate.In the dialog that opens, click Download CSR to download the PEM-encoded CSR file that the issuing CA can sign.
Click Next.
In the Upload Certificate Chain field, click Browse.
Upload the signed certificate file with
.crt
extension.Click Activate.
gcloud
gcloud privateca subordinates activate SUBORDINATE_CA_ID \
--pool=SUBORDINATE_POOL_ID \
--pem-chain ./chain.crt
Replace the following:
- SUBORDINATE_CA_ID: the unique identifier of the subordinate CA that you want to activate.
- SUBORDINATE_POOL_ID: the name of the CA pool that contains the subordinate CA.
The --pem-chain
flag is required. This flag takes the file containing the list of PEM-encoded certificates. The list of certificates starts with the current CA certificate and ends with the root CA certificate.
For more information about the gcloud privateca subordinates activate
command, see gcloud privateca subordinates activate.
The following statement is returned when the signed certificate is uploaded:
Activated certificate authority [SUBORDINATE_CA_ID].
Enabling a subordinate CA
To enable a subordinate CA, do the following:
Console
Go to the Certificate Authority Service page in the Google Cloud console.
Click the CA manager tab.
Under Certificate authorities, select the CA you want to activate.
Click
Activate.In the dialog that opens, click Download CSR to download the PEM-encoded CSR file that the issuing CA can sign.
Click Next.
In the Upload Certificate Chain field, click Browse.
Upload the signed certificate file with
.crt
extension.Click Activate.
gcloud
To enable a newly created CA, run the following command:
gcloud privateca subordinates enable SUBORDINATE_CA_ID --pool=SUBORDINATE_POOL_ID
Replace the following:
- SUBORDINATE_CA_ID: the unique identifier of the subordinate CA.
- SUBORDINATE_POOL_ID: the name of the CA pool that contains the subordinate CA.
For more information about the gcloud privateca subordinates enable
command, see gcloud privateca subordinates enable.
Cloning certificate authorities
To clone an existing CA to renew that CA, or to create a new CA with the same configuration, run the following command:
gcloud privateca roots create NEW_CA_ID --pool=POOL_ID \
--from-ca=EXISTING_CA_ID \
--key-algorithm "ec-p384-sha384"
Replace the following:
- NEW_CA_ID: The unique identifier of the new CA.
- POOL_ID: The name of the CA pool in which you want to create the new CA.
The --from-ca
flag is supported for root and subordinate CA creation. The
existing CA must be in the same CA pool as the new CA.
The --key-algorithm
flag copies all CA configuration from the existing CA
(except for the Cloud KMS key version and Cloud Storage bucket). However,
you can still override any of the configuration values in the new CA by
explicitly providing the appropriate flag. For example, you can still
specify `--subject SUBJECT to use a new subject.
If you omit the --key-algorithm
flag, the algorithm defaults to:
- rsa-pkcs1-4096-sha256
for root CAs.
- rsa-pkcs1-2048-sha256
for subordinate CAs.
For more information about this gcloud
command, see
gcloud privateca roots create.
What's next
- Learn how to enable certificate authorities.
- Learn how to use a certificate issuance policy.
- Learn how to request certificates.
- Learn how to configure, modify, and remove IAM policies.