Repository navigation
Conversation
|
@claude code-review |
This comment was marked as outdated.
This comment was marked as outdated.
|
@claude code-review |
This comment was marked as outdated.
This comment was marked as outdated.
cbfafa5 to
6d1d95c
Compare
|
@claude code-review |
This comment was marked as outdated.
This comment was marked as outdated.
|
@claude code-review |
This comment was marked as outdated.
This comment was marked as outdated.
|
@claude code-review |
This comment was marked as outdated.
This comment was marked as outdated.
eebe660 to
df79b3e
Compare
|
|
||
| --- | ||
|
|
||
| ## 3. Applying this module is admin-equivalent, so nothing else may need it |
There was a problem hiding this comment.
If we're going to need multiple admin users, we should create a formal admin role. Alternatively, we could make "admin" separate from "owner":
- Owner is reserved for a single individual (or a very small number of people) and owns the things only the org should control: billing account linkage, creating/deleting projects, deleting the project itself.
- Admin is a custom role for everything the owner has (including granting and revoking the tfa* roles, applying
deployment/admin/, viewing audit logs) except for billing and project lifecycle permissions. That way we're not handing out owner just to get admin work done.
| # role meant for people. | ||
|
|
||
| resource "google_project_iam_custom_role" "contributor" { | ||
| role_id = "tfaContributor" |
There was a problem hiding this comment.
The current names (Contributor, Corpus Maintainer, Corpus Admin, Reaper) are confusing without reading the detailed explanation for what each role actually does. Could we rename them to commonly used terms like "read-only", "power-user", "admin", etc. that describe the level of access in the name? See my separate comments regarding the Corpus Admin and Reaper roles.
Since custom role IDs can't be reused for 30 days after deletion, it'll be easier to decide on names before this is applied, if it hasn't been already.
| } | ||
|
|
||
| resource "google_project_iam_custom_role" "corpus_admin" { | ||
| role_id = "tfaCorpusAdmin" |
There was a problem hiding this comment.
This role seems unnecessary. If it's only for emergencies and essentially gives admin access, why not have an admin take the action directly? That's simpler than a maintainer requesting access and an admin granting temporary admin access to the maintainer. It also means one less role to manage, and delete access is reserved only for the admin group.
| The general principle: we do not own the identity system here, Google does, so | ||
| verification is delegated to it rather than reimplemented beside it. | ||
|
|
||
| ### Expiring grants |
There was a problem hiding this comment.
A good rule of thumb is to set up roles with full lifecycle management and remove access for anyone who shouldn't have it. Since we don't have robust logging in Google Cloud to track inactivity, I'd suggest making all roles (except Owner, obviously) expire after a set amount of time (like 6-12 months). People still on the project can re-request access, and people who've moved on lose it automatically.
Specifically, I'd suggest:
--expiresbecomes required (or defaults to 180-365 days) rather than opt-in- the expiry applies to every layer/role granted, not only the top one since currently
--role corpus-maintainer --expires 90leavestfaContributorrole permanent - optionally, a periodic reminder can be set up where
list-accesswould show upcoming expiration to the admin so they can give active people a heads-up
I understand the concern that "a grant that silently expires mid-task is its own failure mode," but for a volunteer project with natural turnover, I think forgotten standing access is the bigger risk, and a 6-12 month window will likely make the mid-task surprises rare.
| } | ||
|
|
||
| resource "google_project_iam_custom_role" "reaper" { | ||
| role_id = "tfaReaper" |
There was a problem hiding this comment.
I have a lot of questions about how the reaper role will be used. Normally, a role for something like deleting files or outdated storage buckets is created along with the service or script that uses it, so it's narrowly scoped to that specific action. A generic role that multiple services, scripts or agents can assume becomes hard to manage, and it's hard to track what permissions it has and why, especially if and when we decide to deprecate/delete that role. Each automated program should have its own role defined to only what it needs access to.
I'd strongly recommend moving the reaper role and service account to the PR that builds the reaper itself, scoped to exactly what it's set up to do.
Additionally, regarding protecting the live/production corpus directly: the README notes that the production corpus isn't protected by IAM today; the reaper's code is the only thing stopping it being deleted. Rather than relying on code, could we protect the objects we care most about at the resource level? For example, we can set a deny policy on the promoted corpus, or a retention policy/hold on its bucket, so that no role or service, including admins, can delete it without first deliberately removing that protection.
ovs-11
left a comment
There was a problem hiding this comment.
I've reviewed this from a product/access-management perspective and left a few comments. My comments are mostly about keeping access simple to understand and manage as volunteers come and go. Happy to discuss any of them in more detail.
| # absolute path the caller typed produced a path that never existed, so the module | ||
| # applied with defaults and the caller's group bindings were dropped with no error. | ||
| case "$var_file" in | ||
| /*|*/*) var_file_path="$var_file" ;; |
There was a problem hiding this comment.
-chdir=admin/ makes tofu resolve -var-file from admin/, so once the example is copied to terraform.tfvars, apply-admin fails: "Given variables file admin/terraform.tfvars does not exist" (reproduced with OpenTofu 1.12.6, the version this PR pins).
case "$var_file" in
/*) var_file_path="$var_file" ;;
*/*) var_file_path="$PWD/$var_file" ;;
*) var_file_path="$PWD/admin/$var_file" ;;
esac|
@claude aggregate earlier feedback and run a pr-review |
|
Claude finished @leekahung's task in 2m 29s —— View job PR review: aggregated feedback + fresh pass
1. Earlier feedback: status at
|
| # | From | Feedback | Status |
|---|---|---|---|
| A | CodeQL | jdx/mise-action@v2 unpinned |
✅ Fixed. It's now pinned to a SHA (c37c932… # v2.4.4) and the job has permissions: contents: read. |
| B | leekahung | apply-admin builds -var-file=admin/terraform.tfvars, but -chdir=admin/ resolves it to admin/admin/…, so the apply fails |
❌ Open, and confirmed. deployment/mise.toml:288-304 is unchanged. The [ -f "$var_file_path" ] check runs from deployment/, so it passes, and then tofu can't find the file. This also breaks any relative path containing a slash, so the */* branch has the same bug. Blocker. |
| C | ovs-11 | Split admin from owner: Owner is kept to 1–2 people for billing and project lifecycle, and a custom admin role covers granting roles, apply-admin and audit logs |
❌ Open (design). Today every admin is Owner or projectIamAdmin. |
| D | ovs-11 | Rename the roles by access level (read-only / power-user / admin) | ❌ Open. Time-sensitive: role_id can't be reused for 30 days after deletion, and prevent_destroy blocks a rename-by-replace. Settle the names before the first apply-admin. |
| E | ovs-11 | Drop tfaCorpusAdmin; admins should do break-glass deletes themselves |
❌ Open. This fits with C: if a real admin role exists, corpus deletion can live there and one role (plus the /dev/tty confirmation path) goes away. |
| F | ovs-11 | --expires should be the default (180–365 days), apply to every layer, and list-access should show upcoming expiries |
❌ Open. mise.toml:525-527 still deliberately expires only the named layer, so --role corpus-maintainer --expires 90 leaves tfaContributor standing forever. |
| G | ovs-11 | Move tfaReaper and its service account into the PR that builds the reaper. Protect the promoted corpus at the resource level (deny policy, retention or holds) rather than in code |
❌ Open. See my notes under 2.5. |
2. New findings
2.1 Blocker: B above, with a fix. Make the path absolute before -chdir changes the base directory, so the -f check and tofu agree:
case "$var_file" in
/*) var_file_path="$var_file" ;;
*/*) var_file_path="$PWD/$var_file" ;;
*) var_file_path="$PWD/admin/$var_file" ;;
esac2.2 Verify the exclude condition before merging or applying. bindings.tf:34-47 and admin/README.md:280 say it's still unverified whether resource.service != "storage.googleapis.com" || … evaluates true for Discovery Engine requests. If it doesn't, every maintainer and corpus-admin binding quietly loses its discoveryengine.* permissions, while the console shows a grant that looks correct. The TODO already describes a cheap test (vertex_ai_list_datastores as a test principal). I'd make that a merge gate, not a follow-up.
2.3 list-access hides conditions (mise.toml:592-595). The table shows only role and principal, so an admin can't see which grants expire or whether a maintainer binding carries the state-bucket exclusion. Adding bindings.condition.title and bindings.condition.expression columns is a one-line change, and it's the base for ovs-11's expiry-reminder idea (F).
2.4 --expires can do nothing, silently (mise.toml:514-554). The "already held" check only covers base layers. If someone already holds tfaContributor unconditionally, grant … --expires 30 adds a second, expiring binding next to it. Allow policies are additive, so access never lapses, yet the output says "expiring ". At minimum, warn when the named layer is already bound without a condition. If F is adopted, this becomes the normal case to handle.
2.5 Reaper identity with no consumer (service_accounts.tf, bindings.tf:84-141). This apply creates tfa-corpus-reaper with project-wide storage.buckets.delete and objects.delete, plus run.invoker and eventarc.eventReceiver, for code that doesn't exist yet. Nothing runs as it, but any principal who can impersonate it (Owner, serviceAccountTokenCreator) gets those deletes. That backs G: define it in the reaper PR, scoped to what that code needs. Two caveats on the resource-level protection G asks for:
- GCS retention or holds protect only the bucket. The Discovery Engine datastore that production actually queries has no soft delete (
roles.tf:233-235), anddiscoveryengine.dataStores.deletewould still get past it. - IAM deny policies need
roles/iam.denyAdmin, which I believe can only be granted at organization level. Check whethertenantfirstaidsits under an org before designing around it.
2.6 Offboarding is error-prone (mise.toml:396-406). --revoke defaults to contributor and removes only that layer, so a bare grant user:x --revoke on a maintainer leaves tfaCorpusMaintainer bound. It's documented, but it fails in the unsafe direction for a volunteer project with turnover. Consider making a bare --revoke remove every tfa* role for the principal, and keeping the peel-one-layer behaviour for an explicit --role.
2.7 Leftover plan file. apply-admin writes admin/tfplan and never removes it. It's gitignored (good), but it keeps resource values on the admin's disk indefinitely. Add rm -f admin/tfplan after the apply, or in the exit trap.
2.8 Maintainability (non-blocking, related to ovs-11's summary). The 2,250 added lines are mostly prose. Several comments record the history of earlier review rounds rather than the current code, for example mise.toml "The previous version printed only dots…" and "where the earlier bug lived". That belongs in commit messages. Cutting it down would make the IAM surface much easier for the next volunteer to audit, which is the stated goal of the PR.
Suggested order
- Fix B (blocker) and run 2.2's verification.
- Decide C/D/E (role model and names) before the first
apply-admin, because renames get expensive afterwards. - Decide F (expiry policy) and G (split the reaper out). Then 2.3, 2.4 and 2.6 fall out of those decisions.
- 2.7 and 2.8 can go in whenever.
Not done: I didn't run mise run //deployment:check or any tofu commands, and nothing was applied against GCP. The locally modified .claude/skills/*.md files in the checkout are not part of the PR's commits, so I didn't review them.
What type of PR is this? (check all applicable)
Description
This PR declares custom IAM roles (using OpenTofu) for GCP and aligns access with developer roles.
Related Tickets & Documents
lawsRAG into separate jurisdictions #318QA Instructions, Screenshots, Recordings
Please replace this line with instructions on how to test your changes, a note on the devices and browsers this has been tested on, as well as any relevant images for UI changes.
Added/updated tests?
Documentation
Architecture.mdhas been updated[optional] Are there any post deployment tasks we need to perform?