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
16 changes: 12 additions & 4 deletions .github/workflows/deploy-laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ on:
type: string
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
Expand Down Expand Up @@ -107,13 +110,18 @@ 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).
# 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: require
command: secrets
args: RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
# Ploi pulls the head of its branch, not a commit: only that head can be the approved commit.
- name: Branch the server pulls
Expand All @@ -123,12 +131,12 @@ jobs:
- name: Start (Core checks the approval)
uses: rasgo-studio/.github/actions/deploy-core@main
env:
CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }}
with:
command: start
- name: Deploy (Ploi)
env:
WEBHOOK: ${{ secrets.PLOI_DEPLOY_WEBHOOK }}
WEBHOOK: ${{ env.PLOI_DEPLOY_WEBHOOK }}
run: |
curl -fsS -X POST --max-time 30 -o /dev/null "$WEBHOOK"
echo "Despliegue pedido a Ploi."
Expand All @@ -140,6 +148,6 @@ jobs:
if: always()
uses: rasgo-studio/.github/actions/deploy-core@main
env:
CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }}
with:
command: finish
36 changes: 22 additions & 14 deletions .github/workflows/deploy-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ on:
type: string
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
Expand Down Expand Up @@ -120,16 +123,7 @@ jobs:
uses: rasgo-studio/.github/actions/deploy-core@main
with:
command: contract
- name: Secrets
uses: rasgo-studio/.github/actions/deploy-core@main
env:
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: require
args: RASGO_CORE_DEPLOY_TOKEN CLOUDFLARE_API_TOKEN CLOUDFLARE_ACCOUNT_ID
# The build comes before deploy-start, so a broken build does not spend the approval.
# The build comes before the secrets and deploy-start, so a broken build does not spend the approval.
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
Expand All @@ -141,16 +135,30 @@ 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).
# 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
- name: Start (Core checks the approval)
uses: rasgo-studio/.github/actions/deploy-core@main
env:
CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }}
with:
command: start
- name: Deploy (Cloudflare Pages)
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ env.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ env.CLOUDFLARE_ACCOUNT_ID }}
PAGES_PROJECT: ${{ inputs.pages-project }}
PAGES_BRANCH: ${{ inputs.environment == 'production' && inputs.production-branch || inputs.staging-branch }}
WRANGLER_VERSION: ${{ inputs.wrangler-version }}
Expand All @@ -165,6 +173,6 @@ jobs:
if: always()
uses: rasgo-studio/.github/actions/deploy-core@main
env:
CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }}
with:
command: finish
16 changes: 12 additions & 4 deletions .github/workflows/deploy-wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ on:
type: string
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
Expand Down Expand Up @@ -93,13 +96,18 @@ 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).
# 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: require
command: secrets
args: RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK
# Ploi pulls the head of its branch, not a commit: only that head can be the approved commit.
- name: Branch the server pulls
Expand All @@ -109,12 +117,12 @@ jobs:
- name: Start (Core checks the approval)
uses: rasgo-studio/.github/actions/deploy-core@main
env:
CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }}
with:
command: start
- name: Deploy (Ploi)
env:
WEBHOOK: ${{ secrets.PLOI_DEPLOY_WEBHOOK }}
WEBHOOK: ${{ env.PLOI_DEPLOY_WEBHOOK }}
run: |
curl -fsS -X POST --max-time 30 -o /dev/null "$WEBHOOK"
echo "Despliegue pedido a Ploi."
Expand All @@ -126,6 +134,6 @@ jobs:
if: always()
uses: rasgo-studio/.github/actions/deploy-core@main
env:
CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }}
CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }}
with:
command: finish
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ 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 are set in the environment of the calling repository.
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.
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 All @@ -139,10 +140,24 @@ Calling them:
deploy in `deployments.run_id`, as an artifact of that run (RCOR-45). Only digits are accepted, and the Contract
step stops on anything else. Without it, neither request carries the header and the deploy works as before. Core
ignores a number that is not one of its runs.
- **Secrets** live in the `staging` and `production` environments of the calling repository, with the names its
contract lists (DEV-07): `RASGO_CORE_DEPLOY_TOKEN` always (the Core token of the deploy actor, ops 1), then
`PLOI_DEPLOY_WEBHOOK`, or `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. The repository variable
`RASGO_CORE_URL` points to another Core, for tests.
- **Secrets** have the names the contract lists (DEV-07): `RASGO_CORE_DEPLOY_TOKEN` always (the Core token of the
deploy actor, ops 1), then `PLOI_DEPLOY_WEBHOOK`, or `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. They live in
Bitwarden Secrets Manager, project `actions`, EU region (D-109). The `staging` and `production` environments of the
calling repository keep only `BWS_ACCESS_TOKEN`, the token of the read-only machine account of that project.
- **Keys.** One project holds every repository, so the Secrets step looks for the most specific key first:
`NAME__<COMPONENT>__<ENVIRONMENT>`, then `NAME__<COMPONENT>`, then `NAME`. The component of the contract and the
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.
- **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:
`BWS_PROJECT_ID` (read only that project) and `BWS_SERVER_URL` (another region).
- **Calling.** With `secrets: inherit`, or passing `BWS_ACCESS_TOKEN` explicitly under `secrets:`.
- The repository variable `RASGO_CORE_URL` points to another Core, for tests.
- **Production** runs from `workflow_dispatch` once Sergio has approved it in the Hub, on the tag it deploys:
`gh workflow run deploy.yml --ref acme-v1.4.0 -f environment=production -f approval_id=<id>`. Each approval serves
one deploy of one commit and lasts 24 hours (spec 003 of rasgo-core). Staging with `approval: none` can deploy on
Expand Down
100 changes: 99 additions & 1 deletion actions/deploy-core/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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 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 @@ -79,6 +80,102 @@ cmd_require() {
note "Secretos presentes: $*"
}

