Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions .github/workflows/deploy-laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# deploy-start, calls the Ploi deploy webhook of the site, waits until /version answers with this commit and closes
# the deploy in Core with deploy-finish. Production only deploys with an approval_id that Core confirms.
# Also deploys rasgo-core (adapter monorepo-ploi): one Ploi site per environment.
# Usage in each repository (.github/workflows/deploy.yml), with the secrets in its staging and production environments:
# Usage in each repository (.github/workflows/deploy.yml), with BWS_ACCESS_TOKEN (and the variable BWS_PROJECT_ID) in its
# staging and production environments:
#
# name: Deploy
# on:
Expand Down Expand Up @@ -69,13 +70,7 @@ on:
default: main
secrets:
BWS_ACCESS_TOKEN:
description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); without it, the secrets below come from GitHub as before
required: false
RASGO_CORE_DEPLOY_TOKEN:
description: Core token of the deploy actor (ops 1)
required: false
PLOI_DEPLOY_WEBHOOK:
description: Deploy webhook of the Ploi site of this environment
description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); every other secret comes from there; core.sh stops the deploy without it
required: false

permissions:
Expand Down Expand Up @@ -110,16 +105,14 @@ jobs:
uses: rasgo-studio/.github/actions/deploy-core@main
with:
command: contract
# From Bitwarden when the environment has BWS_ACCESS_TOKEN, from the GitHub secrets otherwise (D-109, RINF-55).
# From Bitwarden Secrets Manager only: the environment keeps BWS_ACCESS_TOKEN and nothing else (D-109).
# The values are masked and left for the next steps of this job, which read them from env.
- name: Secrets
uses: rasgo-studio/.github/actions/deploy-core@main
env:
BWS_ACCESS_TOKEN: ${{ secrets.BWS_ACCESS_TOKEN }}
BWS_PROJECT_ID: ${{ vars.BWS_PROJECT_ID }}
BWS_SERVER_URL: ${{ vars.BWS_SERVER_URL || 'https://vault.bitwarden.eu' }}
RASGO_CORE_DEPLOY_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
PLOI_DEPLOY_WEBHOOK: ${{ secrets.PLOI_DEPLOY_WEBHOOK }}
with:
command: secrets
args: RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
Expand Down
19 changes: 4 additions & 15 deletions .github/workflows/deploy-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# health path answers with this commit and closes the deploy in Core with deploy-finish. Production only deploys
# with an approval_id that Core confirms. The build gets a version.json (component, version, commit) unless it has one.
# The Pages project is a Direct Upload project: its Git integration, if any, does not deploy production by itself.
# Usage in each repository (.github/workflows/deploy.yml), with the secrets in its staging and production environments:
# Usage in each repository (.github/workflows/deploy.yml), with BWS_ACCESS_TOKEN (and the variable BWS_PROJECT_ID) in its
# staging and production environments:
#
# name: Deploy
# on:
Expand Down Expand Up @@ -84,16 +85,7 @@ on:
default: 4.151.0
secrets:
BWS_ACCESS_TOKEN:
description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); without it, the secrets below come from GitHub as before
required: false
RASGO_CORE_DEPLOY_TOKEN:
description: Core token of the deploy actor (ops 1)
required: false
CLOUDFLARE_API_TOKEN:
description: Cloudflare token with Pages edit on the account
required: false
CLOUDFLARE_ACCOUNT_ID:
description: Cloudflare account of the Pages project
description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); every other secret comes from there; core.sh stops the deploy without it
required: false

