mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 22:06:31 +00:00
make swarm-zombie runs act with ACT_BIND=true (Makefile:898), and workflow.sh also binds when roles/web-app-cst-* exist. A bound job works in the host checkout, so the deploy step's make setup -> make dotenv rewrote the host .env: INFINITO_DEPLOY_MODE=swarm, the swarm distro, INFINITO_SWARM_STEP_TIMEOUT_MINUTES=690 and NIX_CONFIG. call-test-deploy.yml puts the act GITHUB_TOKEN into NIX_CONFIG, and nix_config.py copied its access-tokens line into .env, so the token sat in plaintext in the host worktree and the next local gate failed test_distros and test_build. Two layers: - workflow.sh passes INFINITO_DOTENV_HOST_OWNED=true whenever it binds, so the job keeps the host .env (the guard compose.yml already uses). - nix_config.py writes the access-tokens line only on a real GitHub runner (detect_gha_act: GITHUB_ACTIONS without ACT), never under act or on a developer machine. Not covered: .env files that already hold a token need make dotenv-force and the token revoked; self-hosted GitHub runners still write the short-lived job token; INFINITO_API_*_KEY values still pass through. Tests: test_nix_config.py (3, new) and test_workflow.py (3 new of 11); negative control: with the fix lines reverted, 2 of 3 fail in each file. Both files pass (3 and 11). ruff and shellcheck clean. MEDUSA 100 %: three files under env paths scanned under renamed paths, because the scanner's excludes skip any path containing env. Reported by Stage 2.0. 🎯 Fix: 90 % 💥 Break: 5 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 86 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from utils.env.context import BuildContext, EnvBuilder
|
|
from utils.env.handlers import nix_config as handler
|
|
|
|
_TOKENS_LINE = "access-tokens = github.com=placeholder-not-a-token"
|
|
_CALLER = {handler.KEY: f"{_TOKENS_LINE}\naccept-flake-config = true\n"}
|
|
|
|
|
|
def _ctx(*, on_gha: bool = False, on_act: bool = False) -> BuildContext:
|
|
return BuildContext(
|
|
static={},
|
|
static_comments={},
|
|
repo_root=Path("/repo"),
|
|
on_gha=on_gha,
|
|
on_act=on_act,
|
|
)
|
|
|
|
|
|
def _apply(ctx: BuildContext) -> dict[str, str]:
|
|
eb = EnvBuilder()
|
|
handler.apply(eb, ctx)
|
|
return eb.values
|
|
|
|
|
|
class TestNixConfigTokenStaysOffTheHost(unittest.TestCase):
|
|
@patch.dict(os.environ, _CALLER, clear=False)
|
|
def test_a_github_runner_keeps_only_the_access_tokens_line(self) -> None:
|
|
self.assertEqual(_apply(_ctx(on_gha=True)), {handler.KEY: _TOKENS_LINE})
|
|
|
|
@patch.dict(os.environ, _CALLER, clear=False)
|
|
def test_act_never_writes_the_token(self) -> None:
|
|
self.assertNotIn(handler.KEY, _apply(_ctx(on_act=True)))
|
|
|
|
@patch.dict(os.environ, _CALLER, clear=False)
|
|
def test_a_developer_machine_never_writes_the_token(self) -> None:
|
|
self.assertNotIn(handler.KEY, _apply(_ctx()))
|
|
|
|
|
|
if __name__ == "__main__": # pragma: no cover
|
|
unittest.main()
|