Repository navigation
Open
10 / 1310 of 13 issues completedOpen
10 / 1310 of 13 issues completed
Copy link
Labels
In-ProgressWork started and not complete; the comment gives the pull request or the jobenhancementNew feature or requeststatus:partly-fixedPart of the work is fixed; the rest is a story or an owner action
Description
Part of #18. Supersedes the approach of #279 / PR #285. Revised 2026-11-15 after the owner's review.
The owner's direction, 2026-11-15
- "what we need is non complicated format that will work in all git repo and not married to featires in github. what we need is a token or ssh keys."
- "features there are of API integration that we keep ... we need support for gitlab and bitbucket"
- "a logic where request is checkout of the main branch using the requestID as the branch and folder name ... this were we create the PR and merge it after request is fullfilled"
- "do we need PVC ... and cleanup that occurs when no job is running"
- "proper logging in case we have merge issues"
- "a direct requst will be wrong": no direct commit to main. Every change goes through a PR or MR.
Design: two layers, as Renovate does
Renovate's model is the reference: one shared Git layer, plus a thin platform adapter for each host for PRs only (Renovate platforms; Renovate's "gitFs" refactor, renovate#2774).
1. The Git layer: the Git protocol only, the same for every host.
- Credential: exactly one of these, in Secret
cmapi-git, in the Argo CD and Flux Secret shapes.- An HTTPS token. It goes through
GIT_ASKPASSor a credential file. It is never in a URL, argv, a log or.git/config. TLS verification stays on, withCMAPI_GIT_CA_BUNDLE. - An SSH key with a pinned
known_hosts. An unknown host key is a refusal, neverStrictHostKeyChecking=no.
- An HTTPS token. It goes through
- Working storage: each worker pod has one bare mirror (partial clone,
--filter=blob:none). It sits in anemptyDir(node disk, notmedium: Memory) with asizeLimitand anephemeral-storagerequest and limit on the worker, not a PVC. Measured: the repository is 21 KB, and CRC's node allows 115 GB of ephemeral storage. A generic ephemeral volume is the fallback if the clone ever grows to gigabytes. Each request gets agit worktreeat<workdir>/<cluster>/<requestId>, on branchcmapi/<cluster>/<requestId>, cut fromorigin/mainafter a fetch. This replaces today'scmapi/<cluster>/<namespace>/<requestId>(jobs/open_pr.py:48). The owner agreed on 2026-11-15. The cluster keeps the name unique across the three instances, andcmapi/keeps bot branches apart. A branch that already exists on a retry is reused only if its head carries this request's trailers and plan hash. That gives a clean checkout per request and no cross-contamination. - Why not a PVC: the remote is the source of truth, so a lost
emptyDircosts only one re-clone. Resilience: 2 or 3 replicas of the API and worker per instance, with shared state in PostgreSQL, proven #225 runs 2 or 3 worker replicas, and an RWO PVC cannot be shared between them; RWX adds a storage dependency for a cache. Record this decision with its measurements: clone time and size oncmapi-cluster-configs. - Write: render the files into the worktree, make one commit (the message carries the request ID, plan hash, approval and requester), and push the request branch. Pushes to
mainnever happen. - Cleanup: remove the worktree (
git worktree remove) when its request reaches a final state. A sweeper runs when no Git job is running: it callsgit worktree prune, removes the directory of any request that is not in flight, and runsgit gc --auto. Its result is logged and counted.
2. The platform layer: a thin host API, for the PR only.
- Operations: open a PR or MR from the request branch, read its state, merge it, and comment and close on failure.
- Adapters:
github: REST.gitlab: Merge Requests API, cloud and self-managed.bitbucket: Cloud REST 2.0, and Data Center REST.gitea: already exists.- Each is tested against its host's published API description.
- Host CI is optional and off by default. The gate is cmapi's own plan-time kubeconform and Kyverno checks, plus approval in cmapi. When it is enabled, only the commit-status API each host has in common is read. Never GitHub's Checks API: fine-grained tokens cannot call it (BUG-69).
Merge after the request is fulfilled
delivery.mode: apply(CRC): apply before merge, the Atlantis model (runatlantis.io).- Apply the rendered files from the request branch.
- Confirm by reading them back (
core/sync.py,confirmed_by_read). - Then merge the PR. So
mainrecords only what succeeded.
- On an apply failure: comment on the PR and close it, leave
mainuntouched, and mark the request failed with the reason.
delivery.mode: argocd: merge first, because Argo CD followsmain. Then wait for the sync. That is the behaviour today.- Before every merge:
- Fetch
main. - Run
git merge-tree --write-tree(Git 2.38 or later) to find conflicts with no checkout. - Check that the request's folder on
mainstill matches the plan's base.
- The one-open-request-per-namespace rule (
core/db/repo.py:6,change-pending) means two requests never change the same folder, so a conflict is a real fault.
- Fetch
Logging for merge problems
Every Git and platform operation logs one structured event with: request_id, cluster, namespace, branch, op (fetch, worktree, commit, push, pr_open, pr_state, merge_check, merge, cleanup), the main sha, the base sha, the head sha, attempt, outcome, the duration, and the Git exit code with redacted stderr.
- A conflict also logs the conflicted paths from
merge-tree. - A host API failure also logs its status and message.
- The same reason goes on the request's timeline, so the portal and
GET /requests/{id}show why. - Counted in
cmapi_git_operations_total{op,result}. - A test proves that no token appears in any of it.
How to prove it
- Against a real bare repository (
file://, and SSH with a throwaway sshd and a pinned key), with a stub platform:- create, change and delete;
- two concurrent requests on different namespaces;
- a conflicting
main, refused with its paths logged; - an unknown host key, refused;
- cleanup after a final state and by the sweeper;
- no secret in a log, argv or
.git/config.
- Each fails on main and passes after.
- Each platform adapter against its host's published API description.
- On CRC (
applymode):req-20261115-0002gets a fresh branch and PR, is applied, is confirmed, and its PR is merged. Then D19 runs.
Sub-issues
Collapse Sub-issuesSub-issues
Loading 13 sub-issues
Metadata
Metadata
Assignees
Labels
In-ProgressWork started and not complete; the comment gives the pull request or the jobenhancementNew feature or requeststatus:partly-fixedPart of the work is fixed; the rest is a story or an owner action
Activity
[-]Plain Git delivery: a token or an SSH key, no host API (PRs, checks, statuses)[/-][+]Git delivery: Git protocol for branches and commits, a thin PR adapter for GitHub, GitLab, Bitbucket and Gitea[/+]ephico2real2 commentedon Nov 15, 2026
Design review: Fable 5.2, a second model family. Scope was cut to D1, D2 and D4 because of its quota. Full text:
workbench/cmapi/review-286-fable/REPORT.md. The coordinator checked each code claim against the code and ran the mirror hypothesis. Each one below is accepted into the design.F1 (HIGH): an applied change whose merge then fails has no state.
failedis not inOPEN_STATES(core/db/models.py:17, checked). Failing the request would release the namespace lock while the cluster holds a change thatmainlacks. The next plan readsmain(jobs/open_pr.py:41-45) and would overwrite it.merge-treeand the plan-base check before the apply, and again before the merge.merge_failed, inOPEN_STATES. The PR and the branch are kept. Retry with backoff, then alert and wait for:retry.change-pending), the PR stays open, and:retryreachessynced.F2 (HIGH): the credentials are two Secrets.
cmapi-git-ssh, of typekubernetes.io/ssh-auth, keyssh-privatekey, for the Git transport, mounted in the worker only.cmapi-git, keytoken, for the host API only, never given to a git process.plain.py:135-136, checked) goes.F3 (HIGH): an API credential is needed for each host. SSH covers only fetch and push.
mainis protected on the host, so the rule that cmapi never pushes tomainis enforced there too.[memory]are verified at the primary source before they go into the docs.F4 (MEDIUM): the SSH details.
ssh-publickey, neverssh-privatekey.pub. cmapi logs the key's fingerprint at start and refuses a mismatch.known_hostsis in ConfigMapcmapi-git-known-hosts, holding every key type the host publishes (GitHub: ed25519, ecdsa and rsa). It is mounted as a directory, not bysubPath, so a rotation needs no restart. To rotate: add the new key, then remove the old one.BatchMode=yes). A key that is encrypted or does not parse stops cmapi at start.defaultMode: 0440(group-readable through the pod's fsGroup),readOnly, withitemsfor the key only.Mirror (confirmed by measurement):
git clone --mirrorfetches with+refs/*:refs/*and has norefs/remotes/origin/main. The cache is therefore a bare clone with the fetch refspec+refs/heads/main:refs/remotes/origin/mainand--filter=blob:none, so a fetch never writes into thecmapi/*branches that the worktrees hold.Not reviewed by Fable: D3 (SSH under an arbitrary UID), D5 (worktree concurrency), D6 (
merge-treeexit codes) and D7 (missing cases). They belong to PR-A's design record and its review.ephico2real2 commentedon Nov 15, 2026
The owner's decision, 2026-11-15: a machine user account
cmapi-git-boton each host. It is a GitHub machine user, a GitLab service account or a Bitbucket bot account.cmapi-git-bot.cmapi-git-botwith a configured no-reply email (GIT_AUTHOR_*andGIT_COMMITTER_*). The request ID, plan hash, approval and requester stay in the commit trailers.git@<host>, because these hosts pick the account by its key.The pod's local UID is a separate matter. OpenSSH looks up its own UID at start and stops with "No user exists for uid …" before any config is read. So the image's
/etc/passwdis made group-writable by gid 0, and CRI-O adds the entry, as Red Hat's arbitrary-UID guidance says. A test runs ssh under a UID with no passwd entry.ephico2real2 commentedon Nov 15, 2026
Names, the owner's decision, 2026-11-15:
cmapi-git-bot(Opaque, keytoken, for the host API)cmapi-git-bot-ssh(kubernetes.io/ssh-auth, keyssh-privatekeyand optionalssh-publickey, for the Git transport, mounted in the worker only)cmapi-git-bot-known-hostsThese replace
cmapi-gitandcmapi-git-ssheverywhere. On CRC the bot's new token goes intocmapi-git-bot; the oldcmapi-gitis removed by name after PR-A deploys.ephico2real2 commentedon Nov 15, 2026
Retraction (coordinator). My earlier comment says the image's
/etc/passwdis made group-writable by gid 0 so that CRI-O adds the entry. CRI-O's source refutes it:cri-o/cri-omainutils/utils.go,GeneratePasswdreturns early at line 222 whencheckFilePermissionsis true, and that isstat.Mode&0o022 != 0at line 314. A group- or other-writable/etc/passwdstops the entry. Red Hat (access.redhat.com/articles/4859371) also names a writable/etc/passwdas a privilege-escalation risk.The design:
/etc/passwdstays0644root.nss_wrapperis set only in the environment of git's ssh, only whengetpwuidfails, with a private passwd file./etc/passwdis not group- or other-writable. Found by OB1 run 10.ephico2real2 commentedon Nov 15, 2026
#286: the coordinator's arbitration of the two designs
The coordinator (Opus 5.5) wrote this on 2026-11-15 after reading both designs in full:
workbench/cmapi/design-286-fable/DESIGN.md, 517 lines.wt10-a/docs/reviews/2026-11-15-issue-286/README.mdatdb0738e, 382 lines.Each was written without the other. Where they differ, the choice and its reason are below. Where they agree, the shared text stands. The result goes into the design record of PR-A.
pr_openin apply modeappliedandmerge_failed, both in OPEN_STATES. Anapply_startedevent is committed in its own transactionmerge_failedonly. One job,deliver_pr, does the apply and the mergefailed, which releases the lock while the cluster holds the change: F1 again. Theapply_startedmarker and theappliedstate make "the cluster is ahead ofmain" a state, so the table itself refusesCANCEL,PR_FAILEDandBASE_CHANGEDthere (lifecycle.py:4-5: lock ownership follows the state)push_branch,open_pr,pr_checks,apply,merge) plusgit_cleanupandgit_reconciledeliver_prcombines the apply and the mergeCmapi-Request-Id: our own stale attempt, for example aftermainmoved. A head with no cmapi trailers is a person's work: refuse, log and alert. Never overwrite itawaiting_prunethenAPPLIEDawaiting_pruneprune:confirmfor an unbounded time. Holding a PR and a branch open across a human step adds staleness, for no gain: the namespace exists in both orders until the prune. This is today's tested flow. Recorded as a known exception to "merge after fulfilled"approved_at)flockgit_sweep, a recurring database jobemptyDir. The worker runs one job at a time (worker.py:94: the only thread is the lease heartbeat), so the loop's idle moment is "when no job is running"flockfor each operation classflockgit_reconcile, a periodic job, with the table in 5.3merge-treeexit codeshost_ciorgit.postStatusis setci/*andcmapi/checkalways:revertbefore a merge (sync_failedwith nomerge_sha), and frommerge_failedrestore_applyproposed; the owner decidesmerge_failedmergereads the state first and adopts a mergeredact()and its testBoth agree, and it stands: the two-layer split; the bare
git initwith the single refspec; the worktree path and branch name; the empty lease on the first push; the fence before each external effect; the credential objects and mounts; SSH options; nss_wrapper with/etc/passwdat 0644; and the rejected options.Still to verify before the docs: every cell Fable marked
[memory]in its 3.3 mapping, and OB1's per-host table, at each host's published API description (Fable's test 7.3-b).#286 PR-A: the config check imports no HTTP or logging library; accep…
docs: the Git delivery figures (#286): the architecture, the request …
2 remaining items
Job claim: a tie in run_after is claimed first-queued-first (BUG-74 #293
Merge pull request #288 from ephico2real2/git-layer
ephico2real2 commentedon Nov 15, 2026
OB1 run 11 on CRC (main 21a7f47): two defects found under this issue: #294 (BUG-75, request events stamped with the transaction start: 'applied' before 'apply_started', 'merged' before GitHub merged) and #295 (BUG-76, git_op pr_number stale after :retry; git_reconcile's per-PR events carry no request). The flow itself passed end to end (PRs #5 and #6 merged pinned to the applied head).
Records: Git delivery (#286) live over SSH on CRC, portal slice 2 liv…