Skip to content

Commit 3da1738

Browse files
Merge pull request #1352 from Devils-Knight/remediation
[Feature] Update Packages names & locations
2 parents ffdfe27 + 088800b commit 3da1738

28 files changed

+962
-144
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ require (
66
github.com/asottile/dockerfile v3.1.0+incompatible
77
github.com/aws/aws-lambda-go v1.30.0
88
github.com/aws/aws-sdk-go v1.43.45
9+
github.com/paulvollmer/dependabot-config-go v0.1.1
10+
gopkg.in/yaml.v2 v2.4.0
911
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
1012
)
1113

@@ -29,7 +31,6 @@ require (
2931
github.com/moby/buildkit v0.10.3 // indirect
3032
github.com/opencontainers/go-digest v1.0.0 // indirect
3133
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
32-
github.com/paulvollmer/dependabot-config-go v0.1.1 // indirect
3334
github.com/pkg/errors v0.9.1 // indirect
3435
github.com/sirupsen/logrus v1.8.1 // indirect
3536
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect
@@ -38,7 +39,6 @@ require (
3839
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
3940
google.golang.org/appengine v1.6.7 // indirect
4041
google.golang.org/protobuf v1.28.0 // indirect
41-
gopkg.in/yaml.v2 v2.4.0 // indirect
4242
)
4343

4444
require (

go.sum

Lines changed: 819 additions & 25 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111
"github.com/aws/aws-lambda-go/lambda"
1212
"github.com/aws/aws-sdk-go/aws/session"
1313
"github.com/aws/aws-sdk-go/service/dynamodb"
14+
"github.com/step-security/secure-workflows/remediation/dependabot"
15+
"github.com/step-security/secure-workflows/remediation/docker"
16+
"github.com/step-security/secure-workflows/remediation/secrets"
17+
"github.com/step-security/secure-workflows/remediation/workflow"
18+
"github.com/step-security/secure-workflows/remediation/workflow/permissions"
1419
)
1520

1621
type Handler struct {
@@ -42,7 +47,7 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
4247
if strings.Contains(httpRequest.RawPath, "/secrets") {
4348
if httpRequest.RequestContext.HTTP.Method == "GET" {
4449
authHeader := httpRequest.Headers["authorization"]
45-
githubWorkflowSecrets, err := GetSecrets(httpRequest.QueryStringParameters, authHeader, dynamoDbSvc)
50+
githubWorkflowSecrets, err := secrets.GetSecrets(httpRequest.QueryStringParameters, authHeader, dynamoDbSvc)
4651
if err != nil {
4752
response = events.APIGatewayProxyResponse{
4853
StatusCode: http.StatusInternalServerError,
@@ -58,7 +63,7 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
5863

5964
} else if httpRequest.RequestContext.HTTP.Method == "PUT" {
6065
authHeader := httpRequest.Headers["authorization"]
61-
githubWorkflowSecrets, err := InitSecrets(httpRequest.Body, authHeader, dynamoDbSvc)
66+
githubWorkflowSecrets, err := secrets.InitSecrets(httpRequest.Body, authHeader, dynamoDbSvc)
6267
if err != nil {
6368
response = events.APIGatewayProxyResponse{
6469
StatusCode: http.StatusInternalServerError,
@@ -73,7 +78,7 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
7378
}
7479

7580
} else if httpRequest.RequestContext.HTTP.Method == "POST" {
76-
err := SetSecrets(httpRequest.Body, dynamoDbSvc)
81+
err := secrets.SetSecrets(httpRequest.Body, dynamoDbSvc)
7782
if err != nil {
7883
response = events.APIGatewayProxyResponse{
7984
StatusCode: http.StatusInternalServerError,
@@ -86,7 +91,7 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
8691
}
8792
} else if httpRequest.RequestContext.HTTP.Method == "DELETE" {
8893
authHeader := httpRequest.Headers["authorization"]
89-
err := DeleteSecrets(authHeader, dynamoDbSvc)
94+
err := secrets.DeleteSecrets(authHeader, dynamoDbSvc)
9095
if err != nil {
9196
response = events.APIGatewayProxyResponse{
9297
StatusCode: http.StatusInternalServerError,
@@ -107,9 +112,9 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
107112
// if owner is set, assuming that repo, path are also set
108113
// get the workflow using API
109114
if _, ok := queryStringParams["owner"]; ok {
110-
inputYaml, err = GetGitHubWorkflowContents(httpRequest.QueryStringParameters)
115+
inputYaml, err = workflow.GetGitHubWorkflowContents(httpRequest.QueryStringParameters)
111116
if err != nil {
112-
fixResponse := &SecureWorkflowReponse{WorkflowFetchError: true, HasErrors: true}
117+
fixResponse := &permissions.SecureWorkflowReponse{WorkflowFetchError: true, HasErrors: true}
113118
output, _ := json.Marshal(fixResponse)
114119
response = events.APIGatewayProxyResponse{
115120
StatusCode: http.StatusOK,
@@ -123,7 +128,7 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
123128
inputYaml = httpRequest.Body
124129
}
125130

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

128133
if err != nil {
129134
response = events.APIGatewayProxyResponse{
@@ -148,9 +153,9 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
148153
// if owner is set, assuming that repo, path are also set
149154
// get the dockerfile using API
150155
if _, ok := queryStringParams["owner"]; ok {
151-
dockerFile, err = GetGitHubWorkflowContents(httpRequest.QueryStringParameters)
156+
dockerFile, err = workflow.GetGitHubWorkflowContents(httpRequest.QueryStringParameters)
152157
if err != nil {
153-
fixResponse := &SecureDockerfileResponse{DockerfileFetchError: true}
158+
fixResponse := &docker.SecureDockerfileResponse{DockerfileFetchError: true}
154159
output, _ := json.Marshal(fixResponse)
155160
response = events.APIGatewayProxyResponse{
156161
StatusCode: http.StatusOK,
@@ -164,7 +169,7 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
164169
dockerFile = httpRequest.Body
165170
}
166171

167-
fixResponse, err := SecureDockerFile(dockerFile)
172+
fixResponse, err := docker.SecureDockerFile(dockerFile)
168173
if err != nil {
169174
response = events.APIGatewayProxyResponse{
170175
StatusCode: http.StatusInternalServerError,
@@ -186,7 +191,7 @@ func (h Handler) Invoke(ctx context.Context, req []byte) ([]byte, error) {
186191
updateDependabotConfigRequest := ""
187192
updateDependabotConfigRequest = httpRequest.Body
188193

189-
fixResponse, err := UpdateDependabotConfig(updateDependabotConfigRequest)
194+
fixResponse, err := dependabot.UpdateDependabotConfig(updateDependabotConfigRequest)
190195
if err != nil {
191196
response = events.APIGatewayProxyResponse{
192197
StatusCode: http.StatusInternalServerError,

dependabotconfig.go renamed to remediation/dependabot/dependabotconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package dependabot
22

33
import (
44
"bufio"

dependabotconfig_test.go renamed to remediation/dependabot/dependabotconfig_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package dependabot
22

33
import (
44
"encoding/json"
@@ -10,8 +10,8 @@ import (
1010

1111
func TestConfigDependabotFile(t *testing.T) {
1212

13-
const inputDirectory = "./testfiles/dependabotfiles/input"
14-
const outputDirectory = "./testfiles/dependabotfiles/output"
13+
const inputDirectory = "../../testfiles/dependabotfiles/input"
14+
const outputDirectory = "../../testfiles/dependabotfiles/output"
1515

1616
tests := []struct {
1717
fileName string

securedockerfile.go renamed to remediation/docker/securedockerfile.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package main
1+
package docker
22

33
import (
44
"fmt"
5+
"net/http"
56
"strings"
67

78
"github.com/asottile/dockerfile"
@@ -10,6 +11,8 @@ import (
1011
"github.com/google/go-containerregistry/pkg/v1/remote"
1112
)
1213

14+
var Tr http.RoundTripper = remote.DefaultTransport
15+
1316
type SecureDockerfileResponse struct {
1417
OriginalInput string
1518
FinalOutput string

securedockerfile_test.go renamed to remediation/docker/securedockerfile_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package docker
22

33
import (
44
"io/ioutil"
@@ -9,12 +9,12 @@ import (
99
"github.com/jarcoal/httpmock"
1010
)
1111

12-
var resp = httpmock.File("./testfiles/dockerfiles/response.json").String()
12+
var resp = httpmock.File("../../testfiles/dockerfiles/response.json").String()
1313

1414
func TestSecureDockerFile(t *testing.T) {
1515

16-
const inputDirectory = "./testfiles/dockerfiles/input"
17-
const outputDirectory = "./testfiles/dockerfiles/output"
16+
const inputDirectory = "../../testfiles/dockerfiles/input"
17+
const outputDirectory = "../../testfiles/dockerfiles/output"
1818
// NOTE: http mocking is not working,
1919
// need to investigate this issue
2020
httpmock.Activate()

secrets.go renamed to remediation/secrets/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package secrets
22

33
import (
44
"context"

secrets_test.go renamed to remediation/secrets/secrets_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package secrets
22

33
import (
44
"reflect"

addaction.go renamed to remediation/workflow/hardenrunner/addaction.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
package main
1+
package hardenrunner
22

33
import (
44
"fmt"
55
"strings"
66

7+
metadata "github.com/step-security/secure-workflows/remediation/workflow/metadata"
8+
"github.com/step-security/secure-workflows/remediation/workflow/permissions"
79
"gopkg.in/yaml.v3"
810
)
911

12+
const (
13+
HardenRunnerActionPath = "step-security/harden-runner"
14+
HardenRunnerActionName = "Harden Runner"
15+
)
16+
1017
func AddAction(inputYaml, action string) (string, bool, error) {
11-
workflow := Workflow{}
18+
workflow := metadata.Workflow{}
1219
updated := false
1320
err := yaml.Unmarshal([]byte(inputYaml), &workflow)
1421
if err != nil {
@@ -18,7 +25,7 @@ func AddAction(inputYaml, action string) (string, bool, error) {
1825

1926
for jobName, job := range workflow.Jobs {
2027
// Skip adding action for reusable jobs
21-
if IsCallingReusableWorkflow(job) {
28+
if metadata.IsCallingReusableWorkflow(job) {
2229
continue
2330
}
2431
alreadyPresent := false
@@ -49,9 +56,9 @@ func addAction(inputYaml, jobName, action string) (string, error) {
4956
return "", fmt.Errorf("unable to parse yaml %v", err)
5057
}
5158

52-
jobNode := iterateNode(&t, jobName, "!!map", 0)
59+
jobNode := permissions.IterateNode(&t, jobName, "!!map", 0)
5360

54-
jobNode = iterateNode(&t, "steps", "!!seq", jobNode.Line)
61+
jobNode = permissions.IterateNode(&t, "steps", "!!seq", jobNode.Line)
5562

5663
if jobNode == nil {
5764
return "", fmt.Errorf("jobName %s not found in the input yaml", jobName)

0 commit comments

Comments
 (0)