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

test: re-add tool to populate readme allowlists #129

Closed
wants to merge 6 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin/
tools/readme-url-populator/readme-url-populator
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ repos:
pass_filenames: false
types: [proto]
entry: make protos
- repo: local
hooks:
- id: readme-url-populator
name: readme url populator
entry: bash -c 'go run tools/readme-url-populator/main.go'
language: system
always_run: true
files: ^README\.md$
197 changes: 111 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,38 +94,51 @@ inbound:

Under the hood, this config adds these allowlist items:

- GET `https://github.example.com/api/v3/repos/:owner/:repo`
- GET `https://github.example.com/api/v3/repos/:owner/:repo/pulls`
- GET `https://github.example.com/api/v3/orgs/:org/installation`
- GET `https://github.example.com/api/v3/orgs/:org/repos`
- GET `https://github.example.com/api/v3/installation/repositories`
- GET `https://github.example.com/api/v3/users/:user/installation`
- GET `https://github.example.com/api/v3/users/:user/installation/repositories`
- GET `https://github.example.com/api/v3/app`
- GET `https://github.example.com/api/v3/repos/:org/:repo/actions/secrets/public-key`
- GET `https://github.example.com/api/v3/repos/:org/:repo/contents/.github/workflows/semgrep.yml`
- GET `https://github.example.com/api/v3/repos/:org/:repo/installation`
- GET `https://github.example.com/api/v3/app/hook/config`
- GET `https://github.example.com/api/v3/orgs/:org/teams`
- GET `https://github.example.com/api/v3/orgs/:org/teams/:team_slug/members`
- GET `https://github.example.com/api/v3/orgs/:org/members`
- GET `https://github.example.com/api/v3/users/:username`
- PUT `https://github.example.com/api/v3/repos/:org/:repo/contents/.github/workflows/semgrep.yml`
- PUT `https://github.example.com/api/v3/repos/:org/:repo/actions/secrets/SEMGREP_APP_TOKEN`
- POST `https://github.example.com/api/v3/app/installations/:id/access_tokens`
- POST `https://github.example.com/api/v3/app-manifests/:code/conversions`
- POST `https://github.example.com/api/v3/repos/:owner/:repo/pulls/:number/comments`
- POST `https://github.example.com/api/v3/repos/:owner/:repo/issues/:number/comments`
- POST `https://github.example.com/api/v3/repos/:org/:repo/check-runs`
- POST `https://github.example.com/api/v3/repos/:org/:repo/statuses/:commit`
- PATCH `https://github.example.com/api/v3/repos/:org/:repo/check-runs/:check_run_id`
- PATCH `https://github.example.com/api/v3/orgs/:org/hooks/:hook_id`
- DELETE `https://github.example.com/api/v3/orgs/:org/hooks/:hook_id`
<!-- BeginAutogeneratedAllowList:Github -->
- GET `https://github.example.com/app`
- GET `https://github.example.com/app/hook/config`
- GET `https://github.example.com/installation/repositories`
- GET `https://github.example.com/orgs/:org/hooks`
- GET `https://github.example.com/orgs/:org/installation`
- GET `https://github.example.com/orgs/:org/members`
- GET `https://github.example.com/orgs/:org/repos`
- GET `https://github.example.com/orgs/:org/teams`
- GET `https://github.example.com/orgs/:org/teams/:team_slug/members`
- GET `https://github.example.com/repos/:org/:repo/actions/secrets/public-key`
- GET `https://github.example.com/repos/:org/:repo/compare/:basehead`
- GET `https://github.example.com/repos/:org/:repo/contents/.github/workflows/semgrep.yml`
- GET `https://github.example.com/repos/:org/:repo/installation`
- GET `https://github.example.com/repos/:owner/:repo`
- GET `https://github.example.com/repos/:owner/:repo/pulls`
- GET `https://github.example.com/repos/:owner/:repo/pulls/comments/:comment_id/reactions`
- GET `https://github.example.com/user`
- GET `https://github.example.com/user/repos`
- GET `https://github.example.com/users/:user/installation`
- GET `https://github.example.com/users/:user/installation/repositories`
- GET `https://github.example.com/users/:username`
- POST `https://github.example.com/app-manifests/:code/conversions`
- POST `https://github.example.com/app/installations/:id/access_tokens`
- POST `https://github.example.com/orgs/:org/hooks`
- POST `https://github.example.com/repos/:org/:repo/check-runs`
- POST `https://github.example.com/repos/:org/:repo/pulls/comments/:comment_id/replies`
- POST `https://github.example.com/repos/:org/:repo/statuses/:commit`
- POST `https://github.example.com/repos/:owner/:repo/issues/:number/comments`
- POST `https://github.example.com/repos/:owner/:repo/pulls/:number/comments`
- PUT `https://github.example.com/repos/:org/:repo/actions/secrets/SEMGREP_APP_TOKEN`
- PUT `https://github.example.com/repos/:org/:repo/contents/.github/workflows/semgrep.yml`
- PATCH `https://github.example.com/orgs/:org/hooks/:hook_id`
- PATCH `https://github.example.com/repos/:org/:repo/check-runs/:check_run_id`
- PATCH `https://github.example.com/repos/:org/:repo/pulls/:number/comments/:comment_id`
- DELETE `https://github.example.com/orgs/:org/hooks/:hook_id`
<!-- EndAutogeneratedAllowList:Github -->

