fix: make access control terraform check a hard error#511
Conversation
Replace the advisory `check` block with a `terraform_data` precondition that actually blocks `terraform plan`/`apply` when no access control is configured. Add missing test for unsafeAllowAllUsers with populated allowlists. Follow-up to #502.
📝 WalkthroughWalkthroughThe changes add test coverage for access control behavior when Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
There was a problem hiding this comment.
Summary
This PR replaces a non-blocking Terraform check with a hard-fail terraform_data precondition, adds coverage for the unsafeAllowAllUsers plus populated allowlist case, and simplifies a small destructuring in checkAccessAllowed. I reviewed the 3 changed files (+31/-10) and did not find any blocking correctness, security, performance, or maintainability issues in the diff.
Critical Issues
None.
Suggestions
terraform/environments/production/checks.tf:15- The new guard looks appropriate for turning this into a hard error. The remaining gap is operational verification: it would still be valuable to run the manualterraform planscenarios from the PR description in an environment with Terraform installed so we confirm the failure/success paths end to end.
Nitpicks
None.
Positive Feedback
- The new access-control tests cover the important edge case where
unsafeAllowAllUsersis true but allowlists are still populated, which protects the intended precedence rule. - Replacing the advisory Terraform validation with a blocking precondition matches the stated goal and makes the safety check materially stronger.
- The code change in
checkAccessAllowedstays minimal and easy to follow.
Questions
None.
Verdict
Approve: Ready to merge based on the diff review and local test results. I also ran npm test -w @open-inspect/web, and all 184 tests passed. I could not run the Terraform plan checks locally because the Terraform CLI is not installed in this environment.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
terraform/environments/production/checks.tf (1)
20-24: Optional: extract the allowlist-non-empty computation to a local.The
split+trimspace+ filter pattern is duplicated forallowed_usersandallowed_email_domains, and the same parsing likely exists where these values are consumed downstream. Lifting these intolocals(e.g.,local.allowed_users_list,local.allowed_email_domains_list) would keep the precondition readable and ensure the gate uses the exact same parsing as the actual consumers — eliminating drift risk if one side changes normalization later.♻️ Suggested refactor
+locals { + allowed_users_list = [for item in split(",", var.allowed_users) : trimspace(item) if trimspace(item) != ""] + allowed_email_domains_list = [for item in split(",", var.allowed_email_domains) : trimspace(item) if trimspace(item) != ""] +} + resource "terraform_data" "access_control_gate" { lifecycle { precondition { condition = ( var.unsafe_allow_all_users || - length([for item in split(",", var.allowed_users) : trimspace(item) if trimspace(item) != ""]) > 0 || - length([for item in split(",", var.allowed_email_domains) : trimspace(item) if trimspace(item) != ""]) > 0 + length(local.allowed_users_list) > 0 || + length(local.allowed_email_domains_list) > 0 ) error_message = "At least one access control allowlist must be configured. Set allowed_users or allowed_email_domains, or set unsafe_allow_all_users = true to explicitly allow all authenticated GitHub users." } } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@terraform/environments/production/checks.tf` around lines 20 - 24, Extract the duplicated split/trimspace/filter logic into locals (e.g., local.allowed_users_list and local.allowed_email_domains_list) and use those locals in the existing condition instead of repeating the comprehension; specifically, create locals that compute the parsed non-empty lists from var.allowed_users and var.allowed_email_domains, then replace the two length([...]) expressions in the condition that references var.unsafe_allow_all_users with checks like length(local.allowed_users_list) > 0 and length(local.allowed_email_domains_list) > 0 so the gate and downstream consumers share identical normalization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@terraform/environments/production/checks.tf`:
- Around line 20-24: Extract the duplicated split/trimspace/filter logic into
locals (e.g., local.allowed_users_list and local.allowed_email_domains_list) and
use those locals in the existing condition instead of repeating the
comprehension; specifically, create locals that compute the parsed non-empty
lists from var.allowed_users and var.allowed_email_domains, then replace the two
length([...]) expressions in the condition that references
var.unsafe_allow_all_users with checks like length(local.allowed_users_list) > 0
and length(local.allowed_email_domains_list) > 0 so the gate and downstream
consumers share identical normalization.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f733240c-699a-478a-9c3f-c0339243d63a
📒 Files selected for processing (3)
packages/web/src/lib/access-control.test.tspackages/web/src/lib/access-control.tsterraform/environments/production/checks.tf
Summary
Follow-up to #502 — strengthens the access control guardrails:
checkblock withterraform_dataprecondition — Terraformcheckblocks only produce warnings and don't blockapply. The newpreconditionon aterraform_dataresource makes this a hard error that blocksterraform plan/applywhen neither allowlist norunsafe_allow_all_usersis configured.unsafeAllowAllUsers: truewith populated allowlists — verifies that when both the flag and allowlists are set, the allowlist is still enforced (non-matching users are denied).checkAccessAllowed.Test plan
npm test -w @open-inspect/web— 27 tests pass (2 new)terraform fmt -check— cleanterraform planfails when both allowlists are empty andunsafe_allow_all_users = falseterraform plansucceeds whenunsafe_allow_all_users = trueor an allowlist is setSummary by CodeRabbit
Tests
Refactor
Chores