|
| 1 | +name: Approve Override |
| 2 | + |
| 3 | +# workflow_dispatch — only board members can trigger this. |
| 4 | +# IAM trust condition on javabin-ci-override-approver verifies the actor. |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + repo: |
| 10 | + description: "Repository (e.g. javaBin/moresleep)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + sha: |
| 14 | + description: "Commit SHA to override" |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + reason: |
| 18 | + description: "Reason for override" |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + |
| 22 | +permissions: |
| 23 | + id-token: write |
| 24 | + contents: read |
| 25 | + |
| 26 | +env: |
| 27 | + AWS_ACCOUNT_ID: "553637109631" |
| 28 | + AWS_REGION: eu-central-1 |
| 29 | + |
| 30 | +jobs: |
| 31 | + approve: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - name: Configure AWS credentials via OIDC |
| 35 | + uses: aws-actions/configure-aws-credentials@v4 |
| 36 | + with: |
| 37 | + role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/javabin-ci-override-approver |
| 38 | + aws-region: ${{ env.AWS_REGION }} |
| 39 | + |
| 40 | + - name: Write override token |
| 41 | + env: |
| 42 | + OVERRIDE_REPO: ${{ inputs.repo }} |
| 43 | + OVERRIDE_SHA: ${{ inputs.sha }} |
| 44 | + OVERRIDE_REASON: ${{ inputs.reason }} |
| 45 | + OVERRIDE_ACTOR: ${{ github.actor }} |
| 46 | + run: | |
| 47 | + PARAM_NAME="/javabin/platform-overrides/${OVERRIDE_REPO}/${OVERRIDE_SHA}" |
| 48 | +
|
| 49 | + python3 << 'PYEOF' |
| 50 | + import json, os |
| 51 | + value = json.dumps({ |
| 52 | + "approved_by": os.environ["OVERRIDE_ACTOR"], |
| 53 | + "reason": os.environ["OVERRIDE_REASON"], |
| 54 | + "approved_at": __import__('datetime').datetime.utcnow().isoformat() + "Z", |
| 55 | + "run_id": os.environ.get("GITHUB_RUN_ID", ""), |
| 56 | + }) |
| 57 | + with open("/tmp/override-value.txt", "w") as f: |
| 58 | + f.write(value) |
| 59 | + PYEOF |
| 60 | +
|
| 61 | + aws ssm put-parameter \ |
| 62 | + --name "$PARAM_NAME" \ |
| 63 | + --type String \ |
| 64 | + --value "$(cat /tmp/override-value.txt)" \ |
| 65 | + --overwrite |
| 66 | +
|
| 67 | + echo "Override token written: ${PARAM_NAME}" |
| 68 | +
|
| 69 | + - name: Post to Slack |
| 70 | + env: |
| 71 | + OVERRIDE_REPO: ${{ inputs.repo }} |
| 72 | + OVERRIDE_SHA: ${{ inputs.sha }} |
| 73 | + OVERRIDE_REASON: ${{ inputs.reason }} |
| 74 | + OVERRIDE_ACTOR: ${{ github.actor }} |
| 75 | + GITHUB_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 76 | + run: | |
| 77 | + export SLACK_WEBHOOK_URL=$(aws ssm get-parameter \ |
| 78 | + --name /javabin/slack/platform-override-alerts-webhook \ |
| 79 | + --with-decryption --query Parameter.Value --output text) |
| 80 | +
|
| 81 | + python3 << 'PYEOF' |
| 82 | + import json, os, urllib.request |
| 83 | + webhook_url = os.environ.get("SLACK_WEBHOOK_URL", "") |
| 84 | + if not webhook_url: |
| 85 | + print("No webhook URL, skipping Slack notification") |
| 86 | + exit(0) |
| 87 | + run_url = os.environ["GITHUB_RUN_URL"] |
| 88 | + repo = os.environ["OVERRIDE_REPO"] |
| 89 | + sha = os.environ["OVERRIDE_SHA"] |
| 90 | + actor = os.environ["OVERRIDE_ACTOR"] |
| 91 | + reason = os.environ["OVERRIDE_REASON"] |
| 92 | + payload = json.dumps({ |
| 93 | + "blocks": [ |
| 94 | + {"type": "header", "text": {"type": "plain_text", "text": "Risk Override Approved", "emoji": True}}, |
| 95 | + {"type": "section", "text": {"type": "mrkdwn", "text": f"*Repo:* {repo}\n*SHA:* `{sha}`\n*By:* {actor}\n*Reason:* {reason}"}}, |
| 96 | + {"type": "section", "text": {"type": "mrkdwn", "text": f"<{run_url}|View Approval Run>"}}, |
| 97 | + ], |
| 98 | + "text": f"Risk override approved for {repo}" |
| 99 | + }).encode() |
| 100 | + req = urllib.request.Request(webhook_url, data=payload, headers={"Content-Type": "application/json"}) |
| 101 | + urllib.request.urlopen(req) |
| 102 | + PYEOF |
0 commit comments