permissions:
Expand Down Expand Up @@ -135,17 +127,14 @@ jobs:
uses: rasgo-studio/.github/actions/deploy-core@main
with:
command: version-file
# From Bitwarden when the environment has BWS_ACCESS_TOKEN, from the GitHub secrets otherwise (D-109, RINF-55).
# From Bitwarden Secrets Manager only: the environment keeps BWS_ACCESS_TOKEN and nothing else (D-109).
# After the build, so the build never sees a secret. The values are masked and left for the next steps of this job, which read them from env.
- name: Secrets
uses: rasgo-studio/.github/actions/deploy-core@main
env:
BWS_ACCESS_TOKEN: ${{ secrets.BWS_ACCESS_TOKEN }}
BWS_PROJECT_ID: ${{ vars.BWS_PROJECT_ID }}
BWS_SERVER_URL: ${{ vars.BWS_SERVER_URL || 'https://vault.bitwarden.eu' }}
RASGO_CORE_DEPLOY_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
with:
command: secrets
args: RASGO_CORE_DEPLOY_TOKEN CLOUDFLARE_API_TOKEN CLOUDFLARE_ACCOUNT_ID
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/deploy-wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# deploy-start, calls the Ploi deploy webhook of the site (its deploy script pulls the repository and builds the
# theme), checks the health path and closes the deploy in Core with deploy-finish. Production only deploys with an
# approval_id that Core confirms. Since RINF-4 an Action no longer reaches the servers by SSH: Ploi does the deploy.
# Usage in each repository (.github/workflows/deploy.yml), with the secrets in its staging and production environments:
# Usage in each repository (.github/workflows/deploy.yml), with BWS_ACCESS_TOKEN (and the variable BWS_PROJECT_ID) in its
# staging and production environments:
#
# name: Deploy
# on:
Expand Down Expand Up @@ -57,13 +58,7 @@ on:
default: main
secrets:
BWS_ACCESS_TOKEN:
description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); without it, the secrets below come from GitHub as before
required: false
RASGO_CORE_DEPLOY_TOKEN:
description: Core token of the deploy actor (ops 1)
required: false
PLOI_DEPLOY_WEBHOOK:
description: Deploy webhook of the Ploi site of this environment
description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); every other secret comes from there; core.sh stops the deploy without it
required: false

