Skip to content

Commit 72af549

Browse files
authored
Merge pull request #2 from 223159756/engine-merge
Engine merge
2 parents 5c94415 + 19af346 commit 72af549

125 files changed

Lines changed: 2820 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

6 KB
Binary file not shown.

.github/workflows/Collecter.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Run Collector
2+
3+
on:
4+
push:
5+
branches: [Compliance-Engine]
6+
7+
jobs:
8+
run-collector:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.11'
21+
22+
- name: Install deps
23+
run: pip install google-api-python-client google-auth google-auth-httplib2 google-auth-oauthlib
24+
25+
- name: Run GCP Access Collector
26+
env:
27+
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
28+
run: |
29+
python3 engine/GCPAccess.py
30+
mv iam_policy.json test-configs/iam_policy.json
31+
mv networks.json test-configs/networks.json
32+
33+
- name: Commit and push IAM policy & networks config
34+
run: |
35+
git config user.name "github-actions[bot]"
36+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
37+
git add test-configs/iam_policy.json
38+
git add test-configs/networks.json
39+
git diff --cached --quiet && echo "No changes to commit" || git commit -m "Update iam_policy.json & networks.json"
40+
git push origin Compliance-Engine
41+

.github/workflows/engine-ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build Engine Branch
2+
3+
on:
4+
push:
5+
branches: [Compliance-Engine]
6+
7+
jobs:
8+
build-engine-from-devops:
9+
name: Build Engine Code
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout engine branch code
14+
uses: actions/checkout@v3
15+
with:
16+
ref: Compliance-Engine
17+
18+
- name: Confirm branch
19+
run: git branch
20+
21+
- name: Build container
22+
run: |
23+
docker build -t autoaudit/engine -f docker/engine.Dockerfile .
24+
25+
- name: Run engine container
26+
run: |
27+
docker run --rm autoaudit/engine

.github/workflows/gryp.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# This workflow checks out code, builds an image, performs a container image
7+
# vulnerability scan with Anchore's Grype tool, and integrates the results with GitHub Advanced Security
8+
# code scanning feature. For more information on the Anchore scan action usage
9+
# and parameters, see https://github.com/anchore/scan-action. For more
10+
# information on Anchore's container image scanning tool Grype, see
11+
# https://github.com/anchore/grype
12+
name: Anchore Grype vulnerability scan
13+
14+
on:
15+
push:
16+
branches: [Compliance-Engine]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [Compliance-Engine]
20+
schedule:
21+
- cron: '37 20 * * 4'
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
Anchore-Build-Scan:
28+
permissions:
29+
contents: read # for actions/checkout to fetch code
30+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
31+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Check out the code
36+
uses: actions/checkout@v4
37+
38+
- name: Build the Docker image
39+
run: docker build -t compliance-engine-workflows:latest -f docker/engine.Dockerfile .
40+
41+
- name: Run the Anchore Grype scan action
42+
uses: anchore/scan-action@v3
43+
id: scan
44+
45+
with:
46+
image: docker:compliance-engine-workflows:latest
47+
fail-build: true
48+
severity-cutoff: critical
49+
50+
- name: Upload vulnerability report
51+
uses: github/codeql-action/upload-sarif@v3
52+
with:
53+
sarif_file: ${{ steps.scan.outputs.sarif }}

.gitignore

Whitespace-only changes.

docker/engine.Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY engine/ ./engine/
6+
COPY rules/ ./rules/
7+
COPY test-configs/ ./test-configs/
8+
9+
CMD ["python", "engine/main.py"]

engine/.trigger

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
abcdaas
2+
a

engine/.trigger2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aaa

engine/GCPAccess.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from google.oauth2 import service_account
2+
from googleapiclient.discovery import build
3+
from google.auth import default
4+
import json
5+
import os
6+
7+
service_account_info = json.loads(os.environ["GCP_CREDENTIALS"])
8+
creds = service_account.Credentials.from_service_account_info(
9+
service_account_info,
10+
scopes=["https://www.googleapis.com/auth/cloud-platform"],
11+
)
12+
13+
crm_policy = build("cloudresourcemanager", "v3", credentials=creds)
14+
crm_compute = build("compute", "v1", credentials=creds)
15+
16+
project_id = "coastal-stone-470308-a0"
17+
res_name = f"projects/{project_id}"
18+
19+
policy = crm_policy.projects().getIamPolicy(
20+
resource=res_name,
21+
body={"options": {"requestedPolicyVersion": 3}}
22+
).execute()
23+
24+
networks = []
25+
req = crm_compute.networks().list(project=project_id)
26+
while req is not None:
27+
resp = req.execute()
28+
networks.extend(resp.get("items", []))
29+
req = crm_compute.networks().list_next(previous_request=req, previous_response=resp)
30+
31+
with open("iam_policy.json", "w") as f:
32+
json.dump(policy, f, indent=2)
33+
34+
with open("networks.json", "w") as f:
35+
json.dump(networks, f, indent=2)
36+

engine/Helpers.rego

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package AutoAudit_tester.engine.Helpers
2+
3+
import future.keywords.in
4+
5+
get(path) = v if {
6+
parts := split(path, ".")
7+
some i
8+
pv := walk(input)[i]
9+
p := pv[0]
10+
v := pv[1]
11+
p == parts
12+
}
13+
equals(path, expected) if {
14+
get(path) == expected
15+
}
16+
17+
in_whitelist(path, allowed) if {
18+
val := get(path)
19+
val in allowed
20+
}
21+
not_in_blacklist(path, blocked) if {
22+
val := get(path)
23+
not val in blocked
24+
}
25+
status(bool) = s if {
26+
bool
27+
s := "Compliant"
28+
}
29+
status(bool) = s if {
30+
not bool
31+
s := "NonCompliant"
32+
}

0 commit comments

Comments
 (0)