Self-serve provisioning of an isolated Snowflake test account (#42)#44
Open
GClunies wants to merge 2 commits into
Open
Self-serve provisioning of an isolated Snowflake test account (#42)#44GClunies wants to merge 2 commits into
GClunies wants to merge 2 commits into
Conversation
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
…account Add `provision` and `drop` subcommands to tools/manage_test_account.py plus `make provision-test-account EMAIL=...` / `make drop-test-account` targets (closes datacoves#42): - provision mirrors the developer's current edition/cloud/region by default (detected from their normal SNOWFLAKE_* credentials) with optional --edition/--cloud/--region overrides - ORGADMIN credentials come only from dedicated SNOWFLAKE_ORG_* env vars and are used only for CREATE ACCOUNT / DROP ACCOUNT — never written to any file - the new account's admin is a SERVICE user with a freshly generated local RSA key pair (0600, backed up before overwrite); no password is ever set - polls until the account is reachable, bootstraps it via the existing reset_test_account flow plus static resources, and writes a ready-to-use tests/.env (existing file backed up first) - drop gates on tests/.env agreement, confirms the resolved identifier, and takes --grace-period-in-days (default 3, Snowflake's minimum) - unit tests (49) mock everything testable without a live org - TESTING.md documents prerequisites, provisioning, resume semantics, teardown, and expected cost Note: the pre-existing unreachable reset_test_account() call after main() in the __main__ block is intentionally left untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lkii1Y1STX9aNPLQu5tAJf
… before key mutation Post-review hardening of the provision flow: - SHOW ACCOUNTS rows expose the account name as account_name, not name - the resume check would have raised KeyError against a live org (test fixtures updated to the documented column so a regression fails) - composed region and region group are now validated up front, before the key file is archived/overwritten; a mistyped --region can no longer orphan a working key - recovery hint now covers CREATE ACCOUNT itself: a failure there raises a ClickException with re-run/drop guidance instead of a raw traceback - --grace-period-in-days gets help text; orchestration functions get type hints - tests: shared drop_deps fixture; patch subprocess.run instead of the whole module Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lkii1Y1STX9aNPLQu5tAJf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Contributors must never run the integration test suite (
pytest tests/ --snowflake) against their personal or employer Snowflake account — those tests create and mutate real objects. Today there's no self-serve way to get an isolated, disposable Snowflake account for this purpose.Flow
provisionmirrors the contributor's current edition/cloud/region (detected from their normalSNOWFLAKE_*credentials) by default, with--edition/--cloud/--regionoverrides.reset_test_accountflow plus static resources, and writes a ready-to-usetests/.env.provisionagainst an existing account resumes (skipsCREATE ACCOUNT) rather than failing.dropgates ontests/.envagreement (or--yes), confirms the resolved account identifier, and issuesDROP ACCOUNT ... GRACE_PERIOD_IN_DAYS=<n>(default/minimum 3).Credential separation & zero-leakage construction
SNOWFLAKE_ORG_ACCOUNT/SNOWFLAKE_ORG_USER/SNOWFLAKE_ORG_PASSWORDenv vars, used only forCREATE ACCOUNT/DROP ACCOUNT— they are never written totests/.envor any other file (asserted by a unit test onrender_test_env).SERVICEuser with a freshly generated local RSA key pair (2048-bit, written atomically at0600, backed up before any overwrite) — no password is ever set for it.reset_test_accountare built explicitly from generated values and inert placeholders; a contributor's ownSNOWCAP_VAR_*environment never reaches the new account.tests/.env,tests/.env.bak*,tests/.env.dropped*,tests/.snowcap_test_account_rsa_key.p8*) are git-ignored.Testing done
tests/test_manage_test_account.pycovering SQL builders (including identifier/injection validation), region resolution, env rendering (including the "never contains SNOWFLAKE_ORG" assertion), key/password generation, the org-connection env contract, poll timeout/narrow-exception behavior,provision_test_account's safety-critical branches (resume-skips-create, backup-before-overwrite, apply.sh failure surfacing, upfront input validation before any filesystem mutation),drop_test_account's safety gates, and CLI defaults/--helpcontracts..venv/bin/python -m pytest→ 1582 passed, 245 skipped.SNOWFLAKE_ORG_*credentials available here. Coverage is limited to the mocked unit tests plus--helpsmoke checks.Intentional follow-ups (not addressed in this PR)
generate_rsa_keypaircould reusesnowcap.operations.connector.SecurePathfor the0600secret write instead of its ownos.open/fdopenlogic. Left as-is to avoid churning working, security-equivalent code.reset_test_account()statement aftermain()in thetools/manage_test_account.py__main__block (unreachable —click'smain()raisesSystemExit) was left untouched; it predates this change.Closes #42
🤖 Generated with Claude Code
https://claude.ai/code/session_01Lkii1Y1STX9aNPLQu5tAJf