Skip to content

Commit 8e2fafb

Browse files
skip pinning for actions present in exemption list
1 parent a324a94 commit 8e2fafb

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
128128
inputYaml = httpRequest.Body
129129
}
130130

131-
fixResponse, err := workflow.SecureWorkflow(httpRequest.QueryStringParameters, inputYaml, dynamoDbSvc)
131+
fixResponse, err := workflow.SecureWorkflow(httpRequest.QueryStringParameters, nil, inputYaml, dynamoDbSvc)
132132

133133
if err != nil {
134134
response = events.APIGatewayProxyResponse{

remediation/workflow/hardenrunner/addaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func AddAction(inputYaml, action string, pinActions bool) (string, bool, error)
4747
}
4848

4949
if updated && pinActions {
50-
out, _ = pin.PinAction(action, out)
50+
out, _ = pin.PinAction(action, out, nil)
5151
}
5252

5353
return out, updated, nil

remediation/workflow/pin/pinactions.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ import (
1313
"gopkg.in/yaml.v3"
1414
)
1515

16-
func PinActions(inputYaml string) (string, bool, error) {
16+
func PinActions(inputYaml string, exemptedActions []string) (string, bool, error) {
1717
workflow := metadata.Workflow{}
1818
updated := false
19+
exemptedActionsMap := make(map[string]bool)
20+
for _, exemptedAction := range exemptedActions {
21+
exemptedAction = strings.TrimRight(exemptedAction, "/")
22+
exemptedActionsMap[exemptedAction] = true
23+
}
1924
err := yaml.Unmarshal([]byte(inputYaml), &workflow)
2025
if err != nil {
2126
return inputYaml, updated, fmt.Errorf("unable to parse yaml %v", err)
@@ -28,7 +33,7 @@ func PinActions(inputYaml string) (string, bool, error) {
2833
for _, step := range job.Steps {
2934
if len(step.Uses) > 0 {
3035
localUpdated := false
31-
out, localUpdated = PinAction(step.Uses, out)
36+
out, localUpdated = PinAction(step.Uses, out, exemptedActionsMap)
3237
updated = updated || localUpdated
3338
}
3439
}
@@ -37,7 +42,7 @@ func PinActions(inputYaml string) (string, bool, error) {
3742
return out, updated, nil
3843
}
3944

40-
func PinAction(action, inputYaml string) (string, bool) {
45+
func PinAction(action, inputYaml string, exemptedActionsMap map[string]bool) (string, bool) {
4146

4247
updated := false
4348
if !strings.Contains(action, "@") || strings.HasPrefix(action, "docker://") {
@@ -50,6 +55,11 @@ func PinAction(action, inputYaml string) (string, bool) {
5055
leftOfAt := strings.Split(action, "@")
5156
tagOrBranch := leftOfAt[1]
5257

58+
// skip pinning for exempted actions
59+
if exemptedActionsMap[leftOfAt[0]] {
60+
return inputYaml, updated
61+
}
62+
5363
splitOnSlash := strings.Split(leftOfAt[0], "/")
5464
owner := splitOnSlash[0]
5565
repo := splitOnSlash[1]

remediation/workflow/pin/pinactions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func TestPinActions(t *testing.T) {
284284
log.Fatal(err)
285285
}
286286

287-
output, gotUpdated, err := PinActions(string(input))
287+
output, gotUpdated, err := PinActions(string(input), nil)
288288
if tt.wantUpdated != gotUpdated {
289289
t.Errorf("test failed wantUpdated %v did not match gotUpdated %v", tt.wantUpdated, gotUpdated)
290290
}

remediation/workflow/secureworkflow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const (
1313
HardenRunnerActionName = "Harden Runner"
1414
)
1515

16-
func SecureWorkflow(queryStringParams map[string]string, inputYaml string, svc dynamodbiface.DynamoDBAPI) (*permissions.SecureWorkflowReponse, error) {
16+
func SecureWorkflow(queryStringParams map[string]string, exemptedActions []string, inputYaml string, svc dynamodbiface.DynamoDBAPI) (*permissions.SecureWorkflowReponse, error) {
1717
pinActions, addHardenRunner, addPermissions, addProjectComment := true, true, true, true
1818
pinnedActions, addedHardenRunner, addedPermissions := false, false, false
1919
ignoreMissingKBs := false
@@ -68,7 +68,7 @@ func SecureWorkflow(queryStringParams map[string]string, inputYaml string, svc d
6868

6969
if pinActions {
7070
pinnedAction, pinnedDocker := false, false
71-
secureWorkflowReponse.FinalOutput, pinnedAction, _ = pin.PinActions(secureWorkflowReponse.FinalOutput)
71+
secureWorkflowReponse.FinalOutput, pinnedAction, _ = pin.PinActions(secureWorkflowReponse.FinalOutput, exemptedActions)
7272
secureWorkflowReponse.FinalOutput, pinnedDocker, _ = pin.PinDocker(secureWorkflowReponse.FinalOutput)
7373
pinnedActions = pinnedAction || pinnedDocker
7474
}

remediation/workflow/secureworkflow_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestSecureWorkflow(t *testing.T) {
148148
}
149149
queryParams["addProjectComment"] = "false"
150150

151-
output, err := SecureWorkflow(queryParams, string(input), &mockDynamoDBClient{})
151+
output, err := SecureWorkflow(queryParams, nil, string(input), &mockDynamoDBClient{})
152152

153153
if err != nil {
154154
t.Errorf("Error not expected")

0 commit comments

Comments
 (0)