VibeWright Self-Check for Snowflake 0.1.0: worksheet pack
==============================================================

Each file under checks/ is one read-only statement (WITH ... SELECT). Paste it into a worksheet and
run it with a role that can read SNOWFLAKE.ACCOUNT_USAGE. setup/selfcheck_role.sql shows one way to
create such a role; review it before running it. Nothing here changes your account.

Things to know:

1. Tunables are in the first CTE, "params". Edit the literals there (for example LOOKBACK_DAYS).
2. Files with a wh_config block read warehouse settings. Run  SHOW WAREHOUSES;  immediately before
   the statement, in the same worksheet session.
3. Blocks marked  --<optional: VIEW> ... --<else> ... --</optional>  have two branches. If the view
   (or column) named in the marker is not visible to your role, comment out the first branch and
   uncomment the second.
4. Files named AI_SRC_* are source queries: they return raw rows that the command-line tool adds up
   into the AI findings. SAFE_TO_SUM = 1 marks rows that belong in a de-duplicated total.
5. EST_UNITS_MONTH is in the unit named by "-- @unit:" (credits, AI credits or TB). Multiply by your
   own price to get dollars. Every such figure is an estimate. In a worksheet each file stands
   alone; the command-line tool also makes sure the same credit is not claimed by two findings.
6. FIX_SQL columns are suggestions as text. Review them; nothing runs them for you.
7. The access checks leave out the role and the user of the session (CURRENT_ROLE(), CURRENT_USER()),
   so the audit role does not report itself. AC_UNUSED_PRIVILEGES returns one row per grant; the
   command-line tool groups them and writes a revoke script in which every statement is commented out.
8. Role chains need the command-line tool. AC_SRC_ROLE_EDGES (role-to-role grants) and
   AC_SRC_USER_ROLES (users and their roles) are flat source queries, and AC_SENSITIVE_REACH returns
   the roles that hold SELECT or OWNERSHIP on a sensitive table directly. The tool follows the
   hierarchy from there (USER > ROLE_A > ROLE_B), counts the users behind each table, and builds the
   ACCOUNTADMIN finding, which has no file of its own. It is not done in SQL because Snowflake compiles
   the grants view again for every reference: on my test account one reference to GRANTS_TO_ROLES
   took about 9 seconds, three direct references about 50, and a recursive CTE about 27.
9. For the same reason every file reads each SNOWFLAKE view once, in one base CTE. Keep it that way
   if you edit a query.

Documentation for every check (thresholds, formulas, doc links, limits): docs/CHECKS.md in the
repository, or https://vibe-wright.com/snowflake-self-check
