google-gemini/gemini-cli · error · Error

Host "${hostname}" is not an allowed host for Google Credent

Error message

Host "${hostname}" is not an allowed host for Google Credential provider.

What it means

After the HTTPS check, the provider only mints tokens for hosts on an allowlist: any *.googleapis.com host or a Cloud Run host (*.run.app). For other hosts it refuses, because ADC access tokens are scoped to Google APIs and sending them elsewhere would leak credentials uselessly. This is a deliberate security restriction, not a bug.

Source

Thrown at packages/core/src/agents/auth-provider/google-credentials-provider.ts:62

    if (urlObj.protocol !== 'https:') {
      throw new Error(
        `Protocol "${urlObj.protocol}" is not secure. Google Credential provider requires HTTPS.`,
      );
    }

    const hostname = urlObj.hostname;
    const isRunAppHost = CLOUD_RUN_HOST_REGEX.test(hostname);

    if (isRunAppHost) {
      this.useIdToken = true;
    }
    this.audience = hostname;

    if (
      !this.useIdToken &&
      !ALLOWED_HOSTS.some((pattern) => pattern.test(hostname))
    ) {
      throw new Error(
        `Host "${hostname}" is not an allowed host for Google Credential provider.`,
      );
    }

    // A2A spec requires scopes if configured, otherwise use default cloud-platform
    const scopes =
      this.config.scopes && this.config.scopes.length > 0
        ? this.config.scopes
        : ['https://www.googleapis.com/auth/cloud-platform'];

    this.auth = new GoogleAuth({
      scopes,
    });
  }

  override async initialize(): Promise<void> {
    // We can pre-fetch or validate if necessary here,
    // but deferred fetching is usually better for auth tokens.

View on GitHub (pinned to 5024443c72)

Solutions

  1. Use google-credentials only for Google API or Cloud Run endpoints.
  2. For non-Google hosts, switch to oauth2, http (Bearer), or apiKey auth.
  3. If the service is fronted by Cloud Run, use the *.run.app URL directly so the allowlist matches.
  4. Extend ALLOWED_HOSTS only if you control the target and understand token-scope implications.

Example fix

# before - third-party host rejected
auth:
  type: google-credentials
agent_card_url: https://partner.example/.well-known/agent-card.json

# after - use a Bearer token auth for non-Google hosts
auth:
  type: http
  scheme: Bearer
  token: $PARTNER_TOKEN
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = [/^.+\.googleapis\.com$/, /^(.*\.)?run\.app$/];
function isAllowedGoogleHost(url: string): boolean {
  const host = new URL(url).hostname;
  return ALLOWED.some((re) => re.test(host));
}
if (!isAllowedGoogleHost(targetUrl)) {
  throw new Error('google-credentials only targets googleapis.com or run.app.');
}

Prevention

When it happens

Trigger: targetUrl host is a third-party domain or on-prem service; a custom hostname that is not under googleapis.com or run.app; using google-credentials for a non-Google A2A server; the hostname has a trailing dot or port that changes the regex match.

Common situations: Pointing google-credentials at a partner's A2A server; an internal gateway CNAME that resolves to Cloud Run but whose hostname is not *.run.app; testing against localhost (which also fails the host check, not just HTTPS).

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/4f456022bc1ab731. Report an issue: GitHub.