permissions:
Expand Down Expand Up @@ -96,16 +91,14 @@ jobs:
uses: rasgo-studio/.github/actions/deploy-core@main
with:
command: contract
# From Bitwarden when the environment has BWS_ACCESS_TOKEN, from the GitHub secrets otherwise (D-109, RINF-55).
# From Bitwarden Secrets Manager only: the environment keeps BWS_ACCESS_TOKEN and nothing else (D-109).
# The values are masked and left for the next steps of this job, which read them from env.
- name: Secrets
uses: rasgo-studio/.github/actions/deploy-core@main
env:
BWS_ACCESS_TOKEN: ${{ secrets.BWS_ACCESS_TOKEN }}
BWS_PROJECT_ID: ${{ vars.BWS_PROJECT_ID }}
BWS_SERVER_URL: ${{ vars.BWS_SERVER_URL || 'https://vault.bitwarden.eu' }}
RASGO_CORE_DEPLOY_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
PLOI_DEPLOY_WEBHOOK: ${{ secrets.PLOI_DEPLOY_WEBHOOK }}
with:
command: secrets
args: RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ Every deploy follows the same order, and stops at the first step that fails:
1. **Contract.** Reads `rasgo.deploy.yml` and checks it against the run: the adapter is the one of the workflow, the
environment exists, production has `approval: core`, an environment with `approval: core` got an `approval_id`,
and the run comes from what the environment deploys (its branch, or a tag when `ref: tag`).
2. **Secrets.** The secrets the adapter reads come from Bitwarden Secrets Manager or, while they have not moved, from
the environment of the calling repository (see Secrets below). In `deploy-static.yml` this step runs after the build.
2. **Secrets.** The secrets the adapter reads come from Bitwarden Secrets Manager only (see Secrets below). In `deploy-static.yml` this step runs after the build.
3. **deploy-start.** Asks RASGO Core with the repository, app, environment, commit and `approval_id`. Core answers with
a `deployment_id`, or with 403 and the reason (`pending`, `expired`, `used`, `mismatch`…), and then nothing touches
the server (WFA-01.1, D-104). If Core does not answer, nothing deploys: there is no emergency exit.
Expand Down Expand Up @@ -149,9 +148,9 @@ Calling them:
environment go in capitals, with anything else as `_`: the production webhook of `acme-portal` is
`PLOI_DEPLOY_WEBHOOK__ACME_PORTAL__PRODUCTION`; a token shared by all, such as `RASGO_CORE_DEPLOY_TOKEN`, keeps
its plain name.
- **While they move (RINF-55).** A name not found in Bitwarden is taken from the GitHub secret of the same name, and
the run warns with its name. Without `BWS_ACCESS_TOKEN` everything comes from GitHub, as before. A name in
neither place stops the deploy.
- **Only Bitwarden.** No GitHub secret takes the place of a name: a name not found in Bitwarden, or whose first key
found is empty or still says `PLACEHOLDER`, stops the deploy and the run names its key. Without `BWS_ACCESS_TOKEN`
the deploy stops too.
- **How.** `bws` (bitwarden/sdk-sm 2.1.0, checked against the sha256 pinned in `core.sh`, the same as rasgo-motor) reads the project with the
machine account. Each value is masked and left for the next steps of the job, and the run names the keys it
used, never a value. If Bitwarden does not answer, nothing deploys. Optional repository variables:
Expand Down
66 changes: 30 additions & 36 deletions actions/deploy-core/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Steps shared by the reusable deploy workflows of rasgo-studio (RINF-54, WFA-01.1, D-104).
#
# core.sh require NAME... the named environment variables (the secrets the adapter reads) are set
# core.sh secrets NAME... the same, read from Bitwarden Secrets Manager when BWS_ACCESS_TOKEN is set (D-109)
# core.sh secrets NAME... the same, read from Bitwarden Secrets Manager with BWS_ACCESS_TOKEN (D-109)
# core.sh contract reads rasgo.deploy.yml, checks it against this run and saves the deploy state
# core.sh branch-head the branch the Ploi site pulls is still at the commit of this run
# core.sh version-file [DIR] writes DIR (or OUTPUT_DIR)/version.json with component, version and commit
Expand Down Expand Up @@ -133,47 +133,41 @@ export_secret() {
if [ -n "${GITHUB_ENV:-}" ]; then printf '%s<<%s\n%s\n%s\n' "$name" "$delimiter" "$value" "$delimiter" >> "$GITHUB_ENV"; fi
}

