Skip to content

Commit 1fa410f

Browse files
add daily scan (#263)
* migrate from aws sdk go v1 to v2 * remove unit tests that are not compatible with aws sdk go v2 * fix: address formatting, logging, and documentation review comments * change telemetry to use [].types.TelemetryRecord instead of []*types.TelemetryRecord * refactor: change batch processor to use [] string instead of []*string * refactor create constants for AWS partition identifiers * feat: add ISO region support with constants for partitions and domains * docs: add comment explaining manual payload hash calculation for SDK v2 * docs: clarify empty endpoint behavior in AWS config * refactor: simplify STS assume role implementation to align with OTel * add SDK v2 compatible tests for conn package * add credentials cache for thread-safe credential management * fix indentation in telemetry.go * remove unused getPartition() function * fix IMDS errors in on-premise environments for aws sdk go v2 migration * add codeql and daily scan workflows * remove codeql and fix daily scan role * fix dependency scan * have all steps run and use trivy action * fix image scans * fix metric publishing step * update to run once a day * remove unnecessary step * remove test trigger * update metric publishing * align format with adot daily scans * update cadence * test * Revert "test" This reverts commit 738732f. --------- Co-authored-by: Michael He <yiyuanh@iusevimbtw.com> Co-authored-by: Michael He <53622546+yiyuan-he@users.noreply.github.com>
1 parent e3270f6 commit 1fa410f

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

.github/workflows/daily-scan.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
## SPDX-License-Identifier: Apache-2.0
3+
# Performs a daily scan of:
4+
# * The latest released X-Ray daemon image, using Trivy
5+
# * Project dependencies, using DependencyCheck
6+
#
7+
# Publishes results to CloudWatch Metrics.
8+
name: Daily scan
9+
10+
on:
11+
schedule: # scheduled to run every 6 hours
12+
- cron: '45 */6 * * *' # "At minute 45 past every 6th hour."
13+
workflow_dispatch: # be able to run the workflow on demand
14+
15+
env:
16+
AWS_DEFAULT_REGION: us-east-1
17+
18+
permissions:
19+
id-token: write
20+
contents: read
21+
22+
jobs:
23+
scan_and_report:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout repo for dependency scan
27+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Set up Go for dependency scan
32+
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
33+
with:
34+
go-version-file: go.mod
35+
36+
- name: Configure AWS credentials for dependency scan
37+
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 #5.0.0
38+
with:
39+
role-to-assume: ${{ secrets.SECRET_MANAGER_ROLE_ARN }}
40+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
41+
42+
- name: Get NVD API key for dependency scan
43+
uses: aws-actions/aws-secretsmanager-get-secrets@a9a7eb4e2f2871d30dc5b892576fde60a2ecc802 #v2.0.10
44+
id: nvd_api_key
45+
with:
46+
secret-ids: ${{ secrets.NVD_API_KEY_SECRET_ARN }}
47+
parse-json-secrets: true
48+
49+
- name: Cache Go modules
50+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 #v4.2.4
51+
with:
52+
path: ~/go/pkg/mod
53+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
54+
restore-keys: |
55+
${{ runner.os }}-go-
56+
57+
- name: Build binary
58+
run: make build
59+
env:
60+
VERSION: 0.${{ github.sha }}
61+
62+
# See http://jeremylong.github.io/DependencyCheck/dependency-check-cli/ for installation explanation
63+
- name: Install and run dependency scan
64+
id: dep_scan
65+
if: always()
66+
run: |
67+
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 259A55407DD6C00299E6607EFFDE55BE73A2D1ED
68+
VERSION=$(curl -s https://jeremylong.github.io/DependencyCheck/current.txt | head -n1 | cut -d" " -f1)
69+
curl -Ls "https://github.com/dependency-check/DependencyCheck/releases/download/v$VERSION/dependency-check-$VERSION-release.zip" --output dependency-check.zip
70+
curl -Ls "https://github.com/dependency-check/DependencyCheck/releases/download/v$VERSION/dependency-check-$VERSION-release.zip.asc" --output dependency-check.zip.asc
71+
gpg --verify dependency-check.zip.asc
72+
unzip dependency-check.zip
73+
./dependency-check/bin/dependency-check.sh --enableExperimental --failOnCVSS 0 --nvdApiKey ${{ env.NVD_API_KEY_NVD_API_KEY }} -s "."
74+
75+
- name: Print dependency scan results on failure
76+
if: ${{ steps.dep_scan.outcome != 'success' }}
77+
run: less dependency-check-report.html
78+
79+
- name: Perform high image scan on latest
80+
if: always()
81+
id: high_scan_latest
82+
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 #v0.33.1
83+
with:
84+
image-ref: 'public.ecr.aws/xray/aws-xray-daemon:latest'
85+
severity: 'CRITICAL,HIGH'
86+
exit-code: '1'
87+
88+
- name: Perform low image scan on latest
89+
if: always()
90+
id: low_scan_latest
91+
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 #v0.33.1
92+
with:
93+
image-ref: 'public.ecr.aws/xray/aws-xray-daemon:latest'
94+
severity: 'MEDIUM,LOW,UNKNOWN'
95+
exit-code: '1'
96+
97+
- name: Configure AWS Credentials for emitting metrics
98+
if: always()
99+
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 #5.0.0
100+
with:
101+
role-to-assume: ${{ secrets.AWS_INTEG_TEST_ROLE_ARN }}
102+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
103+
104+
- name: Publish high scan status on latest
105+
if: always()
106+
run: |
107+
value="${{ steps.high_scan_latest.outcome == 'success' && '1.0' || '0.0' }}"
108+
aws cloudwatch put-metric-data --namespace 'MonitorDaemon' \
109+
--metric-name Success \
110+
--dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=daily_scan_high \
111+
--value $value
112+
113+
- name: Publish low scan status on latest
114+
if: always()
115+
run: |
116+
value="${{ steps.low_scan_latest.outcome == 'success' && steps.dep_scan.outcome == 'success' && '1.0' || '0.0' }}"
117+
aws cloudwatch put-metric-data --namespace 'MonitorDaemon' \
118+
--metric-name Success \
119+
--dimensions repository=${{ github.repository }},branch=${{ github.ref_name }},workflow=daily_scan_low \
120+
--value $value

0 commit comments

Comments
 (0)