Skip to content

feat(rules): CEL environment and compile checks - #605

Open
ccf-lisa[bot] wants to merge 2 commits into
effectors/11-config-outboxfrom
effectors/12-rules-cel
Open

ccf-lisa[bot] wants to merge 2 commits into
effectors/11-config-outboxfrom
effectors/12-rules-cel

Conversation

@ccf-lisa

@ccf-lisa ccf-lisa Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What

New package internal/service/rules (API LLD, CEL environment):

  • NewEvidenceEnv: the evidence source's CEL environment: subject as a native object type (EvidenceSubject and its parts, snake_case cel names), now as 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 → string or list(string)), a static cost estimate against CCF_EFFECTOR_CEL_COST_LIMIT (bounded string and list sizes), errors with line and column, warnings for unguarded map lookups (subject.labels["team"] or subject.labels.team without "team" in subject.labels or has(subject.labels.team)), whether the expression reads now, and a partial-evaluation program for DependsOnNow (is this subject's result decided by its data, or by time). Compiled programs are cached by kind and text (bounded).
  • EvalBool, EvalTargets against an Activation{Subject, Now}.
  • The subject document types (subject.go) and Sources(): 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, UsesNow and DependsOnNow (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 test pass; make swag no diff; go mod tidy no diff; go test -tags integration -p 1 on ./internal/service/rules/ pass.

Size

Counted: 961 lines.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: de477869-de93-41c6-b206-70e9233c9627

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ccf-lisa
ccf-lisa Bot added this pull request to stack #604 December 1, 2026 18:00
@ccf-lisa
ccf-lisa Bot force-pushed the effectors/12-rules-cel branch from cdfd275 to d66e232 Compare December 1, 2026 18:49
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>
@ccf-lisa
ccf-lisa Bot force-pushed the effectors/12-rules-cel branch from d66e232 to 792961f Compare December 2, 2026 12:07

@gusfcarvalho gusfcarvalho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread internal/service/rules/cel.go Resolved
Comment thread internal/service/rules/sources.go Resolved
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 gusfcarvalho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant