Este tema proporciona una descripción general de Cloud HSM y te muestra cómo crear y usar claves de encriptación protegidas con HSM en Cloud Key Management Service.
¿Qué es Cloud HSM?
Cloud HSM es un servicio de módulo de seguridad de hardware (HSM) alojado en la nube que te permite alojar claves de encriptación y realizar operaciones criptográficas en un de HSM certificados con el nivel 3 del estándar FIPS 140-2. Google administra el clúster de HSM por ti, así que no debes preocuparte por el agrupamiento, escalamiento o aplicación de parches. Debido a que Cloud HSM usa Cloud KMS como en su frontend, puedes aprovechar todas las comodidades y funciones que que proporciona Cloud KMS.
Crea un llavero de claves
Cuando creas una clave, debes agregarla a un llavero de claves en una ubicación de Google Cloud determinada. Puedes crear un llavero de claves nuevo o usar uno existente. En este tema, crearás un llavero de claves nuevo y le agregarás una nueva.
Crea un llavero de claves en una ubicación de Google Cloud que sea compatible con Cloud HSM.
Console
Ve a la página Administración de claves en la consola de Google Cloud.
Haz clic en Crear llavero de claves.
En Nombre del llavero de claves, ingresa un nombre para tu llavero de claves.
En Ubicación del llavero de claves, selecciona una ubicación, como
"us-east1"
.Haz clic en Crear.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
-
En tu entorno, ejecuta el comando
gcloud kms keyrings create
:gcloud kms keyrings create KEY_RING \ --location LOCATION
Reemplaza lo siguiente:
KEY_RING
: Es el nombre del llavero de claves que contiene la clave.LOCATION
: Es la ubicación de Cloud KMS del llavero de claves.
Para obtener información sobre todas las marcas y los valores posibles, ejecuta el comando con la marca
--help
.
C#
Para ejecutar este código, primero configura un entorno de desarrollo de C# e instala el SDK de C# para Cloud KMS.
Go
Para ejecutar este código, primero configura un entorno de desarrollo de Go y, luego, instala el SDK de Go para Cloud KMS.
Java
Para ejecutar este código, primero configura un entorno de desarrollo de Java y, luego, instala el SDK de Java para Cloud KMS.
Node.js
Para ejecutar este código, primero configura un entorno de desarrollo de Node.js y, luego, instala el SDK de Node.js para Cloud KMS.
PHP
Para ejecutar este código, primero obtén información sobre cómo usar PHP en Google Cloud y, luego, instala el SDK de PHP para Cloud KMS.
Python
Para ejecutar este código, primero configura un entorno de desarrollo de Python y, luego, instala el SDK de Python para Cloud KMS.
Ruby
Para ejecutar este código, primero configura un entorno de desarrollo de Ruby y, luego, instala el SDK de Ruby para Cloud KMS.
API
En estos ejemplos, se usa curl como un cliente HTTP para demostrar el uso de la API. Para obtener más información sobre el control de acceso, consulta Accede a la API de Cloud KMS.
curl "https://cloudkms.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/keyRings?key_ring_id=KEY_RING" \ --request "POST" \ --header "authorization: Bearer TOKEN"
Reemplaza lo siguiente:
PROJECT_ID
: El ID del proyecto que contiene el llavero.KEY_RING
: Es el nombre del llavero de claves que contiene la clave.LOCATION
: Es la ubicación de Cloud KMS del llavero de claves.
Consulta la documentación sobre la API de KeyRing.create
para obtener más información.
Crea una clave
Sigue estos pasos para crear una clave de Cloud HSM en el llavero de claves y la ubicación especificados.
Console
Ve a la página Administración de claves en la consola de Google Cloud.
Haz clic en el nombre del llavero de claves para el que crearás la clave.
Haz clic en Crear clave.
En ¿Qué tipo de clave quieres crear?, elige Clave generada.
Ingresa el nombre en el campo Nombre de la clave.
Haz clic en el menú desplegable Nivel de protección y selecciona HSM.
Haz clic en el menú desplegable Propósito y selecciona Encriptación/desencriptación simétrica.
Acepta los valores predeterminados de Período de rotación y A partir del.
Haz clic en Crear.
gcloud
Para usar Cloud KMS en la línea de comandos, primero Instala o actualiza a la versión más reciente de Google Cloud CLI.
gcloud kms keys create key \ --keyring key-ring \ --location location \ --purpose "encryption" \ --protection-level "hsm"
Reemplaza key por un nombre para la clave nueva. Reemplaza key-ring por el nombre del llavero de claves existente donde se ubicará la clave. Reemplaza location por la ubicación de Cloud KMS para el llavero de claves.
Para obtener información sobre todas las marcas y los valores posibles, ejecuta el comando con la marca --help
.
C#
Para ejecutar este código, primero configura un entorno de desarrollo de C# e instala el SDK de C# para Cloud KMS.
Go
Para ejecutar este código, primero configura un entorno de desarrollo de Go y, luego, instala el SDK de Go para Cloud KMS.
Java
Para ejecutar este código, primero configura un entorno de desarrollo de Java y, luego, instala el SDK de Java para Cloud KMS.
Node.js
Para ejecutar este código, primero configura un entorno de desarrollo de Node.js y, luego, instala el SDK de Node.js para Cloud KMS.
PHP
Para ejecutar este código, primero obtén información sobre cómo usar PHP en Google Cloud y, luego, instala el SDK de PHP para Cloud KMS.
Python
Para ejecutar este código, primero configura un entorno de desarrollo de Python y, luego, instala el SDK de Python para Cloud KMS.
Ruby
Para ejecutar este código, primero configura un entorno de desarrollo de Ruby y, luego, instala el SDK de Ruby para Cloud KMS.
Encripta datos
Ahora que tienes una clave, puedes usarla para encriptar texto o contenido binario.
gcloud
Para usar Cloud KMS en la línea de comandos, primero Instala o actualiza a la versión más reciente de Google Cloud CLI.
gcloud kms encrypt \ --key key \ --keyring key-ring \ --location location \ --plaintext-file file-with-data-to-encrypt \ --ciphertext-file file-to-store-encrypted-data
Reemplaza key por el nombre de la clave que se usará para la encriptación. Reemplaza key-ring por el nombre del llavero de claves en el que se encuentra la clave. Reemplaza location por la ubicación de Cloud KMS para el llavero de claves. Reemplaza file-with-data-to-encrypt y file-to-store-encrypted-data por las rutas de los archivos locales para leer los datos de texto simple y guardar el resultado encriptado.
Para obtener información sobre todas las marcas y los valores posibles, ejecuta el comando con la marca --help
.
C#
Para ejecutar este código, primero configura un entorno de desarrollo de C# e instala el SDK de C# para Cloud KMS.
Go
Para ejecutar este código, primero configura un entorno de desarrollo de Go y, luego, instala el SDK de Go para Cloud KMS.
Java
Para ejecutar este código, primero configura un entorno de desarrollo de Java y, luego, instala el SDK de Java para Cloud KMS.
Node.js
Para ejecutar este código, primero configura un entorno de desarrollo de Node.js y, luego, instala el SDK de Node.js para Cloud KMS.
PHP
Para ejecutar este código, primero obtén información sobre cómo usar PHP en Google Cloud y, luego, instala el SDK de PHP para Cloud KMS.
Python
Para ejecutar este código, primero configura un entorno de desarrollo de Python y, luego, instala el SDK de Python para Cloud KMS.
Ruby
Para ejecutar este código, primero configura un entorno de desarrollo de Ruby y, luego, instala el SDK de Ruby para Cloud KMS.
API
En estos ejemplos, se usa curl como un cliente HTTP para demostrar el uso de la API. Para obtener más información sobre el control de acceso, consulta Accede a la API de Cloud KMS.
Cuando usas JSON y la API de REST, debes codificar el contenido en Base64 antes de que pueda encriptarlo Cloud KMS.
Para encriptar datos, realiza una solicitud POST
, proporciona la información del proyecto y la clave que corresponda, y especifica el texto codificado en Base64 que se encriptará en el campo plaintext
del cuerpo de la solicitud.
curl "https://cloudkms.googleapis.com/v1/projects/project-id/locations/location/keyRings/key-ring-name/cryptoKeys/key-name:encrypt" \ --request "POST" \ --header "authorization: Bearer token" \ --header "content-type: application/json" \ --data "{\"plaintext\": \"base64-encoded-input\"}"
Esta es una carga útil de ejemplo con datos codificados en Base64:
{ "plaintext": "U3VwZXIgc2VjcmV0IHRleHQgdGhhdCBtdXN0IGJlIGVuY3J5cHRlZAo=", }
Desencripta contenido cifrado
A fin de desencriptar contenido, debes utilizar la misma clave que usaste para encriptarlo.
gcloud
Para usar Cloud KMS en la línea de comandos, primero Instala o actualiza a la versión más reciente de Google Cloud CLI.
gcloud kms decrypt \ --key key \ --keyring key-ring \ --location location \ --ciphertext-file file-path-with-encrypted-data \ --plaintext-file file-path-to-store-plaintext
Reemplaza key por el nombre de la clave que se usará para la desencriptación. Reemplaza key-ring por el nombre del llavero de claves donde se ubicará la clave. Reemplaza location por la ubicación de Cloud KMS para el llavero de claves. Reemplaza file-path-with-encrypted-data y file-path-to-store-plaintext por las rutas de acceso de los archivos locales para leer los datos encriptados y guardar el resultado desencriptado.
Para obtener información sobre todas las marcas y los valores posibles, ejecuta el comando con la marca --help
.
C#
Para ejecutar este código, primero configura un entorno de desarrollo de C# e instala el SDK de C# para Cloud KMS.
Go
Para ejecutar este código, primero configura un entorno de desarrollo de Go y, luego, instala el SDK de Go para Cloud KMS.
Java
Para ejecutar este código, primero configura un entorno de desarrollo de Java y, luego, instala el SDK de Java para Cloud KMS.
Node.js
Para ejecutar este código, primero configura un entorno de desarrollo de Node.js y, luego, instala el SDK de Node.js para Cloud KMS.
PHP
Para ejecutar este código, primero obtén información sobre cómo usar PHP en Google Cloud y, luego, instala el SDK de PHP para Cloud KMS.
Python
Para ejecutar este código, primero configura un entorno de desarrollo de Python y, luego, instala el SDK de Python para Cloud KMS.
Ruby
Para ejecutar este código, primero configura un entorno de desarrollo de Ruby y, luego, instala el SDK de Ruby para Cloud KMS.
API
En estos ejemplos, se usa curl como un cliente HTTP para demostrar el uso de la API. Para obtener más información sobre el control de acceso, consulta Accede a la API de Cloud KMS.
El texto desencriptado que se muestra en el archivo JSON de Cloud KMS está codificado en base64.
Para desencriptar datos, haz una solicitud POST
y proporciona la información del proyecto y de la clave correspondientes y especifica el texto encriptado (algoritmo de cifrado) que se desencriptará en el campo ciphertext
del cuerpo de la solicitud.
curl "https://cloudkms.googleapis.com/v1/projects/project-id/locations/location/keyRings/key-ring-name/cryptoKeys/key-name:decrypt" \ --request "POST" \ --header "authorization: Bearer token" \ --header "content-type: application/json" \ --data "{\"ciphertext\": \"encrypted-content\"}"
Esta es una carga útil de ejemplo con datos codificados en Base64:
{ "ciphertext": "CiQAhMwwBo61cHas7dDgifrUFs5zNzBJ2uZtVFq4ZPEl6fUVT4kSmQ...", }
Próximos pasos
En el ejemplo de encriptación que se brinda en este tema, se usa una clave simétrica con el nivel de protección HSM. Para encriptar con una clave asimétrica con el nivel de protección HSM, sigue los pasos de Encripta y desencripta datos con una clave asimétrica, pero aplica estas modificaciones:
- Crea el llavero de claves en una de las regiones compatibles con Cloud HSM.
- Crea la clave con el nivel de protección HSM.
Para usar una clave asimétrica con el nivel de protección HSM para elíptica firma de curvas o firma RSA, sigue los pasos que se indican en Crear y validar firmas con estos cambios:
- Crea el llavero de claves en una de las regiones compatibles con Cloud HSM.
- Crea la clave con el nivel de protección HSM.
Comienza a usar la API.
Consulta la Referencia de la API de Cloud KMS.
Lee las guías prácticas para comenzar a crear, rotar y configurar. y permisos sobre las claves.
Lee los conceptos para entender mejor la jerarquía de objetos, los estados clave y la rotación de claves.
Obtén más información sobre Logging en Cloud KMS. Ten en cuenta que el registro es basada en operaciones y se aplica a claves con HSM y niveles de protección.
Obtén más información sobre cómo Cloud HSM protege tus datos en la Informe sobre la arquitectura de Cloud HSM.
Limitaciones conocidas
El tamaño del mensaje se limita a 8 KiB (en contraposición a 64 KiB para claves de software de Cloud KMS) para el texto simple proporcionado por el usuario y texto cifrado, incluidos los datos autenticados adicionales.
Es posible que Cloud HSM no esté disponible en ciertas ubicaciones birregionales o multirregionales. Para obtener detalles, consulta Regiones compatibles para Cloud HSM.
Si usas claves de Cloud HSM con claves de encriptación administradas por el cliente (CMEK) en otros servicios de Google Cloud, las ubicaciones usar en los servicios debe coincidir con las ubicaciones de tu Cloud HSM claves exactas. Esto se aplica a las regiones, birregionales y multirregionales ubicaciones.
Para obtener más información sobre las integraciones de CMEK, consulta la sección Encriptación en reposo.
Operaciones de clave actuales para claves asimétricas almacenadas en Cloud HSM puede incurrir en una latencia notablemente mayor en comparación con el uso claves de software de Cloud KMS.
HSM para bastidor Bare Metal
Google Cloud ofrece opciones de HSM adicionales, como usuario único. El HSM para bastidor Bare Metal está disponible para que los clientes almacenen sus propios HSM en el espacio que proporciona Google. Consulte con su representante de cuenta para información adicional.