npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

n8n-nodes-gcloud-sa-impersonate

v0.1.0

Published

n8n community node for Google Cloud Service Account Token Impersonation

Readme

n8n-nodes-gcloud-sa-impersonate

A custom n8n node for impersonating Google Cloud Service Accounts to generate access tokens.

Features

  • 🔐 Impersonate Google Cloud Service Accounts without credentials
  • 🚀 Generate access tokens with configurable lifetime
  • ⚙️ Configurable GCE metadata server URL
  • 🎯 Support for custom scopes and delegation chains
  • 🐳 Docker-based development environment with GCE metadata server emulator

Installation

For Development

  1. Clone the repository:
git clone https://github.com/your-username/n8n-nodes-gcloud-sa-impersonate.git
cd n8n-nodes-gcloud-sa-impersonate
  1. Install dependencies:
npm install
  1. Build the node:
npm run build

Using Docker Compose (Recommended for Testing)

This project includes a complete Docker Compose setup with a GCE metadata server emulator for testing.

Prerequisites

  1. Google Cloud Authentication: Set up Application Default Credentials
gcloud auth application-default login
  1. Service Account Permissions: Ensure your user account has the following IAM permissions on the target service account:
# Replace with your email and service account
gcloud iam service-accounts add-iam-policy-binding \
  YOUR_SERVICE_ACCOUNT@PROJECT_ID.iam.gserviceaccount.com \
  --member="user:[email protected]" \
  --role="roles/iam.serviceAccountTokenCreator"

gcloud iam service-accounts add-iam-policy-binding \
  YOUR_SERVICE_ACCOUNT@PROJECT_ID.iam.gserviceaccount.com \
  --member="user:[email protected]" \
  --role="roles/iam.serviceAccountUser"

Setup Steps

  1. Set environment variables:
# Required: Your Google Cloud Project details
export GOOGLE_PROJECT_ID=your-project-id
export GOOGLE_NUMERIC_PROJECT_ID=123456789012
export GOOGLE_SERVICE_ACCOUNT=your-service-account@your-project-id.iam.gserviceaccount.com

# Required: Access token for GCE metadata server emulator
# Get this value by running: gcloud auth print-access-token
export GOOGLE_ACCESS_TOKEN=$(gcloud auth print-access-token)
  1. Create a .env file (optional, for docker-compose):
# Copy environment variables to .env file for docker-compose
cat << EOF > .env
GOOGLE_PROJECT_ID=${GOOGLE_PROJECT_ID}
GOOGLE_NUMERIC_PROJECT_ID=${GOOGLE_NUMERIC_PROJECT_ID}
GOOGLE_SERVICE_ACCOUNT=${GOOGLE_SERVICE_ACCOUNT}
GOOGLE_ACCESS_TOKEN=${GOOGLE_ACCESS_TOKEN}
EOF
  1. Generate metadata server configuration:
# This script uses the environment variables above to generate metadata-config/config.json
./bin/gen-config-json.sh
  1. Copy your ADC credentials:
cp ~/.config/gcloud/application_default_credentials.json ./adc.json

Running the Stack

  1. Start the services:
docker-compose up --build
  1. Access n8n:
  • URL: http://localhost:5678
  • Username: admin
  • Password: admin
  1. Get fresh access token (refresh every ~1 hour):
export GOOGLE_ACCESS_TOKEN=$(gcloud auth print-access-token)
docker-compose up -d

Node Configuration

When creating a workflow in n8n, configure the "Google Cloud SA Impersonate" node with:

| Parameter | Description | Default | Example | |-----------|-------------|---------|---------| | GCE Metadata Server URL | Metadata server endpoint | https://metadata.google.internal/ | http://gce-metadata:8080 (for Docker) | | Target Service Account Email | Service account to impersonate | - | [email protected] | | Scopes | OAuth 2.0 scopes (comma-separated) | https://www.googleapis.com/auth/cloud-platform | https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/storage | | Delegates | Delegation chain (optional) | - | [email protected] | | Token Lifetime | Access token lifetime | 300s | 3600s, 1h |

Example Node Output

{
  "accessToken": "ya29.c.b0Aaekm1....",
  "expireTime": "2024-08-07T06:32:18Z",
  "targetServiceAccount": "[email protected]",
  "scopes": ["https://www.googleapis.com/auth/cloud-platform"],
  "lifetime": "300s"
}

Troubleshooting

Common Issues

  1. 403 Permission Error:

    • Ensure service account impersonation permissions are granted
    • Check Organization Policies for impersonation restrictions
    • Verify IAM Credentials API is enabled
  2. GCE Metadata Server Connection Failed:

    • For Docker: Use http://gce-metadata:8080
    • For GCE instances: Use https://metadata.google.internal/
    • Check container networking and port accessibility
  3. Invalid Access Token:

    • Refresh the GOOGLE_ACCESS_TOKEN environment variable
    • Ensure ADC credentials (adc.json) are up to date

Debug Commands

# Test service account impersonation directly
gcloud auth print-access-token --impersonate-service-account=YOUR_SA@PROJECT.iam.gserviceaccount.com

# Check metadata server emulator
curl -H "Metadata-Flavor: Google" http://localhost:8080/computeMetadata/v1/instance/service-accounts/default/token

# View container logs
docker-compose logs gce-metadata
docker-compose logs n8n

Development

Building the Node

npm run build

Linting and Formatting

npm run lint
npm run format

Testing

The Docker Compose setup provides an isolated testing environment with:

  • n8n instance with the custom node pre-installed
  • GCE metadata server emulator for testing without actual GCE instances
  • Persistent data volumes for n8n workflows

Architecture

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   n8n Node      │───▶│ GCE Metadata    │───▶│ Google Cloud    │
│                 │    │ Server Emulator │    │ IAM API         │
└─────────────────┘    └─────────────────┘    └─────────────────┘
  1. n8n Node requests access token from metadata server
  2. GCE Metadata Server Emulator authenticates using your ADC credentials
  3. Google Cloud IAM API performs service account impersonation
  4. Access token is returned through the chain

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request