Conversation
…_fields Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds support for multi-dimensional Casbin authorization requests in step.authz_check_casbin by allowing configurable extra_fields and improving template data to reference prior step outputs without key collisions.
Changes:
- Add
extra_fieldstostep.authz_check_casbinand include resolved values inaudit_event. - Extend template data with a nested
.stepsmap for referencing specific prior step outputs. - Update
CasbinModule.Enforce(and wrapper) to accept variadic extra request dimensions and forward them as(sub, extra..., obj, act).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| internal/step_authz_check.go | Parses/resolves extra_fields, forwards extra dimensions into enforcement, expands template data with nested .steps, and augments audit output. |
| internal/module_casbin.go | Extends Enforce to support extra request dimensions and forwards them to Casbin in the desired order. |
| authz/authz.go | Updates the public wrapper’s Enforce signature to match the new variadic API. |
| internal/step_authz_check_test.go | Adds tests covering static/template/nested-step extra fields and audit output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return nil, fmt.Errorf("step.authz_check_casbin %q: extra_fields[%d] must be a map with \"key\" and \"value\"", name, i) | ||
| } | ||
| key, _ := item["key"].(string) | ||
| val, _ := item["value"].(string) | ||
| if key == "" { |
There was a problem hiding this comment.
PR description/examples refer to step.authz_check, but this repository’s step type appears to be step.authz_check_casbin (as reflected in the step’s error messages here). Consider aligning the PR description/README/examples so users don’t configure a non-existent step type.
| } | ||
| for i, ef := range s.extraFields { | ||
| evt[ef.key] = extraVals[i] | ||
| } | ||
| result.Output["audit_event"] = evt |
There was a problem hiding this comment.
extra_fields keys are written directly into audit_event, so a user-supplied key like type, subject, allowed, etc. would overwrite core audit fields (and could change types). Consider rejecting reserved keys at config-parse time or nesting extras under a dedicated key (e.g., audit_event.extra_fields).
| ef := extraField{key: key, value: val} | ||
| if isTemplate(val) { | ||
| ef.tmpl, err = template.New(fmt.Sprintf("extra_field_%d", i)).Parse(val) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("step.authz_check_casbin %q: parse extra_fields[%d] template: %w", name, i, err) |
There was a problem hiding this comment.
There’s no validation for duplicate extra_fields keys. If the config repeats a key, the later value will overwrite the earlier one in audit_event, producing confusing/incomplete audit output. Consider validating keys are unique (or structuring audit output to preserve duplicates).
|
@copilot apply changes based on the comments in this thread |
…nt structure Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Applied all review feedback in f232ba1:
Two new tests added: |
step.authz_check_casbinwas limited to the 3-tuple Casbin request(sub, obj, act), making per-tenant authorization impossible without hacks like encoding tenant in the object path.Changes
extra_fieldsconfig onstep.authz_check_casbin— ordered list of{key, value}pairs inserted betweensuband(obj, act), producing tuples like(sub, tenant, obj, act). Eachvaluesupports Go template syntax. Validated at config-parse time: returns an error ifextra_fieldsis not a list, if any entry is missingkeyorvalue, or if duplicate keys are present.{{.steps.<name>.<key>}}template access —buildTemplateDatanow exposes step outputs under astepsmap (only whentriggerDatadoes not already define astepskey) in addition to the existing flat merge, enabling templates to reference specific prior step outputs. Note: dot-notation only works for valid Go identifiers; use{{ index .steps "step-name" "key" }}for step names containing dashes or other special characters.CasbinModule.Enforceacceptsextra ...string— variadic extra dims forwarded to Casbin as[sub, extra..., obj, act]; fully backward compatible with existing 3-tuple models.audit_event— resolved extra field values appear nested underaudit_event.extra_fields(a sub-map keyed by field name) to avoid collisions with reserved audit keys such astype,subject,action, etc.Example
Matches a 4-tuple Casbin model:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.