mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-22 16:10:40 +07:00
infra: Basic-auth file leaves the repository (spec-v6 D16) — deploy/htpasswd gitignored, written on the VPS from the HTPASSWD_CONTENT secret; Gitea mirrors brought to full parity (permissions, STACK_DIR/CONTAINER_NAME guards)
This commit is contained in:
1 parent
c535e7a295
commit
a5ff55bacf
11 files changed
+199
-63
No files matched your search
@@ -1,8 +1,11 @@
|
||||
name: Redeploy Nginx
|
||||
|
||||
# Infra files only (spec-v4-deploy-infra D1): a change to the nginx template,
|
||||
# the compose definition, or the Basic-auth file redeploys the container —
|
||||
# content commits never do. workflow_dispatch is the token-rotation runbook.
|
||||
# Infra files only (spec-v4-deploy-infra D1): a change to the nginx template or
|
||||
# the compose definition redeploys the container — content commits never do.
|
||||
# workflow_dispatch is the token-rotation runbook. The Basic-auth file is no
|
||||
# longer repository content (spec-v6 D16): the HTPASSWD_CONTENT secret carries
|
||||
# it and the job writes it on the server, so credential rotation is a secret
|
||||
# edit + a dispatch, never a commit.
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
@@ -10,7 +13,6 @@ on:
|
||||
paths:
|
||||
- nginx.conf
|
||||
- compose.yaml
|
||||
- deploy/htpasswd
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
@@ -27,7 +29,7 @@ jobs:
|
||||
# The stack directory and the container name are the server's deployment layout,
|
||||
# not repository content: both come from repository variables (spec-v6 D15), and
|
||||
# STACK_DIR is the same value `deploy.yml` uses. A missing STACK_DIR would rsync
|
||||
# the three infra files into the remote user's home and then run docker in the
|
||||
# the two infra files into the remote user's home and then run docker in the
|
||||
# wrong place; a CONTAINER_NAME that disagrees with the service this repository
|
||||
# ships would recreate nothing and probe a container that does not exist. Both are
|
||||
# refused here — before any rsync, before anything reaches the server.
|
||||
@@ -62,12 +64,12 @@ jobs:
|
||||
fi
|
||||
echo "Stack: $STACK_DIR, container: $CONTAINER_NAME"
|
||||
|
||||
# Ship exactly the three triggered files. Never .env, never secrets/ (D6).
|
||||
# Ship exactly the two triggered files. Never .env, never secrets/ (D6).
|
||||
# The action builds the rsync source as "$GITHUB_WORKSPACE/$path" and passes
|
||||
# it as one argument (entrypoint.sh) — so NO --relative: -R mirrors the whole
|
||||
# absolute workspace path onto the server (run 2026-10-23 created
|
||||
# dong-site/workspace/dong.nguyen/cv/… on the VPS). Plain -avz lands each
|
||||
# file's basename in remote_path; the htpasswd step names deploy/ itself.
|
||||
# file's basename in remote_path.
|
||||
- name: Sync nginx.conf
|
||||
uses: burnett01/rsync-deployments@v9
|
||||
with:
|
||||
@@ -88,16 +90,33 @@ jobs:
|
||||
remote_port: ${{ secrets.DEPLOY_SSH_PORT }}
|
||||
remote_user: ${{ secrets.DEPLOY_USER }}
|
||||
remote_key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
|
||||
- name: Sync deploy/htpasswd
|
||||
uses: burnett01/rsync-deployments@v9
|
||||
|
||||
# The Basic-auth file is repository-secret content, not repository content
|
||||
# (spec-v6 D16): the HTPASSWD_CONTENT secret carries the one htpasswd line
|
||||
# (user + bcrypt hash). The secret is inlined into a single-quoted shell
|
||||
# literal — a bcrypt hash is riddled with `$` and appleboy's `envs:`
|
||||
# mechanism exports values unquoted, so the remote shell would expand `$2y…`
|
||||
# away; the htpasswd character set (user name + bcrypt base64) contains no
|
||||
# single quote, so this quoting is exact. Written BEFORE the test step:
|
||||
# nginx -t opens auth_basic_user_file, so its mount needs a real file.
|
||||
# chmod 600 keeps the credential readable only by the stack owner.
|
||||
- name: Write deploy/htpasswd from the secret
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
switches: -avz
|
||||
path: deploy/htpasswd
|
||||
remote_path: ${{ vars.STACK_DIR }}/deploy/
|
||||
remote_host: ${{ secrets.DEPLOY_HOST }}
|
||||
remote_port: ${{ secrets.DEPLOY_SSH_PORT }}
|
||||
remote_user: ${{ secrets.DEPLOY_USER }}
|
||||
remote_key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
|
||||
host: ${{ secrets.DEPLOY_HOST }}
|
||||
port: ${{ secrets.DEPLOY_SSH_PORT }}
|
||||
username: ${{ secrets.DEPLOY_USER }}
|
||||
key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
|
||||
script: |
|
||||
cd "${{ vars.STACK_DIR }}"
|
||||
HTPASSWD='${{ secrets.HTPASSWD_CONTENT }}'
|
||||
if [ -z "$HTPASSWD" ]; then
|
||||
echo "HTPASSWD_CONTENT is not set as a repository secret — add the output of: htpasswd -nbB <user> '<pass>'" >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p deploy
|
||||
printf '%s\n' "$HTPASSWD" > deploy/htpasswd
|
||||
chmod 600 deploy/htpasswd
|
||||
|
||||
# Test-before-touch (D3): the throwaway container runs the same entrypoint
|
||||
# render pipeline as production, with placeholder values — nginx -t checks
|
||||
|
||||
Reference in new issue
Block a user