# Each NAME from Bitwarden Secrets Manager (the machine account of BWS_ACCESS_TOKEN, EU region), or else from the
# GitHub secret of the same name while it has not been moved (RINF-55): the run says which, never the value.
# Each NAME from Bitwarden Secrets Manager only (the machine account of BWS_ACCESS_TOKEN, EU region, D-109): the first
# key of bws_keys that exists wins. A key that is empty or still says PLACEHOLDER is not deployed, and no GitHub secret
# takes its place. The run names the keys, never the values.
cmd_secrets() {
local name list key value missing="" from_bws="" from_github=""
if [ -n "${BWS_ACCESS_TOKEN:-}" ]; then
ensure_bws
list="$(mktemp)"
chmod 600 "$list"
if [ -n "${BWS_PROJECT_ID:-}" ]; then
BWS_SERVER_URL="${BWS_SERVER_URL:-https://vault.bitwarden.eu}" bws secret list "$BWS_PROJECT_ID" --output json > "$list" 2> /dev/null ||
{ rm -f "$list"; fail "Bitwarden Secrets Manager no responde con el token de este entorno; no se despliega."; }
else
BWS_SERVER_URL="${BWS_SERVER_URL:-https://vault.bitwarden.eu}" bws secret list --output json > "$list" 2> /dev/null ||
{ rm -f "$list"; fail "Bitwarden Secrets Manager no responde con el token de este entorno; no se despliega."; }
fi
local name list key value found missing="" placeholder="" from_bws=""
[ -n "${BWS_ACCESS_TOKEN:-}" ] ||
fail "Falta BWS_ACCESS_TOKEN en el entorno ${DEPLOY_ENVIRONMENT:-} del repositorio: es el único secret que va en GitHub; el resto está en Bitwarden Secrets Manager (D-109)."
ensure_bws
list="$(mktemp)"
chmod 600 "$list"
if [ -n "${BWS_PROJECT_ID:-}" ]; then
BWS_SERVER_URL="${BWS_SERVER_URL:-https://vault.bitwarden.eu}" bws secret list "$BWS_PROJECT_ID" --output json > "$list" 2> /dev/null ||
{ rm -f "$list"; fail "Bitwarden Secrets Manager no responde con el token de este entorno; no se despliega."; }
else
BWS_SERVER_URL="${BWS_SERVER_URL:-https://vault.bitwarden.eu}" bws secret list --output json > "$list" 2> /dev/null ||
{ rm -f "$list"; fail "Bitwarden Secrets Manager no responde con el token de este entorno; no se despliega."; }
fi
for name in "$@"; do
value=""
if [ -n "${list:-}" ]; then
while IFS= read -r key; do
if jq -e --arg k "$key" 'any(.[]; .key == $k)' "$list" > /dev/null; then
value="$(jq -r --arg k "$key" '[.[] | select(.key == $k)][0].value' "$list")"
from_bws="$from_bws $key"
break
fi
done < <(bws_keys "$name")
fi
if [ -z "$value" ] && [ -n "${!name:-}" ]; then
value="${!name}"
from_github="$from_github $name"
fi
if [ -z "$value" ]; then missing="$missing $name"; continue; fi
value="" found=""
while IFS= read -r key; do
if jq -e --arg k "$key" 'any(.[]; .key == $k)' "$list" > /dev/null; then
value="$(jq -r --arg k "$key" '[.[] | select(.key == $k)][0].value' "$list")"
found="$key"
break
fi
done < <(bws_keys "$name")
if [ -z "$found" ]; then missing="$missing $name"; continue; fi
if [ -z "$value" ] || [[ "$value" =~ ^[[:space:]]*PLACEHOLDER([^A-Za-z0-9_]|$) ]]; then placeholder="$placeholder $found"; continue; fi
from_bws="$from_bws $found"
export_secret "$name" "$value"
done
if [ -n "${list:-}" ]; then rm -f "$list"; fi
[ -z "$missing" ] || fail "Faltan secretos en el entorno ${DEPLOY_ENVIRONMENT:-}:$missing. Van en Bitwarden Secrets Manager, proyecto actions, con el nombre que lista rasgo.deploy.yml (D-109)."
rm -f "$list"
if [ -n "$from_bws" ]; then note "Desde Bitwarden:$from_bws"; fi
if [ -n "$from_github" ]; then
note "Desde los secrets de GitHub:$from_github"
if [ -n "${BWS_ACCESS_TOKEN:-}" ]; then printf '::warning::Aún no están en Bitwarden:%s (RINF-55).\n' "$from_github"; fi
fi
[ -z "$placeholder" ] || fail "Siguen en PLACEHOLDER o vacíos en Bitwarden:$placeholder. Pon el valor en el proyecto de este entorno (D-109); no se despliega."
[ -z "$missing" ] || fail "Faltan secretos en el entorno ${DEPLOY_ENVIRONMENT:-}:$missing. Van en Bitwarden Secrets Manager, proyecto actions, con el nombre que lista rasgo.deploy.yml (D-109)."
}

