From da860b25c5a33179ffac48138cbf89d30280d70b Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Mon, 23 Nov 2026 12:12:44 +0100 Subject: [PATCH 1/8] docs(spec): add spec and plan for runner env var redaction Org-level setting that replaces identity runner environment variable values with [REDACTED] in new attestations, enforced at push. Refs #3841 Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: a6ea453b-a3ca-450f-aba0-241be6b95a2b --- .../issue-3841-runner-env-var-redaction.md | 186 ++++++++++++++++++ .../issue-3841-runner-env-var-redaction.md | 135 +++++++++++++ 2 files changed, 321 insertions(+) create mode 100644 docs/plans/issue-3841-runner-env-var-redaction.md create mode 100644 docs/specs/issue-3841-runner-env-var-redaction.md diff --git a/docs/plans/issue-3841-runner-env-var-redaction.md b/docs/plans/issue-3841-runner-env-var-redaction.md new file mode 100644 index 000000000..9ed762e88 --- /dev/null +++ b/docs/plans/issue-3841-runner-env-var-redaction.md @@ -0,0 +1,186 @@ +--- +owner: migmartri +ticket: https://github.com/chainloop-dev/chainloop/issues/3841 +spec: docs/specs/issue-3841-runner-env-var-redaction.md +--- + + + +# Plan issue-3841: Redaction of runner environment variables + +## Overview + +The new organization setting follows the path of the existing setting that removes all runner variables. It goes from the organization update API to the database, the `attestation init` response, and the local attestation state. The CLI applies the redaction where it already resolves the runner and contract variables. Each runner integration marks its identity variables in the list of variables that it already declares. The control plane checks pushed attestations next to the existing contract check at push. + +## Architecture and impact + +```mermaid +flowchart LR + Admin[org update] --> Org[(Organization setting)] + Org --> Init[attestation init response
with resolved list] + Init --> CLI[CLI env var resolution
replaces values] + CLI --> Push[attestation push] + Org --> Check[push check
next to the contract check] + Push --> Check + Runners[runner integrations
identity marks] --> List[known identity list] + List --> Init + List --> Check +``` + +The components stay the same. The setting takes the path of the existing runner variable setting, and the push takes one more check. + +- Runner integrations: mark which of their variables identify a person. +- Shared attestation module: the known identity list, and the rules to redact a value and to find a clear value. +- Control plane: stores and checks the setting, sends it at init with the resolved list, and rejects a push that does not obey it. +- CLI: the `org update` flags, the organization details, and the redaction of the resolved variables. + +| Impact on | What changes | +|-----------|--------------| +| Users and other parts of the product | Organization admins get two new `org update` flags. Attestations of organizations with the setting store `[REDACTED]` for the redacted variables. | +| Data and migrations | One nullable JSON column on the organizations table. Null means no redaction. | +| Configuration and deployment | None. | +| Compatibility | The API only adds fields. A CLI without redaction support fails at push only in an organization with the setting, and only when a redacted variable has a clear value. | +| Rollback | Turn the setting off with `--env-var-redaction none`. A code rollback leaves the column unused. | + +## Milestones + +| # | Milestone | Requirements | Depends on | +|---|-----------|--------------|------------| +| M1 | Organization env var redaction, applied by the CLI and enforced at push | R-001, R-002, R-003, R-004, R-005, R-006 | none | + +### M1: Organization env var redaction, applied by the CLI and enforced at push + +An admin sets the mode, the CLI replaces the values, and the control plane rejects a push with a clear value. The milestone touches the runner integrations, the shared attestation module, the control plane organization and push paths, and the CLI. It builds on three existing parts: the runner variable setting, the env var resolution of the crafter, and the push-time contract check. This is Reuse first rung 2, an existing pattern. + +**Done when:** an admin sets known identity and a GitHub Actions attestation stores `GITHUB_ACTOR: [REDACTED]`, and a push with a clear value fails. Checked by the runner, crafter, organization, and push tests. + +**Steps**, in build order. Open a step to see what changes and the files it touches. + +
+01 / 07 · Each runner says which of its variables identify a person (R-004) + +The env var definition gets an `Identity` flag next to `Optional`. The definitions change to keyed fields, because a third field breaks the positional literals. `KnownIdentityEnvVars() []string` returns the union of the flags of all runners. The flags are on `GITHUB_ACTOR`, `GITLAB_USER_EMAIL`, `GITLAB_USER_LOGIN` (GitLab and Dagger), `BUILD_REQUESTEDFOR`, `BUILD_REQUESTEDFOREMAIL`, and TeamCity `USER` and `HOME`. + +| File | Change | +|------|--------| +| `pkg/attestation/crafter/runners/runners.go` | Add `Identity` and `KnownIdentityEnvVars`. | +| `pkg/attestation/crafter/runners/*.go` | Keyed definitions, and the identity flags. | +| `pkg/attestation/crafter/runners/*_test.go` | Expected definitions with the flags. | +| `pkg/attestation/crafter/runners/identity_test.go` | Add `TestKnownIdentityEnvVars` and `TestIdentityFlagsPerRunner`: the union, and the flags of each runner. | +| `.golangci.yml` | Turn off goconst for test files and the runners package, where env var names are data. | + +
+ +
+02 / 07 · One set of redaction rules for the CLI and the control plane (R-002, R-004, R-005) + +A new package holds the placeholder `[REDACTED]` and the mode type (`none`, `known-identity`, `custom`). `Names(mode, custom)` gives the names of a mode, and a custom list must have one non-empty name. `Apply(env, names)` replaces present values and keeps the keys. `Violations(env, names)` gives the sorted names with a non-empty value other than the placeholder. + +| File | Change | +|------|--------| +| `pkg/attestation/envredaction/envredaction.go` | Add the package. | +| `pkg/attestation/envredaction/envredaction_test.go` | Add table tests for `Names`, `Apply`, and `Violations`, with empty and absent values. | + +
+ +
+03 / 07 · An admin can set and read the redaction mode (R-001) + +The API gets an `EnvVarRedaction` message (type and names) on the organization update request and on the organization item. The organization stores it in a JSON column. The update checks the setting, keeps the names only for custom, and clears the column for none. A missing value in the request changes nothing. + +| File | Change | +|------|--------| +| `app/controlplane/api/controlplane/v1/response_messages.proto`, `organization.proto` | Add the message and the fields, then regenerate. | +| `app/controlplane/pkg/data/ent/schema/organization.go` | Add the JSON column, then generate and sync the migration. | +| `app/controlplane/pkg/biz/organization.go` | Add `EnvVarRedaction` with validation. | +| `app/controlplane/pkg/data/organization.go` | Set or clear the column, and read it. | +| `app/controlplane/internal/service/organization.go`, `context.go` | Convert between the API and the use case. | +| `app/controlplane/pkg/biz/organization_integration_test.go` | Add the update cases: each mode, invalid input, none, and no change. | +| `app/controlplane/internal/service/envvarredaction_test.go` | Add `TestEnvVarRedactionConversion`. | + +
+ +
+04 / 07 · The init response gives the setting with the resolved names (R-001, R-004) + +The `attestation init` response carries the setting. For known identity it also carries the names that the control plane enforces at push (spec D-003). The CLI copies the setting into the local attestation state. + +| File | Change | +|------|--------| +| `app/controlplane/api/controlplane/v1/workflow_run.proto` | Add the field to the init response. | +| `pkg/attestation/crafter/api/attestation/v1/crafting_state.proto` | Add the setting to the attestation state. | +| `app/controlplane/internal/service/attestation.go`, `organization.go` | Fill the field with `envVarRedactionForInit`. | +| `app/cli/pkg/action/attestation_init.go`, `env_var_redaction.go` | Copy the setting into the crafter options. | +| `app/controlplane/internal/service/envvarredaction_test.go` | Add `TestEnvVarRedactionForInit`. | + +
+ +
+05 / 07 · The CLI stores `[REDACTED]` for the runner and contract variables (R-002, R-005, R-006) + +After the crafter resolves the runner variables and the env allow list of the contract, it applies the redaction to the result. This happens before it writes the state, so the real value never reaches the state. Known identity uses the names from the state. Custom checks its list. The redaction also applies when the organization skips the runner variables. + +| File | Change | +|------|--------| +| `pkg/attestation/crafter/crafter.go` | Add the option, and apply the redaction in `ResolveEnvVars`. | +| `pkg/attestation/crafter/crafter_test.go` | Add `TestResolveEnvVars` cases: known identity, the list from the control plane, custom on the allow list, skip plus redaction, and an invalid custom list. | + +
+ +
+06 / 07 · `org update` sets the mode, and the organization details show it (R-001) + +`--env-var-redaction none|known-identity|custom` sets the mode, and the repeatable `--redacted-env-var` gives the custom list. The CLI rejects names without the custom mode before it calls the API. The context output shows the mode and the custom list. + +| File | Change | +|------|--------| +| `app/cli/cmd/organization_update.go` | Add the two flags. | +| `app/cli/cmd/organization_describe.go` | Show the setting. | +| `app/cli/pkg/action/org_update.go`, `membership_list.go`, `env_var_redaction.go` | Build the request, and add the setting to the output. | +| `app/cli/pkg/action/env_var_redaction_test.go` | Add `TestNewEnvVarRedactionItem` and `TestEnvVarRedactionConversions`. | +| `app/cli/documentation/cli-reference.md` | Regenerate. | + +
+ +
+07 / 07 · A push with a clear redacted value fails (R-003) + +The push check runs after the contract check, in the save and in the check that runs before a CAS upload. It uses the setting of the organization at push time. The error names the variables. It tells the user to update the CLI, or to run the attestation again if the setting changed. + +| File | Change | +|------|--------| +| `app/controlplane/pkg/biz/workflowrun.go` | Add `validateEnvVarRedaction`, and call it in `SaveAttestation` and `ValidateAttestationContract`. | +| `app/controlplane/pkg/biz/workflowrun_contract_integration_test.go` | Add `TestSaveAttestationEnforcesEnvVarRedaction`: accepted and rejected pushes, and nothing stored on a rejection. | + +
+ +Verify: `make test` + +## Open Questions + +None. + +## Skipped and risks + +| Skipped step | Reason | Follow-up | +|--------------|--------|-----------| +| Redaction of the head commit author and the pull request logins | Not environment variables. Out of scope in the spec. | [issue 3842](https://github.com/chainloop-dev/chainloop/issues/3842) | +| A CLI fallback to its own list when the control plane sends none | Only a control plane that sends the list has the setting, so the fallback cannot run. | none | + +Not checked: a manual end-to-end run in a real CI runner. + +| Risk | Mitigation | +|------|------------| +| Pipelines with a CLI without redaction support fail at push after an admin turns on the setting. | The error tells the user to update the CLI. The release notes give the minimum CLI version. | diff --git a/docs/specs/issue-3841-runner-env-var-redaction.md b/docs/specs/issue-3841-runner-env-var-redaction.md new file mode 100644 index 000000000..cb03ec8a4 --- /dev/null +++ b/docs/specs/issue-3841-runner-env-var-redaction.md @@ -0,0 +1,135 @@ +--- +owner: migmartri +ticket: https://github.com/chainloop-dev/chainloop/issues/3841 +prd: +--- + + + +# Spec issue-3841: Redaction of runner environment variables + +## Summary + +Each attestation stores the environment variables that the CLI finds in the CI runner. Some of these variables identify a person, for example the user who started the pipeline. This spec adds an organization setting that replaces the values of those variables with `[REDACTED]`. The setting has three modes: none, a list of identity variables that Chainloop keeps, or a custom list of variable names. The control plane rejects a pushed attestation that does not obey the setting. + +## Problem + +- Some organizations cannot store personal data in attestations, for example for GDPR. They must keep the other runner details. +- The only organization setting today removes all runner variables. The organization must then add each variable that it wants to keep to the env allow list of each contract. +- An empty value for an identity variable in the CI step does not work for each pipeline. The CLI requires some identity variables, and an empty value makes `attestation init` fail. + +## Goals and Non-Goals + +- Goal: an organization admin can hide the values of identity variables in new attestations, and keep all other runner details. +- In scope: push enforcement (R-003). It could ship after the CLI part, but the ticket proposes it. +- Non-goal: redact attestations that are already stored. The CLI signs each attestation, and a stored attestation does not change. +- Non-goal: name patterns (globs). The ticket asks for exact names only. +- Non-goal: a contract setting. Contracts cannot change or turn off the redaction. +- Non-goal: the author name and email of the head commit, and the author and reviewer logins of the pull request. They are not environment variables, and they need a different mechanism. Follow-up: [issue 3842](https://github.com/chainloop-dev/chainloop/issues/3842). +- Non-goal: redaction of materials or annotations. The ticket covers only the environment variables, and the user or the contract selects what materials and annotations contain. + +## Requirements + +### R-001: Organization redaction setting +An organization admin MUST be able to set the redaction mode of the organization to one of: none, known identity, or custom. The custom mode MUST have at least one variable name. The organization details MUST show the mode and the custom list. The default is none. +- Done when: `chainloop org update --env-var-redaction known-identity` sets the mode, and the organization details show it. + +### R-002: Redact, do not drop +When a redacted variable has a value, the attestation MUST keep the variable name with the value `[REDACTED]`. Then the attestation shows that the value existed and that the organization hid it on purpose. The check of required runner variables also still passes. The team did not remove the variable: a required variable then fails `attestation init`, and a reader cannot tell a hidden value from a missing one. +- Done when: in an Azure Pipelines run with known identity, the attestation has `BUILD_REQUESTEDFOR: [REDACTED]`, and `attestation init` does not fail. + +### R-003: Push enforcement +The control plane MUST reject a pushed attestation when a variable that the setting redacts has a non-empty value other than `[REDACTED]`. The check MUST use the setting of the organization at push time. The error MUST name the variables. It MUST tell the user to update the CLI, or to run the attestation again if the setting changed during the run. +- Done when: a CLI without redaction support pushes an attestation that has `GITHUB_ACTOR` with a real value, in an organization with known identity. The push fails. + +### R-004: Known identity list +The known identity mode MUST redact each variable that a runner integration of Chainloop marks as identity (D-001). The first list is: `GITHUB_ACTOR`, `GITLAB_USER_EMAIL`, `GITLAB_USER_LOGIN`, `BUILD_REQUESTEDFOR`, `BUILD_REQUESTEDFOREMAIL`, `USER`, and `HOME`. TeamCity marks `USER` and `HOME`, because `HOME` often contains the user name. + +### R-005: Custom list +The custom mode MUST redact only the listed variables. It MUST NOT add the known identity list. + +### R-006: Scope of the redaction +The redaction MUST apply to the variables that the runner finds and to the variables in the env allow list of the contract. A contract MUST NOT be able to show a redacted value. + +## Constraints + +- Compatibility: the API change only adds fields. +- The setting does not change the existing setting that removes all runner variables. Both can be on at the same time. +- Public repository: no internal links, and no customer or user information. + +## Proposal + +An organization admin sets the mode with `chainloop org update --env-var-redaction none|known-identity|custom`. The repeatable `--redacted-env-var NAME` flag gives the custom list. + +The CLI gets the setting from the control plane in the response of `attestation init`, as for the existing runner variable setting. The CLI keeps the setting in the local attestation state. When the CLI resolves the variables of the runner and of the contract, it replaces each redacted value with `[REDACTED]`. It does this before it writes the state. Thus the real value does not go to the state, the signed attestation, or the control plane. + +For the known identity mode, the `attestation init` response also gives the resolved list of names, and the CLI applies that list (D-003). At push, the control plane runs the redaction check next to the existing contract check. + +```mermaid +sequenceDiagram + participant A as Org admin + participant CLI as CLI in CI runner + participant CP as Control plane + A->>CP: org update --env-var-redaction known-identity + CLI->>CP: attestation init + CP-->>CLI: Redaction setting (with the other org settings) + CLI->>CLI: Resolve runner and contract variables, replace redacted values with [REDACTED] + CLI->>CP: attestation push (signed) + CP->>CP: Check each redacted variable is [REDACTED], empty, or absent + CP-->>CLI: Stored, or rejected with the names of the variables +``` + +## Decision Record + +### D-001: Identity marks live in each runner integration, and the list is their union +Each runner integration marks which of its variables identify a person. The known identity list is the union of the marks of all runners, and it applies to each attestation. +- Why: the person who adds or changes a runner integration sees the marks next to the variables. The union does not depend on the runner type that the attestation reports. Thus a client cannot skip the push check with a different runner type. +- Alternatives considered: + - One central list, apart from the runner integrations: it gets out of date when a runner integration changes. + - Only the identity variables of the runner of the attestation: push enforcement then depends on a runner type that the client reports. +- Source: drafting + +### D-002: The control plane enforces the setting at push +The control plane rejects an attestation that does not obey the setting. It does not trust the client to redact. +- Why: the CLI applies the redaction and signs the result, so an older CLI ignores the setting and nothing else stops the personal data. +- Alternatives considered: + - Document a minimum CLI version: nothing stops an older CLI, so the setting is only advice. +- Source: drafting + +### D-003: The control plane sends the resolved known identity list +In the known identity mode, the `attestation init` response gives the names of the variables to redact. The CLI applies that list. +- Why: the push check uses the list of the control plane. A later control plane release can mark a new identity variable. If the CLI used its own list, each push from a current CLI would then fail until the pipeline updates the CLI. +- Alternatives considered: + - Each side uses its own copy of the list. A new mark ships in the CLI one release before the control plane enforces it. This depends on the release order and on the CLI update of each pipeline. +- Source: drafting + +## Open Questions + +No open questions. + +## Risks + +| Risk | Mitigation | +|------|------------| +| An organization turns on redaction, and pipelines with an older CLI fail at push. | The error names the variables and tells the user to update the CLI. The release notes give the minimum CLI version. | +| An admin changes the setting while an attestation is in progress. The push uses the new setting, which the CLI did not apply. | The push fails with the error from R-003, and a new run of the pipeline uses the new setting. Changes to the setting are rare. | +| A personal value is in a variable that is not on the known identity list. | The custom mode covers it. A runner integration can mark more variables in a later release. | From c8ebf3783e6c23ae8bf3e8070d2f4de54ad015ed Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Mon, 23 Nov 2026 12:20:05 +0100 Subject: [PATCH 2/8] docs(plan): clarify the runner definition change in step 01 Refs #3841 Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: a6ea453b-a3ca-450f-aba0-241be6b95a2b --- docs/plans/issue-3841-runner-env-var-redaction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plans/issue-3841-runner-env-var-redaction.md b/docs/plans/issue-3841-runner-env-var-redaction.md index 9ed762e88..db604e847 100644 --- a/docs/plans/issue-3841-runner-env-var-redaction.md +++ b/docs/plans/issue-3841-runner-env-var-redaction.md @@ -75,7 +75,7 @@ The env var definition gets an `Identity` flag next to `Optional`. The definitio | File | Change | |------|--------| -| `pkg/attestation/crafter/runners/runners.go` | Add `Identity` and `KnownIdentityEnvVars`. | +| `pkg/attestation/crafter/runners/runners.go` | Add the `Identity` field to `EnvVarDefinition`, next to `Optional`. Add `KnownIdentityEnvVars`, which returns the names that any runner marks with `Identity`. | | `pkg/attestation/crafter/runners/*.go` | Keyed definitions, and the identity flags. | | `pkg/attestation/crafter/runners/*_test.go` | Expected definitions with the flags. | | `pkg/attestation/crafter/runners/identity_test.go` | Add `TestKnownIdentityEnvVars` and `TestIdentityFlagsPerRunner`: the union, and the flags of each runner. | From 2da8d2ad5d17d54e699269a5c13fab51c317a6ac Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Mon, 23 Nov 2026 12:37:24 +0100 Subject: [PATCH 3/8] docs(spec): address review on runner env var redaction Make the check-before-storage ordering explicit in R-003, document the cross-runner effect of the known identity union in D-001, and align the plan with the implementation. Refs #3841 Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: a6ea453b-a3ca-450f-aba0-241be6b95a2b --- .../issue-3841-runner-env-var-redaction.md | 17 +++++++++-------- .../issue-3841-runner-env-var-redaction.md | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/plans/issue-3841-runner-env-var-redaction.md b/docs/plans/issue-3841-runner-env-var-redaction.md index db604e847..d784b8854 100644 --- a/docs/plans/issue-3841-runner-env-var-redaction.md +++ b/docs/plans/issue-3841-runner-env-var-redaction.md @@ -78,7 +78,8 @@ The env var definition gets an `Identity` flag next to `Optional`. The definitio | `pkg/attestation/crafter/runners/runners.go` | Add the `Identity` field to `EnvVarDefinition`, next to `Optional`. Add `KnownIdentityEnvVars`, which returns the names that any runner marks with `Identity`. | | `pkg/attestation/crafter/runners/*.go` | Keyed definitions, and the identity flags. | | `pkg/attestation/crafter/runners/*_test.go` | Expected definitions with the flags. | -| `pkg/attestation/crafter/runners/identity_test.go` | Add `TestKnownIdentityEnvVars` and `TestIdentityFlagsPerRunner`: the union, and the flags of each runner. | +| `pkg/attestation/crafter/runners/identity_test.go` | Add `TestKnownIdentityEnvVars` and `TestIdentityFlagsPerRunner`: the sorted union, and the flags of each runner. | +| `pkg/attestation/crafter/runner_test.go` | Add `TestKnownIdentityEnvVarsCoversEveryRunner`: each runner of the runner factories has its identity variables in the union. | | `.golangci.yml` | Turn off goconst for test files and the runners package, where env var names are data. | @@ -115,14 +116,14 @@ The API gets an `EnvVarRedaction` message (type and names) on the organization u
04 / 07 · The init response gives the setting with the resolved names (R-001, R-004) -The `attestation init` response carries the setting. For known identity it also carries the names that the control plane enforces at push (spec D-003). The CLI copies the setting into the local attestation state. +The `attestation init` response carries the setting with the names that the control plane enforces at push, also for known identity (spec D-003). The CLI copies only these names into the local attestation state. | File | Change | |------|--------| | `app/controlplane/api/controlplane/v1/workflow_run.proto` | Add the field to the init response. | -| `pkg/attestation/crafter/api/attestation/v1/crafting_state.proto` | Add the setting to the attestation state. | +| `pkg/attestation/crafter/api/attestation/v1/crafting_state.proto` | Add the names to redact to the attestation state. | | `app/controlplane/internal/service/attestation.go`, `organization.go` | Fill the field with `envVarRedactionForInit`. | -| `app/cli/pkg/action/attestation_init.go`, `env_var_redaction.go` | Copy the setting into the crafter options. | +| `app/cli/pkg/action/attestation_init.go` | Copy the names into the crafter options. | | `app/controlplane/internal/service/envvarredaction_test.go` | Add `TestEnvVarRedactionForInit`. |
@@ -130,12 +131,12 @@ The `attestation init` response carries the setting. For known identity it also
05 / 07 · The CLI stores `[REDACTED]` for the runner and contract variables (R-002, R-005, R-006) -After the crafter resolves the runner variables and the env allow list of the contract, it applies the redaction to the result. This happens before it writes the state, so the real value never reaches the state. Known identity uses the names from the state. Custom checks its list. The redaction also applies when the organization skips the runner variables. +After the crafter resolves the runner variables and the env allow list of the contract, it applies the redaction to the result. This happens before it writes the state, so the real value never reaches the state. The crafter uses the names from the state, so it has no logic for each mode. The redaction also applies when the organization skips the runner variables. | File | Change | |------|--------| | `pkg/attestation/crafter/crafter.go` | Add the option, and apply the redaction in `ResolveEnvVars`. | -| `pkg/attestation/crafter/crafter_test.go` | Add `TestResolveEnvVars` cases: known identity, the list from the control plane, custom on the allow list, skip plus redaction, and an invalid custom list. | +| `pkg/attestation/crafter/crafter_test.go` | Add `TestResolveEnvVars` cases: the known identity list, names on the runner variables and the allow list, and skip plus redaction. |
@@ -161,8 +162,8 @@ The push check runs after the contract check, in the save and in the check that | File | Change | |------|--------| -| `app/controlplane/pkg/biz/workflowrun.go` | Add `validateEnvVarRedaction`, and call it in `SaveAttestation` and `ValidateAttestationContract`. | -| `app/controlplane/pkg/biz/workflowrun_contract_integration_test.go` | Add `TestSaveAttestationEnforcesEnvVarRedaction`: accepted and rejected pushes, and nothing stored on a rejection. | +| `app/controlplane/pkg/biz/workflowrun.go` | Add `validatePredicate`, which runs the contract and redaction checks, and call it in `SaveAttestation` and `ValidateAttestationContract`. Load the organization one time for each call. | +| `app/controlplane/pkg/biz/workflowrun_contract_integration_test.go` | Add `TestSaveAttestationEnforcesEnvVarRedaction`: the pre-CAS check and the save both reject a clear value, accept the other cases, and store nothing on a rejection. | diff --git a/docs/specs/issue-3841-runner-env-var-redaction.md b/docs/specs/issue-3841-runner-env-var-redaction.md index cb03ec8a4..a7b7aa87e 100644 --- a/docs/specs/issue-3841-runner-env-var-redaction.md +++ b/docs/specs/issue-3841-runner-env-var-redaction.md @@ -58,7 +58,7 @@ When a redacted variable has a value, the attestation MUST keep the variable nam - Done when: in an Azure Pipelines run with known identity, the attestation has `BUILD_REQUESTEDFOR: [REDACTED]`, and `attestation init` does not fail. ### R-003: Push enforcement -The control plane MUST reject a pushed attestation when a variable that the setting redacts has a non-empty value other than `[REDACTED]`. The check MUST use the setting of the organization at push time. The error MUST name the variables. It MUST tell the user to update the CLI, or to run the attestation again if the setting changed during the run. +The control plane MUST reject a pushed attestation when a variable that the setting redacts has a non-empty value other than `[REDACTED]`. The check MUST use the setting of the organization at push time. The control plane MUST run the check before it stores the attestation, also in a CAS backend. The error MUST name the variables. It MUST tell the user to update the CLI, or to run the attestation again if the setting changed during the run. - Done when: a CLI without redaction support pushes an attestation that has `GITHUB_ACTOR` with a real value, in an organization with known identity. The push fails. ### R-004: Known identity list @@ -80,7 +80,7 @@ The redaction MUST apply to the variables that the runner finds and to the varia An organization admin sets the mode with `chainloop org update --env-var-redaction none|known-identity|custom`. The repeatable `--redacted-env-var NAME` flag gives the custom list. -The CLI gets the setting from the control plane in the response of `attestation init`, as for the existing runner variable setting. The CLI keeps the setting in the local attestation state. When the CLI resolves the variables of the runner and of the contract, it replaces each redacted value with `[REDACTED]`. It does this before it writes the state. Thus the real value does not go to the state, the signed attestation, or the control plane. +The CLI gets the setting from the control plane in the response of `attestation init`, as for the existing runner variable setting. The CLI keeps the names to redact in the local attestation state. When the CLI resolves the variables of the runner and of the contract, it replaces each redacted value with `[REDACTED]`. It does this before it writes the state. Thus the real value does not go to the state, the signed attestation, or the control plane. For the known identity mode, the `attestation init` response also gives the resolved list of names, and the CLI applies that list (D-003). At push, the control plane runs the redaction check next to the existing contract check. @@ -101,7 +101,7 @@ sequenceDiagram ## Decision Record ### D-001: Identity marks live in each runner integration, and the list is their union -Each runner integration marks which of its variables identify a person. The known identity list is the union of the marks of all runners, and it applies to each attestation. +Each runner integration marks which of its variables identify a person. The known identity list is the union of the marks of all runners, and it applies to each attestation. TeamCity marks `USER` and `HOME`. Thus the known identity mode also redacts them in attestations from other runners. An example is a contract that adds them to its env allow list. - Why: the person who adds or changes a runner integration sees the marks next to the variables. The union does not depend on the runner type that the attestation reports. Thus a client cannot skip the push check with a different runner type. - Alternatives considered: - One central list, apart from the runner integrations: it gets out of date when a runner integration changes. From 146be113bac65ff2c18e756a85066720ba99bd0e Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Mon, 23 Nov 2026 17:21:59 +0100 Subject: [PATCH 4/8] feat: redact identity env vars of the runner by org setting Add an organization setting that replaces the values of runner environment variables with [REDACTED]. Modes are none, known-identity (the identity variables that each runner integration marks) and custom. The control plane sends the resolved names at attestation init, the CLI applies them, and the control plane rejects a push that does not obey the setting. Refs #3841 Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: a6ea453b-a3ca-450f-aba0-241be6b95a2b --- .golangci.yml | 4 + app/cli/cmd/organization_describe.go | 7 + app/cli/cmd/organization_update.go | 18 + app/cli/documentation/cli-reference.md | 2 + app/cli/pkg/action/attestation_init.go | 4 + app/cli/pkg/action/env_var_redaction.go | 64 +++ app/cli/pkg/action/env_var_redaction_test.go | 87 ++++ app/cli/pkg/action/membership_list.go | 22 +- app/cli/pkg/action/org_update.go | 3 + .../api/controlplane/v1/organization.pb.go | 56 ++- .../api/controlplane/v1/organization.proto | 3 + .../controlplane/v1/response_messages.pb.go | 386 ++++++++++++------ .../controlplane/v1/response_messages.proto | 18 + .../api/controlplane/v1/workflow_run.pb.go | 22 +- .../api/controlplane/v1/workflow_run.proto | 3 + .../frontend/attestation/v1/crafting_state.ts | 24 ++ .../frontend/controlplane/v1/organization.ts | 24 +- .../controlplane/v1/response_messages.ts | 146 +++++++ .../frontend/controlplane/v1/workflow_run.ts | 23 ++ ...attestation.v1.Attestation.jsonschema.json | 14 + .../attestation.v1.Attestation.schema.json | 14 + ...ServiceInitResponse.Result.jsonschema.json | 14 + ...tionServiceInitResponse.Result.schema.json | 14 + ...olplane.v1.EnvVarRedaction.jsonschema.json | 44 ++ ...ontrolplane.v1.EnvVarRedaction.schema.json | 44 ++ .../controlplane.v1.OrgItem.jsonschema.json | 8 + .../controlplane.v1.OrgItem.schema.json | 8 + ...zationServiceUpdateRequest.jsonschema.json | 8 + ...ganizationServiceUpdateRequest.schema.json | 8 + .../internal/service/attestation.go | 11 +- app/controlplane/internal/service/context.go | 1 + .../internal/service/envvarredaction_test.go | 68 +++ .../internal/service/organization.go | 38 ++ app/controlplane/pkg/biz/organization.go | 48 +++ .../pkg/biz/organization_integration_test.go | 72 ++++ app/controlplane/pkg/biz/workflowrun.go | 77 +++- .../workflowrun_contract_integration_test.go | 79 ++++ .../pkg/biz/workflowrun_verification_test.go | 6 +- .../ent/migrate/migrations/20261123100446.sql | 2 + .../pkg/data/ent/migrate/migrations/atlas.sum | 3 +- .../pkg/data/ent/migrate/schema.go | 1 + app/controlplane/pkg/data/ent/mutation.go | 75 +++- app/controlplane/pkg/data/ent/organization.go | 16 +- .../pkg/data/ent/organization/organization.go | 3 + .../pkg/data/ent/organization/where.go | 10 + .../pkg/data/ent/organization_create.go | 71 ++++ .../pkg/data/ent/organization_update.go | 37 ++ app/controlplane/pkg/data/ent/runtime.go | 2 +- .../pkg/data/ent/schema/organization.go | 4 + app/controlplane/pkg/data/organization.go | 10 + .../api/attestation/v1/crafting_state.pb.go | 20 +- .../api/attestation/v1/crafting_state.proto | 5 + pkg/attestation/crafter/crafter.go | 9 + pkg/attestation/crafter/crafter_test.go | 55 ++- pkg/attestation/crafter/runner_test.go | 18 + .../crafter/runners/azurepipeline.go | 18 +- .../crafter/runners/azurepipeline_test.go | 18 +- .../crafter/runners/circleci_build.go | 10 +- .../crafter/runners/circleci_build_test.go | 12 +- .../crafter/runners/daggerpipeline.go | 32 +- .../crafter/runners/daggerpipeline_test.go | 32 +- .../crafter/runners/githubaction.go | 24 +- .../crafter/runners/githubaction_test.go | 26 +- .../crafter/runners/gitlabpipeline.go | 38 +- .../crafter/runners/gitlabpipeline_test.go | 38 +- .../crafter/runners/identity_test.go | 35 ++ pkg/attestation/crafter/runners/jenkinsjob.go | 14 +- .../crafter/runners/jenkinsjob_test.go | 16 +- pkg/attestation/crafter/runners/runners.go | 28 +- .../crafter/runners/teamcitypipeline.go | 16 +- .../crafter/runners/teamcitypipeline_test.go | 18 +- .../crafter/runners/tektonpipeline.go | 14 +- pkg/attestation/envredaction/envredaction.go | 89 ++++ .../envredaction/envredaction_test.go | 154 +++++++ 74 files changed, 2108 insertions(+), 357 deletions(-) create mode 100644 app/cli/pkg/action/env_var_redaction.go create mode 100644 app/cli/pkg/action/env_var_redaction_test.go create mode 100644 app/controlplane/api/gen/jsonschema/controlplane.v1.EnvVarRedaction.jsonschema.json create mode 100644 app/controlplane/api/gen/jsonschema/controlplane.v1.EnvVarRedaction.schema.json create mode 100644 app/controlplane/internal/service/envvarredaction_test.go create mode 100644 app/controlplane/pkg/data/ent/migrate/migrations/20261123100446.sql create mode 100644 pkg/attestation/crafter/runners/identity_test.go create mode 100644 pkg/attestation/envredaction/envredaction.go create mode 100644 pkg/attestation/envredaction/envredaction_test.go diff --git a/.golangci.yml b/.golangci.yml index fae1ddb9b..c4dd440a9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -65,6 +65,10 @@ linters: rules: - path: _test\.go text: Potential hardcoded credentials + # Env var names in runner definitions are data, not magic strings + - path: pkg/attestation/crafter/runners/ + linters: + - goconst - linters: - staticcheck text: 'SA1019.*crafting_schema\.proto' diff --git a/app/cli/cmd/organization_describe.go b/app/cli/cmd/organization_describe.go index aef1a3464..1ceea5a6a 100644 --- a/app/cli/cmd/organization_describe.go +++ b/app/cli/cmd/organization_describe.go @@ -64,6 +64,13 @@ func contextTableOutput(config *action.ConfigContextItem) error { orgInfo += "\nBlock attestations on released versions: enabled" } + if r := m.Org.EnvVarRedaction; r != nil { + orgInfo += fmt.Sprintf("\nEnv var redaction: %s", r.Mode) + if len(r.EnvVars) > 0 { + orgInfo += fmt.Sprintf(" (%s)", strings.Join(r.EnvVars, ", ")) + } + } + gt.AppendRow(table.Row{"Organization", orgInfo}) } diff --git a/app/cli/cmd/organization_update.go b/app/cli/cmd/organization_update.go index 179949ef7..36c42ef82 100644 --- a/app/cli/cmd/organization_update.go +++ b/app/cli/cmd/organization_update.go @@ -18,8 +18,11 @@ package cmd import ( "fmt" "strconv" + "strings" "github.com/chainloop-dev/chainloop/app/cli/pkg/action" + "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/runners" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" "github.com/spf13/cobra" ) @@ -34,6 +37,8 @@ func newOrganizationUpdateCmd() *cobra.Command { enableAIAgentCollector bool blockAttestationsOnReleasedVersions bool skipRunnerEnvVars bool + envVarRedaction string + redactedEnvVars []string ) cmd := &cobra.Command{ @@ -69,6 +74,14 @@ func newOrganizationUpdateCmd() *cobra.Command { opts.SkipRunnerEnvVars = &skipRunnerEnvVars } + if cmd.Flags().Changed("env-var-redaction") || cmd.Flags().Changed("redacted-env-var") { + redaction, err := action.NewEnvVarRedactionPb(envVarRedaction, redactedEnvVars) + if err != nil { + return err + } + opts.EnvVarRedaction = redaction + } + if cmd.Flags().Changed("api-token-max-days-inactive") { days, err := strconv.Atoi(apiTokenMaxDaysInactive) if err != nil { @@ -102,5 +115,10 @@ func newOrganizationUpdateCmd() *cobra.Command { cmd.Flags().BoolVar(&enableAIAgentCollector, "enable-ai-agent-collector", false, "enable automatic AI agent config collection during attestation init") cmd.Flags().BoolVar(&blockAttestationsOnReleasedVersions, "block-attestations-on-released-versions", false, "reject new attestations pushed to project versions that are already released") cmd.Flags().BoolVar(&skipRunnerEnvVars, "skip-runner-env-vars", false, "opt out of storing the environment variables automatically discovered by the CI runner in the attestation") + cmd.Flags().StringVar(&envVarRedaction, "env-var-redaction", "", fmt.Sprintf( + "replace the values of environment variables with %s in new attestations, one of: %s, %s (variables that identify a person: %s), %s (the variables in --redacted-env-var)", + envredaction.RedactedValue, envredaction.ModeNone, envredaction.ModeKnownIdentity, + strings.Join(runners.KnownIdentityEnvVars(), ", "), envredaction.ModeCustom)) + cmd.Flags().StringArrayVar(&redactedEnvVars, "redacted-env-var", nil, "exact name of an environment variable to redact, can be set multiple times. Requires --env-var-redaction custom") return cmd } diff --git a/app/cli/documentation/cli-reference.md b/app/cli/documentation/cli-reference.md index d0f757571..acc30b54b 100644 --- a/app/cli/documentation/cli-reference.md +++ b/app/cli/documentation/cli-reference.md @@ -2774,10 +2774,12 @@ Options --block[=true|false] set the default policy violation blocking strategy --block-attestations-on-released-versions[=true|false] reject new attestations pushed to project versions that are already released --enable-ai-agent-collector[=true|false] enable automatic AI agent config collection during attestation init +--env-var-redaction string replace the values of environment variables with [REDACTED] in new attestations, one of: none, known-identity (variables that identify a person: BUILD_REQUESTEDFOR, BUILD_REQUESTEDFOREMAIL, GITHUB_ACTOR, GITLAB_USER_EMAIL, GITLAB_USER_LOGIN, HOME, USER), custom (the variables in --redacted-env-var) -h, --help[=true|false] help for update --name string organization name --policies-allowed-hostnames strings set the allowed hostnames for the policy engine --prevent-implicit-workflow-creation[=true|false] prevent workflows and projects from being created implicitly during attestation init +--redacted-env-var stringArray exact name of an environment variable to redact, can be set multiple times. Requires --env-var-redaction custom --restrict-contract-creation[=true|false] restrict contract creation (org-level and project-level) to only organization admins (owner/admin roles) --skip-runner-env-vars[=true|false] opt out of storing the environment variables automatically discovered by the CI runner in the attestation ``` diff --git a/app/cli/pkg/action/attestation_init.go b/app/cli/pkg/action/attestation_init.go index d0d5efa4c..1c0144447 100644 --- a/app/cli/pkg/action/attestation_init.go +++ b/app/cli/pkg/action/attestation_init.go @@ -232,6 +232,7 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun policiesAllowedHostnames []string enableAIAgentCollector bool skipRunnerEnvVars bool + redactedEnvVars []string // Timestamp Authority URL for new attestations timestampAuthorityURL, signingCAName string uiDashboardURL string @@ -266,6 +267,8 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun policiesAllowedHostnames = result.GetPoliciesAllowedHostnames() enableAIAgentCollector = result.GetEnableAiAgentCollector() skipRunnerEnvVars = result.GetSkipRunnerEnvVars() + // the control plane resolves the names for every mode, so they match its push check + redactedEnvVars = result.GetRedactedEnvVars() signingOpts := result.GetSigningOptions() timestampAuthorityURL = signingOpts.GetTimestampAuthorityUrl() signingCAName = signingOpts.GetSigningCa() @@ -319,6 +322,7 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun BlockOnPolicyViolation: blockOnPolicyViolation, PoliciesAllowedHostnames: policiesAllowedHostnames, SkipRunnerEnvVars: skipRunnerEnvVars, + RedactedEnvVars: redactedEnvVars, SigningOptions: &crafter.SigningOpts{ TimestampAuthorityURL: timestampAuthorityURL, SigningCAName: signingCAName, diff --git a/app/cli/pkg/action/env_var_redaction.go b/app/cli/pkg/action/env_var_redaction.go new file mode 100644 index 000000000..491bef089 --- /dev/null +++ b/app/cli/pkg/action/env_var_redaction.go @@ -0,0 +1,64 @@ +// +// Copyright 2026 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package action + +import ( + "errors" + + pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" +) + +// EnvVarRedactionItem is the org-level redaction of env var values in attestations. +type EnvVarRedactionItem struct { + Mode envredaction.Mode `json:"mode"` + EnvVars []string `json:"envVars,omitempty"` +} + +// NewEnvVarRedactionPb builds the API setting from the CLI flag values. +func NewEnvVarRedactionPb(mode string, envVars []string) (*pb.EnvVarRedaction, error) { + m := envredaction.Mode(mode) + if len(envVars) > 0 && m != envredaction.ModeCustom { + return nil, errors.New("redacted env vars can only be set with the custom mode") + } + + // Names rejects an unknown mode and a custom mode with no names, as the control plane does. + if _, err := envredaction.Names(m, envVars); err != nil { + return nil, err + } + + out := &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_UNSPECIFIED, EnvVars: envVars} + switch m { + case envredaction.ModeKnownIdentity: + out.Type = pb.EnvVarRedaction_TYPE_KNOWN_IDENTITY + case envredaction.ModeCustom: + out.Type = pb.EnvVarRedaction_TYPE_CUSTOM + } + + return out, nil +} + +// pbEnvVarRedactionToAction converts the API setting for output. No redaction returns nil. +func pbEnvVarRedactionToAction(in *pb.EnvVarRedaction) *EnvVarRedactionItem { + switch in.GetType() { + case pb.EnvVarRedaction_TYPE_KNOWN_IDENTITY: + return &EnvVarRedactionItem{Mode: envredaction.ModeKnownIdentity, EnvVars: in.GetEnvVars()} + case pb.EnvVarRedaction_TYPE_CUSTOM: + return &EnvVarRedactionItem{Mode: envredaction.ModeCustom, EnvVars: in.GetEnvVars()} + default: + return nil + } +} diff --git a/app/cli/pkg/action/env_var_redaction_test.go b/app/cli/pkg/action/env_var_redaction_test.go new file mode 100644 index 000000000..b05140bef --- /dev/null +++ b/app/cli/pkg/action/env_var_redaction_test.go @@ -0,0 +1,87 @@ +// +// Copyright 2026 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package action + +import ( + "testing" + + pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" +) + +func TestNewEnvVarRedactionItem(t *testing.T) { + testCases := []struct { + name string + mode string + vars []string + want *pb.EnvVarRedaction + wantErr string + }{ + {name: "none", mode: string(envredaction.ModeNone), want: &pb.EnvVarRedaction{}}, + {name: "known identity", mode: string(envredaction.ModeKnownIdentity), want: &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_KNOWN_IDENTITY}}, + { + name: "custom list", + mode: string(envredaction.ModeCustom), + vars: []string{"BUILD_REQUESTEDFOR", "BUILD_REQUESTEDFOREMAIL"}, + want: &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_CUSTOM, EnvVars: []string{"BUILD_REQUESTEDFOR", "BUILD_REQUESTEDFOREMAIL"}}, + }, + {name: "custom without variables", mode: string(envredaction.ModeCustom), wantErr: "custom env var redaction requires at least one variable name"}, + {name: "variables without custom", mode: string(envredaction.ModeKnownIdentity), vars: []string{"MY_OWNER"}, wantErr: "redacted env vars can only be set with the custom mode"}, + {name: "unknown mode", mode: "unknown-mode", wantErr: "invalid env var redaction mode \"unknown-mode\", valid values are: none, known-identity, custom"}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + got, err := NewEnvVarRedactionPb(tc.mode, tc.vars) + if tc.wantErr != "" { + require.EqualError(t, err, tc.wantErr) + return + } + require.NoError(t, err) + assert.True(t, proto.Equal(tc.want, got), "got %v, want %v", got, tc.want) + }) + } +} + +func TestEnvVarRedactionConversions(t *testing.T) { + testCases := []struct { + name string + in *pb.EnvVarRedaction + wantItem *EnvVarRedactionItem + }{ + {name: "not set", in: nil, wantItem: nil}, + {name: "unspecified", in: &pb.EnvVarRedaction{}, wantItem: nil}, + { + name: "known identity", + in: &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_KNOWN_IDENTITY}, + wantItem: &EnvVarRedactionItem{Mode: envredaction.ModeKnownIdentity}, + }, + { + name: "custom list item", + in: &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_CUSTOM, EnvVars: []string{"OTHER_VAR"}}, + wantItem: &EnvVarRedactionItem{Mode: envredaction.ModeCustom, EnvVars: []string{"OTHER_VAR"}}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.wantItem, pbEnvVarRedactionToAction(tc.in)) + }) + } +} diff --git a/app/cli/pkg/action/membership_list.go b/app/cli/pkg/action/membership_list.go index 8f92dac00..09955bc5a 100644 --- a/app/cli/pkg/action/membership_list.go +++ b/app/cli/pkg/action/membership_list.go @@ -29,16 +29,17 @@ type MembershipList struct { } type OrgItem struct { - ID string `json:"id"` - Name string `json:"name"` - CreatedAt *time.Time `json:"createdAt"` - PolicyViolationBlockingStrategy string `json:"policyViolationBlockingStrategy"` - PolicyAllowedHostnames []string `json:"policyAllowedHostnames,omitempty"` - PreventImplicitWorkflowCreation bool `json:"preventImplicitWorkflowCreation"` - APITokenMaxDaysInactive *string `json:"apiTokenMaxDaysInactive,omitempty"` - EnableAIAgentCollector bool `json:"enableAiAgentCollector"` - BlockAttestationsOnReleasedVersions bool `json:"blockAttestationsOnReleasedVersions"` - SkipRunnerEnvVars bool `json:"skipRunnerEnvVars"` + ID string `json:"id"` + Name string `json:"name"` + CreatedAt *time.Time `json:"createdAt"` + PolicyViolationBlockingStrategy string `json:"policyViolationBlockingStrategy"` + PolicyAllowedHostnames []string `json:"policyAllowedHostnames,omitempty"` + PreventImplicitWorkflowCreation bool `json:"preventImplicitWorkflowCreation"` + APITokenMaxDaysInactive *string `json:"apiTokenMaxDaysInactive,omitempty"` + EnableAIAgentCollector bool `json:"enableAiAgentCollector"` + BlockAttestationsOnReleasedVersions bool `json:"blockAttestationsOnReleasedVersions"` + SkipRunnerEnvVars bool `json:"skipRunnerEnvVars"` + EnvVarRedaction *EnvVarRedactionItem `json:"envVarRedaction,omitempty"` } type MembershipItem struct { @@ -144,6 +145,7 @@ func pbOrgItemToAction(in *pb.OrgItem) *OrgItem { EnableAIAgentCollector: in.EnableAiAgentCollector, BlockAttestationsOnReleasedVersions: in.BlockAttestationsOnReleasedVersions, SkipRunnerEnvVars: in.SkipRunnerEnvVars, + EnvVarRedaction: pbEnvVarRedactionToAction(in.GetEnvVarRedaction()), } if in.DefaultPolicyViolationStrategy == pb.OrgItem_POLICY_VIOLATION_BLOCKING_STRATEGY_BLOCK { diff --git a/app/cli/pkg/action/org_update.go b/app/cli/pkg/action/org_update.go index 480d85083..ff29a6767 100644 --- a/app/cli/pkg/action/org_update.go +++ b/app/cli/pkg/action/org_update.go @@ -44,6 +44,8 @@ type NewOrgUpdateOpts struct { BlockAttestationsOnReleasedVersions *bool // SkipRunnerEnvVars opts out of storing the environment variables automatically discovered by the CI runner in the attestation SkipRunnerEnvVars *bool + // EnvVarRedaction sets the redaction of env var values in new attestations. nil means no change + EnvVarRedaction *pb.EnvVarRedaction } func (action *OrgUpdate) Run(ctx context.Context, name string, opts *NewOrgUpdateOpts) (*OrgItem, error) { @@ -57,6 +59,7 @@ func (action *OrgUpdate) Run(ctx context.Context, name string, opts *NewOrgUpdat EnableAiAgentCollector: opts.EnableAIAgentCollector, BlockAttestationsOnReleasedVersions: opts.BlockAttestationsOnReleasedVersions, SkipRunnerEnvVars: opts.SkipRunnerEnvVars, + EnvVarRedaction: opts.EnvVarRedaction, } if opts.PoliciesAllowedHostnames != nil { diff --git a/app/controlplane/api/controlplane/v1/organization.pb.go b/app/controlplane/api/controlplane/v1/organization.pb.go index ed94bc5a8..281e2ca75 100644 --- a/app/controlplane/api/controlplane/v1/organization.pb.go +++ b/app/controlplane/api/controlplane/v1/organization.pb.go @@ -456,8 +456,10 @@ type OrganizationServiceUpdateRequest struct { BlockAttestationsOnReleasedVersions *bool `protobuf:"varint,9,opt,name=block_attestations_on_released_versions,json=blockAttestationsOnReleasedVersions,proto3,oneof" json:"block_attestations_on_released_versions,omitempty"` // Opt out of storing the environment variables automatically discovered by the CI runner in the attestation SkipRunnerEnvVars *bool `protobuf:"varint,10,opt,name=skip_runner_env_vars,json=skipRunnerEnvVars,proto3,oneof" json:"skip_runner_env_vars,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // Redaction of environment variable values in new attestations. Not set means no change. + EnvVarRedaction *EnvVarRedaction `protobuf:"bytes,11,opt,name=env_var_redaction,json=envVarRedaction,proto3" json:"env_var_redaction,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *OrganizationServiceUpdateRequest) Reset() { @@ -560,6 +562,13 @@ func (x *OrganizationServiceUpdateRequest) GetSkipRunnerEnvVars() bool { return false } +func (x *OrganizationServiceUpdateRequest) GetEnvVarRedaction() *EnvVarRedaction { + if x != nil { + return x.EnvVarRedaction + } + return nil +} + type OrganizationServiceUpdateResponse struct { state protoimpl.MessageState `protogen:"open.v1"` Result *OrgItem `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` @@ -718,7 +727,7 @@ const file_controlplane_v1_organization_proto_rawDesc = "" + " OrganizationServiceCreateRequest\x12\x1b\n" + "\x04name\x18\x01 \x01(\tB\a\xbaH\x04r\x02\x10\x01R\x04name\"U\n" + "!OrganizationServiceCreateResponse\x120\n" + - "\x06result\x18\x01 \x01(\v2\x18.controlplane.v1.OrgItemR\x06result\"\xbf\a\n" + + "\x06result\x18\x01 \x01(\v2\x18.controlplane.v1.OrgItemR\x06result\"\x8d\b\n" + " OrganizationServiceUpdateRequest\x12\x1b\n" + "\x04name\x18\x01 \x01(\tB\a\xbaH\x04r\x02\x10\x01R\x04name\x12>\n" + "\x19block_on_policy_violation\x18\x02 \x01(\bH\x00R\x16blockOnPolicyViolation\x88\x01\x01\x12<\n" + @@ -730,7 +739,8 @@ const file_controlplane_v1_organization_proto_rawDesc = "" + "\x19enable_ai_agent_collector\x18\b \x01(\bH\x04R\x16enableAiAgentCollector\x88\x01\x01\x12Y\n" + "'block_attestations_on_released_versions\x18\t \x01(\bH\x05R#blockAttestationsOnReleasedVersions\x88\x01\x01\x124\n" + "\x14skip_runner_env_vars\x18\n" + - " \x01(\bH\x06R\x11skipRunnerEnvVars\x88\x01\x01B\x1c\n" + + " \x01(\bH\x06R\x11skipRunnerEnvVars\x88\x01\x01\x12L\n" + + "\x11env_var_redaction\x18\v \x01(\v2 .controlplane.v1.EnvVarRedactionR\x0fenvVarRedactionB\x1c\n" + "\x1a_block_on_policy_violationB%\n" + "#_prevent_implicit_workflow_creationB+\n" + ")_restrict_contract_creation_to_org_adminsB\x1e\n" + @@ -782,6 +792,7 @@ var file_controlplane_v1_organization_proto_goTypes = []any{ (*OrgMembershipItem)(nil), // 14: controlplane.v1.OrgMembershipItem (*OffsetPaginationResponse)(nil), // 15: controlplane.v1.OffsetPaginationResponse (*OrgItem)(nil), // 16: controlplane.v1.OrgItem + (*EnvVarRedaction)(nil), // 17: controlplane.v1.EnvVarRedaction } var file_controlplane_v1_organization_proto_depIdxs = []int32{ 12, // 0: controlplane.v1.OrganizationServiceListMembershipsRequest.role:type_name -> controlplane.v1.MembershipRole @@ -791,24 +802,25 @@ var file_controlplane_v1_organization_proto_depIdxs = []int32{ 12, // 4: controlplane.v1.OrganizationServiceUpdateMembershipRequest.role:type_name -> controlplane.v1.MembershipRole 14, // 5: controlplane.v1.OrganizationServiceUpdateMembershipResponse.result:type_name -> controlplane.v1.OrgMembershipItem 16, // 6: controlplane.v1.OrganizationServiceCreateResponse.result:type_name -> controlplane.v1.OrgItem - 16, // 7: controlplane.v1.OrganizationServiceUpdateResponse.result:type_name -> controlplane.v1.OrgItem - 6, // 8: controlplane.v1.OrganizationService.Create:input_type -> controlplane.v1.OrganizationServiceCreateRequest - 8, // 9: controlplane.v1.OrganizationService.Update:input_type -> controlplane.v1.OrganizationServiceUpdateRequest - 10, // 10: controlplane.v1.OrganizationService.Delete:input_type -> controlplane.v1.OrganizationServiceDeleteRequest - 0, // 11: controlplane.v1.OrganizationService.ListMemberships:input_type -> controlplane.v1.OrganizationServiceListMembershipsRequest - 2, // 12: controlplane.v1.OrganizationService.DeleteMembership:input_type -> controlplane.v1.OrganizationServiceDeleteMembershipRequest - 4, // 13: controlplane.v1.OrganizationService.UpdateMembership:input_type -> controlplane.v1.OrganizationServiceUpdateMembershipRequest - 7, // 14: controlplane.v1.OrganizationService.Create:output_type -> controlplane.v1.OrganizationServiceCreateResponse - 9, // 15: controlplane.v1.OrganizationService.Update:output_type -> controlplane.v1.OrganizationServiceUpdateResponse - 11, // 16: controlplane.v1.OrganizationService.Delete:output_type -> controlplane.v1.OrganizationServiceDeleteResponse - 1, // 17: controlplane.v1.OrganizationService.ListMemberships:output_type -> controlplane.v1.OrganizationServiceListMembershipsResponse - 3, // 18: controlplane.v1.OrganizationService.DeleteMembership:output_type -> controlplane.v1.OrganizationServiceDeleteMembershipResponse - 5, // 19: controlplane.v1.OrganizationService.UpdateMembership:output_type -> controlplane.v1.OrganizationServiceUpdateMembershipResponse - 14, // [14:20] is the sub-list for method output_type - 8, // [8:14] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 17, // 7: controlplane.v1.OrganizationServiceUpdateRequest.env_var_redaction:type_name -> controlplane.v1.EnvVarRedaction + 16, // 8: controlplane.v1.OrganizationServiceUpdateResponse.result:type_name -> controlplane.v1.OrgItem + 6, // 9: controlplane.v1.OrganizationService.Create:input_type -> controlplane.v1.OrganizationServiceCreateRequest + 8, // 10: controlplane.v1.OrganizationService.Update:input_type -> controlplane.v1.OrganizationServiceUpdateRequest + 10, // 11: controlplane.v1.OrganizationService.Delete:input_type -> controlplane.v1.OrganizationServiceDeleteRequest + 0, // 12: controlplane.v1.OrganizationService.ListMemberships:input_type -> controlplane.v1.OrganizationServiceListMembershipsRequest + 2, // 13: controlplane.v1.OrganizationService.DeleteMembership:input_type -> controlplane.v1.OrganizationServiceDeleteMembershipRequest + 4, // 14: controlplane.v1.OrganizationService.UpdateMembership:input_type -> controlplane.v1.OrganizationServiceUpdateMembershipRequest + 7, // 15: controlplane.v1.OrganizationService.Create:output_type -> controlplane.v1.OrganizationServiceCreateResponse + 9, // 16: controlplane.v1.OrganizationService.Update:output_type -> controlplane.v1.OrganizationServiceUpdateResponse + 11, // 17: controlplane.v1.OrganizationService.Delete:output_type -> controlplane.v1.OrganizationServiceDeleteResponse + 1, // 18: controlplane.v1.OrganizationService.ListMemberships:output_type -> controlplane.v1.OrganizationServiceListMembershipsResponse + 3, // 19: controlplane.v1.OrganizationService.DeleteMembership:output_type -> controlplane.v1.OrganizationServiceDeleteMembershipResponse + 5, // 20: controlplane.v1.OrganizationService.UpdateMembership:output_type -> controlplane.v1.OrganizationServiceUpdateMembershipResponse + 15, // [15:21] is the sub-list for method output_type + 9, // [9:15] is the sub-list for method input_type + 9, // [9:9] is the sub-list for extension type_name + 9, // [9:9] is the sub-list for extension extendee + 0, // [0:9] is the sub-list for field type_name } func init() { file_controlplane_v1_organization_proto_init() } diff --git a/app/controlplane/api/controlplane/v1/organization.proto b/app/controlplane/api/controlplane/v1/organization.proto index c6d6ef4f7..d863f719a 100644 --- a/app/controlplane/api/controlplane/v1/organization.proto +++ b/app/controlplane/api/controlplane/v1/organization.proto @@ -111,6 +111,9 @@ message OrganizationServiceUpdateRequest { // Opt out of storing the environment variables automatically discovered by the CI runner in the attestation optional bool skip_runner_env_vars = 10; + + // Redaction of environment variable values in new attestations. Not set means no change. + EnvVarRedaction env_var_redaction = 11; } message OrganizationServiceUpdateResponse { diff --git a/app/controlplane/api/controlplane/v1/response_messages.pb.go b/app/controlplane/api/controlplane/v1/response_messages.pb.go index dd0a11e4d..58be5eacb 100644 --- a/app/controlplane/api/controlplane/v1/response_messages.pb.go +++ b/app/controlplane/api/controlplane/v1/response_messages.pb.go @@ -731,6 +731,58 @@ func (OrgItem_PolicyViolationBlockingStrategy) EnumDescriptor() ([]byte, []int) return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{16, 0} } +type EnvVarRedaction_Type int32 + +const ( + // no redaction + EnvVarRedaction_TYPE_UNSPECIFIED EnvVarRedaction_Type = 0 + // redact the variables that Chainloop runner integrations mark as identifying a person + EnvVarRedaction_TYPE_KNOWN_IDENTITY EnvVarRedaction_Type = 1 + // redact only the variables listed in env_vars + EnvVarRedaction_TYPE_CUSTOM EnvVarRedaction_Type = 2 +) + +// Enum value maps for EnvVarRedaction_Type. +var ( + EnvVarRedaction_Type_name = map[int32]string{ + 0: "TYPE_UNSPECIFIED", + 1: "TYPE_KNOWN_IDENTITY", + 2: "TYPE_CUSTOM", + } + EnvVarRedaction_Type_value = map[string]int32{ + "TYPE_UNSPECIFIED": 0, + "TYPE_KNOWN_IDENTITY": 1, + "TYPE_CUSTOM": 2, + } +) + +func (x EnvVarRedaction_Type) Enum() *EnvVarRedaction_Type { + p := new(EnvVarRedaction_Type) + *p = x + return p +} + +func (x EnvVarRedaction_Type) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (EnvVarRedaction_Type) Descriptor() protoreflect.EnumDescriptor { + return file_controlplane_v1_response_messages_proto_enumTypes[13].Descriptor() +} + +func (EnvVarRedaction_Type) Type() protoreflect.EnumType { + return &file_controlplane_v1_response_messages_proto_enumTypes[13] +} + +func (x EnvVarRedaction_Type) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use EnvVarRedaction_Type.Descriptor instead. +func (EnvVarRedaction_Type) EnumDescriptor() ([]byte, []int) { + return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{17, 0} +} + type CASBackendItem_ValidationStatus int32 const ( @@ -764,11 +816,11 @@ func (x CASBackendItem_ValidationStatus) String() string { } func (CASBackendItem_ValidationStatus) Descriptor() protoreflect.EnumDescriptor { - return file_controlplane_v1_response_messages_proto_enumTypes[13].Descriptor() + return file_controlplane_v1_response_messages_proto_enumTypes[14].Descriptor() } func (CASBackendItem_ValidationStatus) Type() protoreflect.EnumType { - return &file_controlplane_v1_response_messages_proto_enumTypes[13] + return &file_controlplane_v1_response_messages_proto_enumTypes[14] } func (x CASBackendItem_ValidationStatus) Number() protoreflect.EnumNumber { @@ -777,7 +829,7 @@ func (x CASBackendItem_ValidationStatus) Number() protoreflect.EnumNumber { // Deprecated: Use CASBackendItem_ValidationStatus.Descriptor instead. func (CASBackendItem_ValidationStatus) EnumDescriptor() ([]byte, []int) { - return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{17, 0} + return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{18, 0} } type WorkflowItem struct { @@ -2468,8 +2520,10 @@ type OrgItem struct { BlockAttestationsOnReleasedVersions bool `protobuf:"varint,11,opt,name=block_attestations_on_released_versions,json=blockAttestationsOnReleasedVersions,proto3" json:"block_attestations_on_released_versions,omitempty"` // Whether the environment variables automatically discovered by the CI runner are skipped from the attestation SkipRunnerEnvVars bool `protobuf:"varint,12,opt,name=skip_runner_env_vars,json=skipRunnerEnvVars,proto3" json:"skip_runner_env_vars,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // Redaction of the values of environment variables stored in new attestations + EnvVarRedaction *EnvVarRedaction `protobuf:"bytes,13,opt,name=env_var_redaction,json=envVarRedaction,proto3" json:"env_var_redaction,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *OrgItem) Reset() { @@ -2586,6 +2640,68 @@ func (x *OrgItem) GetSkipRunnerEnvVars() bool { return false } +func (x *OrgItem) GetEnvVarRedaction() *EnvVarRedaction { + if x != nil { + return x.EnvVarRedaction + } + return nil +} + +// EnvVarRedaction configures which environment variable values are replaced with "[REDACTED]" +// in new attestations. It applies to runner-discovered variables and to the contract's env allow list. +type EnvVarRedaction struct { + state protoimpl.MessageState `protogen:"open.v1"` + Type EnvVarRedaction_Type `protobuf:"varint,1,opt,name=type,proto3,enum=controlplane.v1.EnvVarRedaction_Type" json:"type,omitempty"` + // Exact variable names. Required when type is TYPE_CUSTOM. + EnvVars []string `protobuf:"bytes,2,rep,name=env_vars,json=envVars,proto3" json:"env_vars,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EnvVarRedaction) Reset() { + *x = EnvVarRedaction{} + mi := &file_controlplane_v1_response_messages_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EnvVarRedaction) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EnvVarRedaction) ProtoMessage() {} + +func (x *EnvVarRedaction) ProtoReflect() protoreflect.Message { + mi := &file_controlplane_v1_response_messages_proto_msgTypes[17] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EnvVarRedaction.ProtoReflect.Descriptor instead. +func (*EnvVarRedaction) Descriptor() ([]byte, []int) { + return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{17} +} + +func (x *EnvVarRedaction) GetType() EnvVarRedaction_Type { + if x != nil { + return x.Type + } + return EnvVarRedaction_TYPE_UNSPECIFIED +} + +func (x *EnvVarRedaction) GetEnvVars() []string { + if x != nil { + return x.EnvVars + } + return nil +} + type CASBackendItem struct { state protoimpl.MessageState `protogen:"open.v1"` Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` @@ -2618,7 +2734,7 @@ type CASBackendItem struct { func (x *CASBackendItem) Reset() { *x = CASBackendItem{} - mi := &file_controlplane_v1_response_messages_proto_msgTypes[17] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2630,7 +2746,7 @@ func (x *CASBackendItem) String() string { func (*CASBackendItem) ProtoMessage() {} func (x *CASBackendItem) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_response_messages_proto_msgTypes[17] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[18] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2643,7 +2759,7 @@ func (x *CASBackendItem) ProtoReflect() protoreflect.Message { // Deprecated: Use CASBackendItem.ProtoReflect.Descriptor instead. func (*CASBackendItem) Descriptor() ([]byte, []int) { - return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{17} + return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{18} } func (x *CASBackendItem) GetId() string { @@ -2770,7 +2886,7 @@ type APITokenItem struct { func (x *APITokenItem) Reset() { *x = APITokenItem{} - mi := &file_controlplane_v1_response_messages_proto_msgTypes[18] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2782,7 +2898,7 @@ func (x *APITokenItem) String() string { func (*APITokenItem) ProtoMessage() {} func (x *APITokenItem) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_response_messages_proto_msgTypes[18] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[19] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2795,7 +2911,7 @@ func (x *APITokenItem) ProtoReflect() protoreflect.Message { // Deprecated: Use APITokenItem.ProtoReflect.Descriptor instead. func (*APITokenItem) Descriptor() ([]byte, []int) { - return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{18} + return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{19} } func (x *APITokenItem) GetId() string { @@ -2893,7 +3009,7 @@ type AttestationItem_PolicyEvaluationStatus struct { func (x *AttestationItem_PolicyEvaluationStatus) Reset() { *x = AttestationItem_PolicyEvaluationStatus{} - mi := &file_controlplane_v1_response_messages_proto_msgTypes[21] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2905,7 +3021,7 @@ func (x *AttestationItem_PolicyEvaluationStatus) String() string { func (*AttestationItem_PolicyEvaluationStatus) ProtoMessage() {} func (x *AttestationItem_PolicyEvaluationStatus) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_response_messages_proto_msgTypes[21] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[22] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2989,7 +3105,7 @@ type AttestationItem_EnvVariable struct { func (x *AttestationItem_EnvVariable) Reset() { *x = AttestationItem_EnvVariable{} - mi := &file_controlplane_v1_response_messages_proto_msgTypes[22] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3001,7 +3117,7 @@ func (x *AttestationItem_EnvVariable) String() string { func (*AttestationItem_EnvVariable) ProtoMessage() {} func (x *AttestationItem_EnvVariable) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_response_messages_proto_msgTypes[22] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[23] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3062,7 +3178,7 @@ type AttestationItem_Material struct { func (x *AttestationItem_Material) Reset() { *x = AttestationItem_Material{} - mi := &file_controlplane_v1_response_messages_proto_msgTypes[23] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3074,7 +3190,7 @@ func (x *AttestationItem_Material) String() string { func (*AttestationItem_Material) ProtoMessage() {} func (x *AttestationItem_Material) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_response_messages_proto_msgTypes[23] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[24] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3171,7 +3287,7 @@ type WorkflowContractVersionItem_RawBody struct { func (x *WorkflowContractVersionItem_RawBody) Reset() { *x = WorkflowContractVersionItem_RawBody{} - mi := &file_controlplane_v1_response_messages_proto_msgTypes[28] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3183,7 +3299,7 @@ func (x *WorkflowContractVersionItem_RawBody) String() string { func (*WorkflowContractVersionItem_RawBody) ProtoMessage() {} func (x *WorkflowContractVersionItem_RawBody) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_response_messages_proto_msgTypes[28] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[29] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3223,7 +3339,7 @@ type CASBackendItem_Limits struct { func (x *CASBackendItem_Limits) Reset() { *x = CASBackendItem_Limits{} - mi := &file_controlplane_v1_response_messages_proto_msgTypes[29] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[30] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3235,7 +3351,7 @@ func (x *CASBackendItem_Limits) String() string { func (*CASBackendItem_Limits) ProtoMessage() {} func (x *CASBackendItem_Limits) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_response_messages_proto_msgTypes[29] + mi := &file_controlplane_v1_response_messages_proto_msgTypes[30] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3248,7 +3364,7 @@ func (x *CASBackendItem_Limits) ProtoReflect() protoreflect.Message { // Deprecated: Use CASBackendItem_Limits.ProtoReflect.Descriptor instead. func (*CASBackendItem_Limits) Descriptor() ([]byte, []int) { - return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{17, 0} + return file_controlplane_v1_response_messages_proto_rawDescGZIP(), []int{18, 0} } func (x *CASBackendItem_Limits) GetMaxBytes() int64 { @@ -3485,7 +3601,7 @@ const file_controlplane_v1_response_messages_proto_rawDesc = "" + "created_at\x18\x04 \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\x129\n" + "\n" + "updated_at\x18\x05 \x01(\v2\x1a.google.protobuf.TimestampR\tupdatedAt\x123\n" + - "\x04role\x18\x06 \x01(\x0e2\x1f.controlplane.v1.MembershipRoleR\x04role\"\xe3\a\n" + + "\x04role\x18\x06 \x01(\x0e2\x1f.controlplane.v1.MembershipRoleR\x04role\"\xb1\b\n" + "\aOrgItem\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" + "\x04name\x18\x02 \x01(\tR\x04name\x129\n" + @@ -3501,12 +3617,20 @@ const file_controlplane_v1_response_messages_proto_rawDesc = "" + "\x19enable_ai_agent_collector\x18\n" + " \x01(\bR\x16enableAiAgentCollector\x12T\n" + "'block_attestations_on_released_versions\x18\v \x01(\bR#blockAttestationsOnReleasedVersions\x12/\n" + - "\x14skip_runner_env_vars\x18\f \x01(\bR\x11skipRunnerEnvVars\"\xb4\x01\n" + + "\x14skip_runner_env_vars\x18\f \x01(\bR\x11skipRunnerEnvVars\x12L\n" + + "\x11env_var_redaction\x18\r \x01(\v2 .controlplane.v1.EnvVarRedactionR\x0fenvVarRedaction\"\xb4\x01\n" + "\x1fPolicyViolationBlockingStrategy\x122\n" + ".POLICY_VIOLATION_BLOCKING_STRATEGY_UNSPECIFIED\x10\x00\x12,\n" + "(POLICY_VIOLATION_BLOCKING_STRATEGY_BLOCK\x10\x01\x12/\n" + "+POLICY_VIOLATION_BLOCKING_STRATEGY_ADVISORY\x10\x02B\x1e\n" + - "\x1c_api_token_max_days_inactive\"\xb0\x06\n" + + "\x1c_api_token_max_days_inactive\"\xaf\x01\n" + + "\x0fEnvVarRedaction\x129\n" + + "\x04type\x18\x01 \x01(\x0e2%.controlplane.v1.EnvVarRedaction.TypeR\x04type\x12\x19\n" + + "\benv_vars\x18\x02 \x03(\tR\aenvVars\"F\n" + + "\x04Type\x12\x14\n" + + "\x10TYPE_UNSPECIFIED\x10\x00\x12\x17\n" + + "\x13TYPE_KNOWN_IDENTITY\x10\x01\x12\x0f\n" + + "\vTYPE_CUSTOM\x10\x02\"\xb0\x06\n" + "\x0eCASBackendItem\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" + "\x04name\x18\v \x01(\tR\x04name\x12\x1a\n" + @@ -3613,8 +3737,8 @@ func file_controlplane_v1_response_messages_proto_rawDescGZIP() []byte { return file_controlplane_v1_response_messages_proto_rawDescData } -var file_controlplane_v1_response_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 14) -var file_controlplane_v1_response_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 30) +var file_controlplane_v1_response_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 15) +var file_controlplane_v1_response_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 31) var file_controlplane_v1_response_messages_proto_goTypes = []any{ (RunStatus)(0), // 0: controlplane.v1.RunStatus (PolicyViolationsFilter)(0), // 1: controlplane.v1.PolicyViolationsFilter @@ -3629,112 +3753,116 @@ var file_controlplane_v1_response_messages_proto_goTypes = []any{ (PolicyEvaluationsRef_Reason)(0), // 10: controlplane.v1.PolicyEvaluationsRef.Reason (WorkflowContractVersionItem_RawBody_Format)(0), // 11: controlplane.v1.WorkflowContractVersionItem.RawBody.Format (OrgItem_PolicyViolationBlockingStrategy)(0), // 12: controlplane.v1.OrgItem.PolicyViolationBlockingStrategy - (CASBackendItem_ValidationStatus)(0), // 13: controlplane.v1.CASBackendItem.ValidationStatus - (*WorkflowItem)(nil), // 14: controlplane.v1.WorkflowItem - (*WorkflowRunItem)(nil), // 15: controlplane.v1.WorkflowRunItem - (*ProjectVersion)(nil), // 16: controlplane.v1.ProjectVersion - (*PolicyStatusSummary)(nil), // 17: controlplane.v1.PolicyStatusSummary - (*AttestationItem)(nil), // 18: controlplane.v1.AttestationItem - (*PolicyEvaluationsRef)(nil), // 19: controlplane.v1.PolicyEvaluationsRef - (*PolicyEvaluations)(nil), // 20: controlplane.v1.PolicyEvaluations - (*PolicyEvaluation)(nil), // 21: controlplane.v1.PolicyEvaluation - (*PolicyViolation)(nil), // 22: controlplane.v1.PolicyViolation - (*PolicyReference)(nil), // 23: controlplane.v1.PolicyReference - (*WorkflowContractItem)(nil), // 24: controlplane.v1.WorkflowContractItem - (*ScopedEntity)(nil), // 25: controlplane.v1.ScopedEntity - (*WorkflowRef)(nil), // 26: controlplane.v1.WorkflowRef - (*WorkflowContractVersionItem)(nil), // 27: controlplane.v1.WorkflowContractVersionItem - (*User)(nil), // 28: controlplane.v1.User - (*OrgMembershipItem)(nil), // 29: controlplane.v1.OrgMembershipItem - (*OrgItem)(nil), // 30: controlplane.v1.OrgItem - (*CASBackendItem)(nil), // 31: controlplane.v1.CASBackendItem - (*APITokenItem)(nil), // 32: controlplane.v1.APITokenItem - nil, // 33: controlplane.v1.AttestationItem.AnnotationsEntry - nil, // 34: controlplane.v1.AttestationItem.PolicyEvaluationsEntry - (*AttestationItem_PolicyEvaluationStatus)(nil), // 35: controlplane.v1.AttestationItem.PolicyEvaluationStatus - (*AttestationItem_EnvVariable)(nil), // 36: controlplane.v1.AttestationItem.EnvVariable - (*AttestationItem_Material)(nil), // 37: controlplane.v1.AttestationItem.Material - nil, // 38: controlplane.v1.AttestationItem.Material.AnnotationsEntry - nil, // 39: controlplane.v1.PolicyEvaluation.AnnotationsEntry - nil, // 40: controlplane.v1.PolicyEvaluation.WithEntry - nil, // 41: controlplane.v1.PolicyReference.DigestEntry - (*WorkflowContractVersionItem_RawBody)(nil), // 42: controlplane.v1.WorkflowContractVersionItem.RawBody - (*CASBackendItem_Limits)(nil), // 43: controlplane.v1.CASBackendItem.Limits - (*timestamppb.Timestamp)(nil), // 44: google.protobuf.Timestamp - (v1.CraftingSchema_Runner_RunnerType)(0), // 45: workflowcontract.v1.CraftingSchema.Runner.RunnerType - (*v11.PolicyVulnerabilityFinding)(nil), // 46: attestation.v1.PolicyVulnerabilityFinding - (*v11.PolicySASTFinding)(nil), // 47: attestation.v1.PolicySASTFinding - (*v11.PolicyLicenseViolationFinding)(nil), // 48: attestation.v1.PolicyLicenseViolationFinding - (*v1.CraftingSchema)(nil), // 49: workflowcontract.v1.CraftingSchema + (EnvVarRedaction_Type)(0), // 13: controlplane.v1.EnvVarRedaction.Type + (CASBackendItem_ValidationStatus)(0), // 14: controlplane.v1.CASBackendItem.ValidationStatus + (*WorkflowItem)(nil), // 15: controlplane.v1.WorkflowItem + (*WorkflowRunItem)(nil), // 16: controlplane.v1.WorkflowRunItem + (*ProjectVersion)(nil), // 17: controlplane.v1.ProjectVersion + (*PolicyStatusSummary)(nil), // 18: controlplane.v1.PolicyStatusSummary + (*AttestationItem)(nil), // 19: controlplane.v1.AttestationItem + (*PolicyEvaluationsRef)(nil), // 20: controlplane.v1.PolicyEvaluationsRef + (*PolicyEvaluations)(nil), // 21: controlplane.v1.PolicyEvaluations + (*PolicyEvaluation)(nil), // 22: controlplane.v1.PolicyEvaluation + (*PolicyViolation)(nil), // 23: controlplane.v1.PolicyViolation + (*PolicyReference)(nil), // 24: controlplane.v1.PolicyReference + (*WorkflowContractItem)(nil), // 25: controlplane.v1.WorkflowContractItem + (*ScopedEntity)(nil), // 26: controlplane.v1.ScopedEntity + (*WorkflowRef)(nil), // 27: controlplane.v1.WorkflowRef + (*WorkflowContractVersionItem)(nil), // 28: controlplane.v1.WorkflowContractVersionItem + (*User)(nil), // 29: controlplane.v1.User + (*OrgMembershipItem)(nil), // 30: controlplane.v1.OrgMembershipItem + (*OrgItem)(nil), // 31: controlplane.v1.OrgItem + (*EnvVarRedaction)(nil), // 32: controlplane.v1.EnvVarRedaction + (*CASBackendItem)(nil), // 33: controlplane.v1.CASBackendItem + (*APITokenItem)(nil), // 34: controlplane.v1.APITokenItem + nil, // 35: controlplane.v1.AttestationItem.AnnotationsEntry + nil, // 36: controlplane.v1.AttestationItem.PolicyEvaluationsEntry + (*AttestationItem_PolicyEvaluationStatus)(nil), // 37: controlplane.v1.AttestationItem.PolicyEvaluationStatus + (*AttestationItem_EnvVariable)(nil), // 38: controlplane.v1.AttestationItem.EnvVariable + (*AttestationItem_Material)(nil), // 39: controlplane.v1.AttestationItem.Material + nil, // 40: controlplane.v1.AttestationItem.Material.AnnotationsEntry + nil, // 41: controlplane.v1.PolicyEvaluation.AnnotationsEntry + nil, // 42: controlplane.v1.PolicyEvaluation.WithEntry + nil, // 43: controlplane.v1.PolicyReference.DigestEntry + (*WorkflowContractVersionItem_RawBody)(nil), // 44: controlplane.v1.WorkflowContractVersionItem.RawBody + (*CASBackendItem_Limits)(nil), // 45: controlplane.v1.CASBackendItem.Limits + (*timestamppb.Timestamp)(nil), // 46: google.protobuf.Timestamp + (v1.CraftingSchema_Runner_RunnerType)(0), // 47: workflowcontract.v1.CraftingSchema.Runner.RunnerType + (*v11.PolicyVulnerabilityFinding)(nil), // 48: attestation.v1.PolicyVulnerabilityFinding + (*v11.PolicySASTFinding)(nil), // 49: attestation.v1.PolicySASTFinding + (*v11.PolicyLicenseViolationFinding)(nil), // 50: attestation.v1.PolicyLicenseViolationFinding + (*v1.CraftingSchema)(nil), // 51: workflowcontract.v1.CraftingSchema } var file_controlplane_v1_response_messages_proto_depIdxs = []int32{ - 44, // 0: controlplane.v1.WorkflowItem.created_at:type_name -> google.protobuf.Timestamp - 15, // 1: controlplane.v1.WorkflowItem.last_run:type_name -> controlplane.v1.WorkflowRunItem - 44, // 2: controlplane.v1.WorkflowRunItem.created_at:type_name -> google.protobuf.Timestamp - 44, // 3: controlplane.v1.WorkflowRunItem.finished_at:type_name -> google.protobuf.Timestamp + 46, // 0: controlplane.v1.WorkflowItem.created_at:type_name -> google.protobuf.Timestamp + 16, // 1: controlplane.v1.WorkflowItem.last_run:type_name -> controlplane.v1.WorkflowRunItem + 46, // 2: controlplane.v1.WorkflowRunItem.created_at:type_name -> google.protobuf.Timestamp + 46, // 3: controlplane.v1.WorkflowRunItem.finished_at:type_name -> google.protobuf.Timestamp 0, // 4: controlplane.v1.WorkflowRunItem.status:type_name -> controlplane.v1.RunStatus - 14, // 5: controlplane.v1.WorkflowRunItem.workflow:type_name -> controlplane.v1.WorkflowItem - 45, // 6: controlplane.v1.WorkflowRunItem.runner_type:type_name -> workflowcontract.v1.CraftingSchema.Runner.RunnerType - 27, // 7: controlplane.v1.WorkflowRunItem.contract_version:type_name -> controlplane.v1.WorkflowContractVersionItem - 16, // 8: controlplane.v1.WorkflowRunItem.version:type_name -> controlplane.v1.ProjectVersion - 17, // 9: controlplane.v1.WorkflowRunItem.policy_summary:type_name -> controlplane.v1.PolicyStatusSummary - 44, // 10: controlplane.v1.ProjectVersion.created_at:type_name -> google.protobuf.Timestamp - 44, // 11: controlplane.v1.ProjectVersion.released_at:type_name -> google.protobuf.Timestamp + 15, // 5: controlplane.v1.WorkflowRunItem.workflow:type_name -> controlplane.v1.WorkflowItem + 47, // 6: controlplane.v1.WorkflowRunItem.runner_type:type_name -> workflowcontract.v1.CraftingSchema.Runner.RunnerType + 28, // 7: controlplane.v1.WorkflowRunItem.contract_version:type_name -> controlplane.v1.WorkflowContractVersionItem + 17, // 8: controlplane.v1.WorkflowRunItem.version:type_name -> controlplane.v1.ProjectVersion + 18, // 9: controlplane.v1.WorkflowRunItem.policy_summary:type_name -> controlplane.v1.PolicyStatusSummary + 46, // 10: controlplane.v1.ProjectVersion.created_at:type_name -> google.protobuf.Timestamp + 46, // 11: controlplane.v1.ProjectVersion.released_at:type_name -> google.protobuf.Timestamp 2, // 12: controlplane.v1.PolicyStatusSummary.status:type_name -> controlplane.v1.PolicyStatus - 36, // 13: controlplane.v1.AttestationItem.env_vars:type_name -> controlplane.v1.AttestationItem.EnvVariable - 37, // 14: controlplane.v1.AttestationItem.materials:type_name -> controlplane.v1.AttestationItem.Material - 33, // 15: controlplane.v1.AttestationItem.annotations:type_name -> controlplane.v1.AttestationItem.AnnotationsEntry - 34, // 16: controlplane.v1.AttestationItem.policy_evaluations:type_name -> controlplane.v1.AttestationItem.PolicyEvaluationsEntry - 35, // 17: controlplane.v1.AttestationItem.policy_evaluation_status:type_name -> controlplane.v1.AttestationItem.PolicyEvaluationStatus - 19, // 18: controlplane.v1.AttestationItem.policy_evaluations_ref:type_name -> controlplane.v1.PolicyEvaluationsRef + 38, // 13: controlplane.v1.AttestationItem.env_vars:type_name -> controlplane.v1.AttestationItem.EnvVariable + 39, // 14: controlplane.v1.AttestationItem.materials:type_name -> controlplane.v1.AttestationItem.Material + 35, // 15: controlplane.v1.AttestationItem.annotations:type_name -> controlplane.v1.AttestationItem.AnnotationsEntry + 36, // 16: controlplane.v1.AttestationItem.policy_evaluations:type_name -> controlplane.v1.AttestationItem.PolicyEvaluationsEntry + 37, // 17: controlplane.v1.AttestationItem.policy_evaluation_status:type_name -> controlplane.v1.AttestationItem.PolicyEvaluationStatus + 20, // 18: controlplane.v1.AttestationItem.policy_evaluations_ref:type_name -> controlplane.v1.PolicyEvaluationsRef 10, // 19: controlplane.v1.PolicyEvaluationsRef.reason:type_name -> controlplane.v1.PolicyEvaluationsRef.Reason - 21, // 20: controlplane.v1.PolicyEvaluations.evaluations:type_name -> controlplane.v1.PolicyEvaluation - 39, // 21: controlplane.v1.PolicyEvaluation.annotations:type_name -> controlplane.v1.PolicyEvaluation.AnnotationsEntry - 40, // 22: controlplane.v1.PolicyEvaluation.with:type_name -> controlplane.v1.PolicyEvaluation.WithEntry - 22, // 23: controlplane.v1.PolicyEvaluation.violations:type_name -> controlplane.v1.PolicyViolation - 23, // 24: controlplane.v1.PolicyEvaluation.policy_reference:type_name -> controlplane.v1.PolicyReference - 23, // 25: controlplane.v1.PolicyEvaluation.group_reference:type_name -> controlplane.v1.PolicyReference - 46, // 26: controlplane.v1.PolicyViolation.vulnerability:type_name -> attestation.v1.PolicyVulnerabilityFinding - 47, // 27: controlplane.v1.PolicyViolation.sast:type_name -> attestation.v1.PolicySASTFinding - 48, // 28: controlplane.v1.PolicyViolation.license_violation:type_name -> attestation.v1.PolicyLicenseViolationFinding - 41, // 29: controlplane.v1.PolicyReference.digest:type_name -> controlplane.v1.PolicyReference.DigestEntry - 44, // 30: controlplane.v1.WorkflowContractItem.created_at:type_name -> google.protobuf.Timestamp - 44, // 31: controlplane.v1.WorkflowContractItem.updated_at:type_name -> google.protobuf.Timestamp - 44, // 32: controlplane.v1.WorkflowContractItem.latest_revision_created_at:type_name -> google.protobuf.Timestamp - 26, // 33: controlplane.v1.WorkflowContractItem.workflow_refs:type_name -> controlplane.v1.WorkflowRef - 25, // 34: controlplane.v1.WorkflowContractItem.scoped_entity:type_name -> controlplane.v1.ScopedEntity - 44, // 35: controlplane.v1.WorkflowContractVersionItem.created_at:type_name -> google.protobuf.Timestamp - 49, // 36: controlplane.v1.WorkflowContractVersionItem.v1:type_name -> workflowcontract.v1.CraftingSchema - 42, // 37: controlplane.v1.WorkflowContractVersionItem.raw_contract:type_name -> controlplane.v1.WorkflowContractVersionItem.RawBody - 44, // 38: controlplane.v1.User.created_at:type_name -> google.protobuf.Timestamp - 44, // 39: controlplane.v1.User.updated_at:type_name -> google.protobuf.Timestamp - 30, // 40: controlplane.v1.OrgMembershipItem.org:type_name -> controlplane.v1.OrgItem - 28, // 41: controlplane.v1.OrgMembershipItem.user:type_name -> controlplane.v1.User - 44, // 42: controlplane.v1.OrgMembershipItem.created_at:type_name -> google.protobuf.Timestamp - 44, // 43: controlplane.v1.OrgMembershipItem.updated_at:type_name -> google.protobuf.Timestamp + 22, // 20: controlplane.v1.PolicyEvaluations.evaluations:type_name -> controlplane.v1.PolicyEvaluation + 41, // 21: controlplane.v1.PolicyEvaluation.annotations:type_name -> controlplane.v1.PolicyEvaluation.AnnotationsEntry + 42, // 22: controlplane.v1.PolicyEvaluation.with:type_name -> controlplane.v1.PolicyEvaluation.WithEntry + 23, // 23: controlplane.v1.PolicyEvaluation.violations:type_name -> controlplane.v1.PolicyViolation + 24, // 24: controlplane.v1.PolicyEvaluation.policy_reference:type_name -> controlplane.v1.PolicyReference + 24, // 25: controlplane.v1.PolicyEvaluation.group_reference:type_name -> controlplane.v1.PolicyReference + 48, // 26: controlplane.v1.PolicyViolation.vulnerability:type_name -> attestation.v1.PolicyVulnerabilityFinding + 49, // 27: controlplane.v1.PolicyViolation.sast:type_name -> attestation.v1.PolicySASTFinding + 50, // 28: controlplane.v1.PolicyViolation.license_violation:type_name -> attestation.v1.PolicyLicenseViolationFinding + 43, // 29: controlplane.v1.PolicyReference.digest:type_name -> controlplane.v1.PolicyReference.DigestEntry + 46, // 30: controlplane.v1.WorkflowContractItem.created_at:type_name -> google.protobuf.Timestamp + 46, // 31: controlplane.v1.WorkflowContractItem.updated_at:type_name -> google.protobuf.Timestamp + 46, // 32: controlplane.v1.WorkflowContractItem.latest_revision_created_at:type_name -> google.protobuf.Timestamp + 27, // 33: controlplane.v1.WorkflowContractItem.workflow_refs:type_name -> controlplane.v1.WorkflowRef + 26, // 34: controlplane.v1.WorkflowContractItem.scoped_entity:type_name -> controlplane.v1.ScopedEntity + 46, // 35: controlplane.v1.WorkflowContractVersionItem.created_at:type_name -> google.protobuf.Timestamp + 51, // 36: controlplane.v1.WorkflowContractVersionItem.v1:type_name -> workflowcontract.v1.CraftingSchema + 44, // 37: controlplane.v1.WorkflowContractVersionItem.raw_contract:type_name -> controlplane.v1.WorkflowContractVersionItem.RawBody + 46, // 38: controlplane.v1.User.created_at:type_name -> google.protobuf.Timestamp + 46, // 39: controlplane.v1.User.updated_at:type_name -> google.protobuf.Timestamp + 31, // 40: controlplane.v1.OrgMembershipItem.org:type_name -> controlplane.v1.OrgItem + 29, // 41: controlplane.v1.OrgMembershipItem.user:type_name -> controlplane.v1.User + 46, // 42: controlplane.v1.OrgMembershipItem.created_at:type_name -> google.protobuf.Timestamp + 46, // 43: controlplane.v1.OrgMembershipItem.updated_at:type_name -> google.protobuf.Timestamp 5, // 44: controlplane.v1.OrgMembershipItem.role:type_name -> controlplane.v1.MembershipRole - 44, // 45: controlplane.v1.OrgItem.created_at:type_name -> google.protobuf.Timestamp - 44, // 46: controlplane.v1.OrgItem.updated_at:type_name -> google.protobuf.Timestamp + 46, // 45: controlplane.v1.OrgItem.created_at:type_name -> google.protobuf.Timestamp + 46, // 46: controlplane.v1.OrgItem.updated_at:type_name -> google.protobuf.Timestamp 12, // 47: controlplane.v1.OrgItem.default_policy_violation_strategy:type_name -> controlplane.v1.OrgItem.PolicyViolationBlockingStrategy - 44, // 48: controlplane.v1.CASBackendItem.created_at:type_name -> google.protobuf.Timestamp - 44, // 49: controlplane.v1.CASBackendItem.validated_at:type_name -> google.protobuf.Timestamp - 13, // 50: controlplane.v1.CASBackendItem.validation_status:type_name -> controlplane.v1.CASBackendItem.ValidationStatus - 43, // 51: controlplane.v1.CASBackendItem.limits:type_name -> controlplane.v1.CASBackendItem.Limits - 44, // 52: controlplane.v1.CASBackendItem.updated_at:type_name -> google.protobuf.Timestamp - 25, // 53: controlplane.v1.APITokenItem.scoped_entity:type_name -> controlplane.v1.ScopedEntity - 44, // 54: controlplane.v1.APITokenItem.created_at:type_name -> google.protobuf.Timestamp - 44, // 55: controlplane.v1.APITokenItem.revoked_at:type_name -> google.protobuf.Timestamp - 44, // 56: controlplane.v1.APITokenItem.expires_at:type_name -> google.protobuf.Timestamp - 44, // 57: controlplane.v1.APITokenItem.last_used_at:type_name -> google.protobuf.Timestamp - 20, // 58: controlplane.v1.AttestationItem.PolicyEvaluationsEntry.value:type_name -> controlplane.v1.PolicyEvaluations - 17, // 59: controlplane.v1.AttestationItem.PolicyEvaluationStatus.summary:type_name -> controlplane.v1.PolicyStatusSummary - 38, // 60: controlplane.v1.AttestationItem.Material.annotations:type_name -> controlplane.v1.AttestationItem.Material.AnnotationsEntry - 11, // 61: controlplane.v1.WorkflowContractVersionItem.RawBody.format:type_name -> controlplane.v1.WorkflowContractVersionItem.RawBody.Format - 62, // [62:62] is the sub-list for method output_type - 62, // [62:62] is the sub-list for method input_type - 62, // [62:62] is the sub-list for extension type_name - 62, // [62:62] is the sub-list for extension extendee - 0, // [0:62] is the sub-list for field type_name + 32, // 48: controlplane.v1.OrgItem.env_var_redaction:type_name -> controlplane.v1.EnvVarRedaction + 13, // 49: controlplane.v1.EnvVarRedaction.type:type_name -> controlplane.v1.EnvVarRedaction.Type + 46, // 50: controlplane.v1.CASBackendItem.created_at:type_name -> google.protobuf.Timestamp + 46, // 51: controlplane.v1.CASBackendItem.validated_at:type_name -> google.protobuf.Timestamp + 14, // 52: controlplane.v1.CASBackendItem.validation_status:type_name -> controlplane.v1.CASBackendItem.ValidationStatus + 45, // 53: controlplane.v1.CASBackendItem.limits:type_name -> controlplane.v1.CASBackendItem.Limits + 46, // 54: controlplane.v1.CASBackendItem.updated_at:type_name -> google.protobuf.Timestamp + 26, // 55: controlplane.v1.APITokenItem.scoped_entity:type_name -> controlplane.v1.ScopedEntity + 46, // 56: controlplane.v1.APITokenItem.created_at:type_name -> google.protobuf.Timestamp + 46, // 57: controlplane.v1.APITokenItem.revoked_at:type_name -> google.protobuf.Timestamp + 46, // 58: controlplane.v1.APITokenItem.expires_at:type_name -> google.protobuf.Timestamp + 46, // 59: controlplane.v1.APITokenItem.last_used_at:type_name -> google.protobuf.Timestamp + 21, // 60: controlplane.v1.AttestationItem.PolicyEvaluationsEntry.value:type_name -> controlplane.v1.PolicyEvaluations + 18, // 61: controlplane.v1.AttestationItem.PolicyEvaluationStatus.summary:type_name -> controlplane.v1.PolicyStatusSummary + 40, // 62: controlplane.v1.AttestationItem.Material.annotations:type_name -> controlplane.v1.AttestationItem.Material.AnnotationsEntry + 11, // 63: controlplane.v1.WorkflowContractVersionItem.RawBody.format:type_name -> controlplane.v1.WorkflowContractVersionItem.RawBody.Format + 64, // [64:64] is the sub-list for method output_type + 64, // [64:64] is the sub-list for method input_type + 64, // [64:64] is the sub-list for extension type_name + 64, // [64:64] is the sub-list for extension extendee + 0, // [0:64] is the sub-list for field type_name } func init() { file_controlplane_v1_response_messages_proto_init() } @@ -3752,14 +3880,14 @@ func file_controlplane_v1_response_messages_proto_init() { (*WorkflowContractVersionItem_V1)(nil), } file_controlplane_v1_response_messages_proto_msgTypes[16].OneofWrappers = []any{} - file_controlplane_v1_response_messages_proto_msgTypes[17].OneofWrappers = []any{} + file_controlplane_v1_response_messages_proto_msgTypes[18].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_controlplane_v1_response_messages_proto_rawDesc), len(file_controlplane_v1_response_messages_proto_rawDesc)), - NumEnums: 14, - NumMessages: 30, + NumEnums: 15, + NumMessages: 31, NumExtensions: 0, NumServices: 0, }, diff --git a/app/controlplane/api/controlplane/v1/response_messages.proto b/app/controlplane/api/controlplane/v1/response_messages.proto index 4a68911d6..3b17e0c72 100644 --- a/app/controlplane/api/controlplane/v1/response_messages.proto +++ b/app/controlplane/api/controlplane/v1/response_messages.proto @@ -428,6 +428,8 @@ message OrgItem { bool block_attestations_on_released_versions = 11; // Whether the environment variables automatically discovered by the CI runner are skipped from the attestation bool skip_runner_env_vars = 12; + // Redaction of the values of environment variables stored in new attestations + EnvVarRedaction env_var_redaction = 13; enum PolicyViolationBlockingStrategy { POLICY_VIOLATION_BLOCKING_STRATEGY_UNSPECIFIED = 0; @@ -436,6 +438,22 @@ message OrgItem { } } +// EnvVarRedaction configures which environment variable values are replaced with "[REDACTED]" +// in new attestations. It applies to runner-discovered variables and to the contract's env allow list. +message EnvVarRedaction { + enum Type { + // no redaction + TYPE_UNSPECIFIED = 0; + // redact the variables that Chainloop runner integrations mark as identifying a person + TYPE_KNOWN_IDENTITY = 1; + // redact only the variables listed in env_vars + TYPE_CUSTOM = 2; + } + Type type = 1; + // Exact variable names. Required when type is TYPE_CUSTOM. + repeated string env_vars = 2; +} + message CASBackendItem { string id = 1; string name = 11; diff --git a/app/controlplane/api/controlplane/v1/workflow_run.pb.go b/app/controlplane/api/controlplane/v1/workflow_run.pb.go index d87662b4c..529777e3a 100644 --- a/app/controlplane/api/controlplane/v1/workflow_run.pb.go +++ b/app/controlplane/api/controlplane/v1/workflow_run.pb.go @@ -1429,8 +1429,11 @@ type AttestationServiceInitResponse_Result struct { EnableAiAgentCollector bool `protobuf:"varint,8,opt,name=enable_ai_agent_collector,json=enableAiAgentCollector,proto3" json:"enable_ai_agent_collector,omitempty"` // Whether to skip storing the environment variables automatically discovered by the CI runner in the attestation SkipRunnerEnvVars bool `protobuf:"varint,9,opt,name=skip_runner_env_vars,json=skipRunnerEnvVars,proto3" json:"skip_runner_env_vars,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // Names of the environment variables whose values the CLI replaces with "[REDACTED]". + // The control plane resolves them from the org setting and enforces the same list at push. + RedactedEnvVars []string `protobuf:"bytes,10,rep,name=redacted_env_vars,json=redactedEnvVars,proto3" json:"redacted_env_vars,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *AttestationServiceInitResponse_Result) Reset() { @@ -1519,6 +1522,13 @@ func (x *AttestationServiceInitResponse_Result) GetSkipRunnerEnvVars() bool { return false } +func (x *AttestationServiceInitResponse_Result) GetRedactedEnvVars() []string { + if x != nil { + return x.RedactedEnvVars + } + return nil +} + type AttestationServiceInitResponse_SigningOptions struct { state protoimpl.MessageState `protogen:"open.v1"` // TSA service to be used for signing @@ -1843,9 +1853,9 @@ const file_controlplane_v1_workflow_run_proto_rawDesc = "" + "\x18require_existing_version\x18\a \x01(\bR\x16requireExistingVersion\x12,\n" + "\x12use_latest_version\x18\b \x01(\bR\x10useLatestVersion\x12)\n" + "\x0emark_as_latest\x18\t \x01(\bH\x00R\fmarkAsLatest\x88\x01\x01B\x11\n" + - "\x0f_mark_as_latest\"\xc5\x05\n" + + "\x0f_mark_as_latest\"\xf1\x05\n" + "\x1eAttestationServiceInitResponse\x12N\n" + - "\x06result\x18\x01 \x01(\v26.controlplane.v1.AttestationServiceInitResponse.ResultR\x06result\x1a\xe9\x03\n" + + "\x06result\x18\x01 \x01(\v26.controlplane.v1.AttestationServiceInitResponse.ResultR\x06result\x1a\x95\x04\n" + "\x06Result\x12C\n" + "\fworkflow_run\x18\x02 \x01(\v2 .controlplane.v1.WorkflowRunItemR\vworkflowRun\x12\"\n" + "\forganization\x18\x03 \x01(\tR\forganization\x129\n" + @@ -1854,7 +1864,9 @@ const file_controlplane_v1_workflow_run_proto_rawDesc = "" + "\x1apolicies_allowed_hostnames\x18\x06 \x03(\tR\x18policiesAllowedHostnames\x12(\n" + "\x10ui_dashboard_url\x18\a \x01(\tR\x0euiDashboardUrl\x129\n" + "\x19enable_ai_agent_collector\x18\b \x01(\bR\x16enableAiAgentCollector\x12/\n" + - "\x14skip_runner_env_vars\x18\t \x01(\bR\x11skipRunnerEnvVars\x1ag\n" + + "\x14skip_runner_env_vars\x18\t \x01(\bR\x11skipRunnerEnvVars\x12*\n" + + "\x11redacted_env_vars\x18\n" + + " \x03(\tR\x0fredactedEnvVars\x1ag\n" + "\x0eSigningOptions\x126\n" + "\x17timestamp_authority_url\x18\x01 \x01(\tR\x15timestampAuthorityUrl\x12\x1d\n" + "\n" + diff --git a/app/controlplane/api/controlplane/v1/workflow_run.proto b/app/controlplane/api/controlplane/v1/workflow_run.proto index f29492c05..3495f2a1a 100644 --- a/app/controlplane/api/controlplane/v1/workflow_run.proto +++ b/app/controlplane/api/controlplane/v1/workflow_run.proto @@ -154,6 +154,9 @@ message AttestationServiceInitResponse { bool enable_ai_agent_collector = 8; // Whether to skip storing the environment variables automatically discovered by the CI runner in the attestation bool skip_runner_env_vars = 9; + // Names of the environment variables whose values the CLI replaces with "[REDACTED]". + // The control plane resolves them from the org setting and enforces the same list at push. + repeated string redacted_env_vars = 10; } message SigningOptions { diff --git a/app/controlplane/api/gen/frontend/attestation/v1/crafting_state.ts b/app/controlplane/api/gen/frontend/attestation/v1/crafting_state.ts index e7ccd2de2..c3e0050f0 100644 --- a/app/controlplane/api/gen/frontend/attestation/v1/crafting_state.ts +++ b/app/controlplane/api/gen/frontend/attestation/v1/crafting_state.ts @@ -53,6 +53,12 @@ export interface Attestation { * The contract's env_allow_list is not affected by this flag. */ skipRunnerEnvVars: boolean; + /** + * exact names of the environment variables whose values are replaced with "[REDACTED]", + * as resolved by the control plane from the organization setting. + * It applies to the runner env vars and to the contract's env_allow_list. + */ + redactedEnvVars: string[]; } export interface Attestation_MaterialsEntry { @@ -663,6 +669,7 @@ function createBaseAttestation(): Attestation { policiesAllowedHostnames: [], casBackend: undefined, skipRunnerEnvVars: false, + redactedEnvVars: [], }; } @@ -722,6 +729,9 @@ export const Attestation = { if (message.skipRunnerEnvVars === true) { writer.uint32(160).bool(message.skipRunnerEnvVars); } + for (const v of message.redactedEnvVars) { + writer.uint32(170).string(v!); + } return writer; }, @@ -867,6 +877,13 @@ export const Attestation = { message.skipRunnerEnvVars = reader.bool(); continue; + case 21: + if (tag !== 170) { + break; + } + + message.redactedEnvVars.push(reader.string()); + continue; } if ((tag & 7) === 4 || tag === 0) { break; @@ -919,6 +936,7 @@ export const Attestation = { : [], casBackend: isSet(object.casBackend) ? Attestation_CASBackend.fromJSON(object.casBackend) : undefined, skipRunnerEnvVars: isSet(object.skipRunnerEnvVars) ? Boolean(object.skipRunnerEnvVars) : false, + redactedEnvVars: Array.isArray(object?.redactedEnvVars) ? object.redactedEnvVars.map((e: any) => String(e)) : [], }; }, @@ -971,6 +989,11 @@ export const Attestation = { message.casBackend !== undefined && (obj.casBackend = message.casBackend ? Attestation_CASBackend.toJSON(message.casBackend) : undefined); message.skipRunnerEnvVars !== undefined && (obj.skipRunnerEnvVars = message.skipRunnerEnvVars); + if (message.redactedEnvVars) { + obj.redactedEnvVars = message.redactedEnvVars.map((e) => e); + } else { + obj.redactedEnvVars = []; + } return obj; }, @@ -1029,6 +1052,7 @@ export const Attestation = { ? Attestation_CASBackend.fromPartial(object.casBackend) : undefined; message.skipRunnerEnvVars = object.skipRunnerEnvVars ?? false; + message.redactedEnvVars = object.redactedEnvVars?.map((e) => e) || []; return message; }, }; diff --git a/app/controlplane/api/gen/frontend/controlplane/v1/organization.ts b/app/controlplane/api/gen/frontend/controlplane/v1/organization.ts index b77bb5874..ac444dad3 100644 --- a/app/controlplane/api/gen/frontend/controlplane/v1/organization.ts +++ b/app/controlplane/api/gen/frontend/controlplane/v1/organization.ts @@ -4,6 +4,7 @@ import { BrowserHeaders } from "browser-headers"; import _m0 from "protobufjs/minimal"; import { OffsetPaginationRequest, OffsetPaginationResponse } from "./pagination"; import { + EnvVarRedaction, MembershipRole, membershipRoleFromJSON, membershipRoleToJSON, @@ -97,7 +98,11 @@ export interface OrganizationServiceUpdateRequest { | boolean | undefined; /** Opt out of storing the environment variables automatically discovered by the CI runner in the attestation */ - skipRunnerEnvVars?: boolean | undefined; + skipRunnerEnvVars?: + | boolean + | undefined; + /** Redaction of environment variable values in new attestations. Not set means no change. */ + envVarRedaction?: EnvVarRedaction; } export interface OrganizationServiceUpdateResponse { @@ -691,6 +696,7 @@ function createBaseOrganizationServiceUpdateRequest(): OrganizationServiceUpdate enableAiAgentCollector: undefined, blockAttestationsOnReleasedVersions: undefined, skipRunnerEnvVars: undefined, + envVarRedaction: undefined, }; } @@ -726,6 +732,9 @@ export const OrganizationServiceUpdateRequest = { if (message.skipRunnerEnvVars !== undefined) { writer.uint32(80).bool(message.skipRunnerEnvVars); } + if (message.envVarRedaction !== undefined) { + EnvVarRedaction.encode(message.envVarRedaction, writer.uint32(90).fork()).ldelim(); + } return writer; }, @@ -806,6 +815,13 @@ export const OrganizationServiceUpdateRequest = { message.skipRunnerEnvVars = reader.bool(); continue; + case 11: + if (tag !== 90) { + break; + } + + message.envVarRedaction = EnvVarRedaction.decode(reader, reader.uint32()); + continue; } if ((tag & 7) === 4 || tag === 0) { break; @@ -839,6 +855,7 @@ export const OrganizationServiceUpdateRequest = { ? Boolean(object.blockAttestationsOnReleasedVersions) : undefined, skipRunnerEnvVars: isSet(object.skipRunnerEnvVars) ? Boolean(object.skipRunnerEnvVars) : undefined, + envVarRedaction: isSet(object.envVarRedaction) ? EnvVarRedaction.fromJSON(object.envVarRedaction) : undefined, }; }, @@ -863,6 +880,8 @@ export const OrganizationServiceUpdateRequest = { message.blockAttestationsOnReleasedVersions !== undefined && (obj.blockAttestationsOnReleasedVersions = message.blockAttestationsOnReleasedVersions); message.skipRunnerEnvVars !== undefined && (obj.skipRunnerEnvVars = message.skipRunnerEnvVars); + message.envVarRedaction !== undefined && + (obj.envVarRedaction = message.envVarRedaction ? EnvVarRedaction.toJSON(message.envVarRedaction) : undefined); return obj; }, @@ -886,6 +905,9 @@ export const OrganizationServiceUpdateRequest = { message.enableAiAgentCollector = object.enableAiAgentCollector ?? undefined; message.blockAttestationsOnReleasedVersions = object.blockAttestationsOnReleasedVersions ?? undefined; message.skipRunnerEnvVars = object.skipRunnerEnvVars ?? undefined; + message.envVarRedaction = (object.envVarRedaction !== undefined && object.envVarRedaction !== null) + ? EnvVarRedaction.fromPartial(object.envVarRedaction) + : undefined; return message; }, }; diff --git a/app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts b/app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts index 8e51cc490..50293e064 100644 --- a/app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts +++ b/app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts @@ -974,6 +974,8 @@ export interface OrgItem { blockAttestationsOnReleasedVersions: boolean; /** Whether the environment variables automatically discovered by the CI runner are skipped from the attestation */ skipRunnerEnvVars: boolean; + /** Redaction of the values of environment variables stored in new attestations */ + envVarRedaction?: EnvVarRedaction; } export enum OrgItem_PolicyViolationBlockingStrategy { @@ -1015,6 +1017,58 @@ export function orgItem_PolicyViolationBlockingStrategyToJSON(object: OrgItem_Po } } +/** + * EnvVarRedaction configures which environment variable values are replaced with "[REDACTED]" + * in new attestations. It applies to runner-discovered variables and to the contract's env allow list. + */ +export interface EnvVarRedaction { + type: EnvVarRedaction_Type; + /** Exact variable names. Required when type is TYPE_CUSTOM. */ + envVars: string[]; +} + +export enum EnvVarRedaction_Type { + /** TYPE_UNSPECIFIED - no redaction */ + TYPE_UNSPECIFIED = 0, + /** TYPE_KNOWN_IDENTITY - redact the variables that Chainloop runner integrations mark as identifying a person */ + TYPE_KNOWN_IDENTITY = 1, + /** TYPE_CUSTOM - redact only the variables listed in env_vars */ + TYPE_CUSTOM = 2, + UNRECOGNIZED = -1, +} + +export function envVarRedaction_TypeFromJSON(object: any): EnvVarRedaction_Type { + switch (object) { + case 0: + case "TYPE_UNSPECIFIED": + return EnvVarRedaction_Type.TYPE_UNSPECIFIED; + case 1: + case "TYPE_KNOWN_IDENTITY": + return EnvVarRedaction_Type.TYPE_KNOWN_IDENTITY; + case 2: + case "TYPE_CUSTOM": + return EnvVarRedaction_Type.TYPE_CUSTOM; + case -1: + case "UNRECOGNIZED": + default: + return EnvVarRedaction_Type.UNRECOGNIZED; + } +} + +export function envVarRedaction_TypeToJSON(object: EnvVarRedaction_Type): string { + switch (object) { + case EnvVarRedaction_Type.TYPE_UNSPECIFIED: + return "TYPE_UNSPECIFIED"; + case EnvVarRedaction_Type.TYPE_KNOWN_IDENTITY: + return "TYPE_KNOWN_IDENTITY"; + case EnvVarRedaction_Type.TYPE_CUSTOM: + return "TYPE_CUSTOM"; + case EnvVarRedaction_Type.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} + export interface CASBackendItem { id: string; name: string; @@ -4629,6 +4683,7 @@ function createBaseOrgItem(): OrgItem { enableAiAgentCollector: false, blockAttestationsOnReleasedVersions: false, skipRunnerEnvVars: false, + envVarRedaction: undefined, }; } @@ -4670,6 +4725,9 @@ export const OrgItem = { if (message.skipRunnerEnvVars === true) { writer.uint32(96).bool(message.skipRunnerEnvVars); } + if (message.envVarRedaction !== undefined) { + EnvVarRedaction.encode(message.envVarRedaction, writer.uint32(106).fork()).ldelim(); + } return writer; }, @@ -4764,6 +4822,13 @@ export const OrgItem = { message.skipRunnerEnvVars = reader.bool(); continue; + case 13: + if (tag !== 106) { + break; + } + + message.envVarRedaction = EnvVarRedaction.decode(reader, reader.uint32()); + continue; } if ((tag & 7) === 4 || tag === 0) { break; @@ -4799,6 +4864,7 @@ export const OrgItem = { ? Boolean(object.blockAttestationsOnReleasedVersions) : false, skipRunnerEnvVars: isSet(object.skipRunnerEnvVars) ? Boolean(object.skipRunnerEnvVars) : false, + envVarRedaction: isSet(object.envVarRedaction) ? EnvVarRedaction.fromJSON(object.envVarRedaction) : undefined, }; }, @@ -4827,6 +4893,8 @@ export const OrgItem = { message.blockAttestationsOnReleasedVersions !== undefined && (obj.blockAttestationsOnReleasedVersions = message.blockAttestationsOnReleasedVersions); message.skipRunnerEnvVars !== undefined && (obj.skipRunnerEnvVars = message.skipRunnerEnvVars); + message.envVarRedaction !== undefined && + (obj.envVarRedaction = message.envVarRedaction ? EnvVarRedaction.toJSON(message.envVarRedaction) : undefined); return obj; }, @@ -4848,6 +4916,84 @@ export const OrgItem = { message.enableAiAgentCollector = object.enableAiAgentCollector ?? false; message.blockAttestationsOnReleasedVersions = object.blockAttestationsOnReleasedVersions ?? false; message.skipRunnerEnvVars = object.skipRunnerEnvVars ?? false; + message.envVarRedaction = (object.envVarRedaction !== undefined && object.envVarRedaction !== null) + ? EnvVarRedaction.fromPartial(object.envVarRedaction) + : undefined; + return message; + }, +}; + +function createBaseEnvVarRedaction(): EnvVarRedaction { + return { type: 0, envVars: [] }; +} + +export const EnvVarRedaction = { + encode(message: EnvVarRedaction, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.type !== 0) { + writer.uint32(8).int32(message.type); + } + for (const v of message.envVars) { + writer.uint32(18).string(v!); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EnvVarRedaction { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseEnvVarRedaction(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + + message.type = reader.int32() as any; + continue; + case 2: + if (tag !== 18) { + break; + } + + message.envVars.push(reader.string()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): EnvVarRedaction { + return { + type: isSet(object.type) ? envVarRedaction_TypeFromJSON(object.type) : 0, + envVars: Array.isArray(object?.envVars) ? object.envVars.map((e: any) => String(e)) : [], + }; + }, + + toJSON(message: EnvVarRedaction): unknown { + const obj: any = {}; + message.type !== undefined && (obj.type = envVarRedaction_TypeToJSON(message.type)); + if (message.envVars) { + obj.envVars = message.envVars.map((e) => e); + } else { + obj.envVars = []; + } + return obj; + }, + + create, I>>(base?: I): EnvVarRedaction { + return EnvVarRedaction.fromPartial(base ?? {}); + }, + + fromPartial, I>>(object: I): EnvVarRedaction { + const message = createBaseEnvVarRedaction(); + message.type = object.type ?? 0; + message.envVars = object.envVars?.map((e) => e) || []; return message; }, }; diff --git a/app/controlplane/api/gen/frontend/controlplane/v1/workflow_run.ts b/app/controlplane/api/gen/frontend/controlplane/v1/workflow_run.ts index 5e68be807..4412f4f3e 100644 --- a/app/controlplane/api/gen/frontend/controlplane/v1/workflow_run.ts +++ b/app/controlplane/api/gen/frontend/controlplane/v1/workflow_run.ts @@ -140,6 +140,11 @@ export interface AttestationServiceInitResponse_Result { enableAiAgentCollector: boolean; /** Whether to skip storing the environment variables automatically discovered by the CI runner in the attestation */ skipRunnerEnvVars: boolean; + /** + * Names of the environment variables whose values the CLI replaces with "[REDACTED]". + * The control plane resolves them from the org setting and enforces the same list at push. + */ + redactedEnvVars: string[]; } export interface AttestationServiceInitResponse_SigningOptions { @@ -1351,6 +1356,7 @@ function createBaseAttestationServiceInitResponse_Result(): AttestationServiceIn uiDashboardUrl: "", enableAiAgentCollector: false, skipRunnerEnvVars: false, + redactedEnvVars: [], }; } @@ -1380,6 +1386,9 @@ export const AttestationServiceInitResponse_Result = { if (message.skipRunnerEnvVars === true) { writer.uint32(72).bool(message.skipRunnerEnvVars); } + for (const v of message.redactedEnvVars) { + writer.uint32(82).string(v!); + } return writer; }, @@ -1446,6 +1455,13 @@ export const AttestationServiceInitResponse_Result = { message.skipRunnerEnvVars = reader.bool(); continue; + case 10: + if (tag !== 82) { + break; + } + + message.redactedEnvVars.push(reader.string()); + continue; } if ((tag & 7) === 4 || tag === 0) { break; @@ -1469,6 +1485,7 @@ export const AttestationServiceInitResponse_Result = { uiDashboardUrl: isSet(object.uiDashboardUrl) ? String(object.uiDashboardUrl) : "", enableAiAgentCollector: isSet(object.enableAiAgentCollector) ? Boolean(object.enableAiAgentCollector) : false, skipRunnerEnvVars: isSet(object.skipRunnerEnvVars) ? Boolean(object.skipRunnerEnvVars) : false, + redactedEnvVars: Array.isArray(object?.redactedEnvVars) ? object.redactedEnvVars.map((e: any) => String(e)) : [], }; }, @@ -1489,6 +1506,11 @@ export const AttestationServiceInitResponse_Result = { message.uiDashboardUrl !== undefined && (obj.uiDashboardUrl = message.uiDashboardUrl); message.enableAiAgentCollector !== undefined && (obj.enableAiAgentCollector = message.enableAiAgentCollector); message.skipRunnerEnvVars !== undefined && (obj.skipRunnerEnvVars = message.skipRunnerEnvVars); + if (message.redactedEnvVars) { + obj.redactedEnvVars = message.redactedEnvVars.map((e) => e); + } else { + obj.redactedEnvVars = []; + } return obj; }, @@ -1514,6 +1536,7 @@ export const AttestationServiceInitResponse_Result = { message.uiDashboardUrl = object.uiDashboardUrl ?? ""; message.enableAiAgentCollector = object.enableAiAgentCollector ?? false; message.skipRunnerEnvVars = object.skipRunnerEnvVars ?? false; + message.redactedEnvVars = object.redactedEnvVars?.map((e) => e) || []; return message; }, }; diff --git a/app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.jsonschema.json b/app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.jsonschema.json index 49d088f37..936227f4b 100644 --- a/app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.jsonschema.json +++ b/app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.jsonschema.json @@ -45,6 +45,13 @@ }, "type": "array" }, + "^(redacted_env_vars)$": { + "description": "exact names of the environment variables whose values are replaced with \"[REDACTED]\",\n as resolved by the control plane from the organization setting.\n It applies to the runner env vars and to the contract's env_allow_list.", + "items": { + "type": "string" + }, + "type": "array" + }, "^(runner_environment)$": { "$ref": "attestation.v1.RunnerEnvironment.jsonschema.json", "description": "Runner environment in which the attestation was crafted" @@ -157,6 +164,13 @@ }, "type": "array" }, + "redactedEnvVars": { + "description": "exact names of the environment variables whose values are replaced with \"[REDACTED]\",\n as resolved by the control plane from the organization setting.\n It applies to the runner env vars and to the contract's env_allow_list.", + "items": { + "type": "string" + }, + "type": "array" + }, "runnerEnvironment": { "$ref": "attestation.v1.RunnerEnvironment.jsonschema.json", "description": "Runner environment in which the attestation was crafted" diff --git a/app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.schema.json b/app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.schema.json index edc32cbd8..28e66c399 100644 --- a/app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.schema.json +++ b/app/controlplane/api/gen/jsonschema/attestation.v1.Attestation.schema.json @@ -45,6 +45,13 @@ }, "type": "array" }, + "^(redactedEnvVars)$": { + "description": "exact names of the environment variables whose values are replaced with \"[REDACTED]\",\n as resolved by the control plane from the organization setting.\n It applies to the runner env vars and to the contract's env_allow_list.", + "items": { + "type": "string" + }, + "type": "array" + }, "^(runnerEnvironment)$": { "$ref": "attestation.v1.RunnerEnvironment.schema.json", "description": "Runner environment in which the attestation was crafted" @@ -157,6 +164,13 @@ }, "type": "array" }, + "redacted_env_vars": { + "description": "exact names of the environment variables whose values are replaced with \"[REDACTED]\",\n as resolved by the control plane from the organization setting.\n It applies to the runner env vars and to the contract's env_allow_list.", + "items": { + "type": "string" + }, + "type": "array" + }, "runner_environment": { "$ref": "attestation.v1.RunnerEnvironment.schema.json", "description": "Runner environment in which the attestation was crafted" diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitResponse.Result.jsonschema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitResponse.Result.jsonschema.json index 57bbda5b2..76b3fb382 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitResponse.Result.jsonschema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitResponse.Result.jsonschema.json @@ -18,6 +18,13 @@ }, "type": "array" }, + "^(redacted_env_vars)$": { + "description": "Names of the environment variables whose values the CLI replaces with \"[REDACTED]\".\n The control plane resolves them from the org setting and enforces the same list at push.", + "items": { + "type": "string" + }, + "type": "array" + }, "^(signing_options)$": { "$ref": "controlplane.v1.AttestationServiceInitResponse.SigningOptions.jsonschema.json", "description": "Signing options" @@ -54,6 +61,13 @@ }, "type": "array" }, + "redactedEnvVars": { + "description": "Names of the environment variables whose values the CLI replaces with \"[REDACTED]\".\n The control plane resolves them from the org setting and enforces the same list at push.", + "items": { + "type": "string" + }, + "type": "array" + }, "signingOptions": { "$ref": "controlplane.v1.AttestationServiceInitResponse.SigningOptions.jsonschema.json", "description": "Signing options" diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitResponse.Result.schema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitResponse.Result.schema.json index b6d27a74b..f1fb1cba1 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitResponse.Result.schema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.AttestationServiceInitResponse.Result.schema.json @@ -18,6 +18,13 @@ }, "type": "array" }, + "^(redactedEnvVars)$": { + "description": "Names of the environment variables whose values the CLI replaces with \"[REDACTED]\".\n The control plane resolves them from the org setting and enforces the same list at push.", + "items": { + "type": "string" + }, + "type": "array" + }, "^(signingOptions)$": { "$ref": "controlplane.v1.AttestationServiceInitResponse.SigningOptions.schema.json", "description": "Signing options" @@ -54,6 +61,13 @@ }, "type": "array" }, + "redacted_env_vars": { + "description": "Names of the environment variables whose values the CLI replaces with \"[REDACTED]\".\n The control plane resolves them from the org setting and enforces the same list at push.", + "items": { + "type": "string" + }, + "type": "array" + }, "signing_options": { "$ref": "controlplane.v1.AttestationServiceInitResponse.SigningOptions.schema.json", "description": "Signing options" diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.EnvVarRedaction.jsonschema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.EnvVarRedaction.jsonschema.json new file mode 100644 index 000000000..998f2be87 --- /dev/null +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.EnvVarRedaction.jsonschema.json @@ -0,0 +1,44 @@ +{ + "$id": "controlplane.v1.EnvVarRedaction.jsonschema.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": false, + "description": "EnvVarRedaction configures which environment variable values are replaced with \"[REDACTED]\"\n in new attestations. It applies to runner-discovered variables and to the contract's env allow list.", + "patternProperties": { + "^(env_vars)$": { + "description": "Exact variable names. Required when type is TYPE_CUSTOM.", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "properties": { + "envVars": { + "description": "Exact variable names. Required when type is TYPE_CUSTOM.", + "items": { + "type": "string" + }, + "type": "array" + }, + "type": { + "anyOf": [ + { + "enum": [ + "TYPE_UNSPECIFIED", + "TYPE_KNOWN_IDENTITY", + "TYPE_CUSTOM" + ], + "title": "Type", + "type": "string" + }, + { + "maximum": 2147483647, + "minimum": -2147483648, + "type": "integer" + } + ] + } + }, + "title": "Env Var Redaction", + "type": "object" +} diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.EnvVarRedaction.schema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.EnvVarRedaction.schema.json new file mode 100644 index 000000000..0b2f2c1f2 --- /dev/null +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.EnvVarRedaction.schema.json @@ -0,0 +1,44 @@ +{ + "$id": "controlplane.v1.EnvVarRedaction.schema.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": false, + "description": "EnvVarRedaction configures which environment variable values are replaced with \"[REDACTED]\"\n in new attestations. It applies to runner-discovered variables and to the contract's env allow list.", + "patternProperties": { + "^(envVars)$": { + "description": "Exact variable names. Required when type is TYPE_CUSTOM.", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "properties": { + "env_vars": { + "description": "Exact variable names. Required when type is TYPE_CUSTOM.", + "items": { + "type": "string" + }, + "type": "array" + }, + "type": { + "anyOf": [ + { + "enum": [ + "TYPE_UNSPECIFIED", + "TYPE_KNOWN_IDENTITY", + "TYPE_CUSTOM" + ], + "title": "Type", + "type": "string" + }, + { + "maximum": 2147483647, + "minimum": -2147483648, + "type": "integer" + } + ] + } + }, + "title": "Env Var Redaction", + "type": "object" +} diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.OrgItem.jsonschema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.OrgItem.jsonschema.json index f4fff5c54..de9e24f6c 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.OrgItem.jsonschema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.OrgItem.jsonschema.json @@ -38,6 +38,10 @@ "description": "Whether AI agent config collection is automatically enabled during attestation init", "type": "boolean" }, + "^(env_var_redaction)$": { + "$ref": "controlplane.v1.EnvVarRedaction.jsonschema.json", + "description": "Redaction of the values of environment variables stored in new attestations" + }, "^(policy_allowed_hostnames)$": { "items": { "type": "string" @@ -96,6 +100,10 @@ "description": "Whether AI agent config collection is automatically enabled during attestation init", "type": "boolean" }, + "envVarRedaction": { + "$ref": "controlplane.v1.EnvVarRedaction.jsonschema.json", + "description": "Redaction of the values of environment variables stored in new attestations" + }, "id": { "type": "string" }, diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.OrgItem.schema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.OrgItem.schema.json index f8966c68a..86338188d 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.OrgItem.schema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.OrgItem.schema.json @@ -38,6 +38,10 @@ "description": "Whether AI agent config collection is automatically enabled during attestation init", "type": "boolean" }, + "^(envVarRedaction)$": { + "$ref": "controlplane.v1.EnvVarRedaction.schema.json", + "description": "Redaction of the values of environment variables stored in new attestations" + }, "^(policyAllowedHostnames)$": { "items": { "type": "string" @@ -96,6 +100,10 @@ "description": "Whether AI agent config collection is automatically enabled during attestation init", "type": "boolean" }, + "env_var_redaction": { + "$ref": "controlplane.v1.EnvVarRedaction.schema.json", + "description": "Redaction of the values of environment variables stored in new attestations" + }, "id": { "type": "string" }, diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.OrganizationServiceUpdateRequest.jsonschema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.OrganizationServiceUpdateRequest.jsonschema.json index bd8853a05..361c3b581 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.OrganizationServiceUpdateRequest.jsonschema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.OrganizationServiceUpdateRequest.jsonschema.json @@ -21,6 +21,10 @@ "description": "Enable automatic AI agent config collection during attestation init", "type": "boolean" }, + "^(env_var_redaction)$": { + "$ref": "controlplane.v1.EnvVarRedaction.jsonschema.json", + "description": "Redaction of environment variable values in new attestations. Not set means no change." + }, "^(policies_allowed_hostnames)$": { "description": "array of hostnames that are allowed to be used in the policies", "items": { @@ -64,6 +68,10 @@ "description": "Enable automatic AI agent config collection during attestation init", "type": "boolean" }, + "envVarRedaction": { + "$ref": "controlplane.v1.EnvVarRedaction.jsonschema.json", + "description": "Redaction of environment variable values in new attestations. Not set means no change." + }, "name": { "minLength": 1, "type": "string" diff --git a/app/controlplane/api/gen/jsonschema/controlplane.v1.OrganizationServiceUpdateRequest.schema.json b/app/controlplane/api/gen/jsonschema/controlplane.v1.OrganizationServiceUpdateRequest.schema.json index 14da6f1f8..fd284174b 100644 --- a/app/controlplane/api/gen/jsonschema/controlplane.v1.OrganizationServiceUpdateRequest.schema.json +++ b/app/controlplane/api/gen/jsonschema/controlplane.v1.OrganizationServiceUpdateRequest.schema.json @@ -21,6 +21,10 @@ "description": "Enable automatic AI agent config collection during attestation init", "type": "boolean" }, + "^(envVarRedaction)$": { + "$ref": "controlplane.v1.EnvVarRedaction.schema.json", + "description": "Redaction of environment variable values in new attestations. Not set means no change." + }, "^(policiesAllowedHostnames)$": { "description": "array of hostnames that are allowed to be used in the policies", "items": { @@ -64,6 +68,10 @@ "description": "Enable automatic AI agent config collection during attestation init", "type": "boolean" }, + "env_var_redaction": { + "$ref": "controlplane.v1.EnvVarRedaction.schema.json", + "description": "Redaction of environment variable values in new attestations. Not set means no change." + }, "name": { "minLength": 1, "type": "string" diff --git a/app/controlplane/internal/service/attestation.go b/app/controlplane/internal/service/attestation.go index c22b643b4..0698416d9 100644 --- a/app/controlplane/internal/service/attestation.go +++ b/app/controlplane/internal/service/attestation.go @@ -232,6 +232,11 @@ func (s *AttestationService) Init(ctx context.Context, req *cpAPI.AttestationSer SkipRunnerEnvVars: org.SkipRunnerEnvVars, } + resp.RedactedEnvVars, err = org.EnvVarRedaction.Names() + if err != nil { + return nil, handleUseCaseErr(ctx, err, s.log) + } + resp.SigningOptions = &cpAPI.AttestationServiceInitResponse_SigningOptions{} tsa := s.signingUseCase.GetCurrentTSA() if tsa != nil { @@ -338,9 +343,9 @@ func (s *AttestationService) storeAttestation(ctx context.Context, bundle []byte } // On this path the bundle reaches CAS before SaveAttestation gets to - // validate it, so the contract is checked up front. Otherwise an - // attestation rejected for violating its contract would still have left - // a blob behind in the CAS backend. + // validate it, so the contract and the env var redaction are checked up + // front. Otherwise a rejected attestation would still have left a blob + // behind in the CAS backend. if err = s.wrUseCase.ValidateAttestationContract(ctx, workflowRunID, bundle); err != nil { return nil, handleUseCaseErr(ctx, err, s.log) } diff --git a/app/controlplane/internal/service/context.go b/app/controlplane/internal/service/context.go index 4082164e1..5a820200a 100644 --- a/app/controlplane/internal/service/context.go +++ b/app/controlplane/internal/service/context.go @@ -128,6 +128,7 @@ func bizOrgToPb(m *biz.Organization) *pb.OrgItem { EnableAiAgentCollector: m.EnableAIAgentCollector, BlockAttestationsOnReleasedVersions: m.BlockAttestationsOnReleasedVersions, SkipRunnerEnvVars: m.SkipRunnerEnvVars, + EnvVarRedaction: bizEnvVarRedactionToPb(m.EnvVarRedaction), } if m.APITokenInactivityThresholdDays != nil { diff --git a/app/controlplane/internal/service/envvarredaction_test.go b/app/controlplane/internal/service/envvarredaction_test.go new file mode 100644 index 000000000..eabf5ca6d --- /dev/null +++ b/app/controlplane/internal/service/envvarredaction_test.go @@ -0,0 +1,68 @@ +// +// Copyright 2026 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package service + +import ( + "testing" + + pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1" + "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" + "github.com/stretchr/testify/assert" + "google.golang.org/protobuf/proto" +) + +const fooVar = "FOO" + +func TestEnvVarRedactionConversion(t *testing.T) { + testCases := []struct { + name string + pb *pb.EnvVarRedaction + biz *biz.EnvVarRedaction + // wantPb is what the biz value converts back to, when it differs from pb + wantPb *pb.EnvVarRedaction + }{ + {name: "not set", pb: nil, biz: nil}, + { + name: "unspecified means none", + pb: &pb.EnvVarRedaction{}, + biz: &biz.EnvVarRedaction{Mode: envredaction.ModeNone}, + wantPb: &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_UNSPECIFIED}, + }, + { + name: "known identity", + pb: &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_KNOWN_IDENTITY}, + biz: &biz.EnvVarRedaction{Mode: envredaction.ModeKnownIdentity}, + }, + { + name: "custom", + pb: &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_CUSTOM, EnvVars: []string{fooVar, "BAR"}}, + biz: &biz.EnvVarRedaction{Mode: envredaction.ModeCustom, EnvVars: []string{fooVar, "BAR"}}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.biz, pbEnvVarRedactionToBiz(tc.pb)) + + want := tc.pb + if tc.wantPb != nil { + want = tc.wantPb + } + assert.True(t, proto.Equal(want, bizEnvVarRedactionToPb(tc.biz)), "got %v, want %v", bizEnvVarRedactionToPb(tc.biz), want) + }) + } +} diff --git a/app/controlplane/internal/service/organization.go b/app/controlplane/internal/service/organization.go index 04e566366..e88be837e 100644 --- a/app/controlplane/internal/service/organization.go +++ b/app/controlplane/internal/service/organization.go @@ -23,6 +23,7 @@ import ( "github.com/chainloop-dev/chainloop/app/controlplane/pkg/authz" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/usercontext/entities" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" errors "github.com/go-kratos/kratos/v2/errors" "github.com/google/uuid" @@ -124,6 +125,7 @@ func (s *OrganizationService) Update(ctx context.Context, req *pb.OrganizationSe EnableAIAgentCollector: req.EnableAiAgentCollector, BlockAttestationsOnReleasedVersions: req.BlockAttestationsOnReleasedVersions, SkipRunnerEnvVars: req.SkipRunnerEnvVars, + EnvVarRedaction: pbEnvVarRedactionToBiz(req.EnvVarRedaction), }) if err != nil { return nil, handleUseCaseErr(ctx, err, s.log) @@ -132,6 +134,42 @@ func (s *OrganizationService) Update(ctx context.Context, req *pb.OrganizationSe return &pb.OrganizationServiceUpdateResponse{Result: bizOrgToPb(org)}, nil } +// pbEnvVarRedactionToBiz converts the API setting. nil means "not set"; TYPE_UNSPECIFIED means no redaction. +// The use case validates the setting and keeps the names only for the custom mode. +func pbEnvVarRedactionToBiz(r *pb.EnvVarRedaction) *biz.EnvVarRedaction { + if r == nil { + return nil + } + + mode := envredaction.ModeNone + switch r.GetType() { + case pb.EnvVarRedaction_TYPE_KNOWN_IDENTITY: + mode = envredaction.ModeKnownIdentity + case pb.EnvVarRedaction_TYPE_CUSTOM: + mode = envredaction.ModeCustom + } + + return &biz.EnvVarRedaction{Mode: mode, EnvVars: r.GetEnvVars()} +} + +// bizEnvVarRedactionToPb converts the stored setting. nil (no redaction) stays nil. +// The use case keeps EnvVars only for the custom mode. +func bizEnvVarRedactionToPb(r *biz.EnvVarRedaction) *pb.EnvVarRedaction { + if r == nil { + return nil + } + + out := &pb.EnvVarRedaction{Type: pb.EnvVarRedaction_TYPE_UNSPECIFIED, EnvVars: r.EnvVars} + switch r.Mode { + case envredaction.ModeKnownIdentity: + out.Type = pb.EnvVarRedaction_TYPE_KNOWN_IDENTITY + case envredaction.ModeCustom: + out.Type = pb.EnvVarRedaction_TYPE_CUSTOM + } + + return out +} + func (s *OrganizationService) Delete(ctx context.Context, req *pb.OrganizationServiceDeleteRequest) (*pb.OrganizationServiceDeleteResponse, error) { if _, err := requireCurrentUser(ctx); err != nil { return nil, err diff --git a/app/controlplane/pkg/biz/organization.go b/app/controlplane/pkg/biz/organization.go index bde0e071b..146b4735f 100644 --- a/app/controlplane/pkg/biz/organization.go +++ b/app/controlplane/pkg/biz/organization.go @@ -25,6 +25,7 @@ import ( "github.com/chainloop-dev/chainloop/app/controlplane/pkg/auditor/events" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/authz" config "github.com/chainloop-dev/chainloop/app/controlplane/pkg/conf/controlplane/config/v1" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" "github.com/chainloop-dev/chainloop/pkg/otelx" "github.com/chainloop-dev/chainloop/pkg/servicelogger" "github.com/go-kratos/kratos/v2/log" @@ -54,10 +55,44 @@ type Organization struct { BlockAttestationsOnReleasedVersions bool // SkipRunnerEnvVars opts out of storing the environment variables automatically discovered by the CI runner in the attestation SkipRunnerEnvVars bool + // EnvVarRedaction replaces the values of selected env vars with a placeholder in new attestations. nil = no redaction + EnvVarRedaction *EnvVarRedaction // Suspended indicates whether the organization is suspended Suspended bool } +// EnvVarRedaction is the org-level setting that redacts environment variable values in attestations. +type EnvVarRedaction struct { + Mode envredaction.Mode `json:"mode"` + // EnvVars holds the exact variable names, only for envredaction.ModeCustom + EnvVars []string `json:"env_vars,omitempty"` +} + +// Names returns the variable names that the setting redacts. A nil setting redacts nothing. +func (r *EnvVarRedaction) Names() ([]string, error) { + if r == nil { + return nil, nil + } + return envredaction.Names(r.Mode, r.EnvVars) +} + +// normalize validates the setting and returns the value to store. Only the custom mode keeps +// the variable list, and an empty mode becomes ModeNone, which the repository clears. +func (r *EnvVarRedaction) normalize() (*EnvVarRedaction, error) { + if _, err := r.Names(); err != nil { + return nil, NewErrValidation(err) + } + + switch r.Mode { + case envredaction.ModeKnownIdentity: + return &EnvVarRedaction{Mode: r.Mode}, nil + case envredaction.ModeCustom: + return &EnvVarRedaction{Mode: r.Mode, EnvVars: r.EnvVars}, nil + default: + return &EnvVarRedaction{Mode: envredaction.ModeNone}, nil + } +} + // OrganizationUpdateOpts holds optional fields for updating an organization. // Pointer fields use nil to indicate "no change". For PoliciesAllowedHostnames, // nil means "no change" while an empty slice means "clear the list". @@ -70,6 +105,8 @@ type OrganizationUpdateOpts struct { EnableAIAgentCollector *bool BlockAttestationsOnReleasedVersions *bool SkipRunnerEnvVars *bool + // EnvVarRedaction nil means no change. A value with envredaction.ModeNone clears the setting. + EnvVarRedaction *EnvVarRedaction } type OrganizationRepo interface { @@ -232,6 +269,17 @@ func (uc *OrganizationUseCase) Update(ctx context.Context, userID, orgName strin opts = &OrganizationUpdateOpts{} } + if opts.EnvVarRedaction != nil { + normalized, err := opts.EnvVarRedaction.normalize() + if err != nil { + return nil, err + } + // Copy so the caller's opts are not changed + o := *opts + o.EnvVarRedaction = normalized + opts = &o + } + userUUID, err := uuid.Parse(userID) if err != nil { return nil, NewErrInvalidUUID(err) diff --git a/app/controlplane/pkg/biz/organization_integration_test.go b/app/controlplane/pkg/biz/organization_integration_test.go index 40c9d2191..cf9c9e93c 100644 --- a/app/controlplane/pkg/biz/organization_integration_test.go +++ b/app/controlplane/pkg/biz/organization_integration_test.go @@ -30,6 +30,7 @@ import ( "github.com/google/uuid" "google.golang.org/protobuf/types/known/structpb" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" "github.com/chainloop-dev/chainloop/pkg/credentials" creds "github.com/chainloop-dev/chainloop/pkg/credentials/mocks" @@ -184,6 +185,77 @@ func (s *OrgIntegrationTestSuite) TestUpdate() { s.False(got.SkipRunnerEnvVars) }) + s.Run("env var redaction update", func() { + testCases := []struct { + name string + in *biz.EnvVarRedaction + want *biz.EnvVarRedaction + wantErr bool + }{ + { + name: "known identity", + in: &biz.EnvVarRedaction{Mode: envredaction.ModeKnownIdentity}, + want: &biz.EnvVarRedaction{Mode: envredaction.ModeKnownIdentity}, + }, + { + name: "custom list", + in: &biz.EnvVarRedaction{Mode: envredaction.ModeCustom, EnvVars: []string{"BUILD_REQUESTEDFOR", "MY_OWNER"}}, + want: &biz.EnvVarRedaction{Mode: envredaction.ModeCustom, EnvVars: []string{"BUILD_REQUESTEDFOR", "MY_OWNER"}}, + }, + { + name: "custom without variables is rejected", + in: &biz.EnvVarRedaction{Mode: envredaction.ModeCustom}, + wantErr: true, + }, + { + name: "unknown mode is rejected", + in: &biz.EnvVarRedaction{Mode: "foo"}, + wantErr: true, + }, + { + name: "known identity drops a custom list", + in: &biz.EnvVarRedaction{Mode: envredaction.ModeKnownIdentity, EnvVars: []string{"OTHER_VAR"}}, + want: &biz.EnvVarRedaction{Mode: envredaction.ModeKnownIdentity}, + }, + { + name: "none clears the setting", + in: &biz.EnvVarRedaction{Mode: envredaction.ModeNone}, + want: nil, + }, + } + + for _, tc := range testCases { + s.Run(tc.name, func() { + got, err := s.Organization.Update(ctx, s.user.ID, s.org.Name, &biz.OrganizationUpdateOpts{ + EnvVarRedaction: tc.in, + }) + if tc.wantErr { + s.Error(err) + s.True(biz.IsErrValidation(err), "want validation error, got %v", err) + return + } + s.NoError(err) + s.Equal(tc.want, got.EnvVarRedaction) + + // it is persisted + stored, err := s.Organization.FindByName(ctx, s.org.Name) + s.NoError(err) + s.Equal(tc.want, stored.EnvVarRedaction) + }) + } + + s.Run("not passing a value doesn't change it", func() { + _, err := s.Organization.Update(ctx, s.user.ID, s.org.Name, &biz.OrganizationUpdateOpts{ + EnvVarRedaction: &biz.EnvVarRedaction{Mode: envredaction.ModeKnownIdentity}, + }) + s.NoError(err) + + got, err := s.Organization.Update(ctx, s.user.ID, s.org.Name, &biz.OrganizationUpdateOpts{SkipRunnerEnvVars: toPtrBool(false)}) + s.NoError(err) + s.Equal(&biz.EnvVarRedaction{Mode: envredaction.ModeKnownIdentity}, got.EnvVarRedaction) + }) + }) + s.Run("but not passing a value doesn't clear the hostnames value", func() { got, err := s.Organization.Update(ctx, s.user.ID, s.org.Name, &biz.OrganizationUpdateOpts{ PoliciesAllowedHostnames: []string{"foo.com", "bar.com"}, diff --git a/app/controlplane/pkg/biz/workflowrun.go b/app/controlplane/pkg/biz/workflowrun.go index 20ff7070a..521319b25 100644 --- a/app/controlplane/pkg/biz/workflowrun.go +++ b/app/controlplane/pkg/biz/workflowrun.go @@ -29,6 +29,7 @@ import ( "github.com/chainloop-dev/chainloop/app/controlplane/pkg/pagination" "github.com/chainloop-dev/chainloop/pkg/attestation" attestationapi "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/api/attestation/v1" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" "github.com/chainloop-dev/chainloop/pkg/attestation/renderer/chainloop" "github.com/chainloop-dev/chainloop/pkg/attestation/verifier" "github.com/chainloop-dev/chainloop/pkg/cache/attestationbundle" @@ -422,24 +423,63 @@ func WithSkipBundlePersistence() SaveAttestationOption { } } -// orgBlocksReleasedVersions reports whether the run's organization rejects new -// attestations targeting already-released (immutable) project versions. The -// actual prerelease check happens transactionally at persistence time (see the -// repo SaveAttestation* methods) so it is atomic with the write and can't be -// bypassed by a concurrent release. -func (uc *WorkflowRunUseCase) orgBlocksReleasedVersions(ctx context.Context, run *WorkflowRun) (bool, error) { +// runOrg returns the organization that owns the run, or nil when the run has no workflow loaded. +func (uc *WorkflowRunUseCase) runOrg(ctx context.Context, run *WorkflowRun) (*Organization, error) { if run.Workflow == nil { - return false, nil + return nil, nil } org, err := uc.orgRepo.FindByID(ctx, run.Workflow.OrgID) if err != nil { - return false, fmt.Errorf("finding organization: %w", err) + return nil, fmt.Errorf("finding organization: %w", err) } else if org == nil { - return false, NewErrNotFound("organization") + return nil, NewErrNotFound("organization") } - return org.BlockAttestationsOnReleasedVersions, nil + return org, nil +} + +// validatePredicate runs the checks on the content of a pushed attestation that +// do not depend on how it is stored. Both SaveAttestation and the pre-CAS +// ValidateAttestationContract call it, so they reach the same verdict. +// org is the organization of the run, nil when the run has no workflow loaded. +// It returns the contract schema it validated against. +func (uc *WorkflowRunUseCase) validatePredicate(ctx context.Context, run *WorkflowRun, org *Organization, predicate chainloop.NormalizablePredicate) (*schemaapi.CraftingSchema, error) { + schema, err := uc.validateAgainstContract(ctx, run, predicate) + if err != nil { + return nil, err + } + + if err := validateEnvVarRedaction(org, predicate); err != nil { + return nil, err + } + + return schema, nil +} + +// validateEnvVarRedaction rejects an attestation that stores a clear value for an +// env var that the organization redacts. +// +// The CLI applies the redaction before it signs the attestation, so an older or +// modified client can push the real value. The check uses the organization +// setting at push time. +func validateEnvVarRedaction(org *Organization, predicate chainloop.NormalizablePredicate) error { + if org == nil { + return nil + } + + names, err := org.EnvVarRedaction.Names() + if err != nil { + return fmt.Errorf("resolving env var redaction: %w", err) + } + + if violations := envredaction.Violations(predicate.GetEnvVars(), names); len(violations) > 0 { + return NewErrValidation(fmt.Errorf( + "environment variables %s must have the value %s because of the organization env var redaction setting. Update the Chainloop CLI, or run the attestation again if the setting changed during the run", + strings.Join(violations, ", "), envredaction.RedactedValue)) + } + + return nil } // ValidateAttestationContract checks a bundle's signature and the contract @@ -479,7 +519,12 @@ func (uc *WorkflowRunUseCase) ValidateAttestationContract(ctx context.Context, r return fmt.Errorf("extracting predicate: %w", err) } - _, err = uc.validateAgainstContract(ctx, run, predicate) + org, err := uc.runOrg(ctx, run) + if err != nil { + return err + } + + _, err = uc.validatePredicate(ctx, run, org, predicate) return err } @@ -550,11 +595,17 @@ func (uc *WorkflowRunUseCase) SaveAttestation(ctx context.Context, id string, bu return nil, NewErrNotFound("workflow run") } - blockReleasedVersions, err := uc.orgBlocksReleasedVersions(ctx, run) + org, err := uc.runOrg(ctx, run) if err != nil { return nil, err } + // Whether the org rejects new attestations targeting already-released + // (immutable) project versions. The actual prerelease check happens + // transactionally at persistence time (see the repo SaveAttestation* methods) + // so it is atomic with the write and can't be bypassed by a concurrent release. + blockReleasedVersions := org != nil && org.BlockAttestationsOnReleasedVersions + // calculate the content digest // Todo: this should be calculated in the use case digest, _, err := v1.SHA256(bytes.NewReader(bundle)) @@ -591,7 +642,7 @@ func (uc *WorkflowRunUseCase) SaveAttestation(ctx context.Context, id string, bu } } - contractSchema, err := uc.validateAgainstContract(ctx, run, predicate) + contractSchema, err := uc.validatePredicate(ctx, run, org, predicate) if err != nil { return nil, err } diff --git a/app/controlplane/pkg/biz/workflowrun_contract_integration_test.go b/app/controlplane/pkg/biz/workflowrun_contract_integration_test.go index 9308c8c8e..f585b1d6d 100644 --- a/app/controlplane/pkg/biz/workflowrun_contract_integration_test.go +++ b/app/controlplane/pkg/biz/workflowrun_contract_integration_test.go @@ -22,6 +22,7 @@ import ( "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz/testhelpers" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" "github.com/chainloop-dev/chainloop/pkg/credentials" creds "github.com/chainloop-dev/chainloop/pkg/credentials/mocks" "github.com/google/uuid" @@ -270,6 +271,84 @@ func (s *workflowRunContractIntegrationTestSuite) TestValidateAttestationContrac }) } +// The CLI redacts env vars before it signs, so an older or modified CLI can push +// the real values. The control plane checks the org setting at push time. +// full.json carries the env vars {"owner": "john-c@chainloop.dev", "project": "chatgpt"}. +func (s *workflowRunContractIntegrationTestSuite) TestSaveAttestationEnforcesEnvVarRedaction() { + // env var name in full.json + const projectEnvVar = "project" + + testCases := []struct { + name string + redaction *biz.EnvVarRedaction + attestation string + wantErr string + }{ + {name: "no redaction accepts clear values", attestation: attestationFull}, + { + name: "known identity with no identity vars in the attestation is accepted", + redaction: &biz.EnvVarRedaction{Mode: envredaction.ModeKnownIdentity}, + attestation: attestationFull, + }, + { + name: "custom redaction of a variable that is absent is accepted", + redaction: &biz.EnvVarRedaction{Mode: envredaction.ModeCustom, EnvVars: []string{"GITHUB_ACTOR"}}, + attestation: attestationFull, + }, + { + name: "attestation without env vars is accepted", + redaction: &biz.EnvVarRedaction{Mode: envredaction.ModeCustom, EnvVars: []string{"owner"}}, + attestation: attestationEmpty, + }, + { + name: "custom redaction of a clear value is rejected", + redaction: &biz.EnvVarRedaction{Mode: envredaction.ModeCustom, EnvVars: []string{projectEnvVar, "owner"}}, + attestation: attestationFull, + wantErr: "environment variables owner, project must have the value [REDACTED]", + }, + } + + for i, tc := range testCases { + s.Run(tc.name, func() { + ctx := context.Background() + s.setOrgEnvVarRedaction(ctx, tc.redaction) + run := s.newRunWithContract(fmt.Sprintf("redaction-%d", i), " materials: []") + bundleBytes := testhelpers.BundleBytesFromEnvelope(s.T(), tc.attestation) + + preflightErr := s.WorkflowRun.ValidateAttestationContract(ctx, run.ID.String(), bundleBytes) + digest, err := s.WorkflowRun.SaveAttestation(ctx, run.ID.String(), bundleBytes) + + if tc.wantErr == "" { + require.NoError(s.T(), preflightErr) + require.NoError(s.T(), err) + require.NotNil(s.T(), digest) + return + } + + for _, e := range []error{preflightErr, err} { + require.Error(s.T(), e) + s.True(biz.IsErrValidation(e), "expected a validation error, got %T: %v", e, e) + s.ErrorContains(e, tc.wantErr) + } + + stored, err := s.WorkflowRun.GetByIDInOrg(ctx, s.org.ID, run.ID.String()) + require.NoError(s.T(), err) + s.Empty(stored.Attestation.Digest, "a rejected attestation must not record a digest on the run") + }) + } +} + +func (s *workflowRunContractIntegrationTestSuite) setOrgEnvVarRedaction(ctx context.Context, r *biz.EnvVarRedaction) { + s.T().Helper() + orgUUID, err := uuid.Parse(s.org.ID) + require.NoError(s.T(), err) + if r == nil { + r = &biz.EnvVarRedaction{Mode: envredaction.ModeNone} + } + _, err = s.Repos.OrganizationRepo.Update(ctx, orgUUID, &biz.OrganizationUpdateOpts{EnvVarRedaction: r}) + require.NoError(s.T(), err) +} + func TestWorkflowRunContractEnforcement(t *testing.T) { suite.Run(t, new(workflowRunContractIntegrationTestSuite)) } diff --git a/app/controlplane/pkg/biz/workflowrun_verification_test.go b/app/controlplane/pkg/biz/workflowrun_verification_test.go index 77ea1c2bc..1ae7cfecd 100644 --- a/app/controlplane/pkg/biz/workflowrun_verification_test.go +++ b/app/controlplane/pkg/biz/workflowrun_verification_test.go @@ -194,9 +194,13 @@ func TestValidateAttestationContractEnforcesKeylessVerification(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { repo := repoM.NewWorkflowRunRepo(t) - uc, err := biz.NewWorkflowRunUseCase(&biz.WorkflowRunUseCaseOpts{WfrRepo: repo, SigningUC: tc.signing}) + orgRepo := repoM.NewOrganizationRepo(t) + uc, err := biz.NewWorkflowRunUseCase(&biz.WorkflowRunUseCaseOpts{WfrRepo: repo, OrgRepo: orgRepo, SigningUC: tc.signing}) require.NoError(t, err) + // an attestation that passes the signature check loads the run organization + orgRepo.On("FindByID", mock.Anything, orgID).Return(&biz.Organization{ID: orgID.String()}, nil).Maybe() + runID := uuid.New() // the run has no contract revision, so an attestation that passes // the signature check is stopped at the contract check instead diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/20261123100446.sql b/app/controlplane/pkg/data/ent/migrate/migrations/20261123100446.sql new file mode 100644 index 000000000..3ae4c1efc --- /dev/null +++ b/app/controlplane/pkg/data/ent/migrate/migrations/20261123100446.sql @@ -0,0 +1,2 @@ +-- Modify "organizations" table +ALTER TABLE "organizations" ADD COLUMN "env_var_redaction" jsonb NULL; diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum b/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum index a7e2c006b..8401847de 100644 --- a/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum +++ b/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:4KMWUuBSeBXXhOyu1wmPspCWeaT/kyYJdwYewEOc6JU= +h1:TtllQWhorOS3DxgE0OjvSszcMo9xHKTFT1NE1CrtZ30= 20230706165452_init-schema.sql h1:VvqbNFEQnCvUVyj2iDYVQQxDM0+sSXqocpt/5H64k8M= 20230710111950-cas-backend.sql h1:A8iBuSzZIEbdsv9ipBtscZQuaBp3V5/VMw7eZH6GX+g= 20230712094107-cas-backends-workflow-runs.sql h1:a5rzxpVGyd56nLRSsKrmCFc9sebg65RWzLghKHh5xvI= @@ -147,3 +147,4 @@ h1:4KMWUuBSeBXXhOyu1wmPspCWeaT/kyYJdwYewEOc6JU= 20261116124542.sql h1:PNFvP+qcO1URsP9QsKGpAwaAL9m7yP7bzi/8SHk6yNs= 20261116124543.sql h1:r+8IOuLFQ3iMrQjYN8hPGxItVJu/bidc0/yeEUe6RFQ= 20261117162118.sql h1:kihy12JzE5ELo0Jy79LjMs8X4BBgmCjsh8Q1kpFp60c= +20261123100446.sql h1:m6G8YK7prIatRFKx10ZE1mL3qkL7W1pAcQm3vDwML24= diff --git a/app/controlplane/pkg/data/ent/migrate/schema.go b/app/controlplane/pkg/data/ent/migrate/schema.go index 9fe082722..7b6ed3012 100644 --- a/app/controlplane/pkg/data/ent/migrate/schema.go +++ b/app/controlplane/pkg/data/ent/migrate/schema.go @@ -497,6 +497,7 @@ var ( {Name: "enable_ai_agent_collector", Type: field.TypeBool, Default: false}, {Name: "block_attestations_on_released_versions", Type: field.TypeBool, Default: false}, {Name: "skip_runner_env_vars", Type: field.TypeBool, Default: false}, + {Name: "env_var_redaction", Type: field.TypeJSON, Nullable: true}, {Name: "suspended", Type: field.TypeBool, Default: false}, } // OrganizationsTable holds the schema information for the "organizations" table. diff --git a/app/controlplane/pkg/data/ent/mutation.go b/app/controlplane/pkg/data/ent/mutation.go index 494a7c000..c60f6e01e 100644 --- a/app/controlplane/pkg/data/ent/mutation.go +++ b/app/controlplane/pkg/data/ent/mutation.go @@ -10113,6 +10113,7 @@ type OrganizationMutation struct { enable_ai_agent_collector *bool block_attestations_on_released_versions *bool skip_runner_env_vars *bool + env_var_redaction **biz.EnvVarRedaction suspended *bool clearedFields map[string]struct{} memberships map[uuid.UUID]struct{} @@ -10759,6 +10760,55 @@ func (m *OrganizationMutation) ResetSkipRunnerEnvVars() { m.skip_runner_env_vars = nil } +// SetEnvVarRedaction sets the "env_var_redaction" field. +func (m *OrganizationMutation) SetEnvVarRedaction(bvr *biz.EnvVarRedaction) { + m.env_var_redaction = &bvr +} + +// EnvVarRedaction returns the value of the "env_var_redaction" field in the mutation. +func (m *OrganizationMutation) EnvVarRedaction() (r *biz.EnvVarRedaction, exists bool) { + v := m.env_var_redaction + if v == nil { + return + } + return *v, true +} + +// OldEnvVarRedaction returns the old "env_var_redaction" field's value of the Organization entity. +// If the Organization object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *OrganizationMutation) OldEnvVarRedaction(ctx context.Context) (v *biz.EnvVarRedaction, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEnvVarRedaction is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEnvVarRedaction requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEnvVarRedaction: %w", err) + } + return oldValue.EnvVarRedaction, nil +} + +// ClearEnvVarRedaction clears the value of the "env_var_redaction" field. +func (m *OrganizationMutation) ClearEnvVarRedaction() { + m.env_var_redaction = nil + m.clearedFields[organization.FieldEnvVarRedaction] = struct{}{} +} + +// EnvVarRedactionCleared returns if the "env_var_redaction" field was cleared in this mutation. +func (m *OrganizationMutation) EnvVarRedactionCleared() bool { + _, ok := m.clearedFields[organization.FieldEnvVarRedaction] + return ok +} + +// ResetEnvVarRedaction resets all changes to the "env_var_redaction" field. +func (m *OrganizationMutation) ResetEnvVarRedaction() { + m.env_var_redaction = nil + delete(m.clearedFields, organization.FieldEnvVarRedaction) +} + // SetSuspended sets the "suspended" field. func (m *OrganizationMutation) SetSuspended(b bool) { m.suspended = &b @@ -11315,7 +11365,7 @@ func (m *OrganizationMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *OrganizationMutation) Fields() []string { - fields := make([]string, 0, 13) + fields := make([]string, 0, 14) if m.name != nil { fields = append(fields, organization.FieldName) } @@ -11352,6 +11402,9 @@ func (m *OrganizationMutation) Fields() []string { if m.skip_runner_env_vars != nil { fields = append(fields, organization.FieldSkipRunnerEnvVars) } + if m.env_var_redaction != nil { + fields = append(fields, organization.FieldEnvVarRedaction) + } if m.suspended != nil { fields = append(fields, organization.FieldSuspended) } @@ -11387,6 +11440,8 @@ func (m *OrganizationMutation) Field(name string) (ent.Value, bool) { return m.BlockAttestationsOnReleasedVersions() case organization.FieldSkipRunnerEnvVars: return m.SkipRunnerEnvVars() + case organization.FieldEnvVarRedaction: + return m.EnvVarRedaction() case organization.FieldSuspended: return m.Suspended() } @@ -11422,6 +11477,8 @@ func (m *OrganizationMutation) OldField(ctx context.Context, name string) (ent.V return m.OldBlockAttestationsOnReleasedVersions(ctx) case organization.FieldSkipRunnerEnvVars: return m.OldSkipRunnerEnvVars(ctx) + case organization.FieldEnvVarRedaction: + return m.OldEnvVarRedaction(ctx) case organization.FieldSuspended: return m.OldSuspended(ctx) } @@ -11517,6 +11574,13 @@ func (m *OrganizationMutation) SetField(name string, value ent.Value) error { } m.SetSkipRunnerEnvVars(v) return nil + case organization.FieldEnvVarRedaction: + v, ok := value.(*biz.EnvVarRedaction) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEnvVarRedaction(v) + return nil case organization.FieldSuspended: v, ok := value.(bool) if !ok { @@ -11578,6 +11642,9 @@ func (m *OrganizationMutation) ClearedFields() []string { if m.FieldCleared(organization.FieldAPITokenInactivityThresholdDays) { fields = append(fields, organization.FieldAPITokenInactivityThresholdDays) } + if m.FieldCleared(organization.FieldEnvVarRedaction) { + fields = append(fields, organization.FieldEnvVarRedaction) + } return fields } @@ -11601,6 +11668,9 @@ func (m *OrganizationMutation) ClearField(name string) error { case organization.FieldAPITokenInactivityThresholdDays: m.ClearAPITokenInactivityThresholdDays() return nil + case organization.FieldEnvVarRedaction: + m.ClearEnvVarRedaction() + return nil } return fmt.Errorf("unknown Organization nullable field %s", name) } @@ -11645,6 +11715,9 @@ func (m *OrganizationMutation) ResetField(name string) error { case organization.FieldSkipRunnerEnvVars: m.ResetSkipRunnerEnvVars() return nil + case organization.FieldEnvVarRedaction: + m.ResetEnvVarRedaction() + return nil case organization.FieldSuspended: m.ResetSuspended() return nil diff --git a/app/controlplane/pkg/data/ent/organization.go b/app/controlplane/pkg/data/ent/organization.go index 027adf356..cf1ee91ed 100644 --- a/app/controlplane/pkg/data/ent/organization.go +++ b/app/controlplane/pkg/data/ent/organization.go @@ -10,6 +10,7 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" + "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/organization" "github.com/google/uuid" ) @@ -43,6 +44,8 @@ type Organization struct { BlockAttestationsOnReleasedVersions bool `json:"block_attestations_on_released_versions,omitempty"` // SkipRunnerEnvVars holds the value of the "skip_runner_env_vars" field. SkipRunnerEnvVars bool `json:"skip_runner_env_vars,omitempty"` + // EnvVarRedaction holds the value of the "env_var_redaction" field. + EnvVarRedaction *biz.EnvVarRedaction `json:"env_var_redaction,omitempty"` // Suspended holds the value of the "suspended" field. Suspended bool `json:"suspended,omitempty"` // Edges holds the relations/edges for other nodes in the graph. @@ -162,7 +165,7 @@ func (*Organization) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case organization.FieldPoliciesAllowedHostnames: + case organization.FieldPoliciesAllowedHostnames, organization.FieldEnvVarRedaction: values[i] = new([]byte) case organization.FieldBlockOnPolicyViolation, organization.FieldPreventImplicitWorkflowCreation, organization.FieldRestrictContractCreationToOrgAdmins, organization.FieldEnableAiAgentCollector, organization.FieldBlockAttestationsOnReleasedVersions, organization.FieldSkipRunnerEnvVars, organization.FieldSuspended: values[i] = new(sql.NullBool) @@ -270,6 +273,14 @@ func (_m *Organization) assignValues(columns []string, values []any) error { } else if value.Valid { _m.SkipRunnerEnvVars = value.Bool } + case organization.FieldEnvVarRedaction: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field env_var_redaction", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.EnvVarRedaction); err != nil { + return fmt.Errorf("unmarshal field env_var_redaction: %w", err) + } + } case organization.FieldSuspended: if value, ok := values[i].(*sql.NullBool); !ok { return fmt.Errorf("unexpected type %T for field suspended", values[i]) @@ -395,6 +406,9 @@ func (_m *Organization) String() string { builder.WriteString("skip_runner_env_vars=") builder.WriteString(fmt.Sprintf("%v", _m.SkipRunnerEnvVars)) builder.WriteString(", ") + builder.WriteString("env_var_redaction=") + builder.WriteString(fmt.Sprintf("%v", _m.EnvVarRedaction)) + builder.WriteString(", ") builder.WriteString("suspended=") builder.WriteString(fmt.Sprintf("%v", _m.Suspended)) builder.WriteByte(')') diff --git a/app/controlplane/pkg/data/ent/organization/organization.go b/app/controlplane/pkg/data/ent/organization/organization.go index 440b518fc..899dd7dbf 100644 --- a/app/controlplane/pkg/data/ent/organization/organization.go +++ b/app/controlplane/pkg/data/ent/organization/organization.go @@ -39,6 +39,8 @@ const ( FieldBlockAttestationsOnReleasedVersions = "block_attestations_on_released_versions" // FieldSkipRunnerEnvVars holds the string denoting the skip_runner_env_vars field in the database. FieldSkipRunnerEnvVars = "skip_runner_env_vars" + // FieldEnvVarRedaction holds the string denoting the env_var_redaction field in the database. + FieldEnvVarRedaction = "env_var_redaction" // FieldSuspended holds the string denoting the suspended field in the database. FieldSuspended = "suspended" // EdgeMemberships holds the string denoting the memberships edge name in mutations. @@ -141,6 +143,7 @@ var Columns = []string{ FieldEnableAiAgentCollector, FieldBlockAttestationsOnReleasedVersions, FieldSkipRunnerEnvVars, + FieldEnvVarRedaction, FieldSuspended, } diff --git a/app/controlplane/pkg/data/ent/organization/where.go b/app/controlplane/pkg/data/ent/organization/where.go index 3c1a9060b..44403ea27 100644 --- a/app/controlplane/pkg/data/ent/organization/where.go +++ b/app/controlplane/pkg/data/ent/organization/where.go @@ -431,6 +431,16 @@ func SkipRunnerEnvVarsNEQ(v bool) predicate.Organization { return predicate.Organization(sql.FieldNEQ(FieldSkipRunnerEnvVars, v)) } +// EnvVarRedactionIsNil applies the IsNil predicate on the "env_var_redaction" field. +func EnvVarRedactionIsNil() predicate.Organization { + return predicate.Organization(sql.FieldIsNull(FieldEnvVarRedaction)) +} + +// EnvVarRedactionNotNil applies the NotNil predicate on the "env_var_redaction" field. +func EnvVarRedactionNotNil() predicate.Organization { + return predicate.Organization(sql.FieldNotNull(FieldEnvVarRedaction)) +} + // SuspendedEQ applies the EQ predicate on the "suspended" field. func SuspendedEQ(v bool) predicate.Organization { return predicate.Organization(sql.FieldEQ(FieldSuspended, v)) diff --git a/app/controlplane/pkg/data/ent/organization_create.go b/app/controlplane/pkg/data/ent/organization_create.go index a499f434e..c726a0d0e 100644 --- a/app/controlplane/pkg/data/ent/organization_create.go +++ b/app/controlplane/pkg/data/ent/organization_create.go @@ -12,6 +12,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/apitoken" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/casbackend" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/group" @@ -185,6 +186,12 @@ func (_c *OrganizationCreate) SetNillableSkipRunnerEnvVars(v *bool) *Organizatio return _c } +// SetEnvVarRedaction sets the "env_var_redaction" field. +func (_c *OrganizationCreate) SetEnvVarRedaction(v *biz.EnvVarRedaction) *OrganizationCreate { + _c.mutation.SetEnvVarRedaction(v) + return _c +} + // SetSuspended sets the "suspended" field. func (_c *OrganizationCreate) SetSuspended(v bool) *OrganizationCreate { _c.mutation.SetSuspended(v) @@ -541,6 +548,10 @@ func (_c *OrganizationCreate) createSpec() (*Organization, *sqlgraph.CreateSpec) _spec.SetField(organization.FieldSkipRunnerEnvVars, field.TypeBool, value) _node.SkipRunnerEnvVars = value } + if value, ok := _c.mutation.EnvVarRedaction(); ok { + _spec.SetField(organization.FieldEnvVarRedaction, field.TypeJSON, value) + _node.EnvVarRedaction = value + } if value, ok := _c.mutation.Suspended(); ok { _spec.SetField(organization.FieldSuspended, field.TypeBool, value) _node.Suspended = value @@ -897,6 +908,24 @@ func (u *OrganizationUpsert) UpdateSkipRunnerEnvVars() *OrganizationUpsert { return u } +// SetEnvVarRedaction sets the "env_var_redaction" field. +func (u *OrganizationUpsert) SetEnvVarRedaction(v *biz.EnvVarRedaction) *OrganizationUpsert { + u.Set(organization.FieldEnvVarRedaction, v) + return u +} + +// UpdateEnvVarRedaction sets the "env_var_redaction" field to the value that was provided on create. +func (u *OrganizationUpsert) UpdateEnvVarRedaction() *OrganizationUpsert { + u.SetExcluded(organization.FieldEnvVarRedaction) + return u +} + +// ClearEnvVarRedaction clears the value of the "env_var_redaction" field. +func (u *OrganizationUpsert) ClearEnvVarRedaction() *OrganizationUpsert { + u.SetNull(organization.FieldEnvVarRedaction) + return u +} + // SetSuspended sets the "suspended" field. func (u *OrganizationUpsert) SetSuspended(v bool) *OrganizationUpsert { u.Set(organization.FieldSuspended, v) @@ -1142,6 +1171,27 @@ func (u *OrganizationUpsertOne) UpdateSkipRunnerEnvVars() *OrganizationUpsertOne }) } +// SetEnvVarRedaction sets the "env_var_redaction" field. +func (u *OrganizationUpsertOne) SetEnvVarRedaction(v *biz.EnvVarRedaction) *OrganizationUpsertOne { + return u.Update(func(s *OrganizationUpsert) { + s.SetEnvVarRedaction(v) + }) +} + +// UpdateEnvVarRedaction sets the "env_var_redaction" field to the value that was provided on create. +func (u *OrganizationUpsertOne) UpdateEnvVarRedaction() *OrganizationUpsertOne { + return u.Update(func(s *OrganizationUpsert) { + s.UpdateEnvVarRedaction() + }) +} + +// ClearEnvVarRedaction clears the value of the "env_var_redaction" field. +func (u *OrganizationUpsertOne) ClearEnvVarRedaction() *OrganizationUpsertOne { + return u.Update(func(s *OrganizationUpsert) { + s.ClearEnvVarRedaction() + }) +} + // SetSuspended sets the "suspended" field. func (u *OrganizationUpsertOne) SetSuspended(v bool) *OrganizationUpsertOne { return u.Update(func(s *OrganizationUpsert) { @@ -1556,6 +1606,27 @@ func (u *OrganizationUpsertBulk) UpdateSkipRunnerEnvVars() *OrganizationUpsertBu }) } +// SetEnvVarRedaction sets the "env_var_redaction" field. +func (u *OrganizationUpsertBulk) SetEnvVarRedaction(v *biz.EnvVarRedaction) *OrganizationUpsertBulk { + return u.Update(func(s *OrganizationUpsert) { + s.SetEnvVarRedaction(v) + }) +} + +// UpdateEnvVarRedaction sets the "env_var_redaction" field to the value that was provided on create. +func (u *OrganizationUpsertBulk) UpdateEnvVarRedaction() *OrganizationUpsertBulk { + return u.Update(func(s *OrganizationUpsert) { + s.UpdateEnvVarRedaction() + }) +} + +// ClearEnvVarRedaction clears the value of the "env_var_redaction" field. +func (u *OrganizationUpsertBulk) ClearEnvVarRedaction() *OrganizationUpsertBulk { + return u.Update(func(s *OrganizationUpsert) { + s.ClearEnvVarRedaction() + }) +} + // SetSuspended sets the "suspended" field. func (u *OrganizationUpsertBulk) SetSuspended(v bool) *OrganizationUpsertBulk { return u.Update(func(s *OrganizationUpsert) { diff --git a/app/controlplane/pkg/data/ent/organization_update.go b/app/controlplane/pkg/data/ent/organization_update.go index da01eada9..60e579d28 100644 --- a/app/controlplane/pkg/data/ent/organization_update.go +++ b/app/controlplane/pkg/data/ent/organization_update.go @@ -12,6 +12,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" + "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/apitoken" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/casbackend" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/group" @@ -217,6 +218,18 @@ func (_u *OrganizationUpdate) SetNillableSkipRunnerEnvVars(v *bool) *Organizatio return _u } +// SetEnvVarRedaction sets the "env_var_redaction" field. +func (_u *OrganizationUpdate) SetEnvVarRedaction(v *biz.EnvVarRedaction) *OrganizationUpdate { + _u.mutation.SetEnvVarRedaction(v) + return _u +} + +// ClearEnvVarRedaction clears the value of the "env_var_redaction" field. +func (_u *OrganizationUpdate) ClearEnvVarRedaction() *OrganizationUpdate { + _u.mutation.ClearEnvVarRedaction() + return _u +} + // SetSuspended sets the "suspended" field. func (_u *OrganizationUpdate) SetSuspended(v bool) *OrganizationUpdate { _u.mutation.SetSuspended(v) @@ -652,6 +665,12 @@ func (_u *OrganizationUpdate) sqlSave(ctx context.Context) (_node int, err error if value, ok := _u.mutation.SkipRunnerEnvVars(); ok { _spec.SetField(organization.FieldSkipRunnerEnvVars, field.TypeBool, value) } + if value, ok := _u.mutation.EnvVarRedaction(); ok { + _spec.SetField(organization.FieldEnvVarRedaction, field.TypeJSON, value) + } + if _u.mutation.EnvVarRedactionCleared() { + _spec.ClearField(organization.FieldEnvVarRedaction, field.TypeJSON) + } if value, ok := _u.mutation.Suspended(); ok { _spec.SetField(organization.FieldSuspended, field.TypeBool, value) } @@ -1259,6 +1278,18 @@ func (_u *OrganizationUpdateOne) SetNillableSkipRunnerEnvVars(v *bool) *Organiza return _u } +// SetEnvVarRedaction sets the "env_var_redaction" field. +func (_u *OrganizationUpdateOne) SetEnvVarRedaction(v *biz.EnvVarRedaction) *OrganizationUpdateOne { + _u.mutation.SetEnvVarRedaction(v) + return _u +} + +// ClearEnvVarRedaction clears the value of the "env_var_redaction" field. +func (_u *OrganizationUpdateOne) ClearEnvVarRedaction() *OrganizationUpdateOne { + _u.mutation.ClearEnvVarRedaction() + return _u +} + // SetSuspended sets the "suspended" field. func (_u *OrganizationUpdateOne) SetSuspended(v bool) *OrganizationUpdateOne { _u.mutation.SetSuspended(v) @@ -1724,6 +1755,12 @@ func (_u *OrganizationUpdateOne) sqlSave(ctx context.Context) (_node *Organizati if value, ok := _u.mutation.SkipRunnerEnvVars(); ok { _spec.SetField(organization.FieldSkipRunnerEnvVars, field.TypeBool, value) } + if value, ok := _u.mutation.EnvVarRedaction(); ok { + _spec.SetField(organization.FieldEnvVarRedaction, field.TypeJSON, value) + } + if _u.mutation.EnvVarRedactionCleared() { + _spec.ClearField(organization.FieldEnvVarRedaction, field.TypeJSON) + } if value, ok := _u.mutation.Suspended(); ok { _spec.SetField(organization.FieldSuspended, field.TypeBool, value) } diff --git a/app/controlplane/pkg/data/ent/runtime.go b/app/controlplane/pkg/data/ent/runtime.go index 482787fb4..12642e9dd 100644 --- a/app/controlplane/pkg/data/ent/runtime.go +++ b/app/controlplane/pkg/data/ent/runtime.go @@ -241,7 +241,7 @@ func init() { // organization.DefaultSkipRunnerEnvVars holds the default value on creation for the skip_runner_env_vars field. organization.DefaultSkipRunnerEnvVars = organizationDescSkipRunnerEnvVars.Default.(bool) // organizationDescSuspended is the schema descriptor for suspended field. - organizationDescSuspended := organizationFields[13].Descriptor() + organizationDescSuspended := organizationFields[14].Descriptor() // organization.DefaultSuspended holds the default value on creation for the suspended field. organization.DefaultSuspended = organizationDescSuspended.Default.(bool) // organizationDescID is the schema descriptor for id field. diff --git a/app/controlplane/pkg/data/ent/schema/organization.go b/app/controlplane/pkg/data/ent/schema/organization.go index 47b484421..4973614d6 100644 --- a/app/controlplane/pkg/data/ent/schema/organization.go +++ b/app/controlplane/pkg/data/ent/schema/organization.go @@ -23,6 +23,7 @@ import ( "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" + "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz" "github.com/google/uuid" ) @@ -65,6 +66,9 @@ func (Organization) Fields() []ent.Field { // skip_runner_env_vars opts out of storing the environment variables automatically // discovered by the CI runner in the attestation. The contract's env_allow_list is not affected. field.Bool("skip_runner_env_vars").Default(false), + // env_var_redaction replaces the values of selected env vars with a placeholder in new attestations. + // Empty means no redaction. + field.JSON("env_var_redaction", &biz.EnvVarRedaction{}).Optional(), // Suspended orgs are blocked from all operations. field.Bool("suspended").Default(false), } diff --git a/app/controlplane/pkg/data/organization.go b/app/controlplane/pkg/data/organization.go index b3b54fe8c..87887add9 100644 --- a/app/controlplane/pkg/data/organization.go +++ b/app/controlplane/pkg/data/organization.go @@ -23,6 +23,7 @@ import ( "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent" "github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/organization" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" "github.com/chainloop-dev/chainloop/pkg/otelx" "github.com/go-kratos/kratos/v2/log" "github.com/google/uuid" @@ -111,6 +112,14 @@ func (r *OrganizationRepo) Update(ctx context.Context, id uuid.UUID, updateOpts query.SetPoliciesAllowedHostnames(updateOpts.PoliciesAllowedHostnames) } + if r := updateOpts.EnvVarRedaction; r != nil { + if r.Mode == envredaction.ModeNone { + query.ClearEnvVarRedaction() + } else { + query.SetEnvVarRedaction(r) + } + } + if updateOpts.APITokenInactivityThresholdDays != nil { if *updateOpts.APITokenInactivityThresholdDays == 0 { query.ClearAPITokenInactivityThresholdDays() @@ -186,6 +195,7 @@ func entOrgToBizOrg(eu *ent.Organization) *biz.Organization { EnableAIAgentCollector: eu.EnableAiAgentCollector, BlockAttestationsOnReleasedVersions: eu.BlockAttestationsOnReleasedVersions, SkipRunnerEnvVars: eu.SkipRunnerEnvVars, + EnvVarRedaction: eu.EnvVarRedaction, Suspended: eu.Suspended, } } diff --git a/pkg/attestation/crafter/api/attestation/v1/crafting_state.pb.go b/pkg/attestation/crafter/api/attestation/v1/crafting_state.pb.go index 880291159..cc10fcbd0 100644 --- a/pkg/attestation/crafter/api/attestation/v1/crafting_state.pb.go +++ b/pkg/attestation/crafter/api/attestation/v1/crafting_state.pb.go @@ -189,8 +189,12 @@ type Attestation struct { // skip storing the environment variables automatically discovered by the CI runner. // The contract's env_allow_list is not affected by this flag. SkipRunnerEnvVars bool `protobuf:"varint,20,opt,name=skip_runner_env_vars,json=skipRunnerEnvVars,proto3" json:"skip_runner_env_vars,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache + // exact names of the environment variables whose values are replaced with "[REDACTED]", + // as resolved by the control plane from the organization setting. + // It applies to the runner env vars and to the contract's env_allow_list. + RedactedEnvVars []string `protobuf:"bytes,21,rep,name=redacted_env_vars,json=redactedEnvVars,proto3" json:"redacted_env_vars,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *Attestation) Reset() { @@ -349,6 +353,13 @@ func (x *Attestation) GetSkipRunnerEnvVars() bool { return false } +func (x *Attestation) GetRedactedEnvVars() []string { + if x != nil { + return x.RedactedEnvVars + } + return nil +} + // The runner environment in which the attestation was crafted type RunnerEnvironment struct { state protoimpl.MessageState `protogen:"open.v1"` @@ -2842,7 +2853,7 @@ var File_attestation_v1_crafting_state_proto protoreflect.FileDescriptor const file_attestation_v1_crafting_state_proto_rawDesc = "" + "\n" + - "#attestation/v1/crafting_state.proto\x12\x0eattestation.v1\x1a\x1bbuf/validate/validate.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a)workflowcontract/v1/crafting_schema.proto\"\xbd\x1c\n" + + "#attestation/v1/crafting_state.proto\x12\x0eattestation.v1\x1a\x1bbuf/validate/validate.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a)workflowcontract/v1/crafting_schema.proto\"\xe9\x1c\n" + "\vAttestation\x12I\n" + "\x0einitialized_at\x18\x01 \x01(\v2\x1a.google.protobuf.TimestampB\x06\xbaH\x03\xc8\x01\x01R\rinitializedAt\x12;\n" + "\vfinished_at\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\n" + @@ -2866,7 +2877,8 @@ const file_attestation_v1_crafting_state_proto_rawDesc = "" + "\x1apolicies_allowed_hostnames\x18\x12 \x03(\tR\x18policiesAllowedHostnames\x12G\n" + "\vcas_backend\x18\x13 \x01(\v2&.attestation.v1.Attestation.CASBackendR\n" + "casBackend\x12/\n" + - "\x14skip_runner_env_vars\x18\x14 \x01(\bR\x11skipRunnerEnvVars\x1ab\n" + + "\x14skip_runner_env_vars\x18\x14 \x01(\bR\x11skipRunnerEnvVars\x12*\n" + + "\x11redacted_env_vars\x18\x15 \x03(\tR\x0fredactedEnvVars\x1ab\n" + "\x0eMaterialsEntry\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12:\n" + "\x05value\x18\x02 \x01(\v2$.attestation.v1.Attestation.MaterialR\x05value:\x028\x01\x1a>\n" + diff --git a/pkg/attestation/crafter/api/attestation/v1/crafting_state.proto b/pkg/attestation/crafter/api/attestation/v1/crafting_state.proto index 3caa49e4e..dd23befc2 100644 --- a/pkg/attestation/crafter/api/attestation/v1/crafting_state.proto +++ b/pkg/attestation/crafter/api/attestation/v1/crafting_state.proto @@ -167,6 +167,11 @@ message Attestation { // The contract's env_allow_list is not affected by this flag. bool skip_runner_env_vars = 20; + // exact names of the environment variables whose values are replaced with "[REDACTED]", + // as resolved by the control plane from the organization setting. + // It applies to the runner env vars and to the contract's env_allow_list. + repeated string redacted_env_vars = 21; + message Auth { AuthType type = 1 [(buf.validate.field).enum = { not_in: [0] diff --git a/pkg/attestation/crafter/crafter.go b/pkg/attestation/crafter/crafter.go index 7e0d63db7..f85552a76 100644 --- a/pkg/attestation/crafter/crafter.go +++ b/pkg/attestation/crafter/crafter.go @@ -36,6 +36,7 @@ import ( api "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/api/attestation/v1" "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/materials" "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/runners/commitverification" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" "github.com/chainloop-dev/chainloop/pkg/casclient" "github.com/chainloop-dev/chainloop/pkg/policies" "github.com/go-git/go-git/v6" @@ -227,6 +228,8 @@ type InitOpts struct { PoliciesAllowedHostnames []string // opt out of storing the environment variables automatically discovered by the CI runner SkipRunnerEnvVars bool + // names of the env vars to redact, resolved by the control plane from the org setting + RedactedEnvVars []string // CAS backend information CASBackend *api.Attestation_CASBackend // UIDashboardURL is the base URL to build the attestation view link @@ -530,6 +533,7 @@ func initialCraftingState(cwd string, opts *InitOpts) (*api.CraftingState, error Auth: opts.Auth, PoliciesAllowedHostnames: opts.PoliciesAllowedHostnames, SkipRunnerEnvVars: opts.SkipRunnerEnvVars, + RedactedEnvVars: opts.RedactedEnvVars, CasBackend: opts.CASBackend, }, DryRun: opts.DryRun, @@ -616,6 +620,11 @@ func (c *Crafter) ResolveEnvVars(ctx context.Context, attestationID string) erro } } + // The org can redact the values of some variables. It applies to both the runner + // and the contract variables, so a contract cannot bring back a redacted value. + // The control plane resolves the names, so they match the ones it checks at push. + envredaction.Apply(outputEnvVars, c.CraftingState.GetAttestation().GetRedactedEnvVars()) + // Resolve runner information c.resolveRunnerInfo() diff --git a/pkg/attestation/crafter/crafter_test.go b/pkg/attestation/crafter/crafter_test.go index fdf43aef3..834397ea4 100644 --- a/pkg/attestation/crafter/crafter_test.go +++ b/pkg/attestation/crafter/crafter_test.go @@ -42,6 +42,7 @@ import ( "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/materials" "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/runners" "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/statemanager/filesystem" + "github.com/chainloop-dev/chainloop/pkg/attestation/envredaction" "github.com/chainloop-dev/chainloop/pkg/casclient" mUploader "github.com/chainloop-dev/chainloop/pkg/casclient/mocks" @@ -474,6 +475,8 @@ func (s *crafterSuite) TestResolveEnvVars() { // opt out of storing the auto-discovered runner env vars skipRunnerEnvVars bool + // names of the env vars to redact, resolved by the control plane + redactedEnvVars []string expectedError string expectedEnvVars map[string]string @@ -556,6 +559,46 @@ func (s *crafterSuite) TestResolveEnvVars() { "CUSTOM_VAR_1": "custom_value_1", "CUSTOM_VAR_2": "custom_value_2", }, + }, { + name: "known identity redaction keeps the key and hides the value", + inGithubEnv: true, + redactedEnvVars: runners.KnownIdentityEnvVars(), + envVars: map[string]string{ + "CUSTOM_VAR_1": "custom_value_1", + "CUSTOM_VAR_2": "custom_value_2", + }, + expectedEnvVars: withGitHubEnv(map[string]string{ + "GITHUB_ACTOR": envredaction.RedactedValue, + "CUSTOM_VAR_1": "custom_value_1", + "CUSTOM_VAR_2": "custom_value_2", + }), + }, { + name: "redaction applies to runner vars and the contract allow-list", + inGithubEnv: true, + redactedEnvVars: []string{runnerNameVar, "CUSTOM_VAR_1"}, + envVars: map[string]string{ + "CUSTOM_VAR_1": "custom_value_1", + "CUSTOM_VAR_2": "custom_value_2", + }, + // only the names from the control plane are redacted, GITHUB_ACTOR stays + expectedEnvVars: withGitHubEnv(map[string]string{ + runnerNameVar: envredaction.RedactedValue, + "CUSTOM_VAR_1": envredaction.RedactedValue, + "CUSTOM_VAR_2": "custom_value_2", + }), + }, { + name: "redaction also applies when runner env vars are skipped", + inGithubEnv: true, + skipRunnerEnvVars: true, + redactedEnvVars: []string{"CUSTOM_VAR_2"}, + envVars: map[string]string{ + "CUSTOM_VAR_1": "custom_value_1", + "CUSTOM_VAR_2": "custom_value_2", + }, + expectedEnvVars: map[string]string{ + "CUSTOM_VAR_1": "custom_value_1", + "CUSTOM_VAR_2": envredaction.RedactedValue, + }, }, } @@ -589,6 +632,7 @@ func (s *crafterSuite) TestResolveEnvVars() { require.NoError(s.T(), err) c.CraftingState.Attestation.SkipRunnerEnvVars = tc.skipRunnerEnvVars + c.CraftingState.Attestation.RedactedEnvVars = tc.redactedEnvVars err = c.ResolveEnvVars(context.Background(), "") @@ -605,6 +649,8 @@ func (s *crafterSuite) TestResolveEnvVars() { } } +const runnerNameVar = "RUNNER_NAME" + var gitHubTestingEnvVars = map[string]string{ "GITHUB_REPOSITORY": "chainloop/chainloop", "GITHUB_RUN_ID": "123", @@ -612,10 +658,17 @@ var gitHubTestingEnvVars = map[string]string{ "GITHUB_REF": "refs/heads/main", "GITHUB_REPOSITORY_OWNER": "chainloop", "GITHUB_SHA": "1234567890", - "RUNNER_NAME": "chainloop-runner", + runnerNameVar: "chainloop-runner", "RUNNER_OS": "linux", } +// withGitHubEnv returns the GitHub testing env vars with the overrides applied on top. +func withGitHubEnv(overrides map[string]string) map[string]string { + out := maps.Clone(gitHubTestingEnvVars) + maps.Copy(out, overrides) + return out +} + func (s *crafterSuite) TestAlreadyInitialized() { s.T().Run("already initialized", func(t *testing.T) { statePath := fmt.Sprintf("%s/attestation.json", t.TempDir()) diff --git a/pkg/attestation/crafter/runner_test.go b/pkg/attestation/crafter/runner_test.go index de312a7ae..64db71660 100644 --- a/pkg/attestation/crafter/runner_test.go +++ b/pkg/attestation/crafter/runner_test.go @@ -156,3 +156,21 @@ func TestVerifyCommitWithPlatformLogsUnavailableReason(t *testing.T) { }) } } + +// KnownIdentityEnvVars keeps its own list of runners, because the runners package +// cannot import this one. A runner added here but not there would leave its +// identity variables out of the known identity redaction mode. +func TestKnownIdentityEnvVarsCoversEveryRunner(t *testing.T) { + known := runners.KnownIdentityEnvVars() + logger := zerolog.Nop() + + for runnerType, factory := range RunnerFactories { + t.Run(runnerType.String(), func(t *testing.T) { + for _, def := range factory("", &logger).ListEnvVars() { + if def.Identity { + assert.Contains(t, known, def.Name) + } + } + }) + } +} diff --git a/pkg/attestation/crafter/runners/azurepipeline.go b/pkg/attestation/crafter/runners/azurepipeline.go index 7f18fd668..172a881d1 100644 --- a/pkg/attestation/crafter/runners/azurepipeline.go +++ b/pkg/attestation/crafter/runners/azurepipeline.go @@ -58,15 +58,15 @@ func (r *AzurePipeline) CheckEnv() bool { func (r *AzurePipeline) ListEnvVars() []*EnvVarDefinition { return []*EnvVarDefinition{ - {"BUILD_REQUESTEDFOREMAIL", true}, - {"BUILD_REQUESTEDFOR", false}, - {"BUILD_REPOSITORY_URI", true}, - {"BUILD_REPOSITORY_NAME", true}, - {"BUILD_BUILDID", false}, - {"BUILD_BUILDNUMBER", false}, - {"BUILD_BUILDURI", false}, - {"BUILD_REASON", true}, - {"TF_BUILD", true}, + {Name: "BUILD_REQUESTEDFOREMAIL", Optional: true, Identity: true}, + {Name: "BUILD_REQUESTEDFOR", Identity: true}, + {Name: "BUILD_REPOSITORY_URI", Optional: true}, + {Name: "BUILD_REPOSITORY_NAME", Optional: true}, + {Name: "BUILD_BUILDID"}, + {Name: "BUILD_BUILDNUMBER"}, + {Name: "BUILD_BUILDURI"}, + {Name: "BUILD_REASON", Optional: true}, + {Name: "TF_BUILD", Optional: true}, } } diff --git a/pkg/attestation/crafter/runners/azurepipeline_test.go b/pkg/attestation/crafter/runners/azurepipeline_test.go index 1bac06719..9b95eec08 100644 --- a/pkg/attestation/crafter/runners/azurepipeline_test.go +++ b/pkg/attestation/crafter/runners/azurepipeline_test.go @@ -79,15 +79,15 @@ func (s *azurePipelineSuite) TestCheckEnv() { func (s *azurePipelineSuite) TestListEnvVars() { assert.Equal(s.T(), []*EnvVarDefinition{ - {"BUILD_REQUESTEDFOREMAIL", true}, - {"BUILD_REQUESTEDFOR", false}, - {"BUILD_REPOSITORY_URI", true}, - {"BUILD_REPOSITORY_NAME", true}, - {"BUILD_BUILDID", false}, - {"BUILD_BUILDNUMBER", false}, - {"BUILD_BUILDURI", false}, - {"BUILD_REASON", true}, - {"TF_BUILD", true}, + {Name: "BUILD_REQUESTEDFOREMAIL", Optional: true, Identity: true}, + {Name: "BUILD_REQUESTEDFOR", Identity: true}, + {Name: "BUILD_REPOSITORY_URI", Optional: true}, + {Name: "BUILD_REPOSITORY_NAME", Optional: true}, + {Name: "BUILD_BUILDID"}, + {Name: "BUILD_BUILDNUMBER"}, + {Name: "BUILD_BUILDURI"}, + {Name: "BUILD_REASON", Optional: true}, + {Name: "TF_BUILD", Optional: true}, }, s.runner.ListEnvVars()) } diff --git a/pkg/attestation/crafter/runners/circleci_build.go b/pkg/attestation/crafter/runners/circleci_build.go index c750170c9..953a32b2e 100644 --- a/pkg/attestation/crafter/runners/circleci_build.go +++ b/pkg/attestation/crafter/runners/circleci_build.go @@ -50,15 +50,15 @@ func (r *CircleCIBuild) CheckEnv() bool { func (r *CircleCIBuild) ListEnvVars() []*EnvVarDefinition { return []*EnvVarDefinition{ // Some info about the job - {"CIRCLE_BUILD_URL", false}, - {"CIRCLE_JOB", false}, + {Name: "CIRCLE_BUILD_URL"}, + {Name: "CIRCLE_JOB"}, // Some info about the commit - {"CIRCLE_BRANCH", false}, + {Name: "CIRCLE_BRANCH"}, // Some info about the agent - {"CIRCLE_NODE_TOTAL", false}, - {"CIRCLE_NODE_INDEX", false}, + {Name: "CIRCLE_NODE_TOTAL"}, + {Name: "CIRCLE_NODE_INDEX"}, } } diff --git a/pkg/attestation/crafter/runners/circleci_build_test.go b/pkg/attestation/crafter/runners/circleci_build_test.go index ccd805f61..bf8c40a17 100644 --- a/pkg/attestation/crafter/runners/circleci_build_test.go +++ b/pkg/attestation/crafter/runners/circleci_build_test.go @@ -1,5 +1,5 @@ // -// Copyright 2023 The Chainloop Authors. +// Copyright 2023-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -89,11 +89,11 @@ func (s *circleCIBuildSuite) TestCheckEnv() { func (s *circleCIBuildSuite) TestListEnvVars() { s.Equal([]*EnvVarDefinition{ - {"CIRCLE_BUILD_URL", false}, - {"CIRCLE_JOB", false}, - {"CIRCLE_BRANCH", false}, - {"CIRCLE_NODE_TOTAL", false}, - {"CIRCLE_NODE_INDEX", false}, + {Name: "CIRCLE_BUILD_URL"}, + {Name: "CIRCLE_JOB"}, + {Name: "CIRCLE_BRANCH"}, + {Name: "CIRCLE_NODE_TOTAL"}, + {Name: "CIRCLE_NODE_INDEX"}, }, s.runner.ListEnvVars()) } diff --git a/pkg/attestation/crafter/runners/daggerpipeline.go b/pkg/attestation/crafter/runners/daggerpipeline.go index 6c8eaa200..5f065066a 100644 --- a/pkg/attestation/crafter/runners/daggerpipeline.go +++ b/pkg/attestation/crafter/runners/daggerpipeline.go @@ -54,24 +54,24 @@ func (r *DaggerPipeline) CheckEnv() bool { func (r *DaggerPipeline) ListEnvVars() []*EnvVarDefinition { return []*EnvVarDefinition{ // Version of the Chainloop Client - {"CHAINLOOP_DAGGER_CLIENT", false}, + {Name: "CHAINLOOP_DAGGER_CLIENT"}, // Github Actions PR-specific variables (optional - only present in PR contexts) - {"GITHUB_EVENT_NAME", true}, - {"GITHUB_HEAD_REF", true}, - {"GITHUB_BASE_REF", true}, - {"GITHUB_EVENT_PATH", true}, + {Name: "GITHUB_EVENT_NAME", Optional: true}, + {Name: "GITHUB_HEAD_REF", Optional: true}, + {Name: "GITHUB_BASE_REF", Optional: true}, + {Name: "GITHUB_EVENT_PATH", Optional: true}, // Gitlab CI MR-specific variables (optional - only present in MR contexts) - {"CI_PIPELINE_SOURCE", true}, - {"CI_MERGE_REQUEST_IID", true}, - {"CI_MERGE_REQUEST_TITLE", true}, - {"CI_MERGE_REQUEST_DESCRIPTION", true}, - {"CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", true}, - {"CI_MERGE_REQUEST_TARGET_BRANCH_NAME", true}, - {"CI_MERGE_REQUEST_PROJECT_URL", true}, - {"CI_MERGE_REQUEST_PROJECT_PATH", true}, - {"CI_SERVER_URL", true}, - {"CI_PROJECT_PATH", true}, - {"GITLAB_USER_LOGIN", true}, + {Name: "CI_PIPELINE_SOURCE", Optional: true}, + {Name: "CI_MERGE_REQUEST_IID", Optional: true}, + {Name: "CI_MERGE_REQUEST_TITLE", Optional: true}, + {Name: "CI_MERGE_REQUEST_DESCRIPTION", Optional: true}, + {Name: "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", Optional: true}, + {Name: "CI_MERGE_REQUEST_TARGET_BRANCH_NAME", Optional: true}, + {Name: "CI_MERGE_REQUEST_PROJECT_URL", Optional: true}, + {Name: "CI_MERGE_REQUEST_PROJECT_PATH", Optional: true}, + {Name: "CI_SERVER_URL", Optional: true}, + {Name: "CI_PROJECT_PATH", Optional: true}, + {Name: "GITLAB_USER_LOGIN", Optional: true, Identity: true}, } } diff --git a/pkg/attestation/crafter/runners/daggerpipeline_test.go b/pkg/attestation/crafter/runners/daggerpipeline_test.go index 7bc3b8640..8579e2440 100644 --- a/pkg/attestation/crafter/runners/daggerpipeline_test.go +++ b/pkg/attestation/crafter/runners/daggerpipeline_test.go @@ -64,24 +64,24 @@ func (s *daggerPipelineSuite) TestCheckEnv() { func (s *daggerPipelineSuite) TestListEnvVars() { expected := []*EnvVarDefinition{ - {"CHAINLOOP_DAGGER_CLIENT", false}, + {Name: "CHAINLOOP_DAGGER_CLIENT"}, // Github Actions PR-specific variables - {"GITHUB_EVENT_NAME", true}, - {"GITHUB_HEAD_REF", true}, - {"GITHUB_BASE_REF", true}, - {"GITHUB_EVENT_PATH", true}, + {Name: "GITHUB_EVENT_NAME", Optional: true}, + {Name: "GITHUB_HEAD_REF", Optional: true}, + {Name: "GITHUB_BASE_REF", Optional: true}, + {Name: "GITHUB_EVENT_PATH", Optional: true}, // Gitlab CI MR-specific variables - {"CI_PIPELINE_SOURCE", true}, - {"CI_MERGE_REQUEST_IID", true}, - {"CI_MERGE_REQUEST_TITLE", true}, - {"CI_MERGE_REQUEST_DESCRIPTION", true}, - {"CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", true}, - {"CI_MERGE_REQUEST_TARGET_BRANCH_NAME", true}, - {"CI_MERGE_REQUEST_PROJECT_URL", true}, - {"CI_MERGE_REQUEST_PROJECT_PATH", true}, - {"CI_SERVER_URL", true}, - {"CI_PROJECT_PATH", true}, - {"GITLAB_USER_LOGIN", true}, + {Name: "CI_PIPELINE_SOURCE", Optional: true}, + {Name: "CI_MERGE_REQUEST_IID", Optional: true}, + {Name: "CI_MERGE_REQUEST_TITLE", Optional: true}, + {Name: "CI_MERGE_REQUEST_DESCRIPTION", Optional: true}, + {Name: "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", Optional: true}, + {Name: "CI_MERGE_REQUEST_TARGET_BRANCH_NAME", Optional: true}, + {Name: "CI_MERGE_REQUEST_PROJECT_URL", Optional: true}, + {Name: "CI_MERGE_REQUEST_PROJECT_PATH", Optional: true}, + {Name: "CI_SERVER_URL", Optional: true}, + {Name: "CI_PROJECT_PATH", Optional: true}, + {Name: "GITLAB_USER_LOGIN", Optional: true, Identity: true}, } assert.Equal(s.T(), expected, s.runner.ListEnvVars()) } diff --git a/pkg/attestation/crafter/runners/githubaction.go b/pkg/attestation/crafter/runners/githubaction.go index 0ef2aba08..7ff780a43 100644 --- a/pkg/attestation/crafter/runners/githubaction.go +++ b/pkg/attestation/crafter/runners/githubaction.go @@ -93,19 +93,19 @@ func (r *GitHubAction) CheckEnv() bool { func (r *GitHubAction) ListEnvVars() []*EnvVarDefinition { return []*EnvVarDefinition{ - {"GITHUB_ACTOR", false}, - {"GITHUB_REF", false}, - {"GITHUB_REPOSITORY", false}, - {"GITHUB_REPOSITORY_OWNER", false}, - {"GITHUB_RUN_ID", false}, - {"GITHUB_SHA", false}, - {"RUNNER_NAME", false}, - {"RUNNER_OS", false}, + {Name: "GITHUB_ACTOR", Identity: true}, + {Name: "GITHUB_REF"}, + {Name: "GITHUB_REPOSITORY"}, + {Name: "GITHUB_REPOSITORY_OWNER"}, + {Name: "GITHUB_RUN_ID"}, + {Name: "GITHUB_SHA"}, + {Name: "RUNNER_NAME"}, + {Name: "RUNNER_OS"}, // PR-specific variables (optional - only present in PR contexts) - {"GITHUB_EVENT_NAME", true}, - {"GITHUB_HEAD_REF", true}, - {"GITHUB_BASE_REF", true}, - {"GITHUB_EVENT_PATH", true}, + {Name: "GITHUB_EVENT_NAME", Optional: true}, + {Name: "GITHUB_HEAD_REF", Optional: true}, + {Name: "GITHUB_BASE_REF", Optional: true}, + {Name: "GITHUB_EVENT_PATH", Optional: true}, } } diff --git a/pkg/attestation/crafter/runners/githubaction_test.go b/pkg/attestation/crafter/runners/githubaction_test.go index 774b27f9f..d6ddca76b 100644 --- a/pkg/attestation/crafter/runners/githubaction_test.go +++ b/pkg/attestation/crafter/runners/githubaction_test.go @@ -1,5 +1,5 @@ // -// Copyright 2024-2025 The Chainloop Authors. +// Copyright 2024-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -93,18 +93,18 @@ func (s *githubActionSuite) TestCheckEnv() { func (s *githubActionSuite) TestListEnvVars() { s.Equal([]*EnvVarDefinition{ - {"GITHUB_ACTOR", false}, - {"GITHUB_REF", false}, - {"GITHUB_REPOSITORY", false}, - {"GITHUB_REPOSITORY_OWNER", false}, - {"GITHUB_RUN_ID", false}, - {"GITHUB_SHA", false}, - {"RUNNER_NAME", false}, - {"RUNNER_OS", false}, - {"GITHUB_EVENT_NAME", true}, - {"GITHUB_HEAD_REF", true}, - {"GITHUB_BASE_REF", true}, - {"GITHUB_EVENT_PATH", true}, + {Name: "GITHUB_ACTOR", Identity: true}, + {Name: "GITHUB_REF"}, + {Name: "GITHUB_REPOSITORY"}, + {Name: "GITHUB_REPOSITORY_OWNER"}, + {Name: "GITHUB_RUN_ID"}, + {Name: "GITHUB_SHA"}, + {Name: "RUNNER_NAME"}, + {Name: "RUNNER_OS"}, + {Name: "GITHUB_EVENT_NAME", Optional: true}, + {Name: "GITHUB_HEAD_REF", Optional: true}, + {Name: "GITHUB_BASE_REF", Optional: true}, + {Name: "GITHUB_EVENT_PATH", Optional: true}, }, s.runner.ListEnvVars()) } diff --git a/pkg/attestation/crafter/runners/gitlabpipeline.go b/pkg/attestation/crafter/runners/gitlabpipeline.go index 88903c0a8..1f22f05fb 100644 --- a/pkg/attestation/crafter/runners/gitlabpipeline.go +++ b/pkg/attestation/crafter/runners/gitlabpipeline.go @@ -68,26 +68,26 @@ func (r *GitlabPipeline) CheckEnv() bool { func (r *GitlabPipeline) ListEnvVars() []*EnvVarDefinition { return []*EnvVarDefinition{ - {"GITLAB_USER_EMAIL", false}, - {"GITLAB_USER_LOGIN", false}, - {"CI_SERVER_URL", false}, - {"CI_PROJECT_URL", false}, - {"CI_COMMIT_SHA", false}, - {"CI_JOB_URL", false}, - {"CI_PIPELINE_URL", false}, - {"CI_RUNNER_VERSION", false}, - {"CI_RUNNER_DESCRIPTION", true}, - {"CI_COMMIT_REF_NAME", false}, - {"CI_PROJECT_PATH", false}, + {Name: "GITLAB_USER_EMAIL", Identity: true}, + {Name: "GITLAB_USER_LOGIN", Identity: true}, + {Name: "CI_SERVER_URL"}, + {Name: "CI_PROJECT_URL"}, + {Name: "CI_COMMIT_SHA"}, + {Name: "CI_JOB_URL"}, + {Name: "CI_PIPELINE_URL"}, + {Name: "CI_RUNNER_VERSION"}, + {Name: "CI_RUNNER_DESCRIPTION", Optional: true}, + {Name: "CI_COMMIT_REF_NAME"}, + {Name: "CI_PROJECT_PATH"}, // MR-specific variables (optional - only present in MR contexts) - {"CI_PIPELINE_SOURCE", true}, - {"CI_MERGE_REQUEST_IID", true}, - {"CI_MERGE_REQUEST_TITLE", true}, - {"CI_MERGE_REQUEST_DESCRIPTION", true}, - {"CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", true}, - {"CI_MERGE_REQUEST_TARGET_BRANCH_NAME", true}, - {"CI_MERGE_REQUEST_PROJECT_URL", true}, - {"CI_MERGE_REQUEST_PROJECT_PATH", true}, + {Name: "CI_PIPELINE_SOURCE", Optional: true}, + {Name: "CI_MERGE_REQUEST_IID", Optional: true}, + {Name: "CI_MERGE_REQUEST_TITLE", Optional: true}, + {Name: "CI_MERGE_REQUEST_DESCRIPTION", Optional: true}, + {Name: "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", Optional: true}, + {Name: "CI_MERGE_REQUEST_TARGET_BRANCH_NAME", Optional: true}, + {Name: "CI_MERGE_REQUEST_PROJECT_URL", Optional: true}, + {Name: "CI_MERGE_REQUEST_PROJECT_PATH", Optional: true}, } } diff --git a/pkg/attestation/crafter/runners/gitlabpipeline_test.go b/pkg/attestation/crafter/runners/gitlabpipeline_test.go index b14c25e29..259460fad 100644 --- a/pkg/attestation/crafter/runners/gitlabpipeline_test.go +++ b/pkg/attestation/crafter/runners/gitlabpipeline_test.go @@ -81,25 +81,25 @@ func (s *gitlabPipelineSuite) TestCheckEnv() { func (s *gitlabPipelineSuite) TestListEnvVars() { assert.Equal(s.T(), []*EnvVarDefinition{ - {"GITLAB_USER_EMAIL", false}, - {"GITLAB_USER_LOGIN", false}, - {"CI_SERVER_URL", false}, - {"CI_PROJECT_URL", false}, - {"CI_COMMIT_SHA", false}, - {"CI_JOB_URL", false}, - {"CI_PIPELINE_URL", false}, - {"CI_RUNNER_VERSION", false}, - {"CI_RUNNER_DESCRIPTION", true}, - {"CI_COMMIT_REF_NAME", false}, - {"CI_PROJECT_PATH", false}, - {"CI_PIPELINE_SOURCE", true}, - {"CI_MERGE_REQUEST_IID", true}, - {"CI_MERGE_REQUEST_TITLE", true}, - {"CI_MERGE_REQUEST_DESCRIPTION", true}, - {"CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", true}, - {"CI_MERGE_REQUEST_TARGET_BRANCH_NAME", true}, - {"CI_MERGE_REQUEST_PROJECT_URL", true}, - {"CI_MERGE_REQUEST_PROJECT_PATH", true}, + {Name: "GITLAB_USER_EMAIL", Identity: true}, + {Name: "GITLAB_USER_LOGIN", Identity: true}, + {Name: "CI_SERVER_URL"}, + {Name: "CI_PROJECT_URL"}, + {Name: "CI_COMMIT_SHA"}, + {Name: "CI_JOB_URL"}, + {Name: "CI_PIPELINE_URL"}, + {Name: "CI_RUNNER_VERSION"}, + {Name: "CI_RUNNER_DESCRIPTION", Optional: true}, + {Name: "CI_COMMIT_REF_NAME"}, + {Name: "CI_PROJECT_PATH"}, + {Name: "CI_PIPELINE_SOURCE", Optional: true}, + {Name: "CI_MERGE_REQUEST_IID", Optional: true}, + {Name: "CI_MERGE_REQUEST_TITLE", Optional: true}, + {Name: "CI_MERGE_REQUEST_DESCRIPTION", Optional: true}, + {Name: "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", Optional: true}, + {Name: "CI_MERGE_REQUEST_TARGET_BRANCH_NAME", Optional: true}, + {Name: "CI_MERGE_REQUEST_PROJECT_URL", Optional: true}, + {Name: "CI_MERGE_REQUEST_PROJECT_PATH", Optional: true}, }, s.runner.ListEnvVars()) } diff --git a/pkg/attestation/crafter/runners/identity_test.go b/pkg/attestation/crafter/runners/identity_test.go new file mode 100644 index 000000000..793940fb8 --- /dev/null +++ b/pkg/attestation/crafter/runners/identity_test.go @@ -0,0 +1,35 @@ +// +// Copyright 2026 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package runners + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestKnownIdentityEnvVars(t *testing.T) { + // sorted, so the CLI help, the docs and the init response are stable + assert.Equal(t, []string{ + "BUILD_REQUESTEDFOR", + "BUILD_REQUESTEDFOREMAIL", + "GITHUB_ACTOR", + "GITLAB_USER_EMAIL", + "GITLAB_USER_LOGIN", + "HOME", + "USER", + }, KnownIdentityEnvVars()) +} diff --git a/pkg/attestation/crafter/runners/jenkinsjob.go b/pkg/attestation/crafter/runners/jenkinsjob.go index 1cad696e9..e0c372777 100644 --- a/pkg/attestation/crafter/runners/jenkinsjob.go +++ b/pkg/attestation/crafter/runners/jenkinsjob.go @@ -51,21 +51,21 @@ func (r *JenkinsJob) CheckEnv() bool { func (r *JenkinsJob) ListEnvVars() []*EnvVarDefinition { return []*EnvVarDefinition{ // Some info about the job - {"JOB_NAME", false}, - {"BUILD_URL", false}, + {Name: "JOB_NAME"}, + {Name: "BUILD_URL"}, // Some info about the commit (Jenkins Git Plugin) // NOTE: These variables are marked as optional because their presence // depends the jenkins' configuration (e.g., multibranch pipelines). - {"GIT_BRANCH", true}, - {"GIT_COMMIT", true}, + {Name: "GIT_BRANCH", Optional: true}, + {Name: "GIT_COMMIT", Optional: true}, // Some info about the agent // We've found this one to be optional - {"AGENT_WORKDIR", true}, + {Name: "AGENT_WORKDIR", Optional: true}, // Workspace is required as long as the jobs run inside a `node` block - {"WORKSPACE", false}, - {"NODE_NAME", false}, + {Name: "WORKSPACE"}, + {Name: "NODE_NAME"}, } } diff --git a/pkg/attestation/crafter/runners/jenkinsjob_test.go b/pkg/attestation/crafter/runners/jenkinsjob_test.go index 9d83ea56d..bc1866730 100644 --- a/pkg/attestation/crafter/runners/jenkinsjob_test.go +++ b/pkg/attestation/crafter/runners/jenkinsjob_test.go @@ -1,5 +1,5 @@ // -// Copyright 2024 The Chainloop Authors. +// Copyright 2024-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -78,13 +78,13 @@ func (s *jenkinsJobSuite) TestCheckEnv() { func (s *jenkinsJobSuite) TestListEnvVars() { s.Equal([]*EnvVarDefinition{ - {"JOB_NAME", false}, - {"BUILD_URL", false}, - {"GIT_BRANCH", true}, - {"GIT_COMMIT", true}, - {"AGENT_WORKDIR", true}, - {"WORKSPACE", false}, - {"NODE_NAME", false}, + {Name: "JOB_NAME"}, + {Name: "BUILD_URL"}, + {Name: "GIT_BRANCH", Optional: true}, + {Name: "GIT_COMMIT", Optional: true}, + {Name: "AGENT_WORKDIR", Optional: true}, + {Name: "WORKSPACE"}, + {Name: "NODE_NAME"}, }, s.runner.ListEnvVars()) } diff --git a/pkg/attestation/crafter/runners/runners.go b/pkg/attestation/crafter/runners/runners.go index b5466d651..dfbeeaf98 100644 --- a/pkg/attestation/crafter/runners/runners.go +++ b/pkg/attestation/crafter/runners/runners.go @@ -1,5 +1,5 @@ // -// Copyright 2024-2025 The Chainloop Authors. +// Copyright 2024-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package runners import ( "fmt" "os" + "slices" "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/runners/oidc" ) @@ -25,6 +26,31 @@ import ( type EnvVarDefinition struct { Name string Optional bool + // Identity marks a variable whose value identifies a person (a user name, login or email). + // Organizations can redact these values with the "known identity" redaction mode. + Identity bool +} + +// KnownIdentityEnvVars returns the union of the env vars that any runner marks as Identity. +// The list does not depend on the runner type, so it is the same on the client and at push. +func KnownIdentityEnvVars() []string { + allRunners := []interface{ ListEnvVars() []*EnvVarDefinition }{ + &AzurePipeline{}, &ChainloopSandbox{}, &CircleCIBuild{}, &DaggerPipeline{}, &Generic{}, + &GitHubAction{}, &GitlabPipeline{}, &JenkinsJob{}, &TeamCityPipeline{}, &TektonPipeline{}, + } + + var names []string + for _, r := range allRunners { + for _, def := range r.ListEnvVars() { + if def.Identity { + names = append(names, def.Name) + } + } + } + + // Sorted and unique, so the CLI help, the docs and the init response are stable + slices.Sort(names) + return slices.Compact(names) } func resolveEnvVars(envVarsDefinitions []*EnvVarDefinition) (map[string]string, []*error) { diff --git a/pkg/attestation/crafter/runners/teamcitypipeline.go b/pkg/attestation/crafter/runners/teamcitypipeline.go index 9e320e3e9..bf561e566 100644 --- a/pkg/attestation/crafter/runners/teamcitypipeline.go +++ b/pkg/attestation/crafter/runners/teamcitypipeline.go @@ -44,14 +44,14 @@ func (r *TeamCityPipeline) CheckEnv() bool { func (r *TeamCityPipeline) ListEnvVars() []*EnvVarDefinition { return []*EnvVarDefinition{ - {"BUILD_URL", false}, - {"TEAMCITY_PROJECT_NAME", false}, - {"TEAMCITY_VERSION", true}, - {"BUILD_NUMBER", true}, - {"USER", true}, - {"TEAMCITY_GIT_VERSION", true}, - {"BUILD_VCS_NUMBER", true}, - {"HOME", true}, + {Name: "BUILD_URL"}, + {Name: "TEAMCITY_PROJECT_NAME"}, + {Name: "TEAMCITY_VERSION", Optional: true}, + {Name: "BUILD_NUMBER", Optional: true}, + {Name: "USER", Optional: true, Identity: true}, + {Name: "TEAMCITY_GIT_VERSION", Optional: true}, + {Name: "BUILD_VCS_NUMBER", Optional: true}, + {Name: "HOME", Optional: true, Identity: true}, } } diff --git a/pkg/attestation/crafter/runners/teamcitypipeline_test.go b/pkg/attestation/crafter/runners/teamcitypipeline_test.go index 42ce19c08..75cfef9d5 100644 --- a/pkg/attestation/crafter/runners/teamcitypipeline_test.go +++ b/pkg/attestation/crafter/runners/teamcitypipeline_test.go @@ -1,5 +1,5 @@ // -// Copyright 2025 The Chainloop Authors. +// Copyright 2025-2026 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -70,14 +70,14 @@ func (s *teamCityPipelineSuite) TestCheckEnv() { func (s *teamCityPipelineSuite) TestListEnvVars() { s.Equal([]*EnvVarDefinition{ - {"BUILD_URL", false}, - {"TEAMCITY_PROJECT_NAME", false}, - {"TEAMCITY_VERSION", true}, - {"BUILD_NUMBER", true}, - {"USER", true}, - {"TEAMCITY_GIT_VERSION", true}, - {"BUILD_VCS_NUMBER", true}, - {"HOME", true}, + {Name: "BUILD_URL"}, + {Name: "TEAMCITY_PROJECT_NAME"}, + {Name: "TEAMCITY_VERSION", Optional: true}, + {Name: "BUILD_NUMBER", Optional: true}, + {Name: "USER", Optional: true, Identity: true}, + {Name: "TEAMCITY_GIT_VERSION", Optional: true}, + {Name: "BUILD_VCS_NUMBER", Optional: true}, + {Name: "HOME", Optional: true, Identity: true}, }, s.runner.ListEnvVars()) } diff --git a/pkg/attestation/crafter/runners/tektonpipeline.go b/pkg/attestation/crafter/runners/tektonpipeline.go index 96ebe8f58..6825742a3 100644 --- a/pkg/attestation/crafter/runners/tektonpipeline.go +++ b/pkg/attestation/crafter/runners/tektonpipeline.go @@ -163,13 +163,13 @@ func (r *TektonPipeline) ListEnvVars() []*EnvVarDefinition { // values come from K8s API discovery, not from actual container env vars. // This follows the Dagger runner pattern of promoting encapsulated platform vars. return []*EnvVarDefinition{ - {"HOSTNAME", true}, // optional (best-effort from env) - {"TEKTON_TASKRUN_NAME", false}, // required (always in any TaskRun) - {"TEKTON_TASK_NAME", true}, // optional (absent with inline taskSpec) - {"TEKTON_NAMESPACE", false}, // required (always in any TaskRun) - {"TEKTON_PIPELINE_NAME", true}, // optional (only Pipeline TaskRuns) - {"TEKTON_PIPELINERUN_NAME", true}, // optional (only Pipeline TaskRuns) - {"TEKTON_PIPELINE_TASK_NAME", true}, // optional (only Pipeline TaskRuns) + {Name: "HOSTNAME", Optional: true}, // optional (best-effort from env) + {Name: "TEKTON_TASKRUN_NAME"}, // required (always in any TaskRun) + {Name: "TEKTON_TASK_NAME", Optional: true}, // optional (absent with inline taskSpec) + {Name: "TEKTON_NAMESPACE"}, // required (always in any TaskRun) + {Name: "TEKTON_PIPELINE_NAME", Optional: true}, // optional (only Pipeline TaskRuns) + {Name: "TEKTON_PIPELINERUN_NAME", Optional: true}, // optional (only Pipeline TaskRuns) + {Name: "TEKTON_PIPELINE_TASK_NAME", Optional: true}, // optional (only Pipeline TaskRuns) } } diff --git a/pkg/attestation/envredaction/envredaction.go b/pkg/attestation/envredaction/envredaction.go new file mode 100644 index 000000000..151acba95 --- /dev/null +++ b/pkg/attestation/envredaction/envredaction.go @@ -0,0 +1,89 @@ +// +// Copyright 2026 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package envredaction replaces the values of selected environment variables stored in an +// attestation with a fixed placeholder. The crafter applies it, and the control plane uses +// the same rules to check pushed attestations. +package envredaction + +import ( + "errors" + "fmt" + "slices" + "strings" + + "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/runners" +) + +// RedactedValue replaces the value of a redacted environment variable. +const RedactedValue = "[REDACTED]" + +// Mode selects which environment variables are redacted. +type Mode string + +const ( + // ModeNone disables redaction. + ModeNone Mode = "none" + // ModeKnownIdentity redacts the variables that runner integrations mark as identifying a person. + ModeKnownIdentity Mode = "known-identity" + // ModeCustom redacts only an explicit list of variables. + ModeCustom Mode = "custom" +) + +// Names returns the exact variable names that the mode redacts. +// custom is used only by ModeCustom, which requires at least one non-empty name. +func Names(mode Mode, custom []string) ([]string, error) { + switch mode { + case ModeNone, "": + return nil, nil + case ModeKnownIdentity: + return runners.KnownIdentityEnvVars(), nil + case ModeCustom: + if len(custom) == 0 { + return nil, errors.New("custom env var redaction requires at least one variable name") + } + for _, name := range custom { + if strings.TrimSpace(name) == "" { + return nil, errors.New("custom env var redaction contains an empty variable name") + } + } + return custom, nil + default: + return nil, fmt.Errorf("invalid env var redaction mode %q, valid values are: %s, %s, %s", mode, ModeNone, ModeKnownIdentity, ModeCustom) + } +} + +// Apply replaces, in place, the value of each named variable that is present in env. +// The key stays, so the attestation shows that a value existed and was hidden on purpose. +func Apply(env map[string]string, names []string) { + for _, name := range names { + if _, ok := env[name]; ok { + env[name] = RedactedValue + } + } +} + +// Violations returns, sorted, the named variables that have a non-empty value other than +// RedactedValue. An absent or empty value reveals nothing. +func Violations(env map[string]string, names []string) []string { + var out []string + for _, name := range names { + if v := env[name]; v != "" && v != RedactedValue { + out = append(out, name) + } + } + slices.Sort(out) + return out +} diff --git a/pkg/attestation/envredaction/envredaction_test.go b/pkg/attestation/envredaction/envredaction_test.go new file mode 100644 index 000000000..3335bcbb5 --- /dev/null +++ b/pkg/attestation/envredaction/envredaction_test.go @@ -0,0 +1,154 @@ +// +// Copyright 2026 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package envredaction + +import ( + "testing" + + "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/runners" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +const ( + actorVar = "GITHUB_ACTOR" + shaVar = "GITHUB_SHA" + fooVar = "FOO" + userVar = "USER" + shaValue = "abc" + userName = "jdoe" +) + +func TestNames(t *testing.T) { + testCases := []struct { + name string + mode Mode + custom []string + want []string + wantErr bool + }{ + {name: "none", mode: ModeNone, want: nil}, + {name: "none ignores custom list", mode: ModeNone, custom: []string{fooVar}, want: nil}, + { + name: "known identity", + mode: ModeKnownIdentity, + want: runners.KnownIdentityEnvVars(), + }, + {name: "custom", mode: ModeCustom, custom: []string{fooVar, "BAR"}, want: []string{fooVar, "BAR"}}, + {name: "custom does not add known identity", mode: ModeCustom, custom: []string{fooVar}, want: []string{fooVar}}, + {name: "custom requires a variable", mode: ModeCustom, wantErr: true}, + {name: "custom rejects empty names", mode: ModeCustom, custom: []string{fooVar, " "}, wantErr: true}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + got, err := Names(tc.mode, tc.custom) + if tc.wantErr { + require.Error(t, err) + return + } + require.NoError(t, err) + assert.ElementsMatch(t, tc.want, got) + }) + } +} + +func TestApply(t *testing.T) { + testCases := []struct { + name string + env map[string]string + names []string + want map[string]string + }{ + { + name: "redacts present values and keeps the key", + env: map[string]string{actorVar: userName, shaVar: shaValue}, + names: []string{actorVar}, + want: map[string]string{actorVar: RedactedValue, shaVar: shaValue}, + }, + { + name: "does not add absent variables", + env: map[string]string{shaVar: shaValue}, + names: []string{actorVar}, + want: map[string]string{shaVar: shaValue}, + }, + { + name: "no names leaves env unchanged", + env: map[string]string{actorVar: userName}, + names: nil, + want: map[string]string{actorVar: userName}, + }, + { + name: "exact names only", + env: map[string]string{"GITHUB_ACTOR_ID": "123"}, + names: []string{actorVar}, + want: map[string]string{"GITHUB_ACTOR_ID": "123"}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + Apply(tc.env, tc.names) + assert.Equal(t, tc.want, tc.env) + }) + } +} + +func TestViolations(t *testing.T) { + testCases := []struct { + name string + env map[string]string + names []string + want []string + }{ + { + name: "redacted values are fine", + env: map[string]string{actorVar: RedactedValue, shaVar: shaValue}, + names: []string{actorVar}, + want: nil, + }, + { + name: "absent values are fine", + env: map[string]string{shaVar: shaValue}, + names: []string{actorVar}, + want: nil, + }, + { + name: "clear values are reported sorted", + env: map[string]string{userVar: userName, actorVar: userName, "HOME": RedactedValue}, + names: []string{userVar, actorVar, "HOME"}, + want: []string{actorVar, userVar}, + }, + { + name: "empty values reveal nothing and are fine", + env: map[string]string{actorVar: ""}, + names: []string{actorVar}, + want: nil, + }, + { + name: "nil env", + env: nil, + names: []string{userVar}, + want: nil, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.want, Violations(tc.env, tc.names)) + }) + } +} From c19c23ee1a36ce96b5a33b3a96f33dcd6320838e Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Mon, 23 Nov 2026 17:44:59 +0100 Subject: [PATCH 5/8] docs(plan): align runner env var redaction plan with the code Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: a6ea453b-a3ca-450f-aba0-241be6b95a2b --- docs/plans/issue-3841-runner-env-var-redaction.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/plans/issue-3841-runner-env-var-redaction.md b/docs/plans/issue-3841-runner-env-var-redaction.md index d784b8854..b5c6ce8e7 100644 --- a/docs/plans/issue-3841-runner-env-var-redaction.md +++ b/docs/plans/issue-3841-runner-env-var-redaction.md @@ -71,14 +71,14 @@ An admin sets the mode, the CLI replaces the values, and the control plane rejec
01 / 07 · Each runner says which of its variables identify a person (R-004) -The env var definition gets an `Identity` flag next to `Optional`. The definitions change to keyed fields, because a third field breaks the positional literals. `KnownIdentityEnvVars() []string` returns the union of the flags of all runners. The flags are on `GITHUB_ACTOR`, `GITLAB_USER_EMAIL`, `GITLAB_USER_LOGIN` (GitLab and Dagger), `BUILD_REQUESTEDFOR`, `BUILD_REQUESTEDFOREMAIL`, and TeamCity `USER` and `HOME`. +The env var definition gets an `Identity` flag next to `Optional`. The definitions change to keyed fields, because a third field breaks the positional literals. `KnownIdentityEnvVars() []string` returns the union of the flags of all runners. The flags are on `GITHUB_ACTOR`, `GITLAB_USER_EMAIL` and `GITLAB_USER_LOGIN` (GitLab), `GITLAB_USER_LOGIN` (Dagger), `BUILD_REQUESTEDFOR`, `BUILD_REQUESTEDFOREMAIL`, and TeamCity `USER` and `HOME`. | File | Change | |------|--------| | `pkg/attestation/crafter/runners/runners.go` | Add the `Identity` field to `EnvVarDefinition`, next to `Optional`. Add `KnownIdentityEnvVars`, which returns the names that any runner marks with `Identity`. | | `pkg/attestation/crafter/runners/*.go` | Keyed definitions, and the identity flags. | | `pkg/attestation/crafter/runners/*_test.go` | Expected definitions with the flags. | -| `pkg/attestation/crafter/runners/identity_test.go` | Add `TestKnownIdentityEnvVars` and `TestIdentityFlagsPerRunner`: the sorted union, and the flags of each runner. | +| `pkg/attestation/crafter/runners/identity_test.go` | Add `TestKnownIdentityEnvVars`: the sorted union. The test of each runner checks its flags. | | `pkg/attestation/crafter/runner_test.go` | Add `TestKnownIdentityEnvVarsCoversEveryRunner`: each runner of the runner factories has its identity variables in the union. | | `.golangci.yml` | Turn off goconst for test files and the runners package, where env var names are data. | @@ -114,17 +114,16 @@ The API gets an `EnvVarRedaction` message (type and names) on the organization u
-04 / 07 · The init response gives the setting with the resolved names (R-001, R-004) +04 / 07 · The init response gives the resolved names (R-001, R-004) -The `attestation init` response carries the setting with the names that the control plane enforces at push, also for known identity (spec D-003). The CLI copies only these names into the local attestation state. +The `attestation init` response gives the names that the control plane enforces at push, also for known identity (spec D-003). The CLI copies only these names into the local attestation state. | File | Change | |------|--------| -| `app/controlplane/api/controlplane/v1/workflow_run.proto` | Add the field to the init response. | +| `app/controlplane/api/controlplane/v1/workflow_run.proto` | Add the list of names to the init response. | | `pkg/attestation/crafter/api/attestation/v1/crafting_state.proto` | Add the names to redact to the attestation state. | -| `app/controlplane/internal/service/attestation.go`, `organization.go` | Fill the field with `envVarRedactionForInit`. | +| `app/controlplane/internal/service/attestation.go` | Fill the list with the names of the org setting. | | `app/cli/pkg/action/attestation_init.go` | Copy the names into the crafter options. | -| `app/controlplane/internal/service/envvarredaction_test.go` | Add `TestEnvVarRedactionForInit`. |
@@ -164,6 +163,7 @@ The push check runs after the contract check, in the save and in the check that |------|--------| | `app/controlplane/pkg/biz/workflowrun.go` | Add `validatePredicate`, which runs the contract and redaction checks, and call it in `SaveAttestation` and `ValidateAttestationContract`. Load the organization one time for each call. | | `app/controlplane/pkg/biz/workflowrun_contract_integration_test.go` | Add `TestSaveAttestationEnforcesEnvVarRedaction`: the pre-CAS check and the save both reject a clear value, accept the other cases, and store nothing on a rejection. | +| `app/controlplane/pkg/biz/workflowrun_verification_test.go` | Give the keyless verification test an organization repository mock, because the pre-CAS check now loads the organization. | From f8d28259e81d151d8cc8054f35fe3fbabc0e5db5 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Mon, 23 Nov 2026 17:51:38 +0100 Subject: [PATCH 6/8] docs(spec): state the CAS check timing and its accepted risk Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: a6ea453b-a3ca-450f-aba0-241be6b95a2b --- docs/specs/issue-3841-runner-env-var-redaction.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/specs/issue-3841-runner-env-var-redaction.md b/docs/specs/issue-3841-runner-env-var-redaction.md index a7b7aa87e..c91ad2aed 100644 --- a/docs/specs/issue-3841-runner-env-var-redaction.md +++ b/docs/specs/issue-3841-runner-env-var-redaction.md @@ -58,7 +58,7 @@ When a redacted variable has a value, the attestation MUST keep the variable nam - Done when: in an Azure Pipelines run with known identity, the attestation has `BUILD_REQUESTEDFOR: [REDACTED]`, and `attestation init` does not fail. ### R-003: Push enforcement -The control plane MUST reject a pushed attestation when a variable that the setting redacts has a non-empty value other than `[REDACTED]`. The check MUST use the setting of the organization at push time. The control plane MUST run the check before it stores the attestation, also in a CAS backend. The error MUST name the variables. It MUST tell the user to update the CLI, or to run the attestation again if the setting changed during the run. +The control plane MUST reject a pushed attestation when a variable that the setting redacts has a non-empty value other than `[REDACTED]`. The check MUST use the setting of the organization at push time. The control plane MUST run the check before it stores the attestation. With a CAS backend, it runs the check before the upload with the setting at that time, and again when it saves the attestation. The error MUST name the variables. It MUST tell the user to update the CLI, or to run the attestation again if the setting changed during the run. - Done when: a CLI without redaction support pushes an attestation that has `GITHUB_ACTOR` with a real value, in an organization with known identity. The push fails. ### R-004: Known identity list @@ -131,5 +131,5 @@ No open questions. | Risk | Mitigation | |------|------------| | An organization turns on redaction, and pipelines with an older CLI fail at push. | The error names the variables and tells the user to update the CLI. The release notes give the minimum CLI version. | -| An admin changes the setting while an attestation is in progress. The push uses the new setting, which the CLI did not apply. | The push fails with the error from R-003, and a new run of the pipeline uses the new setting. Changes to the setting are rare. | +| An admin changes the setting while an attestation is in progress. The push uses the new setting, which the CLI did not apply. If the change occurs between the check before the CAS upload and the save, the unredacted bundle stays in the CAS backend. | The push fails with the error from R-003, and a new run of the pipeline uses the new setting. Changes to the setting are rare, and the time between the two checks is short. We accept the bundle in the CAS backend: no workflow run links to it. | | A personal value is in a variable that is not on the known identity list. | The custom mode covers it. A runner integration can mark more variables in a later release. | From 8141e0a91241512ae45f9d205ca7b1593f534001 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Mon, 23 Nov 2026 20:56:45 +0100 Subject: [PATCH 7/8] test(crafter): clear optional GitHub runner vars in env var tests On a pull_request CI run, GITHUB_BASE_REF, GITHUB_HEAD_REF and the event vars leak into the redaction cases of TestResolveEnvVars. Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: a6ea453b-a3ca-450f-aba0-241be6b95a2b --- pkg/attestation/crafter/crafter_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/attestation/crafter/crafter_test.go b/pkg/attestation/crafter/crafter_test.go index 834397ea4..f36c9846f 100644 --- a/pkg/attestation/crafter/crafter_test.go +++ b/pkg/attestation/crafter/crafter_test.go @@ -607,12 +607,17 @@ func (s *crafterSuite) TestResolveEnvVars() { var runner crafter.SupportedRunner = runners.NewGeneric() contract := "testdata/contracts/with_env_vars.yaml" if tc.inGithubEnv { + testLogger := zerolog.New(zerolog.Nop()).Level(zerolog.Disabled) + gh := runners.NewGithubAction(s.T().Context(), &testLogger) + // clear the optional vars that a real GitHub Actions run sets, for example on pull requests + for _, v := range gh.ListEnvVars() { + s.T().Setenv(v.Name, "") + } s.T().Setenv("CI", "true") for k, v := range gitHubTestingEnvVars { s.T().Setenv(k, v) } - testLogger := zerolog.New(zerolog.Nop()).Level(zerolog.Disabled) - runner = runners.NewGithubAction(s.T().Context(), &testLogger) + runner = gh } else if tc.inJenkinsEnv { contract = "testdata/contracts/jenkins_with_env_vars.yaml" s.T().Setenv("JOB_NAME", "some-job") From 28e506b1f6ada6cc554a2b135f92249685831a2d Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Mon, 23 Nov 2026 21:05:23 +0100 Subject: [PATCH 8/8] fix: reject padded redaction names and unknown redaction types A custom name with leading or trailing whitespace never matches a variable, so its value stayed clear. An unknown EnvVarRedaction type became none and cleared the stored setting. Both now fail validation. Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: a6ea453b-a3ca-450f-aba0-241be6b95a2b --- .../internal/service/envvarredaction_test.go | 9 +++++++++ app/controlplane/internal/service/organization.go | 7 ++++++- pkg/attestation/envredaction/envredaction.go | 4 ++++ pkg/attestation/envredaction/envredaction_test.go | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controlplane/internal/service/envvarredaction_test.go b/app/controlplane/internal/service/envvarredaction_test.go index eabf5ca6d..4ddf11107 100644 --- a/app/controlplane/internal/service/envvarredaction_test.go +++ b/app/controlplane/internal/service/envvarredaction_test.go @@ -66,3 +66,12 @@ func TestEnvVarRedactionConversion(t *testing.T) { }) } } + +// An unknown type must not become ModeNone, which clears the stored setting. +func TestEnvVarRedactionUnknownTypeIsRejected(t *testing.T) { + got := pbEnvVarRedactionToBiz(&pb.EnvVarRedaction{Type: pb.EnvVarRedaction_Type(99)}) + assert.NotEqual(t, envredaction.ModeNone, got.Mode) + + _, err := got.Names() + assert.Error(t, err) +} diff --git a/app/controlplane/internal/service/organization.go b/app/controlplane/internal/service/organization.go index e88be837e..94d18f99c 100644 --- a/app/controlplane/internal/service/organization.go +++ b/app/controlplane/internal/service/organization.go @@ -135,18 +135,23 @@ func (s *OrganizationService) Update(ctx context.Context, req *pb.OrganizationSe } // pbEnvVarRedactionToBiz converts the API setting. nil means "not set"; TYPE_UNSPECIFIED means no redaction. +// An unknown type becomes an invalid mode, so the use case rejects it and does not clear the stored setting. // The use case validates the setting and keeps the names only for the custom mode. func pbEnvVarRedactionToBiz(r *pb.EnvVarRedaction) *biz.EnvVarRedaction { if r == nil { return nil } - mode := envredaction.ModeNone + var mode envredaction.Mode switch r.GetType() { + case pb.EnvVarRedaction_TYPE_UNSPECIFIED: + mode = envredaction.ModeNone case pb.EnvVarRedaction_TYPE_KNOWN_IDENTITY: mode = envredaction.ModeKnownIdentity case pb.EnvVarRedaction_TYPE_CUSTOM: mode = envredaction.ModeCustom + default: + mode = envredaction.Mode(r.GetType().String()) } return &biz.EnvVarRedaction{Mode: mode, EnvVars: r.GetEnvVars()} diff --git a/pkg/attestation/envredaction/envredaction.go b/pkg/attestation/envredaction/envredaction.go index 151acba95..78b1495d9 100644 --- a/pkg/attestation/envredaction/envredaction.go +++ b/pkg/attestation/envredaction/envredaction.go @@ -58,6 +58,10 @@ func Names(mode Mode, custom []string) ([]string, error) { if strings.TrimSpace(name) == "" { return nil, errors.New("custom env var redaction contains an empty variable name") } + // an exact name with surrounding whitespace never matches a variable, so its value stays clear + if strings.TrimSpace(name) != name { + return nil, fmt.Errorf("custom env var redaction name %q has leading or trailing whitespace", name) + } } return custom, nil default: diff --git a/pkg/attestation/envredaction/envredaction_test.go b/pkg/attestation/envredaction/envredaction_test.go index 3335bcbb5..bfc97f03c 100644 --- a/pkg/attestation/envredaction/envredaction_test.go +++ b/pkg/attestation/envredaction/envredaction_test.go @@ -51,6 +51,7 @@ func TestNames(t *testing.T) { {name: "custom does not add known identity", mode: ModeCustom, custom: []string{fooVar}, want: []string{fooVar}}, {name: "custom requires a variable", mode: ModeCustom, wantErr: true}, {name: "custom rejects empty names", mode: ModeCustom, custom: []string{fooVar, " "}, wantErr: true}, + {name: "custom rejects names with surrounding whitespace", mode: ModeCustom, custom: []string{" " + fooVar}, wantErr: true}, } for _, tc := range testCases {