| 1 | # Forge git authentication |
| 2 | |
| 3 | Implemented on `forge-git-auth`, from brief commit `4940731` above deployed |
| 4 | base `e99d178`. Copy accepted for now under the task brief. |
| 5 | |
| 6 | Credential-file handling now lives in `internal/runner/forge/credential_file.go`, |
| 7 | so its tests fit the existing package budgets. Runtime wiring uses that reader |
| 8 | for fetch and publication. The file accepts per-repository `api` and `git` values. Legacy |
| 9 | string entries remain API-only. Fetch and publication require a Git PAT and |
| 10 | use `Authorization: Basic base64("x:" + pat)` in `GIT_CONFIG_*`. API readback |
| 11 | and the Amadan description command retain the bearer. Missing PATs produce a |
| 12 | configuration error before fetch. Basic auth values are now redacted from |
| 13 | journal text and downloaded logs. |
| 14 | |
| 15 | ## Controller conversion |
| 16 | |
| 17 | No production credentials were opened or changed during implementation. The |
| 18 | controller owns this conversion. First mint the agent's API bearer with |
| 19 | `amadan agent token create equipo` if it does not already exist. Configure the |
| 20 | agent's private Amadan home with that bearer, then run |
| 21 | `AMADAN_HOME="$HOME/.local/share/equipo-runner/amadan-agent-home" amadan tokens create -label equipo-runner-git`. |
| 22 | The setup and file formats are described in [the live guide](../../live-gate.md#amadan-credentials-for-the-runner). |
| 23 | |
| 24 | Save just the PAT value at |
| 25 | `~/.local/share/equipo-runner/amadan-agent-home/git-pat`, mode `0600`. Keep the |
| 26 | agent home private (`0700`). Run this snippet as the owner of the existing |
| 27 | runner files on docs-t1. It preserves the API bearer, agent identity and other |
| 28 | repository entries, replaces only the Equipo repository entry, and writes the |
| 29 | new file atomically with mode `0600`. It prints no credentials and makes no |
| 30 | network requests. It also accepts an already converted entry. |
| 31 | |
| 32 | ```python |
| 33 | import json |
| 34 | import os |
| 35 | from pathlib import Path |
| 36 | import stat |
| 37 | import tempfile |
| 38 | |
| 39 | root = Path.home() / ".local/share/equipo-runner" |
| 40 | path = root / "amadan.json" |
| 41 | pat_path = root / "amadan-agent-home/git-pat" |
| 42 | repo = "amadan.net/oficina/equipo" |
| 43 | temporary = None |
| 44 | |
| 45 | |
| 46 | def read_private(source): |
| 47 | fd = os.open(source, os.O_RDONLY | os.O_NOFOLLOW) |
| 48 | with os.fdopen(fd, "r", encoding="utf-8") as stream: |
| 49 | info = os.fstat(stream.fileno()) |
| 50 | if (not stat.S_ISREG(info.st_mode) |
| 51 | or stat.S_IMODE(info.st_mode) != 0o600 |
| 52 | or info.st_uid != os.getuid() |
| 53 | or info.st_size > 1024 * 1024): |
| 54 | raise ValueError("Expected a private credential file") |
| 55 | return stream.read() |
| 56 | |
| 57 | |
| 58 | def valid_secret(value): |
| 59 | return (isinstance(value, str) and bool(value) |
| 60 | and not any(c.isspace() or c == "\0" for c in value)) |
| 61 | |
| 62 | |
| 63 | try: |
| 64 | data = json.loads(read_private(path)) |
| 65 | pat = read_private(pat_path).strip() |
| 66 | entry = data["repositories"][repo] |
| 67 | api = entry if isinstance(entry, str) else entry["api"] |
| 68 | if not valid_secret(api) or not valid_secret(pat): |
| 69 | raise ValueError("Expected credential values") |
| 70 | if not isinstance(data["agent"], str) or not data["agent"]: |
| 71 | raise ValueError("Expected agent identity") |
| 72 | data["repositories"][repo] = {"api": api, "git": pat} |
| 73 | fd, temporary = tempfile.mkstemp(prefix=".amadan-", dir=root) |
| 74 | with os.fdopen(fd, "w", encoding="utf-8") as stream: |
| 75 | os.fchmod(stream.fileno(), 0o600) |
| 76 | json.dump(data, stream, indent=2) |
| 77 | stream.write("\n") |
| 78 | stream.flush() |
| 79 | os.fsync(stream.fileno()) |
| 80 | os.replace(temporary, path) |
| 81 | temporary = None |
| 82 | directory = os.open(root, os.O_RDONLY | os.O_DIRECTORY) |
| 83 | try: |
| 84 | os.fsync(directory) |
| 85 | finally: |
| 86 | os.close(directory) |
| 87 | except Exception: |
| 88 | raise SystemExit("Credential conversion failed; check the private files") from None |
| 89 | finally: |
| 90 | if temporary is not None: |
| 91 | os.unlink(temporary) |
| 92 | ``` |
| 93 | |
| 94 | The live read-only fetch is allowed only after the controller converts the |
| 95 | file. It has not been run in this session. No deployment or live provider session |
| 96 | was launched. |
| 97 | |
| 98 | ## Regression evidence |
| 99 | |
| 100 | Tests were written before the implementation. This command failed on the old |
| 101 | code: the new object entries were unreadable, legacy entries were accepted for |
| 102 | git, Basic auth leaked into the journal, and publication still used Bearer: |
| 103 | |
| 104 | ```sh |
| 105 | CGO_ENABLED=0 go test ./internal/runner ./internal/runner/forge -run 'TestForgeCredentialsSplitAndLegacy|TestForgeBasicCredentialsAbsentFromJournalAndLog|TestPublishCredentialIsolationHTTPS' -count=1 |
| 106 | ``` |
| 107 | |
| 108 | `CGO_ENABLED=0 go test ./internal/runner/workspace -run 'TestWorkspaceGit' -count=1` |
| 109 | also failed before implementation: fetch did not use Basic, and a missing PAT |
| 110 | reached git without a configuration diagnostic. |
| 111 | |
| 112 | After implementation and the package move, the following targeted run passed: |
| 113 | |
| 114 | ```sh |
| 115 | CGO_ENABLED=0 go test ./internal/runner ./internal/runner/forge ./internal/runner/workspace -run 'TestForge|TestRunnerConfig$|TestRunnerJournalSecrets|TestPublish|TestAmadan|TestWorkspace' -count=1 |
| 116 | ``` |
| 117 | |
| 118 | The changed protocol redactor is exercised by the runner journal and log tests. |
| 119 | Publication and fetch |
| 120 | use instrumented git commands against disposable local repositories. The tests |
| 121 | check the exact Basic value, absence from arguments and local git commands, |
| 122 | provider environments, saved workspace files and publication state. API tests |
| 123 | carry distinct bearer and PAT values and require the bearer for both HTTP and |
| 124 | the description command. Tests also cover malformed entries, repository |
| 125 | boundaries, missing PATs, control characters, public files and symlinks. |
| 126 | |
| 127 | Each guard below was deliberately broken, tested, and restored. Every command |
| 128 | exited 1 with the corresponding test assertion failure, not a compilation |
| 129 | failure. The final mutation runs followed the package move. The journal and log |
| 130 | assertions both failed when Basic redaction was removed. |
| 131 | |
| 132 | | Broken behavior | Command that caught it | |
| 133 | | --- | --- | |
| 134 | | fetch auth scheme | `CGO_ENABLED=0 go test ./internal/runner/workspace -run ^TestWorkspaceGitBasicIsolation -count=1` | |
| 135 | | publish auth scheme | `CGO_ENABLED=0 go test ./internal/runner/forge -run ^TestPublishCredentialIsolationHTTPS -count=1` | |
| 136 | | API retains bearer | `CGO_ENABLED=0 go test ./internal/runner/forge -run ^TestAmadanDescriptionReadback/valid$ -count=1` | |
| 137 | | legacy refuses git | `CGO_ENABLED=0 go test ./internal/runner/forge -run ^TestForgeCredentialsSplitAndLegacy/legacy -count=1` | |
| 138 | | fetch requires PAT | `CGO_ENABLED=0 go test ./internal/runner/workspace -run ^TestWorkspaceGitRequiresPassword -count=1` | |
| 139 | | publish requires PAT | `CGO_ENABLED=0 go test ./internal/runner/forge -run ^TestPublishEvidenceAndCredentialGuards/git_missing -count=1` | |
| 140 | | publish validates PAT | `CGO_ENABLED=0 go test ./internal/runner/forge -run ^TestPublishEvidenceAndCredentialGuards/git_header -count=1` | |
| 141 | | journal and log redaction | `CGO_ENABLED=0 go test ./internal/runner -run ^TestRunnerJournalSecretsAndLog -count=1` | |
| 142 | | protected credential path | `CGO_ENABLED=0 go test ./internal/runner -run ^TestRunnerConfig$ -count=1` | |
| 143 | | provider environment | `CGO_ENABLED=0 go test ./internal/runner/workspace -run ^TestWorkspaceGitBasicIsolation -count=1` | |
| 144 | | publish persisted state | `CGO_ENABLED=0 go test ./internal/runner/forge -run ^TestPublishCredentialIsolation$ -count=1` | |
| 145 | | fetch credentials in argv | `CGO_ENABLED=0 go test ./internal/runner/workspace -run ^TestWorkspaceGitBasicIsolation -count=1` | |
| 146 | | fetch validates PAT | `CGO_ENABLED=0 go test ./internal/runner/workspace -run ^TestWorkspaceGitPasswordValidation -count=1` | |
| 147 | | local fetch forbids PAT | `CGO_ENABLED=0 go test ./internal/runner/workspace -run ^TestWorkspaceGitPasswordValidation/local -count=1` | |
| 148 | | configuration validates PAT | `CGO_ENABLED=0 go test ./internal/runner/forge -run ^TestForgeCredentialInvalidEntries -count=1` | |
| 149 | |
| 150 | The exact conversion snippet above was extracted and run with disposable fake |
| 151 | homes. Legacy conversion and a second conversion passed without output; |
| 152 | identity and unrelated repository entries stayed unchanged. Mode `0600` was |
| 153 | preserved. Empty values, copied CLI output, public PAT files and symlinks were |
| 154 | refused without altering the credential file or leaving temporary files. |
| 155 | |
| 156 | |
| 157 | ## Full gate |
| 158 | |
| 159 | The first `make -k ci` exited 2. Its reference scan found unclassified paths in |
| 160 | the new guide and the supplied brief, and the new tests exceeded the runner |
| 161 | package's existing line budget. Both checks now pass: the exact references |
| 162 | have reasoned inventory entries, and the credential reader and its tests live |
| 163 | in forge. The budget limits were not raised. |
| 164 | |
| 165 | The first full tests also found two external publication fixtures without |
| 166 | PATs. Those now use distinct test passwords. Release-copy tests encountered a |
| 167 | missing test file because the package move happened while that run read the |
| 168 | checkout. The moved files are staged together for the final run. Build, vet, |
| 169 | formatting, staticcheck, govulncheck, gitleaks, adapter checks, namespace checks, |
| 170 | migrations and performance passed in the first run. The vulnerability scan |
| 171 | found no reachable vulnerabilities; gitleaks found no secrets. |
| 172 | |
| 173 | After updating the external fixtures, this combined targeted command passed |
| 174 | (team 0.969s, app integration 34.896s, runner 0.113s, forge 11.664s, |
| 175 | workspace 1.332s): |
| 176 | |
| 177 | ```sh |
| 178 | CGO_ENABLED=0 go test ./internal/equipo/team ./internal/equipotest ./internal/runner ./internal/runner/forge ./internal/runner/workspace -run 'TestPublishCoreAuthorizationContract$|TestRunnerDirectEndToEnd$|TestForge|TestRunnerConfig$|TestRunnerJournalSecrets|TestPublish|TestAmadan|TestWorkspace' -count=1 |
| 179 | ``` |
| 180 | |
| 181 | The second `make -k ci` exited 0. This was the only full rerun. All lanes passed: |
| 182 | reference inventory, build, vet, formatting, staticcheck, govulncheck, gitleaks, |
| 183 | size budgets, full tests, adapter checks, namespace checks, migrations and |
| 184 | performance. The required sandbox tests include the protected Amadan path. |
| 185 | Cold boot had a 110ms median against the 500ms budget. No budget exceptions |
| 186 | were changed. |
| 187 | |
| 188 | The final checkout was held unchanged throughout that run. Scratch scripts, |
| 189 | logs and conversion fixtures were removed after recording these results. |
| 190 | Production credentials remain untouched. The controller still needs to run the |
| 191 | conversion before any live read-only fetch. No deployment, default-branch push, |
| 192 | push to another repository, live provider session or copy-review server was |
| 193 | started. |
| 194 | |
| 195 | ## Push status |
| 196 | |
| 197 | `git push -u origin HEAD:refs/heads/forge-git-auth` failed because this checkout |
| 198 | has no HTTPS Git authentication (`could not read Username`). The implementation |
| 199 | is committed locally. The controller must enable Git authentication here or |
| 200 | push the branch. No production credential file was read to work around this. |
| 201 | The committed history passed a second secret scan before the push attempt. |
| 202 | |