And if `allowCodeAccess` is set, additionally:

- GET `https://github.example.com/api/v3/repos/:org/:repo/contents/*`
- GET `https://github.example.com/api/v3/repos/:org/:repo/commits`
<!-- BeginAutogeneratedAllowList:Github.AllowCodeAccess -->
- GET `https://github.example.com/repos/:org/:repo/commits`
- GET `https://github.example.com/repos/:org/:repo/contents`
- GET `https://github.example.com/repos/:org/:repo/contents/*`
<!-- EndAutogeneratedAllowList:Github.AllowCodeAccess -->

### GitLab

Expand All @@ -143,34 +156,38 @@ inbound:

Under the hood, this config adds these allowlist items:

- DELETE `https://gitlab.example.com/api/v4/groups/:namespace/hooks/:hook`
- DELETE `https://gitlab.example.com/api/v4/projects/:project/hooks/:hook`
- GET `https://gitlab.example.com/api/v4/groups/:namespace/hooks`
- GET `https://gitlab.example.com/api/v4/namespaces/:namespace`
- GET `https://gitlab.example.com/api/v4/projects/:project`
- GET `https://gitlab.example.com/api/v4/projects/:project/members/all/:user`
- GET `https://gitlab.example.com/api/v4/groups/:namespace/members/all/:user`
- GET `https://gitlab.example.com/api/v4/projects/:project/merge_requests`
- GET `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/versions`
- GET `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions`
- GET `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions/:discussion/notes/:note/award_emoji`
- GET `https://gitlab.example.com/api/v4/projects/:project/repository/branches`
- GET `https://gitlab.example.com/api/v4/:entity_type/:namespace/projects`
- PUT `https://gitlab.example.com/api/v4/groups/:namespace/hooks`
- POST `https://gitlab.example.com/api/v4/groups/:namespace/hooks`
- POST `https://gitlab.example.com/api/v4/projects/:project/hooks`
- POST `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions`
- POST `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions/:discussion/notes`
- PUT `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions/:discussion/notes/:note`
- PUT `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions/:discussion`
<!-- BeginAutogeneratedAllowList:Gitlab -->
- GET `https://gitlab.example.com/:entity_type/:namespace/projects`
- GET `https://gitlab.example.com/groups/:namespace/hooks`
- GET `https://gitlab.example.com/groups/:namespace/members/all/:user`
- GET `https://gitlab.example.com/namespaces/:namespace`
- GET `https://gitlab.example.com/personal_access_tokens/self`
- GET `https://gitlab.example.com/projects/:project`
- GET `https://gitlab.example.com/projects/:project/members/all/:user`
- GET `https://gitlab.example.com/projects/:project/merge_requests`
- GET `https://gitlab.example.com/projects/:project/merge_requests/:number/discussions`
- GET `https://gitlab.example.com/projects/:project/merge_requests/:number/discussions/:discussion/notes/:note/award_emoji`
- GET `https://gitlab.example.com/projects/:project/merge_requests/:number/versions`
- GET `https://gitlab.example.com/projects/:project/repository/branches`
- POST `https://gitlab.example.com/groups/:namespace/hooks`
- POST `https://gitlab.example.com/projects/:project/hooks`
- POST `https://gitlab.example.com/projects/:project/merge_requests/:number/discussions`
- POST `https://gitlab.example.com/projects/:project/merge_requests/:number/discussions/:discussion/notes`
- PUT `https://gitlab.example.com/groups/:namespace/hooks`
- PUT `https://gitlab.example.com/projects/:project/merge_requests/:number/discussions/:discussion`
- PUT `https://gitlab.example.com/projects/:project/merge_requests/:number/discussions/:discussion/notes/:note`
- DELETE `https://gitlab.example.com/groups/:namespace/hooks/:hook`
- DELETE `https://gitlab.example.com/projects/:project/hooks/:hook`
<!-- EndAutogeneratedAllowList:Gitlab -->

