Skip to content

Commit de5e4da

Browse files
committed
Rule to invoke Bandit from webservice running on Cloud Run
1 parent 9544fb4 commit de5e4da

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

rule-types/github/pr_bandit.yaml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# NOTE: This rule leverages the `http.send` function and a Cloud Run service
2+
# https://banditize-562949304223.us-central1.run.app, which is built from
3+
# https://github.com/evankanderson/banditize
4+
5+
# This also requires https://github.com/mindersec/minder/pull/5181 to be merged,
6+
# and the `pr_comment_alert` feature flag enabled.
7+
---
8+
version: v1
9+
type: rule-type
10+
name: pr_bandit
11+
severity:
12+
value: medium
13+
context:
14+
provider: github
15+
release_phase: alpha
16+
description: |
17+
Detects new python static analysis findings in a pull request.
18+
19+
This rule uses https://github.com/PyCQA/bandit as a code scanner,
20+
running it against the base and head branches of a pull request to
21+
detect new security issues.
22+
guidance: |
23+
This pull request introduces new issues detected by the Bandit static
24+
code scanner. Generally, these indicate risky software patterns which
25+
should be addressed before merging the pull request.
26+
def:
27+
in_entity: pull_request
28+
rule_schema:
29+
type: object
30+
properties: {}
31+
ingest:
32+
type: git
33+
git: {}
34+
# Defines the configuration for evaluating data ingested against the given profile
35+
eval:
36+
type: rego
37+
rego:
38+
type: constraints
39+
def: |
40+
package minder
41+
import rego.v1
42+
43+
base_tar := base_file.archive(["."])
44+
head_tar := file.archive(["."])
45+
46+
resp := http.send({
47+
"method": "POST",
48+
"url": "https://banditize-562949304223.us-central1.run.app/pull",
49+
"headers": {
50+
"Content-Type": "application/json",
51+
},
52+
"body": {
53+
"base": base64.encode(base_tar),
54+
"head": base64.encode(head_tar),
55+
},
56+
})
57+
58+
violations contains {"msg": resp.body.simpleFindings} if resp.body.simpleFindings != ""
59+
# violations contains {"msg": "Always fail"}
60+
61+
# violations contains {"msg": json.marshal(resp)}
62+
alert:
63+
type: pull_request_comment
64+
pull_request_comment:
65+
review_message: |
66+
[Bandit](https://bandit.readthedocs.io/) found new issues in this pull request. Please review and address them before merging.
67+
68+
You'll need to run `minder profile status list -n Test-Bandit --detailed -o json | jq -r '.ruleEvaluationStatus[0].details'` to get the actual errors.

0 commit comments

Comments
 (0)