Repository navigation
Redact sensitive variables from bundle plan and saved plans - #7713
andrewnester wants to merge 19 commits into
Conversation
bundle plan no longer prints or saves sensitive values: new_state is redacted once planning is done. A saved plan does not carry them, so deploy --plan requires every sensitive variable of the bundle to be set with --var or BUNDLE_VAR_<name>, and restores each sensitive field from the config when the config sets it. One check runs before approval and reports all missing values in one error. The prepareChanges warning no longer prints the change values, which were visible before redaction. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
a9836b9 to
614d281
Compare
Regression test report ✅Commit: Selected 7 changed tests (limit=20, 0 not selected) 18 tests: regression=18 unreleased=0 coverage=0 failing=0
TestAccept/bundle/deploy/readplan/plan-version-2/DMS=: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): same output as main (9a14ad6) TestAccept/bundle/deploy/readplan/plan-version-2/DMS=true: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): same output as main (9a14ad6) TestAccept/bundle/deploy/readplan/plan-version-mismatch/DMS=: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): same output as main (9a14ad6) TestAccept/bundle/deploy/readplan/plan-version-mismatch/DMS=true: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): TestAccept/bundle/resources/secrets/parent_rename/DMS=/READPLAN=: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): TestAccept/bundle/resources/secrets/parent_rename/DMS=/READPLAN=1: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): TestAccept/bundle/resources/secrets/parent_rename/DMS=true/READPLAN=: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): TestAccept/bundle/resources/secrets/parent_rename/DMS=true/READPLAN=1: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): TestAccept/bundle/resources/secrets/recreate_in_renamed_schema/DMS=/READPLAN=: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): TestAccept/bundle/resources/secrets/recreate_in_renamed_schema/DMS=/READPLAN=1: branch ✅ | main (9a14ad6) ❌ | latest (v1.28.0) ❌main (9a14ad6): latest (v1.28.0): 8 more failure details omitted, see the full report in the run. |
Co-authored-by: Isaac <no-reply@databricks.com>
The acceptance test checks that the literals stay out of plan output, the saved plan and local state, that a saved plan needs the values passed again, that an empty value fails before any state-changing request, and that a rotated value reaches only the PATCH request. Co-authored-by: Isaac <no-reply@databricks.com>
614d281 to
2212f0c
Compare
✅ Integration test reportCommit: 880e130
Top 3 slowest tests (at least 2 minutes):
|
|
/review |
denik
left a comment
There was a problem hiding this comment.
Design: the deploy value isn't tied to the plan value. deploy --plan now sends whatever value is supplied at deploy time, so it can differ from the planned one. For example, a plan updates a secret's comment, and at deploy time BUNDLE_VAR_x holds a different (wrong) value. The PATCH then sends a value nobody reviewed in the plan, and nothing warns. Would a salted fingerprint of each sensitive field in the plan work, with a check at deploy time that the supplied value matches and an error if not? That would keep "the saved plan is what gets applied" true. At minimum, the changelog should say this more strongly.
| return nil | ||
| } | ||
|
|
||
| if entry.NewState != nil { |
There was a problem hiding this comment.
The rule "the plan must not be serialized after this" is only stated in the comment, and nothing enforces it. If someone later re-serializes new_state from the cache after this point, the secrets leak silently. Could we assert it, or add a test that fails if new_state is non-redacted at output time?
There was a problem hiding this comment.
Not asserted in code, because makePlan has no unit-test harness in this package. The check is at output time instead: the variables/sensitive/plan acceptance case pipes bundle plan -o json and the saved plan file through a check that fails the test if a secret literal appears in them. A change that re-serializes unredacted new_state before output fails there. I can add a unit test on the serialized plan if you want one at that level.
There was a problem hiding this comment.
🤖 Supporting detail: this already happens in memory. Apply's resolveReferences(..., false) (bundle_apply.go:142 → bundle_plan.go:1604) calls sv.SyncToJSON(entry.NewState) from the unredacted cache. So after a deploy, the entries of a secret with a reference carry the plaintext again. Today nothing serializes the plan after apply (the only marshal is cmd/bundle/plan.go:112), and apply reads only the cache. Skipping that SyncToJSON when !isPreDeploy would remove the hazard instead of documenting it.
There was a problem hiding this comment.
Done in 4340263. Resolving references now writes new_state back to the plan only before deploy. After apply the redacted entries are not re-serialized, so no plaintext is written back into them. The unit test TestResolveReferencesAfterApplyKeepsRedactedEntry fails when that write is restored.
deploy --plan rejected every sensitive variable that had no --var or BUNDLE_VAR_ value, including variables a resource never uses and variables set by a default, a target or the variable-overrides file. The check now looks only at the resolved config value of each sensitive field the plan sets, so every source of a value counts the same, and the variable-overrides file is no longer a special case. The check reports one error per problem, and it reads the adapter only for resource types with sensitive fields. The acceptance case variables/sensitive/plan-derived covers unused derived, literal-default and target-set sensitive variables. Co-authored-by: Isaac <no-reply@databricks.com>
|
Thanks for the review. The changes for the other comments are in fcecb40. On the design point (the deploy-time value is not tied to the plan-time value): this PR does not add a fingerprint. A fingerprint would change the saved plan format and store secret-derived data in the plan file, so it needs its own decision. Meanwhile the changelog and PR description now say explicitly that |
|
Follow-up on the design point: the deploy-time value stays as documented in this PR (the plan format does not change). If a fingerprint check is wanted later, it can come as a separate PR with a plan-format version bump. |
| @@ -0,0 +1 @@ | |||
| * `bundle plan` no longer shows or saves sensitive variable values, and `bundle deploy --plan` requires them to be supplied again at deploy time (for example with `--var` or `BUNDLE_VAR_<name>`). `deploy --plan` applies the sensitive values supplied at deploy time, which are not checked against the values used at plan time. ([#7713](https://github.com/databricks/cli/pull/7713)) | |||
There was a problem hiding this comment.
first sentence is sufficient
There was a problem hiding this comment.
Done in 0b2cd9c. The entry now keeps only the first sentence. The note that deploy --plan uses the values supplied at deploy time, without comparing them with the plan, came from an earlier review comment; it stays in the PR description.
Co-authored-by: Isaac <no-reply@databricks.com>
Plan JSON now shows sensitive values as [redacted]. Deploy and destroy requests still send the real value. Only the three plan "value" lines changed. Co-authored-by: Isaac <no-reply@databricks.com>
denik
left a comment
There was a problem hiding this comment.
🤖 Automated review of 4af7b65 by Opus, Fable and Astra; each finding verified against the code.
One blocking issue: deploy --plan can send a different secret value than a plain deploy for the same input (inline, reproduced). The rest checked out. Redaction now runs after the plan-time SyncToJSON. A plain deploy still applies from the unredacted cache. No new RPCs. Nothing merged to main since the base conflicts: build, unit tests and the related acceptance tests pass on a merge with current main.
Not posted inline:
- Should fix
bundle/direct/bundle_plan.go:76,bundle/direct/dresources/redact_config.go:64:CheckSensitivePlanValuesrepeats the restore rule's walk with its own adapter lookup.SensitiveFieldRulesreturns the same as the existingdresources.GetResourceConfig(t).SensitiveFields, used inbundle/config/validate/sensitive_variable_references.go; main also hasdresources.IsSensitiveResourceFieldsince #8111. One method that prepares and restores the saved plan's state, run whereprocess.goloads the plan, would keep the check and the apply from drifting. The fix for the blocking item rewrites this code anyway. - Nit (convention)
bundle/direct/bundle_plan.go:80: the dedup keys onerr.Error(), and AGENTS.md says never to branch on error strings. Looking each resource up once and reporting a missing one once would avoid it.
| return nil | ||
| } | ||
|
|
||
| if entry.NewState != nil { |
There was a problem hiding this comment.
🤖 Supporting detail: this already happens in memory. Apply's resolveReferences(..., false) (bundle_apply.go:142 → bundle_plan.go:1604) calls sv.SyncToJSON(entry.NewState) from the unredacted cache. So after a deploy, the entries of a secret with a reference carry the plaintext again. Today nothing serializes the plan after apply (the only marshal is cmd/bundle/plan.go:112), and apply reads only the cache. Skipping that SyncToJSON when !isPreDeploy would remove the hazard instead of documenting it.
…ction Co-authored-by: Isaac <no-reply@databricks.com>
A resource reference and an escaped reference in a sensitive value are restored verbatim from the config, so the create requests of deploy --plan differ from a plain deploy. The test compares the two request bodies and fails on this branch. Co-authored-by: Isaac <no-reply@databricks.com>
The deploy from a saved plan restored the sensitive fields from the raw config string, so a reference was sent as its literal text and an escaped reference as its escaped form. The restore now builds the state the way makePlan does (PrepareInputConfig, PrepareState, unescapeRefs) and keeps the references of sensitive fields for apply to resolve. A value that still holds an unresolved reference is an error. The check before apply and the apply share one restore (restoreSavedPlanStates), so they cannot disagree. A resource missing from the config is reported once. Apply no longer serializes resolved references back into the plan entry, so the redacted plan entries keep no secret after a deploy. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
|
Addressed both items from the review body in 4340263 (plus b1927a2 for a lint fix):
|
A plan from this CLI carries redacted secret values that only a CLI restoring them from the config can apply. Version 3 makes released CLIs refuse these plans, instead of applying the redaction marker as the secret. Version 2 plans stay readable: restore replaces their sensitive fields from the config. Co-authored-by: Isaac <no-reply@databricks.com>
…ction Co-authored-by: Isaac <no-reply@databricks.com>
denik
left a comment
There was a problem hiding this comment.
🤖 Automated review of 7d5e265 by Opus, Fable and Astra; each finding verified against the code.
The previous round's restore bug and plan-version point are fixed. Two Should-fix points remain on the restore (inline): a sensitive field whose reference changes between plan and deploy --plan gets the plan's reference or a reference the graph doesn't order, and the restore duplicates makePlan's build. Build, the bundle/direct, deployplan and cmd/bundle/utils unit tests, and 93 acceptance tests under variables/sensitive, deploy/readplan and resources/secrets pass on a merge with current main (no conflicts). No new RPCs.
Not posted inline:
- Should fix
bundle/direct/bundle_plan.go:83:newAdapterForKeyis a second way to build client-less adapters.RecordMissingInternalIDs(bundle_plan.go:1021) usesdresources.InitAll(nil)withgetAdapterForKey; doing the same inCheckSensitivePlanValuesalso keeps the existingresource type "x" not supported, available: ...error for a saved plan with an unknown type. - Should fix
acceptance/bundle/deploy/readplan/plan-version-2/script:2: the test rewritesplan_versionon a job plan, so "version 2 plans have their sensitive fields restored from the config" is covered only by the unit table. A secret whosenew_state.value.valueis set to a stale plaintext in the samejq, with the create request value printed, would pin it. - Nit
bundle/direct/redact.go:185: the "unresolved reference" error prints the sensitive field's value with%q. It looks unreachable today (builtandrefscome from the same config value), but if it ever fires it puts the secret in the output; leaving the value out of the message is safer.
|
🤖 Thanks, both review-body points are covered: the check and the apply share |
A sensitive field whose reference changed between bundle plan and deploy --plan got the plan's reference back, so apply overwrote the literal from the config. A reference to a resource the plan does not depend on was applied without ordering, and failed mid-apply. The restore now builds the value with buildPlannedState, which is the build makePlan uses. It keeps the references the config has, and drops the plan's when the config has none. A reference to a resource the plan does not depend on is an error that asks for bundle plan again. References that planning resolves before deploy are resolved the same way; the rest are left for apply. The plan no longer carries the references of sensitive fields, so a template such as a secret followed by a reference no longer shows in the saved plan. Co-authored-by: Isaac <no-reply@databricks.com>
…ction Co-authored-by: Isaac <no-reply@databricks.com>
|
Addressed the three items from the review body in 062e144 and merge acaf8de:
|
denik
left a comment
There was a problem hiding this comment.
🤖 Automated review of acaf8de by Opus and Astra (two independent Astra passes and an Astra advocate pass; Fable was unavailable this round). Each finding was verified against the code.
Both points from the last round are fixed. A reference that changes to a literal after planning no longer keeps the plan's reference, and a reference to a resource the plan doesn't depend on is refused before approval. makePlan and the restore now share buildPlannedState. One Should-fix point remains, on the new resolveSensitiveRefs (inline, reproduced): a reference to an unchanged resource can deploy a different secret than a plain deploy does, and a bad reference fails mid-apply instead of before approval.
Tested on a merge with current main (no conflicts): build, the bundle/direct, deployplan and cmd/bundle/utils unit tests, and the acceptance tests under variables/sensitive, deploy/readplan and resources/secrets all pass. No new RPCs.
| if err != nil { | ||
| return fmt.Errorf("parsing reference %q: %w", target, err) | ||
| } | ||
| value, err := b.LookupReferencePreDeploy(ctx, targetPath) |
There was a problem hiding this comment.
🤖 Should fix This still resolves differently from planning in two cases. Both are reproduced with scratch acceptance tests on this branch merged into current main:
- A reference to an unchanged resource.
CalculatePlandropsnew_statefor Skip entries, soLookupReferencePreDeployfails here ("missing new_state"). The error is skipped, and apply then resolves the reference from remote state. Example: a deployed schema withname: MySchemaand a new secret withvalue: ${resources.schemas.s.name}. A plain deploy POSTs"value": "MySchema", butdeploy --planPOSTs"value": "myschema"(UC lowercases schema names, and so does the testserver). On main both sendMySchema, because the plan carried the resolved value. - Other lookup errors are skipped too, and
CheckSensitivePlanValuesdoesn't run this step. Say the reference changes afterbundle planto${resources.catalogs.c.nonexistent}. It's the same node, so the depends-on check passes. A plainbundle planfails with "schema mismatch".deploy --planuploads the files, creates the catalog, and only then fails withcannot create resources.secrets.sec: cannot resolve "${resources.catalogs.c.nonexistent}".
Suggested fix: skip only errDelayed, and stop the deploy on any other error before approval, like the other restore errors do. For a Skip target, read the field from the target's local state built from the config (buildPlannedState), which is the value planning uses. A plan-restore step with an unchanged schema whose name has upper case would pin the first case.
There was a problem hiding this comment.
Fixed in d7a97da (merged main in 880e130). Only delayed references are skipped now; any other lookup error stops the deploy, and CheckSensitivePlanValues runs the same resolution before anything is uploaded. An unchanged resource is resolved from its local state built from the config, the way planning builds it.
New plan-restore steps: an already deployed schema MySchema with a secret value: ${resources.schemas.s.name}. Plain deploy and deploy --plan send the same value. On acaf8de --plan sent myschema and the diff failed. A reference that changes to ${resources.catalogs.source_catalog.nonexistent} is refused before upload. On acaf8de it uploaded, created the catalog, then failed mid-apply.
|
🤖 Thanks, the three review-body points are covered. |
A reference in a sensitive field to an unchanged resource was left for apply, which reads the remote state. The API lowercases some names, so a plain deploy and deploy --plan sent different values. A reference that did not resolve was skipped, and the failure came after the catalog was created. An unchanged resource now gets a local state built from the config the way planning builds it, and references resolve from it. Only a delayed reference is left for apply; any other lookup error stops the deploy. CheckSensitivePlanValues runs the same resolution before anything is uploaded. A lookup of a remote-only field without remote state is delayed, not an error. Co-authored-by: Isaac <no-reply@databricks.com>
…ction Co-authored-by: Isaac <no-reply@databricks.com>
Changes
bundle planoutput (text and-o json) and the saved plan file no longer contain sensitive variable values. The plan'snew_stateis redacted once planning is done, alongsideremote_stateandchanges.bundle deploy --planrestores sensitive fields from the current config and fails before approval when a value is missing. The restored value is built by the same function planning uses (buildPlannedState), so a deploy from the plan sends what a plain deploy sends. References that planning resolves before deploy are resolved the same way, including references to unchanged resources, which are read from their local config rather than the remote state; the rest are resolved at apply. A reference that does not resolve fails the check before anything is uploaded. An escaped$${...}is sent as${...}. For every sensitive field: a non-empty config value is restored; a non-zero planned value with an empty config value is an error; both empty is skipped (output-only fields). A reference in the config to a resource the saved plan does not depend on is an error, and the message asks forbundle planagain.CheckSensitivePlanValues, reports one error per resource. It runs the same restore as apply, so the check and the apply cannot disagree. It looks at the resolved config value of each sensitive field the plan sets, so a value from--var,BUNDLE_VAR_<name>, a default, a target or the variable-overrides file all count. Sensitive variables that no planned resource uses need no value.deploy --planapplies the sensitive values supplied at deploy time. They are not compared with the values used at plan time, so a saved plan can be applied with a different secret value than was planned.LoadPlanFromFilestill reads version 2 plans, and their sensitive fields are restored from the config. Acceptancebundle/deploy/readplan/plan-version-2covers a version 2 plan.prepareChangeswarning no longer prints change values. It previously showed old, new and remote values before redaction at the default log level.Why
Fixes #7685.
bundle planandbundle deployshowed and stored sensitive variable values thatbundle validate -o jsonalready redacts. Since a saved plan no longer carries them,deploy --planneeds the values supplied again, and it applies the values given at deploy time, not those at plan time.Tests
bundle/direct/redact_test.go): the restore table covers marker and plaintext replaced, zero in plan but set in config restored, both zero skipped, empty config value error, missing resource error, a reference kept for apply, and an escaped reference sent as its literal. The check table covers a plan without sensitive resources, a set or zero value passing, and an empty config value. A separate test checks one error per resource, and another checks that apply does not write resolved values back into a redacted plan entry.bundle/variables/sensitive/plan-restore: a resource reference and an escaped reference in sensitive values; the create request bodies of a plain deploy and ofdeploy --planmust be identical. It also changes the config betweenbundle plananddeploy --plan: a reference that becomes a literal is sent as the literal, and a literal that becomes a reference is refused with thebundle planmessage.bundle/deploy/readplan/plan-version-2: a version 2 plan with a stale plaintext secret still deploys the value from the config.bundle/variables/sensitive/plan-derived: unused sensitive variables with a derived default, a literal default, and a dev-target value need no value, and a saved plan deploys with the credential from the variable-overrides file.bundle/variables/sensitive/plan: literals are absent from plan output, the saved plan and local state; a saved-plan deploy requires the values again; an empty value fails with no state-changing request; a plain-path create with real values; a rotate step where only the PATCH carries the new value. The test fails on main without this change.This pull request and its description were written by Isaac.