cmd_contract() {
Expand Down
22 changes: 15 additions & 7 deletions tests/deploy-core.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,29 +243,37 @@ export DEPLOY_ENVIRONMENT=staging GITHUB_ENV="$WORK/github_env" BWS_ACCESS_TOKEN
export PLOI_DEPLOY_WEBHOOK=from-github
unset RASGO_CORE_DEPLOY_TOKEN
fake_bws '[{"key":"RASGO_CORE_DEPLOY_TOKEN__ACME_PORTAL","value":"component-token"}]'
expect_ok "secrets: one in Bitwarden, one still in GitHub" secrets RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
expect_fail "secrets: a GitHub secret never takes the place of Bitwarden" "Faltan secretos en el entorno staging: PLOI_DEPLOY_WEBHOOK" secrets RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
check "secrets: the key of the component" test "$(env_value RASGO_CORE_DEPLOY_TOKEN)" = component-token
check "secrets: the GitHub secret while it is not moved" test "$(env_value PLOI_DEPLOY_WEBHOOK)" = from-github
check "secrets: a warning names what is still in GitHub" has "Aún no están en Bitwarden: PLOI_DEPLOY_WEBHOOK"
check "secrets: the GitHub value is not left for the next steps" test -z "$(env_value PLOI_DEPLOY_WEBHOOK)"
check "secrets: the project id goes to bws" grep -Fq 'secret list p1 --output json' "$FAKE/bws.calls"

setup
core contract
export DEPLOY_ENVIRONMENT=production GITHUB_ENV="$WORK/github_env" BWS_ACCESS_TOKEN=bootstrap
unset BWS_PROJECT_ID PLOI_DEPLOY_WEBHOOK RASGO_CORE_DEPLOY_TOKEN
fake_bws '[{"key":"RASGO_CORE_DEPLOY_TOKEN","value":"PLACEHOLDER · Core › rasgo:token"},{"key":"PLOI_DEPLOY_WEBHOOK__ACME_PORTAL__PRODUCTION","value":""},{"key":"PLOI_DEPLOY_WEBHOOK","value":"generic"}]'
expect_fail "secrets: a PLACEHOLDER or empty key stops the deploy" "Siguen en PLACEHOLDER o vacíos en Bitwarden: RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK__ACME_PORTAL__PRODUCTION" secrets RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
check "secrets: a PLACEHOLDER is never left for the next steps" test -z "$(env_value RASGO_CORE_DEPLOY_TOKEN)"
check "secrets: an empty specific key does not fall back to the generic one" test -z "$(env_value PLOI_DEPLOY_WEBHOOK)"
check "secrets: the placeholder text is not printed" test "$(grep -c 'rasgo:token' "$OUT")" = 0

setup
core contract
export GITHUB_ENV="$WORK/github_env" BWS_ACCESS_TOKEN=bootstrap
unset BWS_PROJECT_ID PLOI_DEPLOY_WEBHOOK RASGO_CORE_DEPLOY_TOKEN
fake_bws '[]'
expect_fail "secrets: missing in Bitwarden and in GitHub" "Faltan secretos en el entorno staging: RASGO_CORE_DEPLOY_TOKEN" secrets RASGO_CORE_DEPLOY_TOKEN
expect_fail "secrets: missing in Bitwarden" "Faltan secretos en el entorno staging: RASGO_CORE_DEPLOY_TOKEN" secrets RASGO_CORE_DEPLOY_TOKEN
touch "$FAKE/bws.down"
expect_fail "secrets: Bitwarden down stops the deploy" "no responde" secrets RASGO_CORE_DEPLOY_TOKEN

setup
export GITHUB_ENV="$WORK/github_env" PLOI_DEPLOY_WEBHOOK=x RASGO_CORE_DEPLOY_TOKEN=y
unset BWS_ACCESS_TOKEN BWS_PROJECT_ID
fake_bws '[]'
expect_ok "secrets: without a token, the GitHub secrets as before" secrets RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
expect_fail "secrets: without BWS_ACCESS_TOKEN the deploy stops" "Falta BWS_ACCESS_TOKEN" secrets RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
check "secrets: without a token bws is not called" test ! -f "$FAKE/bws.calls"
check "secrets: without a token there is no warning" test "$(grep -c '::warning::' "$OUT")" = 0
check "secrets: the values reach the next steps" test "$(env_value RASGO_CORE_DEPLOY_TOKEN)" = y
check "secrets: without a token the GitHub values are not used" test -z "$(env_value RASGO_CORE_DEPLOY_TOKEN)"
unset PLOI_DEPLOY_WEBHOOK RASGO_CORE_DEPLOY_TOKEN GITHUB_ENV

# --- branch-head ------------------------------------------------------------------------------------------------
Expand Down
Loading