USE ROLE ACCOUNTADMIN in a Snowflake session: what to check

VERICTO-097 High In CI (offline CLI): BLOCKED

USE ROLE ACCOUNTADMIN; switches the session to the most powerful role in the account, and every statement after it runs with those privileges: dropping databases, changing account parameters, managing users. It only works because the user was granted that role. Nothing is lost by the switch itself; check what ran after it, and stop granting administrative roles to users that applications or agents connect as.

How to recover the data

  • Find the statements that ran with the role: SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY filtered by USER_NAME and ROLE_NAME = 'ACCOUNTADMIN'.
  • Undo unexpected changes (grants, parameters, dropped objects with UNDROP within retention).
  • Revoke the administrative role from service users that do not strictly need it: REVOKE ROLE ACCOUNTADMIN FROM USER app_user;

Why it happens

Administrative roles get granted to service users while setting up an integration, because it is the quickest way past "insufficient privileges", and are never taken away. Generated SQL that hits a permission error may then try USE ROLE ACCOUNTADMIN. USE SECONDARY ROLES ALL has a similar effect: the session gains the privileges of every other role granted to the user.

How to fix it

Give each application or agent its own user with a custom role that has only the privileges it needs, set that role in the connection, and do not grant ACCOUNTADMIN, SECURITYADMIN or SYSADMIN to it. Keep administrative roles to a few named people. USE SECONDARY ROLES NONE keeps a session to its primary role.

How to stop it from happening again

VERICTO-097 · Role switch (Snowflake) · Severity: High · AST node: UseStmt > ROLE ACCOUNTADMIN (administrative role)

The statement the rule reports

-- role.sql
USE ROLE ACCOUNTADMIN;

Real CLI output

$ npx @vericto/vericto-cli@2.3.0 check --offline --dialect snowflake role.sql
note: offline mode: 42 standard rules at default severities, engine 5.1.0. Custom rules, overrides, sensitive columns, allowlists and the audit trail apply online only.
✖ role.sql  BLOCKED  VERICTO-097 high
    UseStmt > ROLE ACCOUNTADMIN (administrative role)
    fix: Set the role in the connection, scoped to what the caller needs
1 blocked · 0 allowed · 0 flagged · 0 monitored   (ruleset standard@engine-5.1.0 · mode: offline (engine 5.1.0, 42 standard rules, no workspace policy))

✖ Vericto blocked 1 statement  (ruleset standard@engine-5.1.0 · mode: offline (engine 5.1.0, 42 standard rules, no workspace policy))
  ✖ role.sql  BLOCKED  VERICTO-097 high
      UseStmt > ROLE ACCOUNTADMIN (administrative role)
      fix: Set the role in the connection, scoped to what the caller needs

This is Vericto enforcing a rule — the exit code is intentional, not a crash.
To allow a finding on purpose, add an inline comment on the statement:
    -- vericto:ignore[VERICTO-097] <reason>   (a reason is required)

The CLI blocks it and exits with code 1, so the CI job fails before the merge.

The corrected version

-- role.sql
USE SECONDARY ROLES NONE;
$ npx @vericto/vericto-cli@2.3.0 check --offline --dialect snowflake role.sql
note: offline mode: 42 standard rules at default severities, engine 5.1.0. Custom rules, overrides, sensitive columns, allowlists and the audit trail apply online only.
0 blocked · 1 allowed · 0 flagged · 0 monitored   (ruleset standard@engine-5.1.0 · mode: offline (engine 5.1.0, 42 standard rules, no workspace policy))

Try it free, no account

The CLI checks your .sql files on your machine with the 42 standard rules: no sign-up, no API key, and no SQL leaves your computer. It is open source (AGPL-3.0-only).

npx @vericto/vericto-cli@2.3.0 check --offline --dialect snowflake migrations/

On every pull request

The vericto/check-sql GitHub Action (Apache-2.0) runs the same offline check on the .sql files a PR changes and annotates the findings on the PR. Save it as .github/workflows/vericto.yml:

on: pull_request
jobs:
  vericto:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with: { fetch-depth: 0 }
      - uses: vericto/check-sql@v1
        with: { offline: true, upload-sarif: false, dialect: snowflake }

At runtime, for AI agents

The SQL an AI agent writes never goes through a PR. The Vericto TCP proxy checks each statement between the application or agent and the database, and the MCP check_sql tool lets the agent check SQL before it runs it. Both use the runtime profile, which also blocks schema changes.

The AST condition in the engine

The rule is evaluated by the dialect's classifier; its full definition is in the open source engine's README (AGPL-3.0-only), at this page's commit.

Frequently asked questions