Skip to content

Commit b56744d

Browse files
committed
feat(ci): enable secure Docker publish workflow with branch restrictions
CHANGES - Activate auto-update-publish.yml workflow for Docker Hub publishing - Add main branch restrictions across all automation workflows - Implement minimum privilege permissions with explicit documentation - Enable multi-platform builds (linux/amd64, linux/arm64) with attestations IMPACT - Automated Docker image publishing with security-first architecture - Enhanced workflow security through branch and repository restrictions - Supply chain protection via pinned actions and artifact attestations - Defense in depth with least privilege access controls TECHNICAL NOTES - Workflow activation pending verification and testing - OIDC attestations provide cryptographic build provenance - Concurrency controls prevent conflicting workflow executions
1 parent 207599a commit b56744d

File tree

4 files changed

+44
-35
lines changed

4 files changed

+44
-35
lines changed

.github/workflows/auto-update-docs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ concurrency:
1111
jobs:
1212
update-docs:
1313
name: Update ${{ matrix.manager }} docs
14-
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server'
14+
# Restrict to home repository and main branch only for security
15+
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server' && github.ref == 'refs/heads/main'
1516
runs-on: ubuntu-latest
1617
permissions:
17-
contents: write
18+
contents: write # Required: commit documentation updates
1819
strategy:
1920
max-parallel: 1 # Prevent commit conflicts
2021
matrix:

.github/workflows/auto-update-index.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ on:
77
jobs:
88
update-index:
99
name: Update Search Index
10-
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server'
10+
# Restrict to home repository and main branch only for security
11+
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server' && github.ref == 'refs/heads/main'
1112
runs-on: ubuntu-latest
1213
permissions:
13-
contents: write
14+
contents: write # Required: commit search index updates
1415

1516
steps:
1617
- name: Checkout repository

.github/workflows/auto-update-publish.yml.example renamed to .github/workflows/auto-update-publish.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@ on:
44
workflow_call: {}
55
workflow_dispatch: {} # Manual trigger for testing
66

7-
env:
8-
# Docker requires lowercase names for both images and cache references
9-
IMAGE_NAME: py-dep-man-companion
10-
REPO_NAME: ${{ vars.DOCKERHUB_USERNAME }}/py-dep-man-companion
11-
127
concurrency: ${{ github.workflow }}-${{ github.ref }}
138

149
jobs:
1510
build-and-push-image:
16-
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server'
11+
# Restrict to home repository and main branch only for security
12+
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server' && github.ref == 'refs/heads/main'
1713
runs-on: ubuntu-latest
1814
permissions:
19-
contents: read
20-
attestations: write
21-
id-token: write
15+
contents: read # Minimum: checkout repository
16+
attestations: write # Required: artifact attestation
17+
id-token: write # Required: OIDC token for attestation
18+
environment: docker-hub-publish
19+
env:
20+
# Docker requires lowercase names for both images and cache references
21+
IMAGE_NAME: py-dep-man-companion
22+
REPO_NAME: ${{ vars.DOCKER_HUB_USERNAME }}/py-dep-man-companion
2223

2324
steps:
2425
- name: Checkout repository
@@ -27,16 +28,16 @@ jobs:
2728
ref: ${{ github.ref }}
2829

2930
- name: Log in to Docker Hub
30-
# Pinned 3rd party action to commit hash of release v3.3.0 on 08/15/2024 to prevent supply chain attacks
31-
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
31+
# Pinned 3rd party action to commit hash of release v3.4.0 on 2025-03-14 to prevent supply chain attacks
32+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
3233
with:
33-
username: ${{ vars.DOCKERHUB_USERNAME }}
34-
password: ${{ secrets.DOCKERHUB_PAT }}
34+
username: ${{ vars.DOCKER_HUB_USERNAME }}
35+
password: ${{ secrets.DOCKER_HUB_PAT }}
3536

3637
- name: Extract metadata (tags, labels) for Docker
3738
id: meta
38-
# Pinned 3rd party action to commit hash of release v5.5.1 on 01/23/2024 to prevent supply chain attacks
39-
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
39+
# Pinned 3rd party action to commit hash of release v5.7.0 on 2025-02-26 to prevent supply chain attacks
40+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804
4041
with:
4142
images: ${{ env.REPO_NAME }}
4243
tags: |
@@ -47,18 +48,18 @@ jobs:
4748
4849
# Add support for more platforms, i.e. linux/arm64 (macOS M1/M2) with QEMU
4950
- name: Set up QEMU
50-
# Pinned 3rd party action to commit hash of release v3.2.0 on 08/15/2024 to prevent supply chain attacks
51-
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf
51+
# Pinned 3rd party action to commit hash of release v3.6.0 on 2025-02-28 to prevent supply chain attacks
52+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392
5253

5354
# Enable advanced build features like cache export
5455
- name: Set up Docker Buildx
55-
# Pinned 3rd party action to commit hash of release v3.6.1 on 08/15/2024 to prevent supply chain attacks
56-
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db
56+
# Pinned 3rd party action to commit hash of release v3.11.1 on 2025-06-18 to prevent supply chain attacks
57+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435
5758

5859
- name: Build and push Docker image
5960
id: push
60-
# Pinned 3rd party action to commit hash of release v6.7.0 on 08/15/2024 to prevent supply chain attacks
61-
uses: docker/build-push-action@16ebe778df0e7752d2cfcbd924afdbbd89c1a755
61+
# Pinned 3rd party action to commit hash of release v6.18.0 on 2025-05-27 to prevent supply chain attacks
62+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
6263
with:
6364
context: .
6465
push: true

.github/workflows/auto-update.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,28 @@ on:
99
jobs:
1010
update-docs:
1111
name: Update Documentation
12+
# Restrict to home repository and main branch only for security
13+
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server' && github.ref == 'refs/heads/main'
1214
permissions:
13-
contents: write
15+
contents: write # Required: commit documentation updates
1416
uses: ./.github/workflows/auto-update-docs.yml
1517

1618
update-index:
1719
name: Update Search Index
1820
needs: update-docs
21+
# Restrict to home repository and main branch only for security
22+
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server' && github.ref == 'refs/heads/main'
1923
permissions:
20-
contents: write
24+
contents: write # Required: commit search index updates
2125
uses: ./.github/workflows/auto-update-index.yml
2226

23-
# publish:
24-
# name: Publish Image
25-
# needs: update-index
26-
# permissions:
27-
# contents: read
28-
# attestations: write
29-
# id-token: write
30-
# uses: ./.github/workflows/auto-update-publish.yml
27+
publish:
28+
name: Publish Image
29+
needs: update-index
30+
# Restrict to home repository and main branch only for security
31+
if: github.repository == 'KemingHe/python-dependency-manager-companion-mcp-server' && github.ref == 'refs/heads/main'
32+
permissions:
33+
contents: read # Minimum: checkout repository
34+
attestations: write # Required: artifact attestation
35+
id-token: write # Required: OIDC token for attestation
36+
uses: ./.github/workflows/auto-update-publish.yml

0 commit comments

Comments
 (0)