← Back to Pull requests

feat: generate dynamic credentials via ephemeral resources #123

Closed
unknown closed this pull request without merging on Oct 13, 2026 23:50 UTC
View on GitHub
unknown unknown commented on Oct 05, 2026 23:35 UTC
Author

What

Adds two ephemeral resources that generate dynamic credentials from the AWS and Azure dynamic secret definitions the provider already manages:

  • beyondtrust_workload_credentials_aws_dynamic_secret — STS assume-role session

  • beyondtrust_workload_credentials_azure_dynamic_secret — service principal password
  • They reuse the managed resource type names, following the existing static_secret precedent. The framework's duplicate-name check is per-registry, so the two coexist.

    Why

    The provider could already define dynamic secrets but had no way to generate from one, leaving the feature half-finished: you could declare "mint me an STS session from this role" and then had to leave Terraform to get one. POST /dynamic/{name}/generate was unimplemented, and provider.go still carried commented-out placeholders where that work was meant to land.

    Generated credentials are returned exactly once and never stored server-side, so an ephemeral resource is the only Terraform primitive that fits.

    Design notes

    The two types are deliberately asymmetric.

    | | AWS | Azure |
    |---|---|---|
    | Implements Close | No | Yes |
    | revoke_on_close | Absent | Present, defaults true |
    | expiration | Present | Absent |

    AWS gets no Close: an assumed-role lease is never revocable, so it would spend a guaranteed-failing DELETE plus a can_revoke_lease check the caller may not hold, on every apply, to swallow an error. Azure gets no expiration: the generate response carries none, and fabricating one would mean a second request into the lease-durability window or a client-side guess. Neither sets RenewAt — there is no renew endpoint.

    Two behaviours that look like bugs and aren't, both documented prominently:

  • An apply generates credentials twice per instance, once per graph walk.

  • The dynamic secret must already exist. An ephemeral resource is opened while the plan is built, so a config that creates the definition and generates from it in one apply fails. depends_on does not help, because the open precedes it.
  • Permissions. Generating needs GenerateDynamicCredential on the dynamic secret. Owner on the secret or its folder does not include it, so anyone other than a product admin needs a direct grant. The docs cover this with an example policy.

    Testing

  • Unit and round-trip tests (make test-unit) cover both resources: request shapes, schema, the revoke retry, and a full Open then Close against a fake API, including revoke_on_close = false.

  • CI acceptance covers AWS end to end from the admin-site job. The test grants itself GenerateDynamicCredential through the admin API, opens the ephemeral resource, and checks that an STS session came back. It runs there because the grant is written on the admin site. It generates from an existing dynamic secret (BEYONDTRUST_TEST_AWS_DYNAMIC_SECRET), because AWS credentials cannot be revoked early and a dynamic secret cannot be deleted while it has active leases; docs/TESTING_AWS.md has the setup.

  • The Azure acceptance tests live on test/add_azure_acc_tests. They are waiting on a service-side fix: generating twice in quick succession, which every Terraform apply does, currently fails for Azure. Azure revocation here is covered by the round-trip tests and was verified end to end by hand.
  • SMOP-1467

    🤖 Generated with Claude Code

    Diff: 431 lines (+323 / -108) across 5 files Reviewer: sdahal-bt Review duration: 11534m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 431 lines diff across 5 files
    0.45
    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.363
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #123"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.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: 19.5% · Safe to merge
    19.5%