# Key of NAME in Bitwarden for this deploy, most specific first: NAME__<COMPONENT>__<ENVIRONMENT>, NAME__<COMPONENT>,
# NAME. One project (actions) holds the secrets of every repository, so a value that differs per site carries its
# component and environment in the key, in capitals with anything else as _ (acme-portal, production:
# PLOI_DEPLOY_WEBHOOK__ACME_PORTAL__PRODUCTION).
bws_keys() {
local name="$1" component environment
component="$(state_get component 2> /dev/null | tr '[:lower:]' '[:upper:]' | tr -c 'A-Z0-9\n' '_' || true)"
environment="$(printf '%s' "${DEPLOY_ENVIRONMENT:-}" | tr '[:lower:]' '[:upper:]' | tr -c 'A-Z0-9' '_')"
if [ -n "$component" ] && [ -n "$environment" ]; then printf '%s\n' "${name}__${component}__${environment}"; fi
if [ -n "$component" ]; then printf '%s\n' "${name}__${component}"; fi
printf '%s\n' "$name"
}

# bws on the PATH, or the pinned release of bitwarden/sdk-sm checked against its sha256: the one pinned here for
# 2.1.0 (from bws-sha256-checksums-2.1.0.txt, the same as rasgo-motor), BWS_SHA256 when it is set, or for another
# BWS_VERSION the checksum file of that release.
BWS_PINNED_VERSION=2.1.0
BWS_PINNED_SHA256=ba8233c3a4aee5d43e3c73bbd04d99e9bc5aba13bbbfd06d89b073abe732b860
ensure_bws() {
command -v bws > /dev/null 2>&1 && return 0
local version="${BWS_VERSION:-$BWS_PINNED_VERSION}" dir base url sum expected
dir="${RUNNER_TEMP:-/tmp}/bws-$version"
base="https://github.com/bitwarden/sdk-sm/releases/download/bws-v$version"
mkdir -p "$dir"
url="$base/bws-x86_64-unknown-linux-gnu-$version.zip"
curl -fsSL --max-time 60 -o "$dir/bws.zip" "$url" || fail "No se pudo descargar bws $version de bitwarden/sdk-sm."
sum="$(sha256sum "$dir/bws.zip" | cut -d' ' -f1)"
if [ -n "${BWS_SHA256:-}" ]; then
expected="$BWS_SHA256"
elif [ "$version" = "$BWS_PINNED_VERSION" ]; then
expected="$BWS_PINNED_SHA256"
else
curl -fsSL --max-time 30 -o "$dir/sums.txt" "$base/bws-sha256-checksums-$version.txt" ||
fail "No se pudo descargar la suma sha256 de bws $version."
expected="$(grep "bws-x86_64-unknown-linux-gnu-$version.zip" "$dir/sums.txt" | cut -d' ' -f1)"
fi
[ -n "$expected" ] && [ "$sum" = "$expected" ] || fail "La suma sha256 de bws $version no coincide; no se usa."
unzip -oq "$dir/bws.zip" -d "$dir"
chmod +x "$dir/bws"
PATH="$dir:$PATH"
note "bws $version comprobado (sha256 $sum)."
}

# NAME=value for the next steps of the job: every line masked first, then written with a delimiter of its own.
export_secret() {
local name="$1" value="$2" line delimiter
while IFS= read -r line; do
if [ -n "$line" ]; then printf '::add-mask::%s\n' "$line"; fi
done <<< "$value"
delimiter="rasgo_$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')"
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.
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
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
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)."
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
}

cmd_contract() {
local file="${CONTRACT_FILE:-rasgo.deploy.yml}" env="${DEPLOY_ENVIRONMENT:-}" json
local adapter component ref url approval path expect timeout version app branch public tag run_id
Expand Down Expand Up @@ -340,14 +437,15 @@ main() {
shift || true
case "$command" in
require) cmd_require "$@" ;;
secrets) cmd_secrets "$@" ;;
contract) cmd_contract ;;
branch-head) cmd_branch_head ;;
version-file) cmd_version_file "$@" ;;
start) cmd_start ;;
health) cmd_health ;;
finish) cmd_finish ;;
*)
note "Uso: core.sh require|contract|branch-head|version-file|start|health|finish"
note "Uso: core.sh require|secrets|contract|branch-head|version-file|start|health|finish"
exit 2
;;
esac
Expand Down
Loading
Loading