From b4e3340034b02f697ca2f799ab6c4805750d87a7 Mon Sep 17 00:00:00 2001 From: Amperstrand <141745238+Amperstrand@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:56:51 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20the=20PR-#35/#51=20review-debt=20quartet?= =?UTF-8?q?=20=E2=80=94=20derived=20pricing=20pairs,=20lazy=20cache=20dir,?= =?UTF-8?q?=20unique=20download=20temp,=20#51=20changelog=20backfill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #57 (r3696609579): dev-zone-probe derives the pricing tier from the selected package (explicit PACKAGE_PRICING map; unknown packages refused; an explicit --pricing-id must agree with the derived value) — package 81 can no longer be submitted with package 80's pricing 241. #54 (r4124126778): _find_cloudflared iterates system installs FIRST; the cache dir is consulted (and created) only when no installed binary exists — a missing/read-only/foreign-owned cache dir no longer shadows /usr/local/bin/cloudflared. #55 (r4124126788): the download partial gets a unique name per invocation (pid + uuid) — two fresh-cache races can no longer fight over one partial path (second chmod failure / first caller executing a partially-replaced binary). #53 (r4124126757): CHANGELOG [Unreleased] backfills the #51 security arc's user-visible changes (restored generated-client enum classes, safe cloudflared cache, regression suites) with the #51/#33/#34 pointers. Verified: tests/test_tunnel_security.py 5/5 green; full suite matches the pristine base exactly (6 pre-existing env-dependent failures on both sides — register tests need coincurve/nostr extras, catalog/unit are environment-sensitive). --- CHANGELOG.md | 1 + scripts/dev-zone-probe.py | 41 +++++++++++++++++++++++++++++++++++---- shc_toolkit/tunnel.py | 23 ++++++++++++++-------- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bad9f9..259e7b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - **`scripts/deploy-tollgate.sh`: cdk-cli 0.17.1 → 0.18.3, sha256-verified before install.** The download was the last unguarded cdk-cli fetch in the org (same class as tollgate-auth SECURITY_AUDIT_WINDOW3 M1: `curl -sL` straight to `/usr/local/bin` — a replaced GitHub release asset or build-path MITM would land in the wallet-running path undetected). The pinned SHA (`bb7a8b0f…`, x86_64) is cross-checked against the release's official `SHA256SUMS`; org-wide 0.18.3 alignment (tollgate-auth #30, cashu-audit #61). `tollgate/README.md` manual-install section mirrors the verified flow. ### Fixed +- **Backfill: the #51 security arc's user-visible changes (#53 review debt).** PR #51 restored the generated client's public enum classes (dropped in a regeneration — downstream `from shc_toolkit.generated…` imports had broken), made the cloudflared cache safe (user-owned dir, atomic unique-named download, never a shared-writable path), and landed the regression suites — but the changelog never recorded any of it. Enum contract pinned by `tests/test_generated_enum_contract.py`; cache behavior by `tests/test_tunnel_security.py` (both run in CI per the #56 entry below). Context: #51/#33/#34. - **CI: regression test files outside every mandatory suite (#56).** `tests/test_generated_enum_contract.py` and `tests/test_tunnel_security.py` (both from the #51 security arc) were collected by neither `shc-tests.yml` (unit job ran only `tests/test_unit.py`) nor `coverage.yml` (the four legacy files) — enum/tunnel-cache regressions could pass CI unexecuted. Both files are now in both workflow commands, and the jobs install the `generated` extra (`attrs`, `python-dateutil`) the enum-contract file imports. AGENTS.md's mandated local suite updated to match. - **typecheck.yml no longer ran on PRs at all (#58).** The trigger was `workflow_dispatch` + tag push only, so ruff/mypy config changes merged with no lint running. `pull_request` (targeting `main`) restored; stale "245 tests" verification figures in `pyproject.toml` and the 2026-07-24 CHANGELOG entry corrected to the actual collected count (491, `pytest tests/ --collect-only -q`). diff --git a/scripts/dev-zone-probe.py b/scripts/dev-zone-probe.py index d949741..acd1367 100755 --- a/scripts/dev-zone-probe.py +++ b/scripts/dev-zone-probe.py @@ -36,11 +36,24 @@ from shc_toolkit import create_client PKG_ID = 80 -PRICING_ID = 241 ORDER_FORM_ID = 11 PACKAGE_GROUP_ID = 14 MODULE_GROUP_ID = 7 +# Valid (package, pricing) pairs on the order form (PR #35 review debt: +# pricing 241 belongs to package 80's tier — submitting package 81 with +# pricing 241 is an invalid pair the server rejects before probing). +# The pricing tier is DERIVED from the selected package; unknown packages +# are refused rather than paired with a wrong-tier pricing id. +PACKAGE_PRICING = { + 80: 241, # daily + 81: 245, + 82: 249, + 83: 253, + 84: 257, +} +PRICING_ID = PACKAGE_PRICING[PKG_ID] + def _wait_tcp22(ip: str, timeout: int) -> tuple[bool, float]: """Poll TCP/22 until open or deadline. Returns (reachable, seconds_waited).""" @@ -87,8 +100,8 @@ def main() -> int: parser.add_argument( "--pricing-id", type=int, - default=PRICING_ID, - help="pricing tier (default 241 = daily)", + default=None, + help="pricing tier; derived from the package when omitted (241 = package 80 daily). Must agree with the derived value if given", ) parser.add_argument( "--net-timeout", @@ -108,6 +121,26 @@ def main() -> int: sid: int | None = None t0 = time.time() + # Pricing tier is derived from the package; an explicit --pricing-id + # must agree with the derived value (anything else is an invalid pair + # the server rejects before probing — PR #35 review debt). + derived_pricing = PACKAGE_PRICING.get(args.package_id) + if derived_pricing is None: + print( + f"FATAL: package {args.package_id} has no known pricing tier " + f"(known: {', '.join(f'{k}->{v}' for k, v in sorted(PACKAGE_PRICING.items()))})", + file=sys.stderr, + ) + sys.exit(2) + if args.pricing_id is not None and args.pricing_id != derived_pricing: + print( + f"FATAL: --pricing-id {args.pricing_id} does not match package " + f"{args.package_id}'s tier ({derived_pricing})", + file=sys.stderr, + ) + sys.exit(2) + pricing_id = derived_pricing + def _cancel(*_args): if sid: try: @@ -127,7 +160,7 @@ def _cancel(*_args): try: result = c.submit_order( package_id=args.package_id, - pricing_id=args.pricing_id, + pricing_id=pricing_id, order_form_id=ORDER_FORM_ID, package_group_id=PACKAGE_GROUP_ID, module_group_id=MODULE_GROUP_ID, diff --git a/shc_toolkit/tunnel.py b/shc_toolkit/tunnel.py index 002792d..a3ea73d 100644 --- a/shc_toolkit/tunnel.py +++ b/shc_toolkit/tunnel.py @@ -39,6 +39,7 @@ import logging import os import subprocess +import uuid import time from typing import TYPE_CHECKING @@ -420,18 +421,24 @@ def _check_ssh( def _find_cloudflared() -> str: """Find or download the cloudflared binary. - Search order: system installs, then the validated user cache. The - download lands in the user-owned cache dir via an atomic - temp-file-and-rename — never in a shared directory where another - local user could plant or swap the executable that connect_local() - runs (PR #33 review). + Search order: system installs first; only when none is found is the + user cache dir consulted (and created) — a missing/read-only/foreign- + owned cache dir must never shadow an already-installed binary (PR #51 + review). The download lands in the user-owned cache dir via an + atomic temp-file-and-rename with a UNIQUE temp name per download — + never in a shared directory where another local user could plant or + swap the executable that connect_local() runs, and never on a shared + partial path two racing invocations would fight over (PR #33/#51 + review). """ - cached = os.path.join(_cloudflared_cache_dir(), "cloudflared") - for path in [*_CF_BINARY_PATHS, cached]: + for path in _CF_BINARY_PATHS: if os.path.isfile(path) and os.access(path, os.X_OK): return path + cached = os.path.join(_cloudflared_cache_dir(), "cloudflared") + if os.path.isfile(cached) and os.access(cached, os.X_OK): + return cached log.info("Downloading cloudflared binary to %s ...", cached) - partial = cached + ".download" + partial = cached + f".download.{os.getpid()}.{uuid.uuid4().hex[:8]}" subprocess.run( ["wget", "-q", "-O", partial, _CLOUDFLARED_URL], check=True,