Skip to content

refactor(policies): expose project context via input.chainloop_metadata#3100

Open
migmartri wants to merge 1 commit intochainloop-dev:mainfrom
migmartri:worktree-serene-watching-sifakis
Open

refactor(policies): expose project context via input.chainloop_metadata#3100
migmartri wants to merge 1 commit intochainloop-dev:mainfrom
migmartri:worktree-serene-watching-sifakis

Conversation

@migmartri
Copy link
Copy Markdown
Member

Summary

Replaces the bctx.Context-based project context plumbing introduced in #3094 with input-level injection. The rego engine now merges project_name / project_version_name into input.chainloop_metadata at evaluation time, so policy authors can read them from input and forward them as operands to chainloop.* built-ins:

effective := chainloop.effective_assessments({
    "project_name":         input.chainloop_metadata.project_name,
    "project_version_name": input.chainloop_metadata.project_version_name,
    "finding_type":         "VULNERABILITY",
    "lookups":              lookups,
})

The previous bctx.Context mechanism had no consumers in the codebase — built-ins receive operands plus context but do not read input, and the EE built-ins that will consume project scope take it as part of their request payload. Exposing the values on input is the simpler contract: authors see and pass the values explicitly, mirroring how chainloop.discover already reads input.chainloop_metadata.digest.

The public API (engine.WithProjectContext, policies.WithProjectContext, crafter wiring, and the chainloop policy develop eval --project / --project-version flags) is unchanged. Existing keys on input.chainloop_metadata (e.g. the intoto descriptor populated for materials) are preserved.

Refs #3090

Test plan

  • go test ./pkg/policies/... (370 tests)
  • chainloop policy develop eval --policy <p> --material <m> --kind <k> --project demo --project-version v1.2.3 and confirm a policy reading input.chainloop_metadata.project_name sees the value alongside the existing material descriptor fields

Replaces the bctx.Context-based propagation introduced in chainloop-dev#3094 with an
input-level injection: the rego engine now merges project_name /
project_version_name into input.chainloop_metadata at evaluation time, so
policy authors can read them from input and forward them as operands to
chainloop.* built-ins.

The previous context-based plumbing had no consumers — built-ins receive
operands and context but do not read input directly, and the EE built-ins
that will consume project scope are expected to take it as part of their
request payload. Exposing the values on input is the simpler contract:
authors see and pass the values explicitly, mirroring how chainloop.discover
already reads input.chainloop_metadata.digest.

Refs chainloop-dev#3090

Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri requested a review from a team May 10, 2026 21:05
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

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