Repository navigation
feat(planner): SG3 — bind omitted secret ref dimensions from the job's scope #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,7 +115,16 @@ func mergeBindingRefs(secretEnv map[string]string, bindings []model.ResolvedSecr | |
|
|
||
| merged := make(map[string]string, len(secretEnv)+len(bindings)) | ||
| for k, v := range secretEnv { | ||
| merged[k] = v | ||
| bound, ok, err := bindContext(v, workspace, project, env) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("secretEnv %s: %w", k, err) | ||
| } | ||
| if !ok { | ||
| // No scope to bind from (an unlinked repo planned offline): keep the | ||
| // reference exactly as authored, as every CLI before SG3 did. | ||
| bound = v | ||
| } | ||
| merged[k] = bound | ||
| } | ||
|
|
||
| for _, b := range bindings { | ||
|
|
@@ -164,7 +173,7 @@ func mergeBindingRefs(secretEnv map[string]string, bindings []model.ResolvedSecr | |
| // visible here is an env var name the HARD map (secretEnv ∪ profile | ||
| // bindings) also claims — one name cannot be fail-closed and best-effort at | ||
| // once, so that is a compile error naming the key. | ||
| func mergeOptionalRefs(optionalSecretEnv, hardRefs map[string]string) (map[string]string, error) { | ||
| func mergeOptionalRefs(optionalSecretEnv, hardRefs map[string]string, workspace, project, env string) (map[string]string, error) { | ||
| if len(optionalSecretEnv) == 0 { | ||
| return nil, nil | ||
| } | ||
|
|
@@ -173,11 +182,65 @@ func mergeOptionalRefs(optionalSecretEnv, hardRefs map[string]string) (map[strin | |
| if _, taken := hardRefs[k]; taken { | ||
| return nil, fmt.Errorf("key %s is bound as both a required reference (secretEnv or a profile secretBinding) and an optionalSecretEnv reference — one env var cannot be fail-closed and best-effort at once", k) | ||
| } | ||
| merged[k] = v | ||
| bound, ok, err := bindContext(v, workspace, project, env) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("optionalSecretEnv %s: %w", k, err) | ||
| } | ||
| if !ok { | ||
| bound = v | ||
| } | ||
| merged[k] = bound | ||
| } | ||
| return merged, nil | ||
| } | ||
|
|
||
| // bindContext fills a secret reference's omitted workspace, project and env | ||
| // from the job's own scope (specs/orun-scope-engine SG3, design.md § 2), so one | ||
| // manifest line — `secret://DATABASE_URL`, or `secret://env:prod/WIRING_X` for | ||
| // a job that reads another environment's value — works in every workspace, | ||
| // repository and environment it is planned into. | ||
| // | ||
| // It never overrides an authored dimension and never widens: the server still | ||
| // receives a fully pinned reference and still verifies its workspace and | ||
| // project against the run. A reference that is already pinned is returned in | ||
| // its AUTHORED spelling, so a manifest that did not change keeps its plan | ||
| // digest. The component dimension is left as authored: the server derives it | ||
| // from the lease, and an emitted segment is only an assertion. | ||
| // | ||
| // ok is false when a dimension is omitted and the plan has none to give; the | ||
| // caller then keeps the reference as authored, exactly as before SG3, so a plan | ||
| // that compiles today never stops compiling. A value that is not a secret:// reference, or does not parse, is | ||
| // returned unchanged for the expander's guards to report. | ||
| func bindContext(raw, workspace, project, env string) (string, bool, error) { | ||
| if !scoperef.IsSchemeRef(raw, scoperef.SchemeSecret) { | ||
| return raw, true, nil | ||
| } | ||
| ref, err := scoperef.Parse(raw) | ||
| if err != nil { | ||
| return raw, true, nil | ||
| } | ||
| if ref.Workspace != "" && ref.Project != "" && ref.Env != "" { | ||
| return raw, true, nil | ||
| } | ||
| if ref.Workspace == "" { | ||
| ref.Workspace = workspace | ||
|
Comment on lines
+225
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| } | ||
| if ref.Project == "" { | ||
| ref.Project = project | ||
| } | ||
| if ref.Env == "" { | ||
| ref.Env = env | ||
| } | ||
| if ref.Workspace == "" || ref.Project == "" || ref.Env == "" { | ||
| return "", false, nil | ||
| } | ||
| bound := ref.String() | ||
| if _, err := scoperef.Parse(bound); err != nil { | ||
| return "", false, fmt.Errorf("binding the reference to the run's scope produced an invalid reference: %w", err) | ||
| } | ||
| return bound, true, nil | ||
| } | ||
|
|
||
| // sameRef reports whether two reference spellings denote the same reference. | ||
| // An unparseable side falls back to exact string equality — the caller has | ||
| // already validated the binding's own reference, and a malformed secretEnv | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a workflow step’s
connectionsgrant and the job’ssecretEnvdeclare the same contextual secret, this binds only the job ref;renderConnectionsleaves the grant assecret://KEY. The runner matches grants tojob.SecretRefsby exact ref, sobuildConnectionPayloadsthen fails with a grant-not-among-job-refs error. Bind the workflow grant through the same context too, or normalize it during lookup.Useful? React with 👍 / 👎.