cloudrun-secure.sh

Overview

The cloudrun-secure.sh script is designed to deploy the Zoo Animal MCP server to Google Cloud Run with enforced authentication, ensuring secure access to the service. Unlike public or unauthenticated deployments, this script configures the Cloud Run service to require valid identity tokens for any incoming requests, thereby protecting the server endpoints from unauthorized access.

This deployment approach is essential for production environments or sensitive applications where data privacy and access control are critical. The script leverages Google Cloud CLI commands to generate identity tokens and invoke the deployment with appropriate flags to disable unauthenticated access.


Script Breakdown and Functionality

The script is a short shell script containing two main steps:

echo "Deploying Cloud Run End Point in Secure Mode"

export ID_TOKEN=$(gcloud auth print-identity-token)

gcloud run deploy zoo-mcp-server \
    --no-allow-unauthenticated \
    --region=europe-west1 \
    --source=. \
    --labels=dev-tutorial=codelab-gde-medium-secure

Detailed Explanation


Usage Example

To use this script effectively, the user should ensure:

  1. They are authenticated with gcloud CLI and have the necessary IAM roles to deploy Cloud Run services.

  2. The Google Cloud project and environment variables are properly configured (typically via sourcing set_env.sh and running init.sh as per Cloud Run Deployment Automation).

  3. Run the script from the root directory of the source code containing the MCP server:

./cloudrun-secure.sh

This will initiate a secure deployment that enforces authentication for all requests to the zoo-mcp-server.


Important Implementation Details


Interaction with Other System Components


Visual Diagram of Deployment Workflow

flowchart TD
Start[Start Deployment] --> GenerateToken[Generate Identity Token]
GenerateToken --> DeployCmd[Run gcloud deploy with --no-allow-unauthenticated]
DeployCmd --> CloudRun["Cloud Run Service (Secure)"]
CloudRun -->|Requires Token| Client[Authorized Client]
Client -->|Sends Token| CloudRun
CloudRun --> MCPServer[Zoo Animal MCP Server]

Reference to Related Topics