Declarative Google Tag Manager permission management — plan, review, apply.
- Plan & Apply — Terraform-like workflow for safe, reviewable changes
- Roles & Policy — Reusable permission templates with admin limits and approval rules
- Drift Detection — Detect unauthorized changes via CI cron
- Color Diff — Green/yellow/red output for add/update/delete
- Config Includes — Split configs across files for large organizations
- Backup — Save current GTM state as YAML snapshots
- Permission Matrix — User × container permission overview
- GitHub Action — Plan on PR, apply on merge with PR comments
brew install h13/tap/gtm-usersgo install github.com/h13/gtm-users/cmd/gtm-users@latestsource <(gtm-users completion bash) # bash
source <(gtm-users completion zsh) # zsh
gtm-users completion fish | source # fishgtm-users init --account-id 123456789 --credentials sa.jsonaccount_id: "123456789"
mode: additive
roles:
viewer:
account_access: user
container_access:
- container_id: "GTM-XXXX"
permission: read
publisher:
account_access: user
container_access:
- container_id: "GTM-XXXX"
permission: publish
policy:
max_admins: 2
require_approve_for_publish:
- "GTM-XXXX"
users:
- email: alice@example.com
role: publisher
- email: bob@example.com
role: viewer
- email: carol@example.com
account_access: admingtm-users validate --config gtm-users.yamlgtm-users plan --config gtm-users.yaml --credentials sa.jsongtm-users apply --config gtm-users.yaml --credentials sa.json| Command | Description |
|---|---|
validate |
Check config syntax and semantics offline |
plan |
Show diff between desired and actual state |
apply |
Apply planned changes to the GTM API |
export |
Export current GTM permissions as YAML |
init |
Bootstrap a config file from current GTM state |
drift |
Detect configuration drift (exit code 2 if found) |
matrix |
Display user × container permission matrix |
backup |
Save current GTM state as a YAML snapshot |
completion |
Generate shell completion scripts |
| Flag | Default | Description |
|---|---|---|
--config |
gtm-users.yaml |
Path to config file |
--credentials |
— | Path to GCP service account credentials JSON |
--format |
text |
Output format (text or json) |
--no-color |
false |
Disable colored output |
| Field | Required | Description |
|---|---|---|
account_id |
Yes | GTM account ID |
mode |
No | additive (default) or authoritative |
includes |
No | List of config files to include |
roles |
No | Reusable permission templates |
policy |
No | Validation rules (admin limits, approval requirements) |
users |
Yes | Array of user permission entries |
- additive — Only add or update users listed in the config. Unmanaged users are left untouched.
- authoritative — Remove users not listed in the config.
Define reusable permission templates and assign them to users:
roles:
editor:
account_access: user
container_access:
- container_id: "GTM-XXXX"
permission: edit
users:
- email: alice@example.com
role: editorUsers can override role fields by specifying them inline.
Enforce organizational rules:
policy:
max_admins: 2 # limit admin count
require_approve_for_publish:
- "GTM-XXXX" # publish requires approveSplit large configs across files:
includes:
- roles/common.yaml
- teams/engineering.yamlIncluded roles merge with the main config (main overrides on conflict). Users are appended.
| Value | Description |
|---|---|
admin |
Account administrator |
user |
Standard user |
noAccess |
No account-level access |
| Value | Description |
|---|---|
read |
Read only |
edit |
Edit access |
approve |
Approve access |
publish |
Publish access |
Run drift on a schedule to detect unauthorized changes:
# .github/workflows/drift.yaml
on:
schedule:
- cron: "0 9 * * 1-5"
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: h13/gtm-users@v1
with:
command: drift
credentials: ${{ secrets.GCP_SA_KEY }}Exit code 2 indicates drift was detected.
Available on the GitHub Marketplace.
name: GTM Users
on:
pull_request:
paths: ["gtm-users.yaml"]
push:
branches: [main]
paths: ["gtm-users.yaml"]
permissions:
contents: read
pull-requests: write
jobs:
plan:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: h13/gtm-users@v1
with:
command: plan
credentials: ${{ secrets.GCP_SA_KEY }}
apply:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: h13/gtm-users@v1
with:
command: apply
credentials: ${{ secrets.GCP_SA_KEY }}
auto-approve: "true"stages:
- validate
- deploy
variables:
GTM_USERS_VERSION: "v1.2.0"
.gtm-users:
image: golang:latest
before_script:
- go install github.com/h13/gtm-users/cmd/gtm-users@$GTM_USERS_VERSION
plan:
extends: .gtm-users
stage: validate
script:
- gtm-users plan --config gtm-users.yaml --credentials "$GCP_CREDENTIALS_FILE"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
apply:
extends: .gtm-users
stage: deploy
script:
- gtm-users apply --config gtm-users.yaml --credentials "$GCP_CREDENTIALS_FILE" --auto-approve
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- gtm-users.yamlProvide a GCP service account credentials JSON file via the --credentials flag.
The service account requires the Tag Manager - Manage Users scope.
When using the GitHub Action, pass the JSON content directly via the credentials input
(typically stored as a GitHub secret).
When --credentials is omitted, the tool falls back to
Application Default Credentials.
This enables keyless authentication via Workload Identity Federation (WIF) on
GitHub Actions, GitLab CI, Cloud Build, and other CI/CD platforms.
For GitHub Actions, use google-github-actions/auth
to configure WIF before running gtm-users without the credentials input.