Repository navigation
feat: redact runner environment variables by organization setting #3846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
da860b2
docs(spec): add spec and plan for runner env var redaction
migmartri c8ebf37
docs(plan): clarify the runner definition change in step 01
migmartri 2da8d2a
docs(spec): address review on runner env var redaction
migmartri 146be11
feat: redact identity env vars of the runner by org setting
migmartri c19c23e
docs(plan): align runner env var redaction plan with the code
migmartri f8d2825
docs(spec): state the CAS check timing and its accepted risk
migmartri 8141e0a
test(crafter): clear optional GitHub runner vars in env var tests
migmartri 28e506b
fix: reject padded redaction names and unknown redaction types
migmartri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.