gws commands in environments without a browser, such as:
- GitHub Actions, GitLab CI, CircleCI
- Docker containers
- SSH sessions on remote servers
- Automated scripts and cron jobs
Overview
The headless authentication flow:- Authenticate interactively on a machine with a browser
- Export the encrypted credentials to a file
- Transfer the file to your CI/headless environment
- Set
GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILEto point to the file - Run
gwscommands — they’ll “just work” with no login prompt
Export Credentials from Interactive Machine
Configure CI Environment
Using Environment Variable
Set the path to your credentials file:Using CI Secrets
Most CI platforms support encrypted secrets. Store the credentials file content as a secret:GitHub Actions
- Go to your repo → Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
GWS_CREDENTIALS - Value: Paste the contents of
credentials.json
GitLab CI
- Go to Settings → CI/CD → Variables
- Add variable
GWS_CREDENTIALS(masked) - Paste the contents of
credentials.json
CircleCI
- Go to Project Settings → Environment Variables
- Add
GWS_CREDENTIALS - Paste the contents of
credentials.json
Docker
Using .env Files
gws automatically loads environment variables from a .env file in the current directory:
Credential Precedence
When runninggws commands, credentials are resolved in this order:
| Priority | Source | Set via |
|---|---|---|
| 1 | Pre-obtained access token | GOOGLE_WORKSPACE_CLI_TOKEN |
| 2 | Credentials file (env var) | GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE |
| 3 | Encrypted credentials | ~/.config/gws/credentials.enc (from gws auth login) |
| 4 | Plaintext credentials | ~/.config/gws/credentials.json |
Environment variables can also be loaded from a
.env file in the working directory.Using Pre-Obtained Access Tokens
If another tool (e.g.,gcloud, Application Default Credentials) already provides access tokens, you can bypass credential files entirely:
Security Best Practices
Use CI-native secrets management
Use CI-native secrets management
- Store credentials in GitHub Secrets, GitLab Variables, or CircleCI Environment Variables
- Never hardcode credentials in workflow files
- Use masked/protected variables when available
Restrict credential scope
Restrict credential scope
- Create credentials with read-only scopes when possible:
- Use different credentials for different CI jobs
Rotate credentials regularly
Rotate credentials regularly
- Re-run
gws auth loginand export new credentials monthly - Update CI secrets after rotation
- Run
gws auth logouton the source machine after export
Audit credential usage
Audit credential usage
- Monitor OAuth token usage in Google Cloud Console
- Set up alerts for unusual API activity
- Use service accounts for production workloads (see next section)
Debugging
Check which credentials are being used
credential_source field:
Test authentication
Limitations
- Exported credentials are tied to the OAuth client used during
gws auth login - If the original OAuth client is deleted in GCP Console, the credentials will stop working
- Refresh tokens can be revoked by the user at https://myaccount.google.com/permissions
When to Use Service Accounts Instead
Consider using service accounts if:- You need credentials that never expire
- You’re running automated workflows in a Google Workspace domain with Domain-Wide Delegation
- You want credentials that aren’t tied to a specific user account
- You need to access resources across multiple user accounts
Next Steps
Service Accounts
Use service accounts for server-to-server authentication
Interactive Auth
Return to local development setup