Repository navigation
feat(rules): CEL environment and compile checks - #605
ccf-lisa[bot] wants to merge 2 commits into
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
cdfd275 to
d66e232
Compare
internal/service/rules: the evidence source's CEL environment (subject as a native type, now, the strings, lists and math extensions), compile with type checks per expression kind (when: bool; target: string or list(string)), a static cost estimate against CCF_EFFECTOR_CEL_COST_LIMIT, unguarded map lookup warnings, now detection and partial evaluation for now-dependent results, and a bounded compile cache. The evidence subject document types and the source description (types, fields, extensions) the rule editor and validation share. Nothing uses the package yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d66e232 to
792961f
Compare
gusfcarvalho
left a comment
There was a problem hiding this comment.
ccf-review: REQUEST_CHANGES
1 Must-fix, 1 Should-fix.
Stack (gh stack 604): #592 → #593 → #594 → #595 → #596 → #597 → #598 → #599 → #600 → #601 → #602 → #603 → #605 → #606 → #607 → #608 → #609 → #610 → #611 → #612 → #613 → #614 → #615 → #616 → #617 → #618 → #619 → #620 → #621 → #622 → #623 → #624 → #625 → #626 → #627 → #628 → #629 → #630
subject.labels.owner reads a map key like subject.labels["owner"] and fails the same way on subjects without it, so the save-time warning covers it too. has(m.k) stays a guard. The evidence source names its authz resource with authz.ResourceEvidence instead of a copy of the literal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gusfcarvalho
left a comment
There was a problem hiding this comment.
ccf-review: APPROVE
no findings.
Stack (gh stack 604): #592 → #593 → #594 → #595 → #596 → #597 → #598 → #599 → #600 → #601 → #602 → #603 → #605 → #606 → #607 → #608 → #609 → #610 → #611 → #612 → #613 → #614 → #615 → #616 → #617 → #618 → #619 → #620 → #621 → #622 → #623 → #624 → #625 → #626 → #627 → #628 → #629 → #630
What
New package
internal/service/rules(API LLD, CEL environment):NewEvidenceEnv: the evidence source's CEL environment:subjectas a native object type (EvidenceSubjectand its parts, snake_casecelnames),nowas a timestamp, the standard library plus the strings, lists and math extensions.Env.Compile(kind, expr): parse and type-check, with the output type each kind needs (when→bool; target →stringorlist(string)), a static cost estimate againstCCF_EFFECTOR_CEL_COST_LIMIT(bounded string and list sizes), errors with line and column, warnings for unguarded map lookups (subject.labels["team"]orsubject.labels.teamwithout"team" in subject.labelsorhas(subject.labels.team)), whether the expression readsnow, and a partial-evaluation program forDependsOnNow(is this subject's result decided by its data, or by time). Compiled programs are cached by kind and text (bounded).EvalBool,EvalTargetsagainst anActivation{Subject, Now}.subject.go) andSources(): the source description (kinds, variables, types with every field typed and described, extensions) the rule editor and validation will share.go.mod:github.com/google/cel-go v0.31.0.Nothing uses the package yet.
Why
Plan: stack 2, PR 12. First PR of stack 2 (engine and delivery), on top of #603. The plan's PR 12 also listed the subject document; its types are here, its database builder moves to the next PR (#13 in the plan) to keep this one under 1000 lines.
Test evidence
cel_test.go: when expressions over every field kind, rejections (unknown field, wrong output type, empty, syntax) with positions, the cost limit, targets (single and list), missing-key errors, guard warnings,UsesNowandDependsOnNow(undetermined, decided either way),has(subject.expires), the cache (and its bound), the source description. 85.9% coverage.Gate on this branch:
go build ./...pass;go vet -tags integration ./...pass;make lint(golangci-lint v2.15.0, CI config) 0 new issues;make testpass;make swagno diff;go mod tidyno diff;go test -tags integration -p 1on./internal/service/rules/pass.Size
Counted: 961 lines.
🤖 Generated with Claude Code