Skip to content

Commit e43c658

Browse files
committed
Security fixes
1 parent 6bfcfd9 commit e43c658

4 files changed

Lines changed: 61 additions & 7 deletions

File tree

.github/workflows/changelog-bundle.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,29 @@ on:
1414
type: string
1515
report:
1616
description: >
17-
Buildkite promotion report URL or local file path.
17+
Buildkite promotion report HTTPS URL or local file path.
1818
Mutually exclusive with release-version.
1919
type: string
2020
output:
2121
description: 'Output file path for the bundle (e.g. docs/releases/v9.2.0.yaml)'
2222
type: string
2323
required: true
24+
base-branch:
25+
description: 'Base branch for the pull request (defaults to repository default branch)'
26+
type: string
2427
repo:
2528
description: 'GitHub repository name; falls back to bundle.repo in changelog.yml'
2629
type: string
2730
owner:
2831
description: 'GitHub repository owner; falls back to bundle.owner in changelog.yml'
2932
type: string
3033

34+
permissions: {}
35+
36+
concurrency:
37+
group: changelog-bundle-${{ inputs.output }}
38+
cancel-in-progress: false
39+
3140
jobs:
3241
generate:
3342
runs-on: ubuntu-latest
@@ -54,4 +63,5 @@ jobs:
5463
- uses: elastic/docs-actions/changelog/bundle-pr@v1
5564
with:
5665
output: ${{ inputs.output }}
66+
base-branch: ${{ inputs.base-branch }}
5767
github-token: ${{ github.token }}

changelog/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ Your `docs/changelog.yml` must include a `bundle` section so docs-builder knows
196196
```yaml
197197
bundle:
198198
directory: docs/changelog
199-
repo: my-repo
200-
owner: elastic
201199
```
202200

203201
The reusable workflow splits into two jobs with separate permissions: `generate` (read-only, produces the bundle artifact) and `create-pr` (write access, opens a pull request with the bundle file).
@@ -244,6 +242,7 @@ name: changelog-bundle
244242
245243
on:
246244
schedule:
245+
# At 08:00 AM, Monday through Friday
247246
- cron: '0 8 * * 1-5'
248247
workflow_dispatch:
249248
inputs:

changelog/bundle-create/action.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ inputs:
3131
description: >
3232
GitHub repository owner. Falls back to bundle.owner in changelog.yml,
3333
then to elastic.
34+
artifact-name:
35+
description: 'Name for the uploaded artifact (must match bundle-pr artifact-name)'
36+
default: 'changelog-bundle'
3437
github-token:
3538
description: 'GitHub token (needed for release-version to access GitHub API)'
3639
default: '${{ github.token }}'
@@ -75,9 +78,12 @@ runs:
7578
fi
7679
7780
if [ -n "$REPORT" ]; then
78-
if [[ "$REPORT" == http://* ]] || [[ "$REPORT" == https://* ]]; then
81+
if [[ "$REPORT" == https://* ]]; then
7982
curl -fsSL "$REPORT" -o .bundle-report.html
8083
REPORT=".bundle-report.html"
84+
elif [[ "$REPORT" == http://* ]]; then
85+
echo "::error::Report URL must use HTTPS: ${REPORT}"
86+
exit 1
8187
fi
8288
bundle_args+=(--report "$REPORT")
8389
docker_args+=(--network none)
@@ -88,7 +94,7 @@ runs:
8894
- name: Upload bundle artifact
8995
uses: actions/upload-artifact@v6
9096
with:
91-
name: changelog-bundle
97+
name: ${{ inputs.artifact-name }}
9298
path: ${{ inputs.output }}
9399
if-no-files-found: error
94100
retention-days: 1

changelog/bundle-pr/action.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ inputs:
1111
(e.g. docs/releases/v9.2.0.yaml). Must match the path used
1212
by the bundle-create action.
1313
required: true
14+
base-branch:
15+
description: 'Base branch for the pull request (defaults to repository default branch)'
16+
default: ''
17+
artifact-name:
18+
description: 'Name of the artifact uploaded by bundle-create'
19+
default: 'changelog-bundle'
1420
github-token:
1521
description: 'GitHub token with contents:write and pull-requests:write permissions'
1622
default: '${{ github.token }}'
@@ -23,20 +29,46 @@ runs:
2329
with:
2430
persist-credentials: false
2531

32+
- name: Validate output path
33+
shell: bash
34+
env:
35+
OUTPUT: ${{ inputs.output }}
36+
run: |
37+
if [[ "$OUTPUT" != *.yml && "$OUTPUT" != *.yaml ]]; then
38+
echo "::error::Output path must end in .yml or .yaml: ${OUTPUT}"
39+
exit 1
40+
fi
41+
if [[ "$OUTPUT" == /* ]]; then
42+
echo "::error::Output path must be relative: ${OUTPUT}"
43+
exit 1
44+
fi
45+
if [[ "$OUTPUT" == *..* ]]; then
46+
echo "::error::Output path must not contain '..': ${OUTPUT}"
47+
exit 1
48+
fi
49+
2650
- name: Download bundle artifact
2751
uses: actions/download-artifact@v6
2852
with:
29-
name: changelog-bundle
53+
name: ${{ inputs.artifact-name }}
3054
path: .bundle-artifact
3155

3256
- name: Create pull request
3357
shell: bash
3458
env:
3559
OUTPUT: ${{ inputs.output }}
60+
BASE_BRANCH: ${{ inputs.base-branch }}
3661
GH_TOKEN: ${{ inputs.github-token }}
3762
GIT_REPOSITORY: ${{ github.repository }}
3863
run: |
3964
BUNDLE_NAME=$(basename "$OUTPUT" .yaml)
65+
BUNDLE_NAME=$(basename "$BUNDLE_NAME" .yml)
66+
67+
if [[ ! "$BUNDLE_NAME" =~ ^[a-zA-Z0-9._+-]+$ ]]; then
68+
echo "::error::Bundle name contains disallowed characters: ${BUNDLE_NAME}"
69+
exit 1
70+
fi
71+
4072
BRANCH="changelog-bundle/${BUNDLE_NAME}"
4173
4274
mkdir -p "$(dirname "$OUTPUT")"
@@ -55,15 +87,22 @@ runs:
5587
5688
git commit -m "Add changelog bundle ${BUNDLE_NAME}"
5789
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GIT_REPOSITORY}.git"
90+
# Force-push: branch is ephemeral and always rebuilt from scratch
5891
git push -f origin "$BRANCH"
5992
git remote set-url origin "https://github.com/${GIT_REPOSITORY}.git"
6093
94+
BASE_FLAG=()
95+
if [ -n "$BASE_BRANCH" ]; then
96+
BASE_FLAG=(--base "$BASE_BRANCH")
97+
fi
98+
6199
EXISTING_PR=$(gh pr list --head "$BRANCH" --json number --jq '.[0].number // empty')
62100
if [ -n "$EXISTING_PR" ]; then
63101
echo "PR #${EXISTING_PR} already exists for branch ${BRANCH}, updated with latest bundle"
64102
else
65103
gh pr create \
66104
--title "Add changelog bundle ${BUNDLE_NAME}" \
67105
--body "Auto-generated changelog bundle for ${BUNDLE_NAME}." \
68-
--head "$BRANCH"
106+
--head "$BRANCH" \
107+
"${BASE_FLAG[@]}"
69108
fi

0 commit comments

Comments
 (0)