From 41d35753451eaae639164044a413e4f89c2a8e3a Mon Sep 17 00:00:00 2001 From: fufsob Date: Tue, 6 Oct 2026 04:22:11 +0000 Subject: [PATCH] fix: update workflow fixes --- .github/workflows/dependency-updates.yml | 60 +++++++++++++++++++++-- nix/checks/amnezia-wg-inbound-runtime.nix | 4 +- nix/checks/proxy-inbounds-runtime.nix | 3 +- pkgs/tg-ws-proxy.nix | 4 ++ scripts/proxy_inbound.py | 13 +++++ scripts/test-build-inbound.py | 13 +++++ 6 files changed, 92 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dependency-updates.yml b/.github/workflows/dependency-updates.yml index 4033871..32c6ebd 100644 --- a/.github/workflows/dependency-updates.yml +++ b/.github/workflows/dependency-updates.yml @@ -22,9 +22,10 @@ concurrency: jobs: update-dependencies: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 outputs: has_changes: ${{ steps.changes.outputs.has_changes }} + checks_failed: ${{ steps.checks.outputs.failed }} steps: # No token left in .git/config for the steps that run fetched code (flake updates, # update-pins.sh, nix builds); create-pull-request authenticates on its own. @@ -86,15 +87,33 @@ jobs: mapfile -t attrs < <(scripts/update-pins.sh --attrs) nix build --no-link "${attrs[@]}" + # A failing check does not hold the update back: the pull request opens as a draft + # naming the failures, and the run still ends red (open-pull-request's last step). - name: Run flake checks + id: checks if: steps.changes.outputs.has_changes == 'true' - run: nix flake check --print-build-logs + run: | + set -uo pipefail + log="$RUNNER_TEMP/flake-check.log" + if nix flake check --keep-going --print-build-logs 2>&1 | tee "$log"; then + echo "failed=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + echo "failed=true" >> "$GITHUB_OUTPUT" + # The check attributes nix marks failed; else the derivations it could not build. + { + grep -oE '❌ checks\.[^[:space:]]+' "$log" | sed 's/^❌ //' || + grep -oE "Cannot build '/nix/store/[a-z0-9]{32}-[^']+\.drv'" "$log" | + sed -E "s|^.*/[a-z0-9]{32}-||; s|\.drv'$||" + } | sort -u > "$RUNNER_TEMP/failed-checks.txt" || true - name: Compose pull request body if: steps.changes.outputs.has_changes == 'true' env: SHOULD_UPDATE_NIXPKGS: ${{ steps.nixpkgs_gate.outputs.should_update_nixpkgs }} CHANGED_WATCH_ATTRS: ${{ steps.nixpkgs_gate.outputs.nixpkgs_changed_watch_attrs }} + CHECKS_FAILED: ${{ steps.checks.outputs.failed }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} run: | set -euo pipefail { @@ -114,6 +133,18 @@ jobs: echo "- changed watched attrs: \`$CHANGED_WATCH_ATTRS\`" echo "- zapret: refreshed every run" echo + echo "### Flake checks" + if [[ "$CHECKS_FAILED" == "true" ]]; then + echo "Failed, so this pull request is a draft ([run log]($RUN_URL)):" + if [[ -s "$RUNNER_TEMP/failed-checks.txt" ]]; then + while IFS= read -r check; do echo "- \`$check\`"; done < "$RUNNER_TEMP/failed-checks.txt" + else + echo "- no failing check named in the log; see the run" + fi + else + echo "- all passed" + fi + echo echo '```' git diff --stat echo '```' @@ -146,7 +177,7 @@ jobs: open-pull-request: needs: update-dependencies if: needs.update-dependencies.outputs.has_changes == 'true' - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: contents: write pull-requests: write @@ -175,8 +206,11 @@ jobs: fi - name: Create or update pull request + id: pr uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 with: + # always-true also turns an open pull request back into a draft. + draft: ${{ needs.update-dependencies.outputs.checks_failed == 'true' && 'always-true' || 'false' }} branch: ci/update-dependencies delete-branch: false add-paths: | @@ -189,3 +223,23 @@ jobs: labels: | dependencies nix + + # draft: false leaves an existing draft alone; once the checks pass, mark it ready. + - name: Mark the pull request ready for review + if: needs.update-dependencies.outputs.checks_failed != 'true' && steps.pr.outputs.pull-request-operation == 'updated' + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ steps.pr.outputs.pull-request-number }} + run: | + set -euo pipefail + if [[ "$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json isDraft --jq .isDraft)" == "true" ]]; then + gh pr ready "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" + fi + + - name: Fail the run on failed checks + if: needs.update-dependencies.outputs.checks_failed == 'true' + env: + PR_URL: ${{ steps.pr.outputs.pull-request-url }} + run: | + echo "::error::Flake checks failed; the update is a draft pull request: $PR_URL" + exit 1 diff --git a/nix/checks/amnezia-wg-inbound-runtime.nix b/nix/checks/amnezia-wg-inbound-runtime.nix index 81e22b9..a072067 100644 --- a/nix/checks/amnezia-wg-inbound-runtime.nix +++ b/nix/checks/amnezia-wg-inbound-runtime.nix @@ -176,7 +176,9 @@ pkgs.testers.runNixOSTest { server.succeed("ip link show awgi-home") server.succeed("ip link show awgi-roam") server.succeed("nft list table inet proxy_suite_awg_inbounds") - server.succeed("test $(jq '[.[] | select(.type == \"amneziawg\")] | length' /run/proxy-suite-inbounds/links.json) = 4") + # The unit is active once its start script runs; it writes the links just before + # XRay's exec, so they may not be there yet. + server.wait_until_succeeds("test \"$(jq '[.[] | select(.type == \"amneziawg\")] | length' /run/proxy-suite-inbounds/links.json)\" = 4", timeout=60) server.succeed("test -n \"$(proxy-ctl inbounds link home phone --config --qr)\"") import_profiles(alice, "phone", "tablet") import_profiles(bob, "laptop", "watch") diff --git a/nix/checks/proxy-inbounds-runtime.nix b/nix/checks/proxy-inbounds-runtime.nix index fe688c5..9e0d740 100644 --- a/nix/checks/proxy-inbounds-runtime.nix +++ b/nix/checks/proxy-inbounds-runtime.nix @@ -7,7 +7,8 @@ let # Fixed so the client can be configured against it at build time. Real # deployments keep these in a secret manager. uuid = "b831381d-6324-4d53-ad4f-8cda48b30811"; - ssPassword = "dGhpcy1pcy1hLTE2Ynl0ZS1rZXk="; + # Base64 of exactly 16 bytes, the 2022-blake3-aes-128-gcm key length (XRay 26.9.30 refuses others). + ssPassword = "dGhpcy1pcy0xNi1ieXRlcw=="; # Public addresses: blockPrivate would refuse the origin on a private one. serverAddress = "11.0.0.1"; # XRay refuses plain VLESS to a public IP, so the client dials a private one. diff --git a/pkgs/tg-ws-proxy.nix b/pkgs/tg-ws-proxy.nix index 76b98bf..e5e17c0 100644 --- a/pkgs/tg-ws-proxy.nix +++ b/pkgs/tg-ws-proxy.nix @@ -14,6 +14,10 @@ let websockets requests cryptography + # proxy/cf_h2.py since v1.11: httpx with its HTTP/2 extra (h2), CA bundle from certifi. + httpx + h2 + certifi ] ); in diff --git a/scripts/proxy_inbound.py b/scripts/proxy_inbound.py index 5638e7b..a1ab89e 100644 --- a/scripts/proxy_inbound.py +++ b/scripts/proxy_inbound.py @@ -15,6 +15,7 @@ import os import secrets import urllib.parse +import inbound_runtime from awg_inbound import client_entries from proxy_parsing import build_outbound @@ -222,10 +223,22 @@ def render_xray_inbound(listener: dict) -> dict: if len(users) == 1: settings["password"] = _user_secret(users[0], listener_type, tag) settings["email"] = users[0].get("name") or f"{tag}-0" + keys = [(settings["email"], settings["password"])] else: # Multi-user is 2022-blake3-aes only: the server key, then one key per user. settings["password"] = _server_secret(listener, tag) settings["clients"] = _clients(listener, tag) + keys = [("server", settings["password"])] + [(c["email"], c["password"]) for c in settings["clients"]] + # Keys from files are only seen here; XRay refuses one of another length with a bare + # "bad key" and does not start at all. + method = listener["method"] + if method in inbound_runtime.SS2022_KEY_BYTES: + for name, key in keys: + if not inbound_runtime._ss2022_key_ok(key, method): + raise ValueError( + f"listener '{tag}': the {name} key is not base64 of " + f"{inbound_runtime.SS2022_KEY_BYTES[method]} bytes, as {method} needs" + ) elif listener_type in ("socks", "http"): settings = {"auth": "password", "accounts": _accounts(listener, tag)} if listener_type == "socks": diff --git a/scripts/test-build-inbound.py b/scripts/test-build-inbound.py index 4c33132..a668918 100644 --- a/scripts/test-build-inbound.py +++ b/scripts/test-build-inbound.py @@ -242,6 +242,19 @@ class RenderInboundTests(unittest.TestCase): with self.assertRaisesRegex(ValueError, "no server password"): render_xray_inbound(multi_user_shadowsocks(serverPassword=None)) + def test_shadowsocks_2022_key_of_wrong_length_is_rejected(self): + # 20 bytes for a 16-byte method: XRay would fail its whole start on it. + with tempfile.TemporaryDirectory() as tmp: + key_path = os.path.join(tmp, "password") + with open(key_path, "w", encoding="utf-8") as handle: + handle.write("dGhpcy1pcy1hLTE2Ynl0ZS1rZXk=\n") + with self.assertRaisesRegex(ValueError, "the ss key is not base64 of 16 bytes"): + render_xray_inbound( + listener(type="shadowsocks", users=[{"name": "ss", "password": None, "passwordFile": key_path}]) + ) + with self.assertRaisesRegex(ValueError, "the server key is not base64 of 16 bytes"): + render_xray_inbound(multi_user_shadowsocks(serverPassword="c2hvcnQ=")) + def test_socks_accounts_and_udp(self): ib = render_xray_inbound( listener(type="socks", users=[{"name": "me", "password": "pw", "passwordFile": None}])