And if `allowCodeAccess` is set, additionally:

- GET `https://gitlab.example.com/api/v4/projects/:project/repository/files/*`
- GET `https://gitlab.example.com/api/v4/projects/:project/repository/commits`
- GET `https://gitlab.example.com/api/v4/projects/:project/repository/compare`
- POST `https://gitlab.example.com/api/v4/projects/:project/statuses/:commit`
- GET `https://gitlab.example.com/api/v4/personal_access_tokens/self`
<!-- BeginAutogeneratedAllowList:Gitlab.AllowCodeAccess -->
- GET `https://gitlab.example.com/projects/:project/repository/commits`
- GET `https://gitlab.example.com/projects/:project/repository/compare`
- GET `https://gitlab.example.com/projects/:project/repository/files/*`
- GET `https://gitlab.example.com/projects/:project/statuses/:commit`
<!-- EndAutogeneratedAllowList:Gitlab.AllowCodeAccess -->

### Bitbucket

Expand All @@ -186,25 +203,29 @@ inbound:

Under the hood, this config adds these allowlist items:

- GET `https://bitbucket.example.com/rest/api/latest/projects/:project`
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/repos`
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/repo/:repo`
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/default-branch`
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/:repo/pull-requests`
- POST `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/pull-requests/:number/comments`
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/pull-requests/:number/comments/:comment`
- PUT `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/pull-requests/:number/comments/:comment`
- POST `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/pull-requests/:number/blocker-comments`
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/webhooks`
- POST `https://bitbucket.example.com/rest/api/latest/projects/:project/webhooks`
- PUT `https://bitbucket.example.com/rest/api/latest/projects/:project/webhooks/:webhook`
- DELETE `https://bitbucket.example.com/rest/api/latest/projects/:project/webhooks/:webhook`
<!-- BeginAutogeneratedAllowList:Bitbucket -->
- GET `https://bitbucket.example.com/projects/:project`
- GET `https://bitbucket.example.com/projects/:project/repos`
- GET `https://bitbucket.example.com/projects/:project/repos/:repo`
- GET `https://bitbucket.example.com/projects/:project/repos/:repo/default-branch`
- GET `https://bitbucket.example.com/projects/:project/repos/:repo/pull-requests`
- GET `https://bitbucket.example.com/projects/:project/repos/:repo/pull-requests/:number/comments/:comment`
- GET `https://bitbucket.example.com/projects/:project/webhooks`
- POST `https://bitbucket.example.com/projects/:project/repos/:repo/pull-requests/:number/blocker-comments`
- POST `https://bitbucket.example.com/projects/:project/repos/:repo/pull-requests/:number/comments`
- POST `https://bitbucket.example.com/projects/:project/webhooks`
- PUT `https://bitbucket.example.com/projects/:project/repos/:repo/pull-requests/:number/comments/:comment`
- PUT `https://bitbucket.example.com/projects/:project/webhooks/:webhook`
- DELETE `https://bitbucket.example.com/projects/:project/webhooks/:webhook`
<!-- EndAutogeneratedAllowList:Bitbucket -->

And if `allowCodeAccess` is set, additionally:

- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/browse/*`
- GET `https://bitbucket.example.com/rest/api/latest//scm/:project/:repo/*`
- POST `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/commit/:commit/builds`
<!-- BeginAutogeneratedAllowList:Bitbucket.AllowCodeAccess -->
- GET `https://bitbucket.example.com/projects/:project/repos/:repo/browse/*`
- GET `https://bitbucket.example.com/scm/:project/:repo/*`
- POST `https://bitbucket.example.com/projects/:project/repos/:repo/commit/:commit/builds`
<!-- EndAutogeneratedAllowList:Bitbucket.AllowCodeAccess -->

### Azure DevOps

Expand All @@ -220,25 +241,29 @@ inbound:

Under the hood, this config adds these allowlist items:

- GET `https://[email protected]/:namespace/_apis/connectionData`
- GET `https://[email protected]/:namespace/_apis/projects/:project`
- GET `https://[email protected]/:namespace/:project/_apis/git/repositories`
- GET `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo`
- GET `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo/pullRequests`
- GET `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/iterations`
- POST `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/threads`
- PATCH `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/threads`
- POST `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/threads/:threadId/comments`
- PATCH `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/threads/:threadId/comments/:commentId`
- GET `https://[email protected]/:namespace/:project/_apis/hooks/subscriptions`
- POST `https://[email protected]/:namespace/:project/_apis/hooks/subscriptions`
- PUT `https://[email protected]/:namespace/:project/_apis/hooks/subscriptions`
- GET `https://[email protected]/:namespace/_apis/groupentitlements`
<!-- BeginAutogeneratedAllowList:AzureDevOps -->
- GET `https://dev.azure.com/:namespace/:project/_apis/git/repositories`
- GET `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo`
- GET `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo/pullRequests`
- GET `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/iterations`
- GET `https://dev.azure.com/:namespace/:project/_apis/hooks/subscriptions`
- GET `https://dev.azure.com/:namespace/_apis/connectionData`
- GET `https://dev.azure.com/:namespace/_apis/groupentitlements`
- GET `https://dev.azure.com/:namespace/_apis/projects/:project`
- POST `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/threads`
- POST `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/threads/:threadId/comments`
- POST `https://dev.azure.com/:namespace/:project/_apis/hooks/subscriptions`
- PUT `https://dev.azure.com/:namespace/:project/_apis/hooks/subscriptions`
- PATCH `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/threads`
- PATCH `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo/pullRequests/:number/threads/:threadId/comments/:commentId`
<!-- EndAutogeneratedAllowList:AzureDevOps -->

And if `allowCodeAccess` is set, additionally:

- GET `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo/items`
- POST `https://[email protected]/:namespace/:project/_apis/git/repositories/:repo/commits/:commit/statuses`
<!-- BeginAutogeneratedAllowList:AzureDevOps.AllowCodeAccess -->
- GET `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo/items`
- POST `https://dev.azure.com/:namespace/:project/_apis/git/repositories/:repo/commits/:commit/statuses`
<!-- EndAutogeneratedAllowList:AzureDevOps.AllowCodeAccess -->

### Allowlist

Expand Down
20 changes: 14 additions & 6 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,20 @@
// Step 5: Apply default values to any remaining unset config fields
defaults.SetDefaults(config)

if err := PopulateAllowLists(config); err != nil {
return nil, fmt.Errorf("failed to populate allowlists: %v", err)
}

return config, nil
}

func PopulateAllowLists(config *Config) error {
if config.Inbound.GitHub != nil {
gitHub := config.Inbound.GitHub

gitHubBaseUrl, err := url.Parse(gitHub.BaseURL)
if err != nil {
return nil, fmt.Errorf("failed to parse github base URL: %v", err)
return fmt.Errorf("failed to parse github base URL: %v", err)
}

var headers map[string]string
Expand All @@ -443,7 +451,7 @@
headers = map[string]string{
"Authorization": fmt.Sprintf("Bearer %v", gitHub.Token),
}
} else {

Check failure on line 454 in pkg/config.go

View workflow job for this annotation

GitHub Actions / build

too many return values
headers = map[string]string{}
}

Expand Down Expand Up @@ -650,7 +658,7 @@

gitLabBaseUrl, err := url.Parse(gitLab.BaseURL)
if err != nil {
return nil, fmt.Errorf("failed to parse gitlab base URL: %v", err)
return fmt.Errorf("failed to parse gitlab base URL: %v", err)
}

var headers map[string]string
Expand Down Expand Up @@ -807,7 +815,7 @@
bitBucketBaseUrl, err := url.Parse(bitBucket.BaseURL)

if err != nil {
return nil, fmt.Errorf("failed to parse bitbucket base URL: %v", err)
return fmt.Errorf("failed to parse bitbucket base URL: %v", err)
}

var headers map[string]string
Expand Down Expand Up @@ -910,13 +918,13 @@

azureDevOpsBaseUrl, err := url.Parse(azureDevOps.BaseURL)
if err != nil {
return nil, fmt.Errorf("failed to parse azure devops base URL: %v", err)
return fmt.Errorf("failed to parse azure devops base URL: %v", err)
}

vsaexBaseUrl := strings.Replace(azureDevOps.BaseURL, "dev.azure.com", "vsaex.dev.azure.com", 1)
vsaexUrl, err := url.Parse(vsaexBaseUrl)
if err != nil {
return nil, fmt.Errorf("failed to parse azure devops vsaex base URL: %v", err)
return fmt.Errorf("failed to parse azure devops vsaex base URL: %v", err)
}

var headers map[string]string
Expand Down Expand Up @@ -1014,5 +1022,5 @@
}
}

return config, nil
return nil
}
Loading
Loading