feat: add beyondtrust_iam_policy resource for Cedar authorization policies #113
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.75) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #113"
general
weight: 0.35
sdahal-bt
Pull Request
Description
Adds
beyondtrust_iam_policy, which manages Cedar authorization policies — granting auser, workload, group or role permission to act on a product resource.
What's here
beyondtrust_iam_policyresource — full CRUD plus import by name. Policy text israw Cedar, stored and returned verbatim.
@siteId,forbid,when/unless, more than one statement, unqualified type names) fail duringplanrather than as an opaque 400 at apply.
Update poll until the policy is active. A
timeoutsblock adjusts how long.text/plainrequest bodies and the IAM service path, plus traceids on API errors.
New dependencies:
cedar-go(Cedar parsing) andterraform-plugin-framework-timeouts.Worth a close look
One
terraform apply, not two. Policies are managed against the admin site while eachpolicy grants access on a target site, and an access token reaches one site — so the config
needs two provider blocks. It does not need two applies, which had been the working
assumption. Terraform's dependency graph spans provider instances, so a policy can reference
a folder created through the other block and ordering is handled. Verified end to end against
a live tenant: folder created on the product site, policy written to the admin site naming it,
correct ordering, clean re-plan, single destroy.
Create refuses to adopt an existing policy. The API's PUT is create-or-replace, and names
are unique per organization. Without a guard, applying over an existing name would silently
overwrite a policy this config never created, and a later destroy would delete it. It errors
and points at
terraform import.Deleted policies are detected as drift. The service keeps serving a policy after deletion
(
PENDING_UNBIND, then aDELETEDtombstone), so a 404 is not the only "it's gone" signal.Testing
Unit tests cover Cedar validation, the polling state machine, retries and error mapping.
Acceptance tests run against a real tenant in two tiers:
TestAccPolicyResource_— create, update in place, replace on rename, import, no-drift,and plan-time rejection.
TestAccPolicyBinding_— proves a policy actually changes what the product API returns:asserts the principal is denied, grants the policy, confirms access flips, then confirms
destroying it takes access away again.
All nine pass in CI, on federated credentials, with nothing skipped.
A skipped acceptance suite reports the same green as a passing one, so the suite prints what
it skipped and why, and CI sets
BEYONDTRUST_TEST_REQUIRE_ACC=1to turn a zero-coverage runinto a failure. The suites can also be triggered manually (
workflow_dispatch, with a suiteselector) for re-checking after a dependency deploys, without pushing a commit to do it.
CI setup — done, but worth knowing
All required secrets and variables are configured in the
acceptance-tests-adminenvironment, and the job is green. Recorded here because the suite depends on them and they
are not obvious from the diff:
| Name | |
| --- | --- |
|
BEYONDTRUST_SITE_ID| product site; environments don't share secrets, so it is set in both ||
BEYONDTRUST_TEST_POLICY_PRINCIPAL| the Cedar entity policies grant to, written in full ||
BEYONDTRUST_TEST_POLICY_PRINCIPAL_SERVICE_NAME| selects the low-privilege identity under test ||
BEYONDTRUST_TEST_POLICY_OWNER_SERVICE_NAME| selects the identity that seeds fixtures ||
BEYONDTRUST_TEST_POLICY_FIXTURE_ROOT| (variable, not secret) the folder fixtures are created inside |Two identities are selected by service name rather than issued long-lived tokens, so CI holds
no standing credentials for either.
There is tenant state the binding tests depend on: a fixture folder, and a policy granting
the seeding identity
Owneron it. A workload identity is created with no permissions at all— being able to authenticate is not being able to write — and product-level folder creation
cannot be granted by policy, since the schema exposes no admin action for a product. Owning a
single folder avoids needing one: ownership cascades to everything beneath, so one grant
covers creating each run's folder, seeding it, and tearing it down, and reaches nothing else.
Deleting either object breaks the binding tests. Both are documented with the HCL to recreate
them in
iam/README.md.This also depended on a service-side fix for requests carrying federated tokens, which are
larger than personal access tokens and were being rejected. That has shipped and is deployed;
no provider change was needed.
Known limitations
When they do, the second provider block and the
provider =lines simply go away.the same policy name overwrite each other silently.
reports active. The binding tests catch that class of mistake by asserting access changes.
Jira tickets and links
Checklist
[SMOP-1294]: https://beyondtrust.atlassian.net/browse/SMOP-1294?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