Skip to content

Commit e776067

Browse files
authored
add github installs url to allowlist (#67)
* add github installs url to allowlist * add github installs url to allowlist * formatting * formatting
1 parent 36a8a1f commit e776067

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

README.md

+36-29
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Semgrep will help you create a configuration file tailored to your Semgrep deplo
4848
**Do not** share the value of `inbound.wireguard.privateKey`. This is your organization's private key. Reach out to Semgrep on Slack if you need to rotate your Wireguard keys.
4949

5050
Example:
51+
5152
```yaml
5253
inbound:
5354
wireguard:
@@ -67,18 +68,20 @@ inbound:
6768
The `httpClient` configuration section modifies the HTTP client used for proxying requests.
6869

6970
Example:
71+
7072
```yaml
7173
inbound:
7274
httpClient:
7375
additionalCACerts:
74-
- /path/to/custom/cert.pem
76+
- /path/to/custom/cert.pem
7577
```
7678

7779
### GitHub
7880

7981
The `github` configuration section simplifies granting Semgrep access to leave PR comments.
8082

8183
Example:
84+
8285
```yaml
8386
inbound:
8487
github:
@@ -90,6 +93,7 @@ Under the hood, this config adds these allowlist items:
9093

9194
- GET `https://github.example.com/api/v3/repos/:owner/:repo`
9295
- GET `https://github.example.com/api/v3/repos/:owner/:repo/pulls`
96+
- GET `https://github.example.com/api/v3/orgs/:org/installation`
9397
- POST `https://github.example.com/api/v3/repos/:owner/:repo/pulls/:number/comments`
9498
- POST `https://github.example.com/api/v3/repos/:owner/:repo/issues/:number/comments`
9599

@@ -98,6 +102,7 @@ Under the hood, this config adds these allowlist items:
98102
Similarly, the `gitlab` configuration section grants Semgrep access to leave MR comments.
99103

100104
Example:
105+
101106
```yaml
102107
inbound:
103108
gitlab:
@@ -115,12 +120,12 @@ Under the hood, this config adds these allowlist items:
115120
- PUT `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions/:discussion/notes/:note`
116121
- PUT `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions/:discussion`
117122

118-
119123
### Allowlist
120124

121125
The `allowlist` configuration section provides finer-grained control over what HTTP requests are allowed to be forwarded out of the broker. The first matching allowlist item is used. No allowlist match means the request will not be proxied.
122126

123127
Examples:
128+
124129
```yaml
125130
inbound:
126131
allowlist:
@@ -135,7 +140,6 @@ inbound:
135140
methods: [GET]
136141
setRequestHeaders:
137142
Authorization: "Bearer ...snip..."
138-
139143
```
140144

141145
### Real-world example
@@ -144,22 +148,22 @@ Here's an example of allowing PR comments for a GitHub Enterprise instance hoste
144148

145149
```yaml
146150
allowlist:
147-
- url: https://git.example.com/api/v3/repos/:owner/:repo
148-
methods: [GET]
149-
setRequestHeaders:
150-
Authorization: "Bearer <GH TOKEN>"
151-
- url: https://git.example.com/api/v3/repos/:owner/:repo/pulls
152-
methods: [GET]
153-
setRequestHeaders:
154-
Authorization: "Bearer <GH TOKEN>"
155-
- url: https://git.example.com/api/v3/repos/:owner/:repo/pulls/:number/comments
156-
methods: [POST]
157-
setRequestHeaders:
158-
Authorization: "Bearer <GH TOKEN>"
159-
- url: https://git.example.com/api/v3/repos/:owner/:repo/issues/:number/comments
160-
methods: [POST]
161-
setRequestHeaders:
162-
Authorization: "Bearer <GH TOKEN>"
151+
- url: https://git.example.com/api/v3/repos/:owner/:repo
152+
methods: [GET]
153+
setRequestHeaders:
154+
Authorization: "Bearer <GH TOKEN>"
155+
- url: https://git.example.com/api/v3/repos/:owner/:repo/pulls
156+
methods: [GET]
157+
setRequestHeaders:
158+
Authorization: "Bearer <GH TOKEN>"
159+
- url: https://git.example.com/api/v3/repos/:owner/:repo/pulls/:number/comments
160+
methods: [POST]
161+
setRequestHeaders:
162+
Authorization: "Bearer <GH TOKEN>"
163+
- url: https://git.example.com/api/v3/repos/:owner/:repo/issues/:number/comments
164+
methods: [POST]
165+
setRequestHeaders:
166+
Authorization: "Bearer <GH TOKEN>"
163167
```
164168

165169
### Logging
@@ -169,11 +173,12 @@ The `logging` configuration section allows you to set additional logging options
169173
```yaml
170174
inbound:
171175
logging:
172-
logRequestBody: false # If true, the contents of any proxied HTTP request matching the allowlist will be logged in the request_body field in the proxy.request event
173-
logResponseBody: false # If true, the contents of any proxied HTTP response will be logged in the response_body field in the proxy.response event
176+
logRequestBody: false # If true, the contents of any proxied HTTP request matching the allowlist will be logged in the request_body field in the proxy.request event
177+
logResponseBody: false # If true, the contents of any proxied HTTP response will be logged in the response_body field in the proxy.response event
174178
```
175179

176180
Here's an example log output of `curl -X POST -H "Content-Type: application/json" "https://httpbin.org/anything" -d '{"foo": "bar"}'` being proxied through the network broker:
181+
177182
```
178183
INFO[0006] request.start client_ip="::1" id=1 method=POST path="/proxy/https://httpbin.org/anything" query= user_agent=curl/8.2.1
179184
INFO[0006] proxy.request allowlist_match="https://httpbin.org/*" client_ip="::1" destinationUrl="https://httpbin.org/anything" id=1 method=POST path="/proxy/https://httpbin.org/anything" query= request_body="{\"foo\": \"bar\"}" user_agent=curl/8.2.1
@@ -186,10 +191,10 @@ INFO[0006] request.response body_size=511 client_ip
186191
```yaml
187192
inbound:
188193
allowlist:
189-
- url: https://httpbin.org/*
190-
methods: [GET, POST, DELETE]
191-
logRequestBody: true
192-
logResponseBody: true
194+
- url: https://httpbin.org/*
195+
methods: [GET, POST, DELETE]
196+
logRequestBody: true
197+
logResponseBody: true
193198
```
194199

195200
## Usage
@@ -205,6 +210,7 @@ semgrep-network-broker -c config.yaml
205210
Multiple config files can be overlaid on top of each other by passing multiple `-c` args (ex. `semgrep-network-broker -c config1.yaml -c config2.yaml -c config3.yaml`). Note that while maps will be merged together, arrays will be _replaced_.
206211

207212
Requirements:
213+
208214
- internet access to `wireguard.semgrep.dev` on UDP port 51820
209215

210216
## Other Commands
@@ -222,6 +228,7 @@ Requirements:
222228
`semgrep-network-broker pubkey` generates a base64 public key for a given private key (via stdin)
223229

224230
### relay
231+
225232
`semgrep-network-broker relay` launches an HTTP server that relays request that match a certain rule.
226233

227234
```yaml
@@ -232,7 +239,7 @@ outbound:
232239
destinationUrl: https://httpbin.org/anything
233240
jsonPath: "$.foo"
234241
equals:
235-
- bar
242+
- bar
236243
```
237244

238245
would result in requests addressed to http://localhost:8080/relay/test being relayed to https://httpbin.org/anything as long as the result of the jsonpath query `$.foo` executed on the request body results in the string `bar`.
@@ -249,9 +256,9 @@ outbound:
249256
destinationUrl: https://httpbin.org/anything
250257
jsonPath: "$.foo"
251258
equals:
252-
- bar
259+
- bar
253260
additionalConfigs:
254-
- destinationUrl: htttps://example.com/fallback
261+
- destinationUrl: htttps://example.com/fallback
255262
```
256263

257-
The example above would relay traffic to https://httpbin.org/anything if the request body contains `{"foo": "bar"}`, otherwise, it'd relay traffic to `htttps://example.com/fallback`.
264+
The example above would relay traffic to https://httpbin.org/anything if the request body contains `{"foo": "bar"}`, otherwise, it'd relay traffic to `htttps://example.com/fallback`.

pkg/config.go

+6
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ func LoadConfig(configFiles []string) (*Config, error) {
302302
URL: gitHubBaseUrl.JoinPath("/repos/:owner/:repo/issues/:number/comments").String(),
303303
Methods: ParseHttpMethods([]string{"POST"}),
304304
SetRequestHeaders: headers,
305+
},
306+
// check app installation
307+
AllowlistItem{
308+
URL: gitHubBaseUrl.JoinPath("/orgs/:org/installation").String(),
309+
Methods: ParseHttpMethods([]string{"GET"}),
310+
SetRequestHeaders: headers,
305311
})
306312
}
307313

0 commit comments

Comments
 (0)