1
+ name : Security Monitoring
2
+
3
+ on :
4
+ schedule :
5
+ - cron : ' 0 9 * * *'
6
+
7
+ concurrency :
8
+ group : ${{ github.workflow }}-${{ github.run_id }}
9
+ cancel-in-progress : true
10
+
11
+ permissions :
12
+ id-token : write
13
+
14
+ jobs :
15
+ check-code-scanning-alerts :
16
+ runs-on : ubuntu-latest
17
+ outputs :
18
+ code_scanning_alert_status : ${{ steps.check-code-scanning-alerts.outputs.code_scanning_alert_status }}
19
+ steps :
20
+ - name : Check for security alerts
21
+ id : check-code-scanning-alerts
22
+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
23
+ with :
24
+ github-token : ${{ secrets.GH_PAT }}
25
+ script : |
26
+ async function checkAlerts() {
27
+ const owner = '${{ github.repository_owner }}';
28
+ const repo = '${{ github.event.repository.name }}';
29
+ const ref = 'refs/heads/master';
30
+
31
+ const codeScanningAlerts = await github.rest.codeScanning.listAlertsForRepo({
32
+ owner,
33
+ repo,
34
+ ref: ref
35
+ });
36
+ const activeCodeScanningAlerts = codeScanningAlerts.data.filter(alert => alert.state === 'open');
37
+ core.setOutput('code_scanning_alert_status', activeCodeScanningAlerts.length > 0 ? '1': '0');
38
+ }
39
+ await checkAlerts();
40
+
41
+ check-dependabot-alerts :
42
+ runs-on : ubuntu-latest
43
+ outputs :
44
+ dependabot_alert_status : ${{ steps.check-dependabot-alerts.outputs.dependabot_alert_status }}
45
+ steps :
46
+ - name : Check for dependabot alerts
47
+ id : check-dependabot-alerts
48
+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
49
+ with :
50
+ github-token : ${{ secrets.GH_PAT }}
51
+ script : |
52
+ async function checkAlerts() {
53
+ const owner = '${{ github.repository_owner }}';
54
+ const repo = '${{ github.event.repository.name }}';
55
+
56
+ const dependabotAlerts = await github.rest.dependabot.listAlertsForRepo({
57
+ owner,
58
+ repo,
59
+ headers: {
60
+ 'accept': 'applications/vnd.github+json'
61
+ }
62
+ });
63
+ const activeDependabotAlerts = dependabotAlerts.data.filter(alert => alert.state === 'open');
64
+ core.setOutput('dependabot_alert_status', activeDependabotAlerts.length > 0 ? '1': '0');
65
+ }
66
+ await checkAlerts();
67
+
68
+ check-secret-scanning-alerts :
69
+ runs-on : ubuntu-latest
70
+ outputs :
71
+ secret_scanning_alert_status : ${{ steps.check-secret-scanning-alerts.outputs.secret_scanning_alert_status }}
72
+ steps :
73
+ - name : Check for secret scanning alerts
74
+ id : check-secret-scanning-alerts
75
+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
76
+ with :
77
+ github-token : ${{ secrets.GH_PAT }}
78
+ script : |
79
+ async function checkAlerts() {
80
+ const owner = '${{ github.repository_owner }}';
81
+ const repo = '${{ github.event.repository.name }}';
82
+
83
+ const secretScanningAlerts = await github.rest.secretScanning.listAlertsForRepo({
84
+ owner,
85
+ repo,
86
+ });
87
+ const activeSecretScanningAlerts = secretScanningAlerts.data.filter(alert => alert.state === 'open');
88
+ core.setOutput('secret_scanning_alert_status', activeSecretScanningAlerts.length > 0 ? '1': '0');
89
+ console.log("Active Secret Scanning Alerts", activeSecretScanningAlerts);
90
+ }
91
+ await checkAlerts();
92
+
93
+ put-metric-data :
94
+ runs-on : ubuntu-latest
95
+ needs : [check-code-scanning-alerts, check-dependabot-alerts, check-secret-scanning-alerts]
96
+ steps :
97
+ - name : Configure AWS Credentials
98
+ uses : aws-actions/configure-aws-credentials@12e3392609eaaceb7ae6191b3f54bbcb85b5002b
99
+ with :
100
+ role-to-assume : ${{ secrets.MONITORING_ROLE_ARN }}
101
+ aws-region : us-west-2
102
+ - name : Put Code Scanning Alert Metric Data
103
+ run : |
104
+ if [ "${{ needs.check-code-scanning-alerts.outputs.code_scanning_alert_status }}" == "1" ]; then
105
+ aws cloudwatch put-metric-data --metric-name CodeScanningAlert --namespace SecurityMonitoringMetrics --value 1 --unit Count --dimensions ProjectName=sagemaker-python-sdk
106
+ else
107
+ aws cloudwatch put-metric-data --metric-name CodeScanningAlert --namespace SecurityMonitoringMetrics --value 0 --unit Count --dimensions ProjectName=sagemaker-python-sdk
108
+ fi
109
+ - name : Put Dependabot Alert Metric Data
110
+ run : |
111
+ if [ "${{ needs.check-dependabot-alerts.outputs.dependabot_alert_status }}" == "1" ]; then
112
+ aws cloudwatch put-metric-data --metric-name DependabotAlert --namespace SecurityMonitoringMetrics --value 1 --unit Count --dimensions ProjectName=sagemaker-python-sdk
113
+ else
114
+ aws cloudwatch put-metric-data --metric-name DependabotAlert --namespace SecurityMonitoringMetrics --value 0 --unit Count --dimensions ProjectName=sagemaker-python-sdk
115
+ fi
116
+ - name : Put Secret Scanning Alert Metric Data
117
+ run : |
118
+ if [ "${{ needs.check-secret-scanning-alerts.outputs.secret_scanning_alert_status }}" == "1" ]; then
119
+ aws cloudwatch put-metric-data --metric-name SecretScanningAlert --namespace SecurityMonitoringMetrics --value 1 --unit Count --dimensions ProjectName=sagemaker-python-sdk
120
+ else
121
+ aws cloudwatch put-metric-data --metric-name SecretScanningAlert --namespace SecurityMonitoringMetrics --value 0 --unit Count --dimensions ProjectName=sagemaker-python-sdk
122
+ fi
0 commit comments