Skip to content
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

fix: allow a job doesn't have permissions if a workflow has empty permissions #10

Merged
merged 1 commit into from
Jan 22, 2023
Merged
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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GitHub Actions linter

## Policies

- `job_permissions`: All jobs should have `permissions`
- `job_permissions`: All jobs should have `permissions` unless workflow's `permissions` is empty `{}`
- Why: For least privilege
- `workflow_secrets`: Workflow should not set secrets to environment variables
- How to fix: set secrets to jobs
Expand Down Expand Up @@ -34,6 +34,17 @@ jobs:
- run: echo hello
```

Or

```yaml
permissions: {} # Set permissions
jobs:
hello:
runs-on: ubuntu-latest
steps:
- run: echo hello
```

### workflow_secrets

:x:
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/job_permissions_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func (policy *JobPermissionsPolicy) Name() string {

func (policy *JobPermissionsPolicy) Apply(ctx context.Context, logE *logrus.Entry, wf *Workflow) error {
failed := false
if wf.Permissions != nil && len(wf.Permissions) == 0 {
return nil
}
for jobName, job := range wf.Jobs {
if job.Permissions == nil {
failed = true
Expand Down
7 changes: 4 additions & 3 deletions pkg/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ type Policy interface {
}

type Workflow struct {
FilePath string `yaml:"-"`
Jobs map[string]*Job
Env map[string]string
FilePath string `yaml:"-"`
Jobs map[string]*Job
Env map[string]string
Permissions map[string]string
}

type Job struct {
Expand Down