This document describes secure practices for managing credentials when using the Google Admin Client (gac).
The Google Admin Client uses OAuth2 for authentication with Google Workspace APIs. This requires two types of credentials:
- Client Secret: OAuth2 client credentials from Google Cloud Console
- Access Token: OAuth2 token stored locally after initial authentication
The tool requires the following Google Workspace API scopes:
https://www.googleapis.com/auth/admin.directory.user.readonly- Read user informationhttps://www.googleapis.com/auth/admin.directory.user- Manage usershttps://www.googleapis.com/auth/admin.directory.group.readonly- Read group informationhttps://www.googleapis.com/auth/admin.directory.group.member.readonly- Read group membershiphttps://www.googleapis.com/auth/admin.directory.group.member- Manage group membership
https://www.googleapis.com/auth/calendar- Full calendar accesshttps://www.googleapis.com/auth/calendar.readonly- Read-only calendar accesshttps://www.googleapis.com/auth/calendar.events- Manage calendar eventshttps://www.googleapis.com/auth/calendar.events.readonly- Read calendar events
https://www.googleapis.com/auth/admin.datatransfer- Manage data transfers
These scopes are configured in cmd/client.go:28-39. If you modify these scopes, you must delete your previously saved token at ~/.credentials/gac.json to re-authenticate.
- Go to Google Cloud Console
- Create or select a project
- Enable the following APIs:
- Admin SDK API
- Google Calendar API
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Select "Desktop app" as application type
- Download the JSON file
The tool supports multiple methods for providing credentials:
Place the client secret file at:
~/.credentials/client_secret.json
The token will be automatically saved to:
~/.credentials/gac.json
Set the credential path in your .google-admin.yaml:
client-secret: /path/to/client_secret.json
cache-file: /path/to/token.jsonexport GAC_CLIENT_SECRET=/path/to/client_secret.json
export GAC_CACHE_FILE=/path/to/token.jsongac --client-secret /path/to/client_secret.json user listCritical: Credential files should have restrictive permissions to prevent unauthorized access.
# Set permissions on credential directory
chmod 700 ~/.credentials
# Set permissions on credential files
chmod 600 ~/.credentials/client_secret.json
chmod 600 ~/.credentials/gac.jsonThe tool will automatically:
- Create the
~/.credentialsdirectory with0700permissions (owner read/write/execute only) - Warn if credential files have overly permissive permissions (world-readable or group-readable)
ls -la ~/.credentialsExpected output:
drwx------ 2 user user 4096 Jan 01 12:00 .
-rw------- 1 user user 623 Jan 01 12:00 client_secret.json
-rw------- 1 user user 418 Jan 01 12:00 gac.json
The tool implements several security measures for credential handling:
-
Path Validation: All credential file paths are validated to prevent directory traversal attacks
- Paths must be within the user's home directory or temp directory
- Paths containing
..sequences are rejected
-
File Permission Checks: Warnings are issued for insecure file permissions
- Files readable by group or world will trigger warnings
- Recommendation to use
chmod 600on credential files
-
Secure Storage Location: Credentials are stored in user-specific locations
- Default:
~/.credentials/directory with0700permissions - Only the file owner can access credential files
- Default:
- Never commit credentials to version control (add
.credentials/to.gitignore) - Never share credential files via email, chat, or file sharing services
- Never store credentials in world-readable locations like
/tmp/with default permissions - Never use production credentials in development without proper safeguards
- Never grant broader API scopes than necessary - use the minimum required scopes
- Use separate credentials for different environments (development, staging, production)
- Rotate credentials periodically by creating new OAuth2 clients
- Revoke unused tokens in Google Cloud Console under "APIs & Services" > "Credentials"
- Enable Google Workspace domain-wide delegation for service accounts when appropriate
- Monitor API usage in Google Cloud Console to detect unusual activity
- Use service accounts for automated/server-side operations instead of user credentials
- Store credentials in encrypted filesystems when possible
- Use environment-specific configuration files that are not checked into version control
On first run, the tool will:
- Check for existing token at
~/.credentials/gac.json - If no token exists, prompt for OAuth2 authorization:
Go to the following link in your browser then type the authorization code: https://accounts.google.com/o/oauth2/auth?... - Open the link in your browser
- Authenticate with a Google Workspace admin account
- Grant the requested permissions
- Copy the authorization code
- Paste the code into the terminal
- Token is saved to
~/.credentials/gac.jsonwith0600permissions
The token will be automatically refreshed when it expires (typically 1 hour for access tokens, but refresh tokens are long-lived).
- Ensure the client secret file exists at the specified location
- Verify file permissions (must be readable by current user)
- Check that path doesn't contain directory traversal sequences (
..)
- Verify the authenticated user has Google Workspace admin privileges
- Check that all required API scopes are granted
- Confirm the APIs are enabled in Google Cloud Console
- Delete the token file:
rm ~/.credentials/gac.json - Re-authenticate by running any command
If you see warnings about insecure file permissions:
# Fix credential directory permissions
chmod 700 ~/.credentials
# Fix individual file permissions
chmod 600 ~/.credentials/*.json