En esta página, se explica cómo habilitar un puerto de capa de conexión segura (SSL) cuando se implementa el proxy de servicio extensible (ESP) con Google Kubernetes Engine, Kubernetes o Compute Engine. Se recomienda habilitar un puerto SSL para tu servicio de Endpoints implementado en algunos casos de uso. Por ejemplo, si usas la función de transcodificación de gRPC, se recomienda que tu servicio reciba solicitudes de HTTP 1.1 y de gRPC en el mismo puerto.
Antes de comenzar, asegúrate de haber revisado los instructivos para el tipo de servicio y el entorno que elegiste y de saber cómo implementar el ESP sin SSL.
Configura tus claves y certificados SSL
A fin de configurar tu puerto SSL para que entregue solicitudes HTTPS, sigue los pasos que se muestran a continuación:
Verifica que el archivo de claves de SSL se llame nginx.key y que el archivo de certificados se llame nginx.crt. Para realizar la prueba, puedes generar nginx.key y nginx.cert autofirmados mediante OpenSSL a través del siguiente comando:
Especifica CN y subjectAltName en el certificado del servidor. El valor de estos atributos debe coincidir con el DNS o la IP que usan los clientes para llamar a tu servicio. De lo contrario, fallará el protocolo de enlace de SSL.
Habilitar SSL para el ESP en Kubernetes
Si quieres habilitar el puerto SSL para ESP en Kubernetes, haz lo siguiente:
Crea un secreto de Kubernetes con tu clave y certificado SSL:
Nota: El ejemplo de configuración muestra las líneas que se deben editar. Para implementar el archivo en Cloud Endpoints se necesita el archivo de configuración completo.
Inicia el ESP como se describe en Opciones de especificación de inicio del ESP, pero asegúrate de agregar la marca de inicio --ssl_port a fin de habilitar el puerto SSL.
(Ten en cuenta que el puerto SSL predeterminado es 443)
Inicia el servicio con el archivo de configuración de Kubernetes actualizado mediante kubectl.
kubectl apply -f esp_echo_gke.yaml
Actualiza los certificados SSL
Es importante actualizar los certificados SSL periódicamente.
Para actualizar tus certificados SSL, debes seguir los siguientes pasos:
Crea certificados nuevos, como se describe más arriba en el Paso 1.
Activa los certificados nuevos en los secretos de Kubernetes, como se describe en el paso 3 de arriba.
Actualiza la implementación del ESP de Kubernetes, como se describe en el paso 5.
Habilita SSL para el ESP en Compute Engine
Para habilitar SSL en Compute Engine, primero debes copiar los archivos nginx.key y nginx.crt en la carpeta /etc/nginx/ssl de tu instancia de Compute Engine mediante los siguientes pasos:
Ejecuta el siguiente comando y reemplaza INSTANCE_NAME por el nombre de tu instancia de Compute Engine:
gcloud compute scp nginx.* INSTANCE-NAME
Conéctate a la instancia mediante ssh.
gcloud compute ssh INSTANCE-NAME
En el cuadro de VM de la instancia, crea el directorio y copia los archivos:
En comparación con el comando docker run sin SSL, la versión de SSL del comando crea una configuración diferente. Por ejemplo, el comando de SSL realiza lo siguiente:
Activa la carpeta con la clave y los archivos CRT en el contenedor con --volume.
Usa --ssl_port=443 para indicarle al ESP que habilite SSL en el puerto 443.
Cambia la marca de asignación de puertos --publish.
Actualiza los certificados SSL
Es importante actualizar los certificados SSL periódicamente.
Para actualizar tus certificados SSL, debes seguir los siguientes pasos:
Crea certificados nuevos y cópialos en instancias de VM, como se describe en el paso 1 de arriba.
Copia los certificados nuevos en el directorio /etc/esp/ssl, como se describe en el paso 3 de arriba.
Detén y reinicia el contenedor del ESP con el comando sudo docker run, como se describe en el paso 4.
Prueba el puerto SSL
Para facilitar la prueba, configura las variables de entorno siguientes:
Establece IP_ADDRESS en la dirección IP de la instancia de Compute Engine con el nuevo certificado SSL.
Configura ENDPOINTS_KEY como una clave de API válida.
Una vez habilitado el puerto SSL, puedes usar HTTPS para enviar solicitudes al proxy de servicio extensible. Si tu certificado está autofirmado, usa -k para activar la opción no segura en curl:
Como alternativa, puedes generar el certificado en el formato pem y usar la opción --cacert para usar el certificado autofirmado en curl, como se muestra a continuación:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThis document outlines how to enable a Secure Sockets Layer (SSL) port for services deployed with the Extensible Service Proxy (ESP) on Google Kubernetes Engine, Kubernetes, or Compute Engine, using self-managed SSL certificates.\u003c/p\u003e\n"],["\u003cp\u003eEnabling SSL requires configuring SSL keys and certificates, ensuring they are named \u003ccode\u003enginx.key\u003c/code\u003e and \u003ccode\u003enginx.crt\u003c/code\u003e, and that the server certificate includes both \u003ccode\u003eCN\u003c/code\u003e and \u003ccode\u003esubjectAltName\u003c/code\u003e attributes.\u003c/p\u003e\n"],["\u003cp\u003eOn Kubernetes, SSL is enabled by creating a secret with the SSL key and certificate, then editing the Kubernetes configuration files to mount these secrets as volumes and configuring ESP to use the \u003ccode\u003e--ssl_port\u003c/code\u003e flag.\u003c/p\u003e\n"],["\u003cp\u003eOn Compute Engine, SSL is enabled by copying the \u003ccode\u003enginx.key\u003c/code\u003e and \u003ccode\u003enginx.crt\u003c/code\u003e files to the \u003ccode\u003e/etc/esp/ssl\u003c/code\u003e folder on the instance and using a modified \u003ccode\u003edocker run\u003c/code\u003e command that mounts the SSL directory, uses \u003ccode\u003e--ssl_port=443\u003c/code\u003e, and adjusts port mapping.\u003c/p\u003e\n"],["\u003cp\u003eSSL certificates must be updated periodically by creating new certificates, mounting them to Kubernetes secrets or copying them to Compute Engine instances, and then updating the ESP deployment or restarting the ESP container, respectively.\u003c/p\u003e\n"]]],[],null,["# Enabling SSL for Cloud Endpoints with ESP\n\n[OpenAPI](/endpoints/docs/openapi/enabling-ssl \"View this page for the Cloud Endpoints OpenAPI docs\") \\| gRPC\n\n\u003cbr /\u003e\n\nThis page explains how to enable a Secure Sockets Layer (SSL) port when deploying the Extensible Service Proxy\n(ESP) with Google Kubernetes Engine, Kubernetes, or\nCompute Engine. You may want to enable an SSL port for your deployed Endpoints service for some use cases. For example, if you are using gRPC's transcoding feature, you might want your service to receive both HTTP 1.1 and gRPC requests on the same port.\n\nBefore you begin, make sure that you have already reviewed the [tutorials](/endpoints/docs/grpc/tutorials) for your chosen service type and environment, and know how to deploy ESP without\nSSL.\n| **Note:** This tutorial describes how to use *self-managed SSL certificates* with ESP. Google-managed SSL certificates aren't currently supported by ESP.\n\nConfiguring your SSL keys and certificates\n------------------------------------------\n\nTo configure your SSL port to serve HTTPS requests, follow the steps below:\n\n1. Check to ensure that your SSL key file is named `nginx.key` and your certificate file is named `nginx.crt`. For testing, you can generate a self-signed `nginx.key` and\n `nginx.cert` using OpenSSL with the following command:\n\n ```\n openssl req -x509 -nodes -days 365 -newkey rsa:2048 \\\n -keyout ./nginx.key -out ./nginx.crt\n ```\n2. Specify both `CN` and `subjectAltName` in your server certificate. The value of these attributes\n should match the DNS or IP used by clients to call your service; otherwise, the\n SSL handshake will fail.\n\nEnabling SSL for ESP on Kubernetes\n----------------------------------\n\nTo enable the SSL port for ESP on Kubernetes:\n\n1. Create a Kubernetes secret with your SSL key and certificate:\n\n ```\n kubectl create secret generic nginx-ssl \\\n --from-file=./nginx.crt --from-file=./nginx.key\n ```\n2. Edit the Kubernetes configuration files, for example, `esp_echo_gke.yaml`,\n as shown in the following snippet:\n\n template:\n metadata:\n labels:\n app: esp-echo\n spec:\n volumes:\n - name: nginx-ssl\n secret:\n secretName: nginx-ssl\n containers:\n - name: esp\n image: gcr.io/endpoints-release/endpoints-runtime:1\n args: [\n \"--http_port\", \"8080\",\n \"--ssl_port\", \"443\",\n \"--backend\", \"127.0.0.1:8081\",\n \"--service\", \"SERVICE_NAME\",\n \"--rollout_strategy\", \"managed\",\n ]\n ports:\n - containerPort: 8080\n - containerPort: 443\n volumeMounts:\n - mountPath: /etc/nginx/ssl\n name: nginx-ssl\n readOnly: true\n - name: echo\n image: gcr.io/endpoints-release/echo:latest\n ports:\n - containerPort: 8081\n\n\n **Note**: The configuration sample displays the lines that need to be edited. To deploy the file to Cloud Endpoints, the complete configuration file is required.\n3. Mount the Kubernetes secrets you created as volumes, following the\n directions in the [Kubernetes volumes\n page](http://kubernetes.io/docs/user-guide/volumes/).\n\n4. Start up ESP as described in\n [Specifying startup options for ESP](/endpoints/docs/grpc/specify-proxy-startup-options),\n but make sure you add the startup flag `--ssl_port` to enable the SSL port.\n (Note that the default SSL port is 443.)\n\n5. Start the service with the updated Kubernetes configuration file by using `kubectl`.\n\n ```\n kubectl apply -f esp_echo_gke.yaml\n ```\n | **Note:** If you already have an existing [Kubernetes\n | deployment](http://kubernetes.io/docs/user-guide/deployments/), you can [update the deployment](http://kubernetes.io/docs/user-guide/deployments/#updating-a-deployment) directly.\n\n### Update SSL certificates\n\nIt is important to update your SSL certificates periodically.\nTo update your SSL certificates, you must perform the following steps:\n\n- Create new certificates, as described in Step 1 above.\n- Mount the new certificates to the Kubernetes secrets, as described in Step 3 above.\n- Update the ESP Kubernetes deployment, as described in Step 5 above.\n\nEnabling SSL for ESP on Compute Engine\n--------------------------------------\n\nTo enable SSL on Compute Engine, first copy the `nginx.key` and `nginx.crt` files to\nyour Compute Engine instance's `/etc/nginx/ssl` folder, using the following steps:\n\n1. Run the following command and replace \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e\n with the name of your Compute Engine instance:\n\n ```\n gcloud compute scp nginx.* INSTANCE-NAME\n ```\n2. Connect to the instance using `ssh`.\n\n ```\n gcloud compute ssh INSTANCE-NAME\n ```\n3. In the instance VM box, make the directory and copy in the files:\n\n sudo mkdir -p /etc/esp/ssl\n sudo cp server.* /etc/esp/ssl/\n\n4. Follow the instructions for your service type to deploy with Docker. When you\n run the ESP Docker container, use this command:\n\n ```\n sudo docker run --name=esp \\\n --detach \\\n --publish=443:443 \\\n --net=esp_net \\\n --volume=/etc/nginx/ssl:/etc/nginx/ssl \\\n --link=echo:echo \\\n gcr.io/endpoints-release/endpoints-runtime:1 \\\n --service=SERVICE_NAME \\\n --rollout_strategy=managed \\\n --backend=echo:8080 \\\n --ssl_port=443\n ```\n\n As compared to the non-SSL `docker run` command, the SSL version of the\n command creates a different configuration. For example, the SSL command:\n - Mounts the folder with the key and CRT files to the container by using `--volume`\n - Uses `--ssl_port=443` to tell ESP to enable SSL on port `443`.\n - Changes the port mapping flag `--publish`.\n\n### Update SSL certificates\n\nIt is important to update your SSL certificates periodically.\nTo update your SSL certificates, you must perform the following steps:\n\n- Create new certificates and copy them into VM instances, as described in Step 1 above.\n- Copy the new certificates into the `/etc/esp/ssl` directory, as described in Step 3 above.\n- Stop and restart the ESP container using the `sudo docker run` command, as described in Step 4 above.\n\nTesting the SSL port\n--------------------\n\nTo make the testing easier, set the following environment variables:\n\n1. Set \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e to the IP address of the Compute Engine instance with the new SSL certificate.\n\n | **Note:** The example test commands below assume that the server does not yet have a fully qualified domain name (FQDN) and that \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e has been used as the FQDN when generating the self-signed certificate. When the server does get an FQDN, use the FQDN to generate the certificate. Then, replace \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e with the FQDN in the example commands below.\n2. Set \u003cvar translate=\"no\"\u003eENDPOINTS_KEY\u003c/var\u003e to a valid [API key](https://console.cloud.google.com/apis/credentials).\n\nOnce the SSL port is enabled, you can use HTTPS to send requests to the\nExtensible Service Proxy. If your certificate is self-signed, use `-k` to turn on the insecure option in `curl`: \n\n```\ncurl -k -d '{\"message\":\"hello world\"}' -H \"content-type:application/json\" \\\nhttps://IP_ADDRESS:443/echo?key=ENDPOINTS_KEY\n```\n\nAlternatively, generate the certificate in `pem` format and use the `--cacert` option to use the self-signed certificate in `curl`, as shown below: \n\n openssl x509 -in nginx.crt -out nginx.pem -outform PEM\n curl --cacert \"./nginx.pem\" -d '{\"message\":\"hello world\"}' -H \"content-type:application/json\" \\\n https://\u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e:443/echo?key=\u003cvar translate=\"no\"\u003eENDPOINTS_KEY\u003c/var\u003e"]]