Skip to content

Commit df486df

Browse files
security: container + CI hardening (F-012/013/014/015/016/017)
- F-012 (CTO-4860): add .dockerignore excluding secrets/, *.env, config.json so credential files never enter the build context / image layers. - F-013 (CTO-4861): drop '-G sudo' from the app user in Dockerfile. - F-014 (CTO-4862): pin every GitHub Actions 'uses:' to a 40-char commit SHA. - F-015 (CTO-4863): add top-level 'permissions: contents: read' to the five workflows lacking one (semgrep already had it). - F-016 (CTO-4864): remove C_FORCE_ROOT=true from ops_app_celery.env and add no-new-privileges to the celery service (image already runs as USER app). - F-017 (CTO-4865): add no-new-privileges to web + celery (blast-radius). The dev source bind-mount itself is left for a separate dev/prod deploy decision. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f119cb9 commit df486df

10 files changed

Lines changed: 61 additions & 15 deletions

File tree

.dockerignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Keep secrets and local config out of the build context / image layers (F-012)
2+
secrets/
3+
*.env
4+
.env*
5+
config.json
6+
7+
# VCS / CI
8+
.git/
9+
.github/
10+
.gitignore
11+
12+
# Local bind-mount data — provided at runtime, never baked into the image
13+
mounts/
14+
15+
# Python / build noise
16+
__pycache__/
17+
*.py[cod]
18+
*.egg-info/
19+
.pytest_cache/
20+
.coverage
21+
htmlcov/
22+
.venv/
23+
venv/
24+
25+
# Editor / OS
26+
.vscode/
27+
.idea/
28+
.DS_Store

.github/workflows/commitlint.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
name: Check Commit Messages with Commitlint
22
on: [pull_request]
3+
permissions:
4+
contents: read
5+
36
jobs:
47
commitlint:
58
runs-on: ubuntu-latest
69
steps:
7-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
811
with:
912
fetch-depth: 0
10-
- uses: wagoid/commitlint-github-action@v5
13+
- uses: wagoid/commitlint-github-action@9763196e10f27aef304c9b8b660d31d97fce0f99 # v5
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# github action to run commit-msg hook on pull request commits and push commits to master branch
22
name: Validate sample config
33
on: pull_request
4+
permissions:
5+
contents: read
6+
47
jobs:
58
config-validator:
69
runs-on: ubuntu-latest
710
steps:
8-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
912
- name: Run config-validator
1013
run: python scripts/validator.py config.json.sample

.github/workflows/docker-push.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ on:
44
tags:
55
- v*
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
build:
912
runs-on: ubuntu-latest
1013
steps:
1114
- name: Check out the repo
12-
uses: actions/checkout@v3
15+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
1316
- name: Set up QEMU
14-
uses: docker/setup-qemu-action@v2
17+
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
1518
- name: Set up Docker Buildx
16-
uses: docker/setup-buildx-action@v2
19+
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2
1720
- name: Docker metadata
1821
id: meta
19-
uses: docker/metadata-action@v4
22+
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4
2023
with:
2124
images: |
2225
browserstack/enigma
@@ -25,12 +28,12 @@ jobs:
2528
type=semver,pattern=v{{major}}.{{minor}}
2629
type=semver,pattern=v{{major}}
2730
- name: Login to DockerHub
28-
uses: docker/login-action@v2
31+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
2932
with:
3033
username: ${{ secrets.DOCKERHUB_USERNAME }}
3134
password: ${{ secrets.DOCKERHUB_TOKEN }}
3235
- name: Build and push
33-
uses: docker/build-push-action@v4
36+
uses: docker/build-push-action@0a97817b6ade9f46837855d676c4cca3a2471fc9 # v4
3437
with:
3538
context: .
3639
push: true

.github/workflows/pre-commit.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# github action to run commit-msg hook on pull request commits and push commits to master branch
22
name: Pre Commit Hook
33
on: [pull_request]
4+
permissions:
5+
contents: read
6+
47
jobs:
58
commit-msg-hook:
69
runs-on: ubuntu-latest
710
steps:
8-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
912
- name: Run commit-msg hook
1013
run: |
1114
pip install pre-commit==2.21.0

.github/workflows/semgrep.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ jobs:
2121
image: returntocorp/semgrep:1.166.0
2222
if: (github.actor != 'dependabot[bot]')
2323
steps:
24-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
2525
- run: semgrep --error --config "p/cwe-top-25" --config "p/owasp-top-ten" --config "p/r2c-security-audit"

.github/workflows/unit-tests.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
name: Unit Tests and Lint
22
on: [push]
3+
permissions:
4+
contents: read
5+
36
jobs:
47
build:
58
runs-on: ubuntu-latest
69
strategy:
710
matrix:
811
python-version: ['3.9', '3.10', '3.11']
912
steps:
10-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
1114
- name: Set up Python ${{ matrix.python-version }}
12-
uses: actions/setup-python@v4
15+
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4
1316
with:
1417
python-version: ${{ matrix.python-version }}
1518
- name: Install dependencies

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RUN apt update && apt install -y netcat dnsutils libmariadb-dev
1919
RUN mkdir -p /ebs/logs && touch /ebs/logs/engima.log && chmod 777 /ebs/logs/engima.log
2020

2121
ARG APPUID=1001
22-
RUN useradd -rm -d /home/app -s /bin/bash -g root -G sudo -u "$APPUID" app
22+
RUN useradd -rm -d /home/app -s /bin/bash -g root -u "$APPUID" app
2323
WORKDIR /srv/code/dev
2424
RUN mkdir -p logs
2525
RUN mkdir -p db

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ services:
1818
- ./mounts/logs:/ebs/logs
1919
ports:
2020
- 8000:8000
21+
security_opt:
22+
- no-new-privileges:true
2123
depends_on:
2224
- db
2325
db:
@@ -54,6 +56,8 @@ services:
5456
- ./mounts/logs:/ebs/logs
5557
env_file:
5658
- ./secrets/ops_app_celery.env
59+
security_opt:
60+
- no-new-privileges:true
5761
depends_on:
5862
- db
5963
- redis

secrets/ops_app_celery.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
CELERY_BROKER_URL=redis://redis:6379
22
CELERY_RESULT_BACKEND=redis://redis:6379
3-
C_FORCE_ROOT=true
43
MYSQL_ROOT_PASSWORD=testtest
54
MYSQL_DATABASE=enigma
65
MYSQL_ROOT_HOST=%

0 commit comments

Comments
 (0)