Skip to content

Commit 2fc1224

Browse files
authored
Merge pull request #2 from codebytes/slides
Slides
2 parents cba2068 + 204664c commit 2fc1224

File tree

13 files changed

+386
-14
lines changed

13 files changed

+386
-14
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
"ghcr.io/devcontainers/features/powershell:1": {},
99
"ghcr.io/devcontainers/features/terraform:1": {},
1010
"ghcr.io/devcontainers-contrib/features/terrascan:1": {},
11+
"ghcr.io/devcontainers-contrib/features/checkov:1": {},
1112
"ghcr.io/dhoeric/features/terraform-docs:1": {},
1213
"ghcr.io/dhoeric/features/aztfy:1": {},
1314
"ghcr.io/dhoeric/features/tfsec:1": {},
1415
"ghcr.io/dhoeric/features/trivy:1": {},
16+
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {},
1517
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
1618
"packages": "chromium-browser"
1719
}
@@ -26,6 +28,7 @@
2628
"hashicorp.terraform",
2729
"ms-azuretools.vscode-azureterraform",
2830
"tfsec.tfsec",
31+
"Bridgecrew.checkov",
2932
"yzhang.markdown-all-in-one",
3033
"marp-team.marp-vscode"
3134
]

.github/workflows/checkov.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on: [push]
2+
jobs:
3+
checkov-job:
4+
runs-on: ubuntu-latest
5+
name: checkov-action
6+
steps:
7+
- name: Checkout repo
8+
uses: actions/checkout@master
9+
10+
- name: Run Checkov action
11+
id: checkov
12+
uses: bridgecrewio/checkov-action@master
13+
with:
14+
directory: demos/
15+
file: #example/tfplan.json # optional: provide the path for resource to be scanned. This will override the directory if both are provided.
16+
check: #CKV_AWS_1 # optional: run only a specific check_id. can be comma separated list
17+
skip_check: #CKV_AWS_2 # optional: skip a specific check_id. can be comma separated list
18+
quiet: true # optional: display only failed checks
19+
soft_fail: false # optional: do not return an error code if there are failed checks
20+
framework: terraform # optional: run only on a specific infrastructure {cloudformation,terraform,kubernetes,all}
21+
output_format: junitxml # optional: the output format, one of: cli, json, junitxml, github_failed_only, or sarif. Default: sarif
22+
#output_file_path: reports/results.sarif # folder and name of results file
23+
download_external_modules: true # optional: download external terraform modules from public git repositories and terraform registry
24+
#var_file: ./testdir/gocd.yaml # optional: variable files to load in addition to the default files. Currently only supported for source Terraform and Helm chart scans.
25+
#log_level: DEBUG # optional: set log level. Default WARNING
26+
#config_file: path/this_file
27+
#baseline: cloudformation/.checkov.baseline # optional: Path to a generated baseline file. Will only report results not in the baseline.
28+
container_user: 1000 # optional: Define what UID and / or what GID to run the container under to prevent permission issues

.github/workflows/terrascan.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on: [push]
2+
3+
jobs:
4+
terrascan_job:
5+
runs-on: ubuntu-latest
6+
name: terrascan-action
7+
steps:
8+
- name: Checkout repository
9+
uses: actions/checkout@v2
10+
- name: Run Terrascan
11+
id: terrascan
12+
uses: tenable/terrascan-action@main
13+
with:
14+
iac_type: 'terraform'
15+
iac_version: 'v14'
16+
policy_type: 'azure'
17+
only_warn: true
18+
#scm_token: ${{ secrets.ACCESS_TOKEN }}
19+
#verbose: true
20+
#sarif_upload: true
21+
#non_recursive:
22+
iac_dir: demos
23+
#policy_path:
24+
#skip_rules:
25+
#config_path:
26+
#find_vulnerabilities:
27+
#webhook_url:
28+
#webhook_token:

auth-setup.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
#set vars
4+
#codebytes
5+
githubOrganizationName=$(echo $(git remote get-url origin) | cut -f4 -d"/")
6+
#github-oidc-to-azure
7+
githubRepositoryName=$(basename -s .git `git config --get remote.origin.url`)
8+
9+
#create app registration
10+
applicationRegistrationDetails=$(az ad app create --display-name "${githubRepositoryName}")
11+
applicationRegistrationObjectId=$(echo $applicationRegistrationDetails | jq -r '.id')
12+
applicationRegistrationAppId=$(echo $applicationRegistrationDetails | jq -r '.appId')
13+
14+
#created federated creds
15+
az ad app federated-credential create \
16+
--id $applicationRegistrationObjectId \
17+
--parameters "{\"name\":\"${githubRepositoryName}-pr\",\"issuer\":\"https://token.actions.githubusercontent.com\",\"subject\":\"repo:${githubOrganizationName}/${githubRepositoryName}:pull_request\",\"audiences\":[\"api://AzureADTokenExchange\"]}"
18+
az ad app federated-credential create \
19+
--id $applicationRegistrationObjectId \
20+
--parameters "{\"name\":\"${githubRepositoryName}-env-prod\",\"issuer\":\"https://token.actions.githubusercontent.com\",\"subject\":\"repo:${githubOrganizationName}/${githubRepositoryName}:environment:prod\",\"audiences\":[\"api://AzureADTokenExchange\"]}"
21+
az ad app federated-credential create \
22+
--id $applicationRegistrationObjectId \
23+
--parameters "{\"name\":\"${githubRepositoryName}-branch-main\",\"issuer\":\"https://token.actions.githubusercontent.com\",\"subject\":\"repo:${githubOrganizationName}/${githubRepositoryName}:ref:refs/heads/main\",\"audiences\":[\"api://AzureADTokenExchange\"]}"
24+
25+
az ad sp create --id $applicationRegistrationObjectId
26+
az role assignment create --assignee $applicationRegistrationAppId --role Contributor
27+
28+
AZURE_CLIENT_ID=$applicationRegistrationAppId
29+
AZURE_TENANT_ID=$(az account show --query tenantId --output tsv)
30+
AZURE_SUBSCRIPTION_ID=$(az account show --query id --output tsv)
31+
32+
echo "AZURE_CLIENT_ID: $AZURE_CLIENT_ID"
33+
echo "AZURE_TENANT_ID: $AZURE_TENANT_ID"
34+
echo "AZURE_SUBSCRIPTION_ID: $AZURE_SUBSCRIPTION_ID"
35+
36+
gh secret set AZURE_CLIENT_ID --body "$AZURE_CLIENT_ID"
37+
gh secret set AZURE_TENANT_ID --body "$AZURE_TENANT_ID"
38+
gh secret set AZURE_SUBSCRIPTION_ID --body "$AZURE_SUBSCRIPTION_ID"

0 commit comments

Comments
 (0)