What This Workflow Does
This workflow solves the challenge of securely accessing private Google Cloud Run APIs from your n8n automation platform. Many businesses need to run custom API logic in the cloud but struggle with implementing proper authentication without complex coding. This template provides a turnkey solution that handles JWT authentication automatically.
The workflow generates properly signed JWT tokens using your Google service account credentials, attaches them to API requests, and handles token refresh cycles. It eliminates the security risks of exposing API keys while maintaining the simplicity of calling your private business logic from automation workflows.
How It Works
1. Service account credential setup
The workflow begins by securely loading your Google Cloud service account credentials. These credentials are used to sign the JWT tokens but are never exposed in API calls.
2. JWT token generation
The template automatically generates JWT tokens with the correct audience claim (your Cloud Run service URL) and sets appropriate expiration times (default 1 hour). The token is signed using RS256 algorithm for maximum security.
3. Authenticated API request
The workflow attaches the generated JWT token to the Authorization header as a Bearer token. It formats the request according to Google Cloud Run's requirements for private API access.
Pro tip: For production use, store your service account credentials in n8n's credential vault rather than hardcoding them in the workflow.
4. Response handling
The workflow includes error handling for common scenarios like expired tokens or permission issues. Failed requests automatically trigger token regeneration and retry logic when appropriate.
Who This Is For
This solution is ideal for businesses running custom API logic on Google Cloud Run that needs to be called securely from automation platforms. It's particularly valuable for:
- Developers who want to expose internal tools as private APIs
- Teams processing sensitive data that can't be exposed publicly
- Companies needing to comply with security standards like HIPAA or SOC2
- Startups using Google Cloud Run's free tier for cost-effective scaling
What You'll Need
- An active Google Cloud project with Cloud Run enabled
- A deployed Cloud Run service configured for private access
- A service account with Cloud Run Invoker permissions
- The service account's JSON key file
- n8n instance (cloud or self-hosted) with HTTP Request node available
Quick Setup Guide
- Download the JSON template file
- Import into your n8n instance
- Add your Google service account credentials to n8n's credential store
- Update the Cloud Run service URL in the HTTP Request node
- Test with a simple API call to verify authentication works
- Replace the example API call with your actual business logic
Key Benefits
Eliminates security risks by never exposing API keys or service account credentials in requests. The JWT tokens expire automatically and can't be reused if intercepted.
Saves development time with pre-built JWT generation logic that would typically require custom coding. The workflow handles all cryptographic signing automatically.
Maintains free-tier eligibility by using efficient authentication methods that minimize API call overhead and stay within Google Cloud's free tier limits.
Simplifies compliance with security standards by implementing industry-best practices for API authentication out of the box.
Future-proof architecture that works with Google Cloud's latest authentication requirements and can be easily adapted as standards evolve.