Skip to content

Commit 068b056

Browse files
Devils-Knightvarunsh-coder
authored andcommitted
remediate files & packages
1 parent 31fbcd7 commit 068b056

26 files changed

+140
-112
lines changed

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)

addaction_test.go renamed to remediation/workflow/hardenrunner/addaction_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 hardenrunner
22

33
import (
44
"io/ioutil"
@@ -11,8 +11,8 @@ func TestAddAction(t *testing.T) {
1111
inputYaml string
1212
action string
1313
}
14-
const inputDirectory = "./testfiles/addaction/input"
15-
const outputDirectory = "./testfiles/addaction/output"
14+
const inputDirectory = "../../../testfiles/addaction/input"
15+
const outputDirectory = "../../../testfiles/addaction/output"
1616
tests := []struct {
1717
name string
1818
args args

issue.go renamed to remediation/workflow/issue.go

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

33
import (
44
"context"
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/google/go-github/v40/github"
10+
metadata "github.com/step-security/secure-workflows/remediation/workflow/metadata"
1011
"golang.org/x/oauth2"
1112
)
1213

@@ -22,7 +23,7 @@ func CreateIssue(Action string) (int, error) {
2223
// is action
2324
if len(Action) > 0 {
2425
// is kb not found
25-
_, err := GetActionKnowledgeBase(Action)
26+
_, err := metadata.GetActionKnowledgeBase(Action)
2627

2728
if err != nil {
2829
// does issue already exist?

0 commit comments

Comments
 (0)