Add script for removing inactive users from org - #63
Merged
Conversation
utsavkapoor
approved these changes
Aug 21, 2026
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.
ts-org-inactive-users-cleanup.py
Removes users from the specified ThoughtSpot org after N days of inactivity in
that org. Users stay on the cluster and in their other orgs — only
membership in that one org is removed. Run once per org.
Requirements
pip3 install -r requirements.txtTS: BI Serverusage-stats reporting enabled on your cluster (what theinactivity check is based on).
processing, via one of:
secret_key— can be org-scoped on some deployments— if you'll run this against several orgs, you may need a different
key per org.
account's password works for every org it administers.
Install
python3 -m venv .venv source .venv/bin/activate pip3 install -r requirements.txtEvery run below follows the same three steps, in this order:
list orgs → dry run → live run. Always review the dry-run CSV before
going live. Pick one of the two approaches below for supplying
credentials/target org — don't mix them for the same run.
Approach A:
.envfile (recommended)Keeps
secret_key/password out of your shell history and out ofpsoutput, which passing them as CLI flags would not.
Open
.envand fill inTS_CLUSTER_URL, one of the two auth methodsabove, and
TS_ORG_ID(find it with step 1 below if you don't have ityet).
.envis gitignored — never commit your real one.Approach B: CLI flags (no
.envfile)Every value normally read from
.envhas a matching flag instead. Usefulfor a one-off run, or when credentials come from another secrets store
that injects them as arguments.
(Swap
--username/--passwordfor--secret-key '<key>' --admin-username <user>if you're using Trusted Auth instead of a password.)
Mixing is allowed but resolves by precedence — see Optional flags
below: a real exported env var or an explicit CLI flag always takes
priority over
.env.Multiple orgs?
Run the script again with a different
--org-id(this overrides whateverTS_ORG_IDis set in.env) — each run is independent, and its auditCSV/log file is named after that org's ID
(
ts_org_cleanup_audit_<org_id>.csv), so runs never overwrite each other.Optional flags
.envequivalent--cluster-url <url>TS_CLUSTER_URL--secret-key '<key>'TS_SECRET_KEY--admin-username <user>TS_ADMIN_USERNAME--secret-key)--username <user>TS_USERNAME--password '<password>'TS_PASSWORD--org-id 111TS_ORG_ID--inactivity-days 30--list-orgsNotes
--dry-run) removes users immediately with noconfirmation prompt — this is intentional, so the script can be
scheduled (cron/etc.) without a
yesprompt blocking unattended runs.Always dry-run first.
tsadmin,system, orthoughtspotaccounts.flag, a real env var, or
.envfile) is active — check it if a rundoesn't behave as expected. A stale
TS_SECRET_KEYin your shell orleft in
.envfrom an earlier setup silently overrides CLI flagsotherwise.