|
| 1 | +name: Security Monitoring |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 16 * * *' |
| 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 | + } |
| 90 | + await checkAlerts(); |
| 91 | +
|
| 92 | + put-metric-data: |
| 93 | + runs-on: ubuntu-latest |
| 94 | + needs: [check-code-scanning-alerts, check-dependabot-alerts, check-secret-scanning-alerts] |
| 95 | + steps: |
| 96 | + - name: Configure AWS Credentials |
| 97 | + uses: aws-actions/configure-aws-credentials@12e3392609eaaceb7ae6191b3f54bbcb85b5002b |
| 98 | + with: |
| 99 | + role-to-assume: ${{ secrets.MONITORING_ROLE_ARN }} |
| 100 | + aws-region: us-west-2 |
| 101 | + - name: Put Code Scanning Alert Metric Data |
| 102 | + run: | |
| 103 | + if [ "${{ needs.check-code-scanning-alerts.outputs.code_scanning_alert_status }}" == "1" ]; then |
| 104 | + aws cloudwatch put-metric-data --metric-name CodeScanningAlert --namespace SecurityMonitoringMetrics --value 1 --unit Count --dimensions ProjectName=sagemaker-python-sdk |
| 105 | + else |
| 106 | + aws cloudwatch put-metric-data --metric-name CodeScanningAlert --namespace SecurityMonitoringMetrics --value 0 --unit Count --dimensions ProjectName=sagemaker-python-sdk |
| 107 | + fi |
| 108 | + - name: Put Dependabot Alert Metric Data |
| 109 | + run: | |
| 110 | + if [ "${{ needs.check-dependabot-alerts.outputs.dependabot_alert_status }}" == "1" ]; then |
| 111 | + aws cloudwatch put-metric-data --metric-name DependabotAlert --namespace SecurityMonitoringMetrics --value 1 --unit Count --dimensions ProjectName=sagemaker-python-sdk |
| 112 | + else |
| 113 | + aws cloudwatch put-metric-data --metric-name DependabotAlert --namespace SecurityMonitoringMetrics --value 0 --unit Count --dimensions ProjectName=sagemaker-python-sdk |
| 114 | + fi |
| 115 | + - name: Put Secret Scanning Alert Metric Data |
| 116 | + run: | |
| 117 | + if [ "${{ needs.check-secret-scanning-alerts.outputs.secret_scanning_alert_status }}" == "1" ]; then |
| 118 | + aws cloudwatch put-metric-data --metric-name SecretScanningAlert --namespace SecurityMonitoringMetrics --value 1 --unit Count --dimensions ProjectName=sagemaker-python-sdk |
| 119 | + else |
| 120 | + aws cloudwatch put-metric-data --metric-name SecretScanningAlert --namespace SecurityMonitoringMetrics --value 0 --unit Count --dimensions ProjectName=sagemaker-python-sdk |
| 121 | + fi |
0 commit comments