How to authenticate StackQL to Google Cloud
StackQL authenticates to Google Cloud with a service account key, supplied as JSON content in the GOOGLE_CREDENTIALS environment variable.
Steps
- Create a service account and grant it a role on the target project (
roles/viewersuffices for read-only querying), then create and download a JSON key:
gcloud iam service-accounts keys create stackql-key.json \
--iam-account=stackql-sa@my-project.iam.gserviceaccount.com
- Export the key content:
export GOOGLE_CREDENTIALS=$(cat ./stackql-key.json)
An alternative is passing the key by path with the --auth flag, which is useful for server and MCP deployments:
stackql shell \
--auth='{"google": {"type": "service_account", "credentialsfilepath": "/path/to/stackql-key.json"}}'
- Pull the Google provider (first use only):
REGISTRY PULL google;
- Verify with a query:
SELECT name, status, machineType
FROM google.compute.instances
WHERE project = 'my-project';
This uses the aggregated_list access method, which requires only project and returns instances across all zones. The zonal list method requires both project and zone; SHOW METHODS IN google.compute.instances shows each method's required parameters.
Where the credentials apply
The same variable (or --auth object) works across stackql shell, stackql exec, stackql srv, and stackql mcp. For Claude Desktop and similar MCP clients, set GOOGLE_CREDENTIALS in the env block of the server configuration. In CI, source the key from the platform's secret store - never commit it.
Related concepts
- How to authenticate StackQL to AWS - the AWS equivalent
- How to authenticate StackQL to Azure - the Azure equivalent
- How to use StackQL with AI agents - credentials in MCP deployments
- What is SQL for APIs? - why required parameters surface in WHERE clauses
- Common StackQL errors - including authentication failures