gcloud kms keys create Stay organized with collections Save and categorize content based on your preferences.
- NAME
- gcloud kms keys create - create a new key
- SYNOPSIS
gcloud kms keys create(KEY:--keyring=KEYRING--location=LOCATION)--purpose=PURPOSE[--allowed-access-reasons=[ALLOWED_ACCESS_REASONS,…]][--crypto-key-backend=CRYPTO_KEY_BACKEND][--default-algorithm=DEFAULT_ALGORITHM][--destroy-scheduled-duration=DESTROY_SCHEDULED_DURATION][--import-only][--labels=[KEY=VALUE,…]][--next-rotation-time=NEXT_ROTATION_TIME][--protection-level=PROTECTION_LEVEL; default="software"][--rotation-period=ROTATION_PERIOD][--skip-initial-version-creation][GCLOUD_WIDE_FLAG …]
- DESCRIPTION
- Creates a new key within the given keyring.
The flag
--purposeis always required when creating a key. The flag--default-algorithmis required when creating a symmetric signingkey, an asymmetric key, or an external key. Algorithm and purpose should becompatible.The optional flags
--rotation-periodand--next-rotation-timedefine a rotation schedule for the key. Aschedule can also be defined by the--create-rotation-schedulecommand.The flag
--next-rotation-timemust be in ISO 8601 or RFC3339format, androtation-periodmust be in the form INTEGER[UNIT],where units can be one of seconds (s), minutes (m), hours (h) or days (d).The optional flag
--protection-levelspecifies the physicalenvironment where crypto operations with the key happen. The default is; usesoftwareto create a hardware-backed key,hsmto create an externally backedkey, orexternalto create an externalkey over vpc.external-vpcThe optional flag
--labelsdefines a user specified key/value pairfor the given key.The flag
--skip-initial-version-creationcreates a CryptoKey withno versions. If you import into the CryptoKey, or create a new version in thatCryptoKey, there will be no primary version until one is set using the--set-primary-versioncommand. You must include--skip-initial-version-creationwhen creating a CryptoKey withprotection levelorexternal.external-vpcThe optional flag
--import-onlyrestricts the key to imported keyversions only. To do so, the flag--skip-initial-version-creationmust also be set.The optional flag
--destroy-scheduled-durationdefines the destroyschedule for the key, and must be in the form INTEGER[UNIT], where units can beone of seconds (s), minutes (m), hours (h) or days (d).The flag
--crypto-key-backenddefines the resource name for thebackend where the key resides. Required forkeys.external-vpcThe optional flag
--allowed-access-reasonsdefines the Key AccessJustifications Policy for the key, and is specified as a comma separated list ofzero or more justification codes defined inhttps://cloud.google.com/assured-workloads/key-access-justifications/docs/justification-codes.The key must be enrolled in Key Access Justifications to use this flag. - EXAMPLES
- The following command creates a key named
with protection levelfrodowithin the keyringsoftwareand locationfellowship:us-east1gcloudkmskeyscreatefrodo--location=us-east1--keyring=fellowship--purpose=encryptionThe following command creates a key named
with protection levelstriderwithin the keyringsoftwareand locationrangerswith a specified rotation schedule:globalgcloudkmskeyscreatestrider--location=global--keyring=rangers--purpose=encryption--rotation-period=30d--next-rotation-time=2017-10-12T12:34:56.1234ZThe following command creates a raw encryption key named
with protection levelfoowithin the keyringsoftwareand locationfellowshipwith two specified labels:us-east1gcloudkmskeyscreatefoo--location=us-east1--keyring=fellowship--purpose=raw-encryption--default-algorithm=aes-128-cbc--labels=env=prod,team=kmsThe following command creates an asymmetric key named
with protection levelsamwiseand default algorithmsoftwarewithin the keyringec-sign-p256-sha256and locationfellowship:us-east1gcloudkmskeyscreatesamwise--location=us-east1--keyring=fellowship--purpose=asymmetric-signing--default-algorithm=ec-sign-p256-sha256The following command creates a key named
with protection levelgimliand default algorithmhsmwithin thekeyringgoogle-symmetric-encryptionand locationfellowship:us-east1gcloudkmskeyscreategimli--location=us-east1--keyring=fellowship--purpose=encryption--protection-level=hsmThe following command creates a key named
with protection levellegolasand default algorithmexternalwithin thekeyringexternal-symmetric-encryptionand locationfellowship:us-central1gcloudkmskeyscreatelegolas--location=us-central1--keyring=fellowship--purpose=encryption--default-algorithm=external-symmetric-encryption--protection-level=external--skip-initial-version-creationThe following command creates a key named
with protection levelbilboand default algorithmexternal-vpcand anEkmConnection ofexternal-symmetric-encryptionwithin the keyringeaglesand locationfellowship:us-central1gcloudkmskeyscreatebilbo--location=us-central1--keyring=fellowship--purpose=encryption--default-algorithm=external-symmetric-encryption--protection-level=external-vpc--skip-initial-version-creation--crypto-key-backend="projects/$(gcloudconfiggetproject)/locations/us-central1/ekmConnections/eagles"The following command creates a key named
with protection levelarwenwithin the keyringsoftwareand locationfellowshipwith a Key Access Justificationspolicy that allows access reasonsus-east1andcustomer-initiated-access:google-initiated-system-operationgcloudkmskeyscreatearwen--location=us-east1--keyring=fellowship--purpose=encryption--allowed-access-reasons=customer-initiated-access,google-initiated-system-operation - POSITIONAL ARGUMENTS
- Key resource - The KMS key resource. The arguments in this group can be used tospecify the attributes of this resource. (NOTE) Some attributes are not givenarguments in this group but can be set in other ways.
To set the
projectattribute:- provide the argument
keyon the command line with a fully specifiedname; - set the property
core/project.
This must be specified.
KEY- ID of the key or fully qualified identifier for the key.
To set the
keyattribute:- provide the argument
keyon the command line.
This positional argument must be specified if any of the other arguments in thisgroup are specified.
- provide the argument
--keyring=KEYRING- The KMS keyring of the key.
To set the
keyringattribute:- provide the argument
keyon the command line with a fully specifiedname; - provide the argument
--keyringon the command line.
- provide the argument
--location=LOCATION- The Google Cloud location for the key.
To set the
locationattribute:- provide the argument
keyon the command line with a fully specifiedname; - provide the argument
--locationon the command line.
- provide the argument
- provide the argument
- Key resource - The KMS key resource. The arguments in this group can be used tospecify the attributes of this resource. (NOTE) Some attributes are not givenarguments in this group but can be set in other ways.
- REQUIRED FLAGS
--purpose=PURPOSE- The "purpose" of the key.
PURPOSEmust be one of:asymmetric-encryption,asymmetric-signing,encryption,key-encapsulation,mac,raw-encryption.
- OPTIONAL FLAGS
--allowed-access-reasons=[ALLOWED_ACCESS_REASONS,…]- The list of allowed Key Access Justifications access reasons on the key. The keymust be enrolled in Key Access Justifications to configure this field. Bydefault, this field is absent, and all justification codes are allowed. For moreinformation about justification codes, seehttps://cloud.google.com/assured-workloads/key-access-justifications/docs/justification-codes.
ALLOWED_ACCESS_REASONSmust be one of:customer-authorized-workflow-servicing,customer-initiated-access,customer-initiated-support,google-initiated-review,google-initiated-service,google-initiated-system-operation,google-response-to-production-alert,modified-customer-initiated-access,modified-google-initiated-system-operation,reason-not-expected,reason-unspecified,third-party-data-request. --crypto-key-backend=CRYPTO_KEY_BACKEND- The resource name of the backend environment where the key material for allCryptoKeyVersions associated with this CryptoKey reside and where all relatedcryptographic operations are performed. Currently only applicable forEXTERNAL_VPC and EkmConnection resource names.
--default-algorithm=DEFAULT_ALGORITHM- The default algorithm for the crypto key. For more information about choosing analgorithm, seehttps://cloud.google.com/kms/docs/algorithms.
DEFAULT_ALGORITHMmust be one of:aes-128-cbc,aes-128-ctr,aes-128-gcm,aes-256-cbc,aes-256-ctr,aes-256-gcm,ec-sign-ed25519,ec-sign-p256-sha256,ec-sign-p384-sha384,ec-sign-secp256k1-sha256,external-symmetric-encryption,google-symmetric-encryption,hmac-sha1,hmac-sha224,hmac-sha256,hmac-sha384,hmac-sha512,kem-xwing,ml-kem-1024,ml-kem-768,pq-sign-hash-slh-dsa-sha2-128s-sha256,pq-sign-ml-dsa-65,pq-sign-slh-dsa-sha2-128s,rsa-decrypt-oaep-2048-sha1,rsa-decrypt-oaep-2048-sha256,rsa-decrypt-oaep-3072-sha1,rsa-decrypt-oaep-3072-sha256,rsa-decrypt-oaep-4096-sha1,rsa-decrypt-oaep-4096-sha256,rsa-decrypt-oaep-4096-sha512,rsa-sign-pkcs1-2048-sha256,rsa-sign-pkcs1-3072-sha256,rsa-sign-pkcs1-4096-sha256,rsa-sign-pkcs1-4096-sha512,rsa-sign-pss-2048-sha256,rsa-sign-pss-3072-sha256,rsa-sign-pss-4096-sha256,rsa-sign-pss-4096-sha512,rsa-sign-raw-pkcs1-2048,rsa-sign-raw-pkcs1-3072,rsa-sign-raw-pkcs1-4096. --destroy-scheduled-duration=DESTROY_SCHEDULED_DURATION- The amount of time that versions of the key should spend in theDESTROY_SCHEDULED state before transitioning to DESTROYED. See $gcloud topic datetimes forinformation on duration formats.
--import-only- Restrict this key to imported versions only.
--labels=[KEY=VALUE,…]- List of label KEY=VALUE pairs to add.
Keys must start with a lowercase character and contain only hyphens(
-), underscores (_), lowercase characters, andnumbers. Values must contain only hyphens (-), underscores(_), lowercase characters, and numbers. --next-rotation-time=NEXT_ROTATION_TIME- Next automatic rotation time of the key. See $gcloud topic datetimes forinformation on time formats.
--protection-level=PROTECTION_LEVEL; default="software"- Protection level of the key.
PROTECTION_LEVELmust beone of:software,hsm,hsm-single-tenant,external,external-vpc. --rotation-period=ROTATION_PERIOD- Automatic rotation period of the key. See $gcloud topic datetimes forinformation on duration formats.
--skip-initial-version-creation- Skip creating the first version in a key and setting it as primary duringcreation.
- GCLOUD WIDE FLAGS
- These flags are available to all commands:
--access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.Run
$gcloud helpfor details. - NOTES
- These variants are also available:
gcloudalphakmskeyscreategcloudbetakmskeyscreate
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-16 UTC.