Outcome
By the end of this lesson, you will be able to execute a safe PAT rotation sequence, automate rotation via secret managers, and respond to compromise scenarios (lost device, leaked PAT, departed user).
| Prerequisites | M6.3.L1-L3 |
| Time | 9 minutes |
1. Concept
Anybody holding your token can read what you can read, for as long as it exists.
Replacing one is three steps: make a new token, put it into whatever was using the old one, then revoke the old one.
Do it every quarter as a matter of course, and immediately if you think one has got out.
WHY ROTATE PATs: Limit exposure if leaked Compliance requirement (typically quarterly) User left team / changed role Security incident Periodic hygiene (industry best practice for bearer tokens)Rotation policy
RECOMMENDED: Quarterly rotation (every 90 days): most common Immediate rotation on suspected leak Rotation when a user's role changes (your runbook, not automatic)
TRACKED in ZopNight UI (Settings → API & MCP): Each token's expiry date On the expiry date the token stops working (401)The 90-day cadence balances security (limits exposure window) with operational overhead (not constant rotation pressure).
Manual rotation: safe sequence
SAFE ROTATION (no disruption):
1. Generate new PAT ZopNight → Settings → API & MCP → Create Token Same orgs and write capabilities as before; new name
2. Copy the new PAT (shown only once)
3. Update the client's config (its Authorization header, or the secret store it reads from) Replace old PAT value with new
4. Restart your AI tool (Claude Desktop, Cursor, etc.) Loads the new PAT
5. Verify new PAT works Test query: "Who am I in ZopNight?" Should return your user (auth working)
6. Revoke the OLD PAT ZopNight → Settings → API & MCP → delete the old token This is the moment the old PAT becomes invalid
5-minute process; done correctly, no disruption.Common mistake: revoking the old PAT before step 5. Then the agent breaks until step 4 completes.
Each token also has a Rotate action. It keeps the same token, issues a new secret and can change the expiry, but the old secret stops working the moment you rotate, with no grace period. Use it when you can update the client straight away; use the create-then-revoke sequence above when you need zero downtime.
Automated rotation
For teams with strict policies, automate via:
OPTION A: ZopNight API direct POST /auth/pat/{id}/rotate Body: { userEmail: "...", expiresIn: "90d" } (expiresIn is optional; leave it out to keep the expiry) Returns: the new secret (shown once); same token id The old secret is invalid the moment the call returns, so write the new one to your secret store in the same step
OPTION B: Secret manager integration 1Password CLI rotates and re-syncs HashiCorp Vault rotates on schedule AWS Secrets Manager rotation lambda Each can call ZopNight API + update its store atomically
OPTION C: CI/CD orchestration Github Actions / Jenkins runs rotation script quarterly Script: generate new PAT → update secrets store → notify usersAutomation is the answer at scale. Manual rotation across 100 engineers is operational pain; automated rotation is one runbook.
Coordination with clients (the safe pattern)
PROBLEM: rotate PAT while the agent has an active session
WHAT HAPPENS WITHOUT COORDINATION: Agent has old PAT in process memory You revoke old PAT Agent's next call returns 401 Unauthorized Agent breaks until restarted with new PAT
THE SAFE PATTERN: 1. Generate new PAT 2. Update client config (or its secret store) with new value 3. Restart client (which reloads PAT) 4. Verify new PAT works (test query) 5. ONLY NOW revoke old PAT
If you skip step 4: agent breaks if new PAT is badIf you skip step 5: old PAT stays valid (bad if leaked)The order matters. Verify before revoke.
Multi-device strategy
ENGINEER uses MCP from multiple devices: Cursor on laptop Claude Code on desktop workstation Claude Desktop on personal Mac (if BYOD allowed)
RECOMMENDED: one PAT per device
WHY: If a device is lost (e.g., laptop stolen), revoke that device's PAT; other devices keep working.
If using one PAT across devices, losing one device requires revoking the shared PAT: interrupts work on the other devices.
NAMING convention: pat-laptop-2026-Q2 (or descriptive: "MBP-2026-Q2") pat-workstation-2026-Q2 pat-personal-mac-2026-Q2Lost or stolen device: response
RESPONSE PROCEDURE:
T+0 Engineer reports device lost / stolen T+5min Open ZopNight → Settings → API & MCP T+5min Identify PATs tied to lost device (by name) T+6min Revoke immediately
Other devices continue working (different PATs) Issue new PAT for replacement device when available
LATENCY: PAT revocation effective within 60 seconds AI tools on the lost device receive 401 on next call No way for the lost device to continue using the revoked PATSpeed matters. The longer the PAT is valid on a lost device, the bigger the exposure window.
Compromise scenarios
SCENARIO 1: PAT pushed to public Git Action: revoke immediately; rotate; audit recent usage Forensics: check audit log for unfamiliar usage from the time of push to revocation
SCENARIO 2: PAT in old chat / Slack message Action: rotate when discovered; verify chat is purged Mitigation: secrets scanning on chat archives going forward
SCENARIO 3: Suspected insider misuse Action: revoke; investigate via audit log; report per security incident process Forensics: full audit log review for the user's recent activity
SCENARIO 4: Engineer leaves the company Action: revoke all their PATs (HR-triggered process) Verify: zero MCP calls from those PATs after revocation
SCENARIO 5: User account compromised Action: revoke ALL PATs for that user Investigate via audit log Reset user's password / re-authenticate SSO Investigate downstream actions takenEach scenario has a runbook. Document them; rehearse them annually via tabletop.
PAT naming discipline
BAD NAMES (avoid): "test" "for stuff" "delete me" "" (empty)
GOOD NAMES: "Claude Code on jane-mbp 2026-Q2" "Cursor on dev-vm prod-account 2026-Q2" "CI cron audit-export 2026-Q2" "Datadog integration" "Notion integration via MCP-Notion 2026-Q2"
WHY: makes rotation easier ("rotate all jane-mbp PATs") Makes incident response easier ("revoke every token on jane-mbp") (Audit rows record the user, not which token, so a good name helps in Settings rather than in the audit log)Compliance-heavy orgs: no central PAT policy
ZopNight has no org-wide PAT policy. Each token's limits arechosen when it is minted: Name (the only label; there is no separate description field) Orgs it may act in Expiry Permissions (never more than its owner's)
Not in the product, so run them yourself: Maximum token age and rotation cadence → your runbook Expiry reminders → calendar or secret-manager alerts Approval for new tokens → your access-request processThe quarterly runbook below is where a compliance-heavy org enforces these centrally.
Quarterly rotation runbook
WEEK 1 OF QUARTER (e.g., week of Jan 1, Apr 1, Jul 1, Oct 1): List PATs older than 60 days (ZopNight UI / API) Notify users via email: "your PAT XYZ expires in 30 days" Provide 1-week window for self-rotation Provide updated rotation runbook link
WEEK 2: Generate fresh PATs for users who didn't self-rotate Block usage of stale PATs (or escalate to user's manager) Update SIEM rules if needed
WEEK 3: Audit: zero PATs >90 days old? Verify. File quarterly compliance report Update org's runbook based on lessons learnedThe runbook is reusable each quarter. Document it once; execute four times a year.
Cost
PAT generation: freePAT rotation: freePAT storage: free (metadata only)Audit log entries: per ZopNight's pricingLLM tokens: paid by AI tool, not ZopNight
So rotation has no infra cost: only ops effort.2. Demo
A quarterly rotation cycle:
DAY 1 (Quarter start): Runbook reminder: "Your PAT 'Claude Code on jane-mbp 2026-Q1' expires in 14 days. Plan to rotate this week."
DAY 2 (Jane responds): Jane opens ZopNight → Settings → API & MCP Clicks "Create Token" → "Claude Code on jane-mbp 2026-Q2" Same orgs and write capabilities; new name with the new quarter Generated: zn_pat_b3c5d7... (copies immediately)
Re-adds the server in Claude Code with the new token: claude mcp remove zopnight claude mcp add --transport http zopnight <server-url> \ --header "Authorization: Bearer zn_pat_b3c5d7..."
Restarts Claude Code
Verifies new PAT works: > /mcp ✓ zopnight: connected > "Who am I?" ✓ "jane@platform in Acme Corp"
Revokes old PAT in ZopNight UI
Records the rotation in the team's runbook log (PAT create, rotate and delete are not written to the org audit log)
ELAPSED: 5 minutesDISRUPTION: 30 seconds while Claude Code restarts3. Hands-on (5 min)
Audit your own PATs:
TOTAL PATs you have: _____
OLDEST PAT: Age: _____ days Name: __________ Action needed: rotate / fine
PATs with vague names (replace): __________ __________
PATs >75 days old (rotate this week): __________ __________
ROTATION PLAN: □ Self-rotate this week □ Document in team wiki □ Set calendar reminder for next quarter
SECRETS-MANAGER integration: □ Yes (which: __________) □ No (consider automating quarterly rotation)4. Knowledge check
Q1
Quarterly PAT rotation:
A. A common policy that bounds exposure if a token leaks
B. Excessive overhead for the benefit
C. Annual rotation is quite sufficient
D. Only after a confirmed compromise
Show answer
Correct: A. It limits exposure if a token leaks. 90 days balances a bounded exposure window against operational overhead. Some frameworks and many internal policies ask for a rotation cadence like this; others only require rotation after a suspected leak, so check what your auditor expects.
Q2
Safe rotation order:
A. Revoke the old PAT first, and only then generate and distribute its replacement
B. Generate new → update client config → restart client → verify new works → THEN revoke old
C. Generate and revoke in whatever order is convenient
D. Generate the new one and revoke the old simultaneously
Show answer
Correct: B. Verifying before revoking prevents the agent from breaking if the new PAT is bad.
Q3
PAT accidentally pushed to public Git:
A. Wait and see first
B. Rewrite the git history
C. Tweet about it later
D. Revoke immediately
Show answer
Correct: D. Then issue a new PAT for the same user, check the audit log for any use during the exposure window, document the incident, and add secrets scanning to commit hooks to prevent a repeat.
5. Apply
Quarterly rotation runbook in your team wiki. Clear PAT names. Automated rotation via secret manager for teams >20 engineers. Document compromise-response procedures for each of the 5 scenarios.
ZopNight’s Settings → API & MCP supports the rotation lifecycle natively.
Related lessons
Glossary terms touched
PAT · Credential rotation · Compromised credentials
Module quiz
Complete M6.3 → 10-question quiz.