Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 62c265e

Browse files
authored
feat: csp secu (#101)
* feat: csp dynamic header in nginx.conf * bump: 2.2.0-rc.0 * ci: change branches * ci: update deps * ci: change to pogues-ci * fix: nginx conf (not multi-line allowed) * bump: 2.2.0-rc.1 * fix: csp for font (load as data) & bump to 2.2.0-rc.2
1 parent 80d3006 commit 62c265e

File tree

6 files changed

+140
-220
lines changed

6 files changed

+140
-220
lines changed

.github/workflows/release-develop.yml

Lines changed: 0 additions & 113 deletions
This file was deleted.

.github/workflows/release-main.yml

Lines changed: 78 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,102 @@
1-
name: Build release candidate
1+
name: Main CI
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: ['main']
6+
pull_request:
7+
types: [opened, synchronize, reopened]
78

89
jobs:
9-
check-version:
10+
build:
1011
runs-on: ubuntu-latest
11-
outputs:
12-
release-version: ${{ steps.version.outputs.pe-version }}
13-
tag-already-exists: ${{ steps.checkTag.outputs.exists }}
12+
if: github.event.head_commit.author.name != 'github-actions[bot]'
1413
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v3
17-
18-
- name: Get version
19-
id: version
20-
run: echo "pe-version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT
21-
22-
- name: Print version
23-
run: echo ${{ steps.version.outputs.pe-version }}
24-
25-
- uses: mukunku/tag-exists-action@v1.2.0
26-
id: checkTag
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
2716
with:
28-
tag: ${{ steps.version.outputs.pe-version }}
29-
30-
- if: ${{ steps.checkTag.outputs.exists == 'true' }}
31-
name: "Skip release"
32-
run: echo "Nothing to tag/release, the release ${{ steps.version.outputs.pe-version }} already exists"
17+
node-version: '20'
18+
- run: yarn && yarn build
19+
- uses: actions/upload-artifact@v4
20+
with:
21+
name: public-enemy
22+
path: dist
3323

34-
create-release:
35-
needs: check-version
24+
check_if_version_upgraded:
25+
needs: build
3626
runs-on: ubuntu-latest
37-
if: ${{ needs.check-version.outputs.tag-already-exists == 'false' }}
27+
if: |
28+
github.event_name == 'push' ||
29+
github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login
30+
outputs:
31+
version: ${{ steps.version.outputs.prop }}
32+
is_version_changed: ${{ steps.check.outputs.exists == 'false' }}
33+
is_pre_release: ${{ contains(steps.version.outputs.prop, '-rc' ) }}
3834
steps:
39-
- uses: actions/checkout@v3
35+
- uses: actions/checkout@v4
36+
- id: version
37+
uses: notiz-dev/github-action-json-property@release
4038
with:
41-
ref: ${{ github.ref }}
42-
fetch-depth: 0
43-
44-
- name: Get previous tag
45-
id: previousTag
46-
run: echo "previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep '^[0-9]\+\.[0-9]\+\.[0-9]\+$' | tail -1)" >> $GITHUB_OUTPUT
47-
48-
- name: Create release note
49-
id: changelog
50-
uses: requarks/changelog-action@v1
51-
with:
52-
fromTag: ${{ github.sha }}
53-
toTag: ${{ steps.previousTag.outputs.previousTag}}
54-
token: ${{ secrets.GITHUB_TOKEN }}
55-
writeToFile: false
56-
57-
- uses: softprops/action-gh-release@v1
39+
path: 'package.json'
40+
prop_path: 'version'
41+
## we check if repo contains already this tag, if not version, has changed
42+
- uses: mukunku/tag-exists-action@v1.6.0
43+
id: check
5844
with:
59-
tag_name: ${{ needs.check-version.outputs.release-version }}
60-
target_commitish: ${{ github.head_ref || github.ref }}
61-
name: ${{ needs.check-version.outputs.release-version }}
62-
body: ${{steps.changelog.outputs.changes}}
63-
env:
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
tag: ${{ steps.version.outputs.prop }}
6546

66-
build-release:
67-
needs: create-release
47+
docker_public_enemy:
48+
needs: check_if_version_upgraded
49+
if: |
50+
(github.event_name == 'push' || needs.check_if_version_upgraded.outputs.is_pre_release == 'true') &&
51+
needs.check_if_version_upgraded.outputs.is_version_changed == 'true'
6852
runs-on: ubuntu-latest
6953
steps:
70-
- name: Extract branch name
71-
shell: bash
72-
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT
73-
id: extract_branch
74-
75-
- uses: actions/checkout@v3
76-
with:
77-
ref: ${{ steps.extract_branch.outputs.branch }}
78-
79-
- name: Use Node.js 18
80-
uses: actions/setup-node@v3
54+
- uses: actions/checkout@v4
55+
- uses: docker/setup-qemu-action@v3
56+
- uses: docker/setup-buildx-action@v3
57+
- uses: docker/login-action@v3
8158
with:
82-
node-version: 18
83-
- run: yarn
84-
- run: yarn build
85-
86-
- name: Upload build
87-
uses: actions/upload-artifact@v3
59+
username: ${{ secrets.DOCKERHUB_USERNAME }}
60+
password: ${{ secrets.DOCKERHUB_TOKEN }}
61+
- uses: actions/download-artifact@v4
8862
with:
89-
name: build
63+
name: public-enemy
9064
path: dist
91-
docker:
92-
needs:
93-
- check-version
94-
- build-release
65+
- uses: docker/build-push-action@v6
66+
with:
67+
platforms: linux/amd64,linux/arm64
68+
context: '.'
69+
push: true
70+
tags: |
71+
inseefr/public-enemy:latest,
72+
inseefr/public-enemy:${{ needs.check_if_version_upgraded.outputs.version }}
73+
74+
release:
9575
runs-on: ubuntu-latest
76+
needs: check_if_version_upgraded
77+
# We create release only if the version in the package.json have been upgraded and this CI is running against the main branch.
78+
# We allow branches with a PR open on main to publish pre-release (x.y.z-rc.u) but not actual releases.
79+
if: |
80+
(github.event_name == 'push' || needs.check_if_version_upgraded.outputs.is_pre_release == 'true') &&
81+
needs.check_if_version_upgraded.outputs.is_version_changed == 'true'
9682
steps:
97-
- uses: actions/checkout@v3
98-
99-
- name: Download build
100-
id: download
101-
uses: actions/download-artifact@v3
83+
- uses: actions/checkout@v4
10284
with:
103-
name: build
85+
ref: ${{ github.ref }}
86+
- uses: actions/download-artifact@v4
87+
with:
88+
name: public-enemy
10489
path: dist
105-
106-
- name: Publish to Registry
107-
uses: elgohr/Publish-Docker-Github-Action@v5
90+
- name: Zip bundle
91+
run: cd dist && zip -r ../public-enemy.zip ./*
92+
- uses: softprops/action-gh-release@v2
10893
with:
109-
name: inseefr/public-enemy
110-
username: ${{ secrets.DOCKERHUB_USERNAME }}
111-
password: ${{ secrets.DOCKERHUB_TOKEN }}
112-
tags: "${{ needs.check-version.outputs.release-version }}"
94+
name: Release ${{ needs.check_if_version_upgraded.outputs.version }}
95+
tag_name: ${{ needs.check_if_version_upgraded.outputs.version }}
96+
target_commitish: ${{ github.head_ref || github.ref }}
97+
generate_release_notes: true
98+
draft: false
99+
prerelease: ${{ needs.check_if_version_upgraded.outputs.is_pre_release == 'true' }}
100+
files: ./public-enemy.zip
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ COPY --chown=$NGINX_USER:$NGINX_USER dist /usr/share/nginx/html
1414

1515
# Copy nginx configuration
1616
RUN rm etc/nginx/conf.d/default.conf
17-
COPY --chown=$NGINX_USER:$NGINX_USER container/nginx.conf etc/nginx/conf.d/
17+
COPY --chown=$NGINX_USER:$NGINX_USER container/nginx.conf etc/nginx/conf.d/nginx.conf.template
1818

1919

2020
# Add entrypoint
2121
COPY --chown=$NGINX_USER:$NGINX_USER container/entrypoint.sh /entrypoint.sh
22-
RUN chmod 755 /entrypoint.sh
22+
COPY --chown=$NGINX_USER:$NGINX_USER container/nginx-envs.sh /nginx-envs.sh
23+
RUN chmod 755 /entrypoint.sh && chmod 755 /nginx-envs.sh
2324

24-
ENTRYPOINT [ "/entrypoint.sh" ]
25-
CMD ["nginx", "-g", "daemon off;"]
25+
ENTRYPOINT sh -c "/entrypoint.sh && /nginx-envs.sh && nginx -g 'daemon off;'"

container/nginx-envs.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
function originOf(){
3+
if [[ ! -z $1 ]]; then echo "$(echo "$1" | awk -F[/] '{print $1 "//" $3 }')"; fi
4+
}
5+
function originsOf(){
6+
origins=""; for url in $1; do origins="$origins $(originOf $url)";done; echo $origins
7+
}
8+
9+
# If you are in Micro-front-end environnement i.e, you need to load script from other origin to run your app, you must provide MFE_URL var
10+
export DEFAULT_SRC="'self'"
11+
# Please, avoid inline script, prefer use <script src="my-script.js"/> (be careful with vite-envs library <= 4.6.0)
12+
export SCRIPT_SRC="$DEFAULT_SRC 'unsafe-inline'"
13+
# Some css library inject style as inline, so we allow that.
14+
export STYLE_SRC="$DEFAULT_SRC 'unsafe-inline'"
15+
export FONT_SRC="$DEFAULT_SRC data:"
16+
# Keep 'data:' if you load img as blob inside src attribute of img, remove if not
17+
export IMG_SRC="$DEFAULT_SRC data:"
18+
# Keep 'blob:' if you load dynamically a worker as blob, remove if not
19+
export WORKER_SRC="$DEFAULT_SRC blob:"
20+
# Connect src CSP header is all origin of:
21+
# fetch, XHR, WebSocket, origin appears in ping attribute of <a/>, So all origin of http/ws requests you made (oidc server, api, etc..)
22+
export CONNECT_SRC="$DEFAULT_SRC $(originsOf "$VITE_API_URL $VITE_AUTH_URL")"
23+
# Frame src: the workflow of oidc auth in frontend needs having server auth origin as frame-src (iframe is temporarily created)
24+
export FRAME_SRC="$DEFAULT_SRC $(originOf $VITE_AUTH_URL)"
25+
26+
envsubst '${DEFAULT_SRC} ${SCRIPT_SRC} ${STYLE_SRC} ${FONT_SRC} ${IMG_SRC} ${WORKER_SRC} ${CONNECT_SRC} ${FRAME_SRC}' < /etc/nginx/conf.d/nginx.conf.template > /etc/nginx/conf.d/default.conf
27+

0 commit comments

Comments
 (0)