← Back to Pull requests

feat: add beyondtrust_iam_policy resource for Cedar authorization policies #113

Closed
unknown closed this pull request without merging on Sep 23, 2026 22:42 UTC
View on GitHub
unknown unknown commented on Sep 08, 2026 23:31 UTC
Author

Pull Request

Description

Adds beyondtrust_iam_policy, which manages Cedar authorization policies — granting a
user, workload, group or role permission to act on a product resource.

What's here

  • beyondtrust_iam_policy resource — full CRUD plus import by name. Policy text is

  • raw Cedar, stored and returned verbatim.
  • Plan-time Cedar validation so structural mistakes (missing @siteId, forbid,

  • when/unless, more than one statement, unqualified type names) fail during plan
    rather than as an opaque 400 at apply.
  • Waits for the grant to take effect. Policies activate asynchronously, so Create and

  • Update poll until the policy is active. A timeouts block adjusts how long.
  • Client support for text/plain request bodies and the IAM service path, plus trace

  • ids on API errors.
  • Docs, examples, and acceptance tests wired into CI.
  • New dependencies: cedar-go (Cedar parsing) and terraform-plugin-framework-timeouts.

    Worth a close look

    One terraform apply, not two. Policies are managed against the admin site while each
    policy 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 a DELETED tombstone), 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=1 to turn a zero-coverage run
    into a failure. The suites can also be triggered manually (workflow_dispatch, with a suite
    selector) 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-admin
    environment, 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 Owner on 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

  • Two credentials to provision and rotate until access tokens carry multiple audiences.

  • When they do, the second provider block and the provider = lines simply go away.
  • No concurrency control. The API has no ETag or version, so two configurations managing

  • the same policy name overwrite each other silently.
  • A workload principal is never checked for existence, so a policy naming a wrong id still

  • reports active. The binding tests catch that class of mistake by asserting access changes.

    Jira tickets and links


  • Jira: SMOP-1294
  • Checklist


  • Jira: If this PR has a change associated with a ticket, include it in the section above

  • RFC: If this change is related to an RFC, include it as a link above
  • [SMOP-1294]: https://beyondtrust.atlassian.net/browse/SMOP-1294?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: sdahal-bt Review duration: 21550m
    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
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.5% · Safe to merge
    32.5%