Skip to content

Commit

Permalink
add allowCodeAccess setting for gitlab (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpetr authored Jul 25, 2024
1 parent 4ac870c commit ef8e59f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ inbound:
gitlab:
baseUrl: https://gitlab.example.com/api/v4
token: ...
allowCodeAccess: false # default is false, set to true to allow Semgrep to read file contents
```

Under the hood, this config adds these allowlist items:
Expand All @@ -126,6 +127,10 @@ Under the hood, this config adds these allowlist items:
- 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`

And if `allowCodeAccess` is set, additionally:

- GET `https://gitlab.example.com/api/v4/projects/:project/repository/files/:filepath`

### Bitbucket

Similarly, the `bitbucket` configuration section grants Semgrep access to leave MR comments.
Expand Down
16 changes: 14 additions & 2 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ type GitHub struct {
}

type GitLab struct {
BaseURL string `mapstructure:"baseUrl" json:"baseUrl"`
Token string `mapstructure:"token" json:"token"`
BaseURL string `mapstructure:"baseUrl" json:"baseUrl"`
Token string `mapstructure:"token" json:"token"`
AllowCodeAccess bool `mapstructure:"allowCodeAccess" json:"allowCodeAccess"`
}

type BitBucket struct {
Expand Down Expand Up @@ -455,6 +456,17 @@ func LoadConfig(configFiles []string, deploymentId int) (*Config, error) {
SetRequestHeaders: headers,
},
)

if config.Inbound.GitLab.AllowCodeAccess {
config.Inbound.Allowlist = append(config.Inbound.Allowlist,
// get contents of file
AllowlistItem{
URL: gitLabBaseUrl.JoinPath("/projects/:project/repository/files/:filepath").String(),
Methods: ParseHttpMethods([]string{"GET"}),
SetRequestHeaders: headers,
},
)
}
}

if config.Inbound.BitBucket != nil {
Expand Down

0 comments on commit ef8e59f

Please sign in to comment.