azure-pim-cli 0.1.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,73 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["**"]
6
+ pull_request:
7
+ branches: ["**"]
8
+
9
+ jobs:
10
+ quality:
11
+ name: Quality checks
12
+ runs-on: windows-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Install uv
17
+ uses: astral-sh/setup-uv@v3
18
+ with:
19
+ python-version: "3.12"
20
+ enable-cache: true
21
+
22
+ - name: Install dev deps
23
+ run: uv pip install -e ".[dev]"
24
+
25
+ - name: ruff check
26
+ run: uv run ruff check .
27
+
28
+ - name: ruff format check
29
+ run: uv run ruff format --check .
30
+
31
+ - name: mypy
32
+ run: uv run mypy src/azure_pim_cli
33
+
34
+ test:
35
+ name: Test (Python ${{ matrix.python-version }})
36
+ runs-on: windows-latest
37
+ strategy:
38
+ matrix:
39
+ python-version: ["3.12", "3.13"]
40
+ steps:
41
+ - uses: actions/checkout@v4
42
+
43
+ - name: Install uv
44
+ uses: astral-sh/setup-uv@v3
45
+ with:
46
+ python-version: ${{ matrix.python-version }}
47
+ enable-cache: true
48
+
49
+ - name: Install dev deps
50
+ run: uv pip install -e ".[dev]"
51
+
52
+ - name: pytest
53
+ run: uv run pytest --cov=azure_pim_cli --cov-report=term-missing --cov-fail-under=60
54
+
55
+ build:
56
+ name: Build wheel + sdist
57
+ runs-on: ubuntu-latest
58
+ needs: [quality, test]
59
+ steps:
60
+ - uses: actions/checkout@v4
61
+
62
+ - name: Install uv
63
+ uses: astral-sh/setup-uv@v3
64
+ with:
65
+ python-version: "3.12"
66
+
67
+ - name: Build
68
+ run: uv build
69
+
70
+ - uses: actions/upload-artifact@v4
71
+ with:
72
+ name: dist
73
+ path: dist/
@@ -0,0 +1,46 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ build:
10
+ name: Build wheel + sdist
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - name: Install uv
16
+ uses: astral-sh/setup-uv@v3
17
+ with:
18
+ python-version: "3.12"
19
+
20
+ - name: Build distributions
21
+ run: uv build
22
+
23
+ - name: Upload dist artifacts
24
+ uses: actions/upload-artifact@v4
25
+ with:
26
+ name: dist
27
+ path: dist/
28
+
29
+ publish:
30
+ name: Publish to PyPI
31
+ needs: build
32
+ runs-on: ubuntu-latest
33
+ environment:
34
+ name: pypi
35
+ url: https://pypi.org/p/azure-pim-cli
36
+ permissions:
37
+ id-token: write
38
+ steps:
39
+ - name: Download dist artifacts
40
+ uses: actions/download-artifact@v4
41
+ with:
42
+ name: dist
43
+ path: dist/
44
+
45
+ - name: Publish via Trusted Publishing (OIDC)
46
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .pytest_cache/
7
+ .mypy_cache/
8
+ .ruff_cache/
9
+ .venv/
10
+ venv/
11
+ htmlcov/
12
+ .coverage
13
+ .coverage.*
14
+ *.egg
15
+ MANIFEST
16
+ *.log
17
+ .claude/
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-07-10
11
+
12
+ ### Added
13
+ - Packaged as `azure-pim-cli` on PyPI; install with `pip install azure-pim-cli`.
14
+ - Console script `pim-activate` (replaces `python activate_pim.py`).
15
+ - `python -m azure_pim_cli` entry point.
16
+ - GitHub Actions CI: lint (ruff), type-check (mypy), unit tests (pytest), build artifact.
17
+ - GitHub Actions release workflow: publish to PyPI via Trusted Publisher (OIDC) on `v*` tags.
18
+ - Apache-2.0 license.
19
+ - Unit tests for `cache`, `cli` argument parsing, `graph_client`, and `chrome_launcher`.
20
+
21
+ ### Removed
22
+ - `azrbac_client.py` — unused by the main CLI; removed to reduce surface area.
23
+ - `sniff_portal.py` — dev/debug tool, not part of the public package.
24
+ - `requirements.txt` — superseded by `pyproject.toml` dependencies.
25
+
26
+ ### Known gaps
27
+ - `token_grabber.py` and `acrs_primer.py` lack unit tests (require Playwright fixtures; deferred).
@@ -0,0 +1,181 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of communicating and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the Work, as
121
+ a separate statement, separate from the Licensor's notice.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any warranties or conditions
141
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
142
+ PARTICULAR PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer only
163
+ conditions consistent with this License, provided that you separately
164
+ use best efforts to include with your Work a notice that such
165
+ additional terms are charged for, and not a part of this License.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ Copyright 2026 Wessel van der Linden
170
+
171
+ Licensed under the Apache License, Version 2.0 (the "License");
172
+ you may not use this file except in compliance with the License.
173
+ You may obtain a copy of the License at
174
+
175
+ http://www.apache.org/licenses/LICENSE-2.0
176
+
177
+ Unless required by applicable law or agreed to in writing, software
178
+ distributed under the License is distributed on an "AS IS" BASIS,
179
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180
+ See the License for the specific language governing permissions and
181
+ limitations under the License.
@@ -0,0 +1,289 @@
1
+ Metadata-Version: 2.4
2
+ Name: azure-pim-cli
3
+ Version: 0.1.0
4
+ Summary: Interactive CLI to activate Azure PIM group memberships and approve PIM group requests
5
+ Project-URL: Homepage, https://github.com/TheScriptingGuy/azure-pim-cli
6
+ Project-URL: Issues, https://github.com/TheScriptingGuy/azure-pim-cli/issues
7
+ Project-URL: Changelog, https://github.com/TheScriptingGuy/azure-pim-cli/blob/main/CHANGELOG.md
8
+ Author-email: Wessel van der Linden <wesselvdlinden@gmail.com>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: azure,cli,entra,pim,privileged identity management
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: System :: Systems Administration
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: httpx[http2]>=0.27
24
+ Requires-Dist: playwright>=1.44
25
+ Requires-Dist: python-dateutil>=2.9
26
+ Requires-Dist: questionary>=2.0
27
+ Requires-Dist: rich>=13.7
28
+ Provides-Extra: dev
29
+ Requires-Dist: mypy>=1.10; extra == 'dev'
30
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
31
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
32
+ Requires-Dist: pytest>=8.0; extra == 'dev'
33
+ Requires-Dist: respx>=0.21; extra == 'dev'
34
+ Requires-Dist: ruff>=0.9; extra == 'dev'
35
+ Requires-Dist: types-python-dateutil>=2.9; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # azure-pim-cli
39
+
40
+ [![PyPI version](https://img.shields.io/pypi/v/azure-pim-cli)](https://pypi.org/project/azure-pim-cli/)
41
+ [![CI](https://github.com/wesselvdlinden/azure-pim-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/wesselvdlinden/azure-pim-cli/actions/workflows/ci.yml)
42
+ [![Python](https://img.shields.io/pypi/pyversions/azure-pim-cli)](https://pypi.org/project/azure-pim-cli/)
43
+
44
+ Activate eligible Azure PIM group memberships **and** approve pending PIM group
45
+ requests you can approve, from one interactive picker.
46
+
47
+ Uses a real browser session (Playwright over CDP) to grab a Microsoft Graph
48
+ bearer token from an authenticated Azure Portal, bypassing the Conditional
49
+ Access blocks that break `Connect-MgGraph` / `az CLI` / Cloud Shell in the
50
+ tenant.
51
+
52
+ > **Windows only.** Relies on `robocopy`, `taskkill`, and Chrome paths specific to Windows.
53
+
54
+ ## Install
55
+
56
+ ```powershell
57
+ pip install azure-pim-cli
58
+ playwright install chromium
59
+ ```
60
+
61
+ ## First run
62
+
63
+ ```powershell
64
+ pim-activate
65
+ ```
66
+
67
+ What happens:
68
+
69
+ 1. `--auto-cdp` (on by default) kills any running Chrome, copies your real
70
+ Chrome profile to `C:\temp\chrome_pim_profile` (preserves Intune compliance
71
+ cookies), launches Chrome with `--remote-debugging-port=9222`.
72
+ 2. Playwright attaches over CDP to that Chrome and opens the PIM Approvals
73
+ blade.
74
+ 3. If you're not signed in, complete portal SSO in the Chrome window that pops
75
+ up. The script waits (up to 300s).
76
+ 4. The script sniffs a `graph.microsoft.com` Bearer token from the portal
77
+ session, or scrapes MSAL storage on an already-authenticated tab.
78
+ 5. Prints pending approvals (if any) and eligibilities, then shows the
79
+ interactive checkbox picker.
80
+
81
+ Subsequent runs skip login (session cookies persist in the copied Chrome
82
+ profile).
83
+
84
+ ## Typical output flow
85
+
86
+ ```
87
+ [chrome] launching Chrome with debug port 9222 ...
88
+ [token] captured via storage-existing-tab (expires in ~40m, ...)
89
+ User: user@example.com (05a0a5ea-...)
90
+ Fetching pending PIM group approvals (Graph)...
91
+ >> 2 pending approval(s) awaiting your decision.
92
+ Fetching eligible PIM group assignments...
93
+ >> 3 NEW eligible group(s) since last fetch!
94
+ ? Select PIM items to activate/approve:
95
+ ❯ ◯ APPROVE sg-prj-ExampleProject-... <- user@example.com PT2H
96
+ ◯ ACTIVATE *NEW* sg-app-reporting-reader (member) max 8h MFA=True
97
+ ◯ ACTIVATE sg-db-warehouse-contributor (member) max 8h MFA=True
98
+ ...
99
+ ```
100
+
101
+ If no approvals are pending you'll see:
102
+
103
+ ```
104
+ [dim]No pending approvals for you.[/dim]
105
+ ```
106
+
107
+ and it moves straight to the eligibilities list.
108
+
109
+ ## Common commands
110
+
111
+ ```powershell
112
+ # Combined interactive picker — approvals FIRST, then eligibilities
113
+ pim-activate
114
+
115
+ # List everything, no action (approvals + eligibilities tables)
116
+ pim-activate --list-only
117
+
118
+ # Refresh 24h eligibility cache
119
+ pim-activate --refresh
120
+
121
+ # Only my eligibilities (skip approvals feed)
122
+ pim-activate --eligibilities-only
123
+
124
+ # Only pending approvals I can approve
125
+ pim-activate --approvals-only
126
+
127
+ # Skip Playwright entirely — paste a Graph bearer token from DevTools
128
+ pim-activate --token "eyJ0eXAi..."
129
+ ```
130
+
131
+ ## Bulk activation via `--group` regex
132
+
133
+ `--group REGEX` skips the picker and activates every eligibility whose
134
+ `displayName` matches (case-insensitive). Combine with `--parallel N` for
135
+ concurrent POSTs.
136
+
137
+ ```powershell
138
+ # Activate ALL sg-* eligibilities, 8 workers, 8h
139
+ pim-activate --group "^sg-" --justification "bulk activate" --hours 8 --eligibilities-only --parallel 8
140
+
141
+ # Only analytics groups
142
+ pim-activate --group "-app-" --justification "analytics work" --hours 4 --parallel 4
143
+
144
+ # Dry-run (list matches, no action)
145
+ pim-activate --group "db-warehouse" --list-only
146
+ ```
147
+
148
+ - Regex matches `displayName` on both eligibilities and pending approvals.
149
+ - Groups already active are auto-skipped (avoids `PendingRoleAssignmentRequest`
150
+ errors on reruns).
151
+ - `--parallel` default is 8. Higher risks Graph 429.
152
+ - Polls each request up to 180s; `Timeout` status usually still succeeds — verify
153
+ with `--list-only`.
154
+
155
+ ## Auto-CDP flags
156
+
157
+ `--auto-cdp` is on by default and handles the Chrome profile copy + debug-port
158
+ launch automatically. Override when needed:
159
+
160
+ ```powershell
161
+ # Disable auto-cdp (attach to a manually-launched debug Chrome, or use bundled Playwright)
162
+ pim-activate --no-auto-cdp
163
+
164
+ # Force re-copy real Chrome profile (e.g. cookies stale)
165
+ pim-activate --refresh-chrome-profile
166
+
167
+ # Non-default debug port
168
+ pim-activate --auto-cdp-port 9333
169
+
170
+ # Non-default profile-copy target
171
+ pim-activate --auto-cdp-profile "D:\pim_chrome"
172
+
173
+ # Attach to already-running debug Chrome instead
174
+ pim-activate --no-auto-cdp --cdp-endpoint "http://localhost:9222"
175
+ ```
176
+
177
+ ## All flags
178
+
179
+ | Flag | Default | Description |
180
+ |---|---|---|
181
+ | `--refresh` | off | Bypass 24h eligibility cache |
182
+ | `--list-only` | off | Show tables, no activation/approval |
183
+ | `--group REGEX` | - | Filter both feeds by displayName |
184
+ | `--justification TEXT` | - | Prompted if omitted |
185
+ | `--hours N` | 8 | Duration (clamped per group policy) |
186
+ | `--ticket N` | - | Ticket number for policies that require it |
187
+ | `--approvals-only` | off | Skip eligibilities feed |
188
+ | `--eligibilities-only` | off | Skip pending approvals feed |
189
+ | `--headless` | off | Run Chromium headless (needs prior login) |
190
+ | `--keep-open` | off | Keep browser alive after token grab (debug) |
191
+ | `--token TOKEN` | - | Skip Playwright; use this Graph bearer token |
192
+ | `--parallel N` | 8 | Concurrent workers for bulk actions |
193
+ | `--channel STR` | chrome | Browser channel: `chrome`, `msedge`, `''` for bundled chromium |
194
+ | `--auto-cdp` | on | Auto-launch Chrome with debug port on copied real profile |
195
+ | `--no-auto-cdp` | - | Disable auto-cdp |
196
+ | `--auto-cdp-port` | 9222 | Debug port |
197
+ | `--auto-cdp-profile` | `C:\temp\chrome_pim_profile` | Profile-copy target |
198
+ | `--refresh-chrome-profile` | off | Force re-copy real Chrome profile |
199
+ | `--cdp-endpoint URL` | - | Attach to existing debug Chrome |
200
+
201
+ ## Cache
202
+
203
+ - Eligibilities cached 24h at `%LOCALAPPDATA%\pim_activate\eligible_cache.json`.
204
+ - Pending approvals are **never** cached (time-sensitive).
205
+ - NEW entries flagged `*NEW*` in picker and `*` in list mode.
206
+
207
+ ## Auth model
208
+
209
+ Portal PIM app (`c44b4083-...` / `Microsoft_Azure_PIMCommon`) sits inside the
210
+ authenticated Portal SPA. Its Graph token has all PIM scopes we need. We grab
211
+ that token via Playwright over CDP (attached to a Chrome that runs against a
212
+ copy of your real profile, so Intune compliance cookies come along).
213
+
214
+ - `az account get-access-token --resource https://graph.microsoft.com` fails —
215
+ first-party az CLI cannot request PIM Graph scopes in the tenant.
216
+ - `Connect-MgGraph -UseDeviceCode` fails — CA blocks the Graph PowerShell app.
217
+ - Cloud Shell fails — CA blocks the Cloud Shell session.
218
+ - Portal-in-browser + sniff works.
219
+
220
+ ### Scope caveat
221
+
222
+ Portal caches READ scope on first load of Entra ID blades. ReadWrite scope for
223
+ activation POST is cached only when portal visits the PIM Groups activation
224
+ blade. `--auto-cdp` opens that blade automatically.
225
+
226
+ Approval action needs `PrivilegedAssignmentSchedule.ReadWrite.AzureADGroup`,
227
+ which portal caches when you visit the approvals blade. If Graph 403s on
228
+ approve, open PIM Approvals blade in portal once, then rerun.
229
+
230
+ ## Endpoints used
231
+
232
+ - `GET /v1.0/me`
233
+ - `GET /v1.0/identityGovernance/privilegedAccess/group/eligibilityScheduleInstances`
234
+ - `GET /v1.0/groups/{id}`
235
+ - `GET /v1.0/policies/roleManagementPolicyAssignments`
236
+ - `GET /v1.0/policies/roleManagementPolicies/{id}/rules`
237
+ - `POST /v1.0/identityGovernance/privilegedAccess/group/assignmentScheduleRequests` (`selfActivate`)
238
+ - `GET /v1.0/identityGovernance/privilegedAccess/group/assignmentScheduleRequests/{id}` (poll)
239
+ - `GET /beta/identityGovernance/privilegedAccess/group/assignmentScheduleRequests/filterByCurrentUser(on='approver')` (pending approvals — portal-parity server-side scoping)
240
+ - `GET /beta/identityGovernance/privilegedAccess/group/assignmentApprovals/{approvalId}` (approval steps)
241
+ - `PATCH /beta/identityGovernance/privilegedAccess/group/assignmentApprovals/{approvalId}/steps/{stepId}` (approve)
242
+
243
+ ## Fallback: manual token
244
+
245
+ If Playwright breaks (browser update, CA change), grab a token manually:
246
+
247
+ 1. Open portal.azure.com, sign in.
248
+ 2. F12 → Network tab.
249
+ 3. Navigate to PIM Groups. Find a request to `graph.microsoft.com/*`.
250
+ 4. Copy the `Authorization` header value (drop the `Bearer ` prefix).
251
+ 5. `pim-activate --token "<paste>"`.
252
+
253
+ ## Known limitations
254
+
255
+ - **Denying approvals**: not supported. Use portal.
256
+ - **Non-group PIM** (AAD roles, Azure resource roles): different endpoints.
257
+ - **Scheduled/future activations**: only immediate `selfActivate`.
258
+ - **bash/xterm terminal + interactive picker**: `questionary` needs a Win32
259
+ console — run from cmd.exe, PowerShell, or Windows Terminal. Bash/Cygwin
260
+ raises `NoConsoleScreenBufferError`. Non-interactive flags (`--group`,
261
+ `--list-only`) work in any shell.
262
+
263
+ ## Development
264
+
265
+ ```powershell
266
+ git clone https://github.com/wesselvdlinden/azure-pim-cli
267
+ cd azure-pim-cli
268
+ python -m venv .venv && .venv\Scripts\activate
269
+ pip install -e ".[dev]"
270
+
271
+ # Run tests
272
+ pytest
273
+
274
+ # Lint
275
+ ruff check . && ruff format --check .
276
+
277
+ # Type check
278
+ mypy src/azure_pim_cli
279
+ ```
280
+
281
+ ### Publishing a release
282
+
283
+ 1. On PyPI, create a new project `azure-pim-cli` and configure a **Trusted Publisher**:
284
+ - Owner: `wesselvdlinden`
285
+ - Repo: `azure-pim-cli`
286
+ - Workflow: `release.yml`
287
+ - Environment: `pypi`
288
+ 2. Tag and push: `git tag v0.1.0 && git push origin v0.1.0`
289
+ 3. The `release.yml` workflow builds and publishes automatically via OIDC — no API token needed.