oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1# Forge git authentication
2
3Implemented on `forge-git-auth`, from brief commit `4940731` above deployed
4base `e99d178`. Copy accepted for now under the task brief.
5
6Credential-file handling now lives in `internal/runner/forge/credential_file.go`,
7so its tests fit the existing package budgets. Runtime wiring uses that reader
8for fetch and publication. The file accepts per-repository `api` and `git` values. Legacy
9string entries remain API-only. Fetch and publication require a Git PAT and
10use `Authorization: Basic base64("x:" + pat)` in `GIT_CONFIG_*`. API readback
11and the Amadan description command retain the bearer. Missing PATs produce a
12configuration error before fetch. Basic auth values are now redacted from
13journal text and downloaded logs.
14
15## Controller conversion
16
17No production credentials were opened or changed during implementation. The
18controller 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
20agent'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`.
22The setup and file formats are described in [the live guide](../../live-gate.md#amadan-credentials-for-the-runner).
23
24Save just the PAT value at
25`~/.local/share/equipo-runner/amadan-agent-home/git-pat`, mode `0600`. Keep the
26agent home private (`0700`). Run this snippet as the owner of the existing
27runner files on docs-t1. It preserves the API bearer, agent identity and other
28repository entries, replaces only the Equipo repository entry, and writes the
29new file atomically with mode `0600`. It prints no credentials and makes no
30network requests. It also accepts an already converted entry.
31
32```python
33import json
34import os
35from pathlib import Path
36import stat
37import tempfile
38
39root = Path.home() / ".local/share/equipo-runner"
40path = root / "amadan.json"
41pat_path = root / "amadan-agent-home/git-pat"
42repo = "amadan.net/oficina/equipo"
43temporary = None
44
45
46def 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
58def 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
63try:
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)
87except Exception:
88 raise SystemExit("Credential conversion failed; check the private files") from None
89finally:
90 if temporary is not None:
91 os.unlink(temporary)
92```
93
94The live read-only fetch is allowed only after the controller converts the
95file. It has not been run in this session. No deployment or live provider session
96was launched.
97
98## Regression evidence
99
100Tests were written before the implementation. This command failed on the old
101code: the new object entries were unreadable, legacy entries were accepted for
102git, Basic auth leaked into the journal, and publication still used Bearer:
103
104```sh
105CGO_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`
109also failed before implementation: fetch did not use Basic, and a missing PAT
110reached git without a configuration diagnostic.
111
112After implementation and the package move, the following targeted run passed:
113
114```sh
115CGO_ENABLED=0 go test ./internal/runner ./internal/runner/forge ./internal/runner/workspace -run 'TestForge|TestRunnerConfig$|TestRunnerJournalSecrets|TestPublish|TestAmadan|TestWorkspace' -count=1
116```
117
118The changed protocol redactor is exercised by the runner journal and log tests.
119Publication and fetch
120use instrumented git commands against disposable local repositories. The tests
121check the exact Basic value, absence from arguments and local git commands,
122provider environments, saved workspace files and publication state. API tests
123carry distinct bearer and PAT values and require the bearer for both HTTP and
124the description command. Tests also cover malformed entries, repository
125boundaries, missing PATs, control characters, public files and symlinks.
126
127Each guard below was deliberately broken, tested, and restored. Every command
128exited 1 with the corresponding test assertion failure, not a compilation
129failure. The final mutation runs followed the package move. The journal and log
130assertions 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
150The exact conversion snippet above was extracted and run with disposable fake
151homes. Legacy conversion and a second conversion passed without output;
152identity and unrelated repository entries stayed unchanged. Mode `0600` was
153preserved. Empty values, copied CLI output, public PAT files and symlinks were
154refused without altering the credential file or leaving temporary files.
155
156
157## Full gate
158
159The first `make -k ci` exited 2. Its reference scan found unclassified paths in
160the new guide and the supplied brief, and the new tests exceeded the runner
161package's existing line budget. Both checks now pass: the exact references
162have reasoned inventory entries, and the credential reader and its tests live
163in forge. The budget limits were not raised.
164
165The first full tests also found two external publication fixtures without
166PATs. Those now use distinct test passwords. Release-copy tests encountered a
167missing test file because the package move happened while that run read the
168checkout. The moved files are staged together for the final run. Build, vet,
169formatting, staticcheck, govulncheck, gitleaks, adapter checks, namespace checks,
170migrations and performance passed in the first run. The vulnerability scan
171found no reachable vulnerabilities; gitleaks found no secrets.
172
173After updating the external fixtures, this combined targeted command passed
174(team 0.969s, app integration 34.896s, runner 0.113s, forge 11.664s,
175workspace 1.332s):
176
177```sh
178CGO_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
181The second `make -k ci` exited 0. This was the only full rerun. All lanes passed:
182reference inventory, build, vet, formatting, staticcheck, govulncheck, gitleaks,
183size budgets, full tests, adapter checks, namespace checks, migrations and
184performance. The required sandbox tests include the protected Amadan path.
185Cold boot had a 110ms median against the 500ms budget. No budget exceptions
186were changed.
187
188The final checkout was held unchanged throughout that run. Scratch scripts,
189logs and conversion fixtures were removed after recording these results.
190Production credentials remain untouched. The controller still needs to run the
191conversion before any live read-only fetch. No deployment, default-branch push,
192push to another repository, live provider session or copy-review server was
193started.
194
195## Push status
196
197`git push -u origin HEAD:refs/heads/forge-git-auth` failed because this checkout
198has no HTTPS Git authentication (`could not read Username`). The implementation
199is committed locally. The controller must enable Git authentication here or
200push the branch. No production credential file was read to work around this.
201The committed history passed a second secret scan before the push attempt.
202