Skip to content

fix: add package read permission for container jobs #2527

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

Open
wants to merge 1 commit into
base: int
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions remediation/workflow/permissions/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func AddJobLevelPermissions(inputYaml string, addEmptyTopLevelPermissions bool)

jobState := &JobState{}
jobState.WorkflowEnv = workflow.Env
jobState.IsContainerJob = (job.Container.Image != "")
perms, err := jobState.getPermissions(job.Steps)

if err != nil {
Expand Down Expand Up @@ -369,6 +370,8 @@ type JobState struct {
MissingActions []string
Errors []error
ActionPermissions *metadata.ActionPermissions

IsContainerJob bool // true if the job is running in a container
}

func evaluateEnvironmentVariables(step metadata.Step) string {
Expand Down Expand Up @@ -519,6 +522,11 @@ func (jobState *JobState) getPermissionsForRunStep(step metadata.Step) ([]Permis
func (jobState *JobState) getPermissions(steps []metadata.Step) ([]string, error) {
permissions := []string{}

// If the job is a container job, we need to add packages: read permission
if jobState.IsContainerJob {
permissions = append(permissions, fmt.Sprintf("%s # for container job", packages_read))
}

for _, step := range steps {

if step.Uses != "" { // it is an action
Expand Down
1 change: 1 addition & 0 deletions remediation/workflow/secureworkflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ func TestSecureWorkflowContainerJob(t *testing.T) {
queryParams := make(map[string]string)
queryParams["skipHardenRunnerForContainers"] = "true"
queryParams["addProjectComment"] = "false"
queryParams["addPermissions"] = "true"

output, err := SecureWorkflow(queryParams, string(input), &mockDynamoDBClient{})

Expand Down
3 changes: 3 additions & 0 deletions testfiles/secureworkflow/output/container-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ permissions:

jobs:
test:
permissions:
contents: read # for actions/checkout to fetch code
packages: read # for container job
runs-on: ubuntu-latest
container:
image: cgr.dev/chainguard/wolfi-base@sha256:91ed94ec4e72368a9b5113f2ffb1d8e783a91db489011a89d9fad3e3816a75ba
Expand Down
Loading