Repository navigation
Expand file tree
/
Copy pathcodex-security.yml
More file actions
142 lines (129 loc) · 5.44 KB
/
Copy pathcodex-security.yml
File metadata and controls
142 lines (129 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Codex Security (Amazon Bedrock)
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
workflow_dispatch:
# Uncomment after testing to scan the default branch weekly.
# schedule:
# - cron: "17 3 * * 1"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
scan:
# This job receives AWS credentials. Do not use pull_request_target or
# enable it for untrusted contributors; see the README's trust boundary.
if: >-
github.event_name != 'pull_request' ||
(github.event.pull_request.head.repo.full_name == github.repository &&
github.actor != 'dependabot[bot]' &&
github.event.pull_request.draft == false)
runs-on: ubuntu-24.04
timeout-minutes: 60
permissions:
contents: read
id-token: write
security-events: write
actions: read
env:
CODEX_SECURITY_VERSION: "0.1.27"
BEDROCK_MODEL_ID: ${{ vars.BEDROCK_MODEL_ID }}
# Report-only by default. Set to "high" to fail on high/critical findings.
FAIL_ON_SEVERITY: ""
steps:
- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: "24.21.0"
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.14.7"
# Install outside the checkout, before any repository content is present.
- name: Install Codex Security
working-directory: ${{ runner.temp }}
shell: bash
run: |
npm install --prefix "$RUNNER_TEMP/codex-security-cli" \
--ignore-scripts --no-audit --no-fund \
--registry=https://registry.npmjs.org/ \
"@openai/codex-security@$CODEX_SECURITY_VERSION"
echo "$RUNNER_TEMP/codex-security-cli/node_modules/.bin" >> "$GITHUB_PATH"
- name: Check out the commit to scan
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
# On pull_request, the default checkout is GitHub's PR merge commit.
- name: Assume the Bedrock role with OIDC
id: aws
uses: aws-actions/configure-aws-credentials@cbe3b392738ccf3f987d68400dafcf4b0624a56c # v6.2.4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
role-session-name: codex-security-${{ github.run_id }}
role-duration-seconds: 3600
output-env-credentials: false
output-credentials: true
- name: Scan
id: scan
shell: bash
env:
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ steps.aws.outputs.aws-access-key-id }}
AWS_SECRET_ACCESS_KEY: ${{ steps.aws.outputs.aws-secret-access-key }}
AWS_SESSION_TOKEN: ${{ steps.aws.outputs.aws-session-token }}
EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
args=(
scan "$GITHUB_WORKSPACE"
--provider amazon-bedrock
--model "$BEDROCK_MODEL_ID"
--mode standard
--effort high
--output-dir "$RUNNER_TEMP/codex-security-scan"
--json
)
if [[ "$EVENT_NAME" == "pull_request" ]]; then
args+=(--diff "$BASE_SHA")
fi
if [[ -n "$FAIL_ON_SEVERITY" ]]; then
args+=(--fail-on-severity "$FAIL_ON_SEVERITY")
fi
scan_status=0
codex-security "${args[@]}" > "$RUNNER_TEMP/codex-security-result.json" || scan_status=$?
echo "exit-code=$scan_status" >> "$GITHUB_OUTPUT"
exit "$scan_status"
# A policy violation (1) is still a completed scan. An execution failure
# (2) must not replace code-scanning alerts with retained failure output.
- name: Export completed findings as SARIF
id: sarif
if: ${{ !cancelled() && (steps.scan.outputs.exit-code == '0' || steps.scan.outputs.exit-code == '1') }}
shell: bash
run: |
codex-security export "$RUNNER_TEMP/codex-security-scan" \
--export-format sarif \
--source-root "$GITHUB_WORKSPACE" \
--output "$RUNNER_TEMP/codex-security.sarif"
- name: Upload SARIF to GitHub Code Scanning
if: ${{ !cancelled() && steps.sarif.outcome == 'success' }}
uses: github/codeql-action/upload-sarif@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4.38.0
with:
sarif_file: ${{ runner.temp }}/codex-security.sarif
category: codex-security/${{ github.event_name == 'pull_request' && 'diff' || 'full' }}
- name: Save reports
if: ${{ !cancelled() && steps.scan.outputs.exit-code != '' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: codex-security-${{ github.run_id }}-${{ github.run_attempt }}
retention-days: 7
if-no-files-found: warn
path: |
${{ runner.temp }}/codex-security-result.json
${{ runner.temp }}/codex-security.sarif
${{ runner.temp }}/codex-security-scan/report.md
${{ runner.temp }}/codex-security-scan/coverage.json
${{ runner.temp }}/codex-security-scan/findings.json