nate2-scripts 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ __pycache__
@@ -0,0 +1,70 @@
1
+ # Console Script — Session Investigation Notes
2
+
3
+ ## The Problem
4
+
5
+ Running `co lambda` then `co ec2` (same account) signs out the Lambda tab.
6
+
7
+ ## Root Cause
8
+
9
+ The session cache keys by `AccessKeyId`, which rotates every time Okta refreshes STS credentials (~1 hour). After rotation, the cache misses and re-federates, creating a new browser session that invalidates the previous one.
10
+
11
+ ## How Federation Works
12
+
13
+ 1. CLI credentials (AccessKeyId/SecretAccessKey/SessionToken) are sent to `signin.aws.amazon.com/federation?Action=getSigninToken` → returns a one-time SigninToken
14
+ 2. Browser opens `signin.aws.amazon.com/federation?Action=login&SigninToken=...` → AWS creates a browser console session (cookies) and redirects to destination
15
+ 3. The browser session lasts **12 hours** (script uses 11hr buffer)
16
+ 4. Each `Action=login` call for the **same account** replaces the previous session → other tabs for that account become invalid
17
+ 5. Different accounts get isolated sessions (multi-session console, 2024+) — no conflict
18
+
19
+ ## Key Findings
20
+
21
+ - **Federation does NOT require existing browser cookies** — it creates a session from scratch using CLI creds
22
+ - **Multi-session console** isolates different accounts but NOT multiple sessions within the same account
23
+ - **Re-federating same account** kills existing tabs for that account
24
+ - **The account-specific URL hash** (e.g., `lh2nfmmd` in `905502466771-lh2nfmmd.us-east-1.console.aws.amazon.com`) is per-browser-session, changes on every sign-in, and is NOT retrievable via any AWS API. It's assigned client-side by JavaScript after login.
25
+ - **The hash is NOT cacheable** — it's tied to the browser session lifetime, not the account
26
+ - **DNS lookups** won't help — `*.console.aws.amazon.com` is a wildcard record; the hash is resolved by cookies/frontend
27
+
28
+ ## The Fix
29
+
30
+ Key the session cache by **profile name** (or account ID) instead of `AccessKeyId`:
31
+
32
+ - The browser session is tied to the account, not the specific credential set
33
+ - Even after Okta rotates creds (new AccessKeyId), the browser session from the previous federation is still alive
34
+ - Cache should prevent re-federation as long as it's within 11 hours of the last federation for that profile
35
+
36
+ ## Approaches Considered & Rejected
37
+
38
+ | Approach | Why rejected |
39
+ |----------|-------------|
40
+ | Always federate | Signs out other tabs for same account |
41
+ | Account-specific URL hash (cached) | Hash is per-session, not stable |
42
+ | Selenium/Playwright to discover hash | Hash from WebDriver session ≠ real browser session |
43
+ | AppleScript to read browser URL | Hash is session-bound, same lifecycle as session cache |
44
+ | Browser profiles (Chrome/Firefox) | Still can't open 2nd tab without re-federation within same profile |
45
+ | DNS lookup for hash | Wildcard DNS — hash is cookie-routed, not DNS-routed |
46
+ | Capture hash from federation redirect | Redirect goes to the generic URL; hash rewrite is client-side JS |
47
+
48
+ ## Current Architecture
49
+
50
+ ```
51
+ co <service>
52
+ → check AWS_PROFILE is set
53
+ → parse destination URL
54
+ → get CLI creds (aws configure export-credentials)
55
+ → check session cache
56
+ → valid: open raw URL (webbrowser.open)
57
+ → expired/missing: federate → open federation URL → record cache
58
+ ```
59
+
60
+ ## What Needs to Change
61
+
62
+ ```python
63
+ # Before (buggy): keyed by AccessKeyId which rotates
64
+ cache[creds["AccessKeyId"]] = {"federated_at": time.time()}
65
+
66
+ # After: keyed by profile name which is stable
67
+ cache[profile_name] = {"federated_at": time.time()}
68
+ ```
69
+
70
+ This ensures that within the 11-hour window, `co` opens the raw URL without re-federating, keeping other same-account tabs alive.