Skip to content

Commit bafe2ee

Browse files
committed
Add support for tfsec evidence integration
1 parent f30db41 commit bafe2ee

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "tfsec evidence Integration example"
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
id-token: write
8+
contents: read
9+
10+
jobs:
11+
package-terraform-with-tfsec-evidence:
12+
runs-on: ubuntu-latest
13+
env:
14+
ATTACH_OPTIONAL_CUSTOM_MARKDOWN_TO_EVIDENCE: true
15+
steps:
16+
# Build and publish the packages to JFrog Artifactory
17+
- name: Setup jfrog cli
18+
uses: jfrog/setup-jfrog-cli@v4
19+
env:
20+
JF_URL: ${{ vars.ARTIFACTORY_URL }}
21+
JF_ACCESS_TOKEN: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
22+
- uses: actions/checkout@v4
23+
with:
24+
sparse-checkout: |
25+
examples/tfsec-scan-example/**
26+
sparse-checkout-cone-mode: false
27+
- name: Publish to JFrog Artifactory
28+
run: |
29+
jf tfc --repo-deploy tf-local \
30+
--server-id-deploy setup-jfrog-cli-server
31+
jf tf p --namespace example \
32+
--provider aws \
33+
--tag v0.0.${{ github.run_number }} \
34+
--build-name my-tf-build \
35+
--build-number ${{ github.run_number }}
36+
jf rt bp my-tf-build ${{ github.run_number }}
37+
38+
# Run tfsec to scan Terraform code for security issues
39+
- name: Run tfsec
40+
uses: aquasecurity/tfsec-action@v1.0.0
41+
with:
42+
additional_args: --format json --out tfsec.json
43+
soft_fail: true
44+
45+
# This is an optional step to generate a custom markdown report
46+
- name: Generate optional custom markdown report
47+
if: env.ATTACH_OPTIONAL_CUSTOM_MARKDOWN_TO_EVIDENCE == 'true'
48+
run: |
49+
pwd
50+
ls -al
51+
python ./examples/tfsec-scan-example/tfsec_json_to_markdown_helper.py tfsec.json
52+
53+
# Attaching the evidence to associated package
54+
- name: Attach evidence using jfrog cli
55+
run: |
56+
ls -al
57+
cat tfsec.json
58+
jf evd create \
59+
--build-name my-tf-build \
60+
--build-number ${{ github.run_number }} \
61+
--key "${{ secrets.PRIVATE_KEY }}" \
62+
--key-alias "${{ vars.EVIDENCE_KEY_ALIAS }}" \
63+
--predicate ./tfsec.json \
64+
--predicate-type http://aquasec.com/tfsec/security-scan \
65+
${{ env.ATTACH_OPTIONAL_CUSTOM_MARKDOWN_TO_EVIDENCE == 'true' && '--markdown "tfsec.md"' || '' }}

.github/workflows/trivy-evidence-example.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ jobs:
5353
# Attaching the evidence to associated package
5454
- name: Attach evidence using jfrog cli
5555
run: |
56-
ls -al
5756
jf evd create \
5857
--package-name $IMAGE_NAME \
5958
--package-version $VERSION \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# tfsec Evidence Example
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "aws_vpc" "main" {
2+
cidr_block = var.vpc_cidr
3+
enable_dns_hostnames = true
4+
tags = {
5+
name = "main"
6+
}
7+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import json
2+
import os
3+
import sys
4+
5+
def generate_readme(json_file_path, output_file_path):
6+
try:
7+
# Read the JSON file
8+
with open(json_file_path, 'r') as json_file:
9+
data = json.load(json_file)
10+
11+
# Extract results
12+
results = data.get("results", [])
13+
# Generate markdown content
14+
markdown_content = f"""
15+
### tfsec Scan Report:
16+
# Detected Vulnerabilities by tfsec
17+
18+
"""
19+
for result in results:
20+
markdown_content += f"## Issue: {result.get('description', 'No description')}\n\n"
21+
markdown_content += f"### Impact\n{result.get('impact', 'No impact information')}\n\n"
22+
markdown_content += "### Links\n"
23+
for link in result.get('links', []):
24+
markdown_content += f"- [{link}]({link})\n"
25+
markdown_content += "\n"
26+
markdown_content += "### Location\n"
27+
location = result.get('location', {})
28+
markdown_content += f"- **File:** {location.get('filename', 'Unknown file')}\n"
29+
markdown_content += f"- **Start Line:** {location.get('start_line', 'Unknown start line')}\n"
30+
markdown_content += f"- **End Line:** {location.get('end_line', 'Unknown end line')}\n\n"
31+
markdown_content += "### Details\n"
32+
markdown_content += f"- **Long ID:** `{result.get('long_id', 'Unknown long ID')}`\n"
33+
markdown_content += f"- **Resolution:** {result.get('resolution', 'No resolution provided')}\n"
34+
markdown_content += f"- **Resource:** `{result.get('resource', 'Unknown resource')}`\n"
35+
markdown_content += f"- **Rule Description:** {result.get('rule_description', 'No rule description')}\n"
36+
markdown_content += f"- **Rule ID:** `{result.get('rule_id', 'Unknown rule ID')}`\n"
37+
markdown_content += f"- **Rule Provider:** `{result.get('rule_provider', 'Unknown rule provider')}`\n"
38+
markdown_content += f"- **Rule Service:** `{result.get('rule_service', 'Unknown rule service')}`\n"
39+
markdown_content += f"- **Severity:** `{result.get('severity', 'Unknown severity')}`\n"
40+
markdown_content += f"- **Status:** `{result.get('status', 'Unknown status')}`\n"
41+
markdown_content += f"- **Warning:** `{result.get('warning', 'Unknown warning')}`\n\n"
42+
43+
# Write to the README file
44+
with open(output_file_path, 'w') as output_file:
45+
output_file.write(markdown_content)
46+
47+
print(f"README file generated successfully at {output_file_path}")
48+
49+
except Exception as e:
50+
print(f"An error occurred: {e}")
51+
52+
if __name__ == "__main__":
53+
if len(sys.argv) != 2:
54+
print("Usage: python tfsec_json_to_markdown_helper.py <input_file>")
55+
sys.exit(1)
56+
# Define paths
57+
json_file_path = sys.argv[1]
58+
output_file_path = "tfsec.md" # Adjust path as needed
59+
60+
# Generate README
61+
generate_readme(json_file_path, output_file_path)

0 commit comments

Comments
 (0)