# CLAUDE.md Guidance for Claude Code (claude.ai/code) in this repository. ## What this is `mortis.kamino`: an Ansible Collection (GPL-3.0-or-later, REUSE-compliant) of reusable, hardened roles. Roles arrive here wave by wave; `docker` is in 1.0.0, `fail2ban` in 1.1.0, `network_interfaces` and `systemd_hardening` in 1.2.0, `system_baseline` in 1.3.0, `ufw` in 1.4.0; 1.5.0 adds no role (new `system_baseline` options); `sshd` in 1.6.0; `user_management` in 1.7.0; `traefik`, with the internal `_binary_update`, in 1.8.0; `gitea` in the next release. **Roadmap.** The roles still to come, and the ones that will never be extracted, are listed in the README section "Roadmap". Context: the maintainer's private environment repository (a production home lab driven by Ansible) holds every role until it moves here; a role moves only after its tests exist and the environment has been cut over to `mortis.kamino.` at a pinned tag. The list is informational, not enforced by any hook. Keep it true by hand: the pull request that adds a role under `roles/` also removes it from the Roadmap list, and when the list is empty the section goes too. When something looks wrong or missing there, say so to the operator; the plan itself is theirs (epic #486 in the environment repository, which you cannot read from here). Fork pull requests from untrusted users are not accepted for now: a fork controls its own workflow file, so the `if:` guards are a convenience, not a boundary (see the header of `molecule.yml`). Do not change visibility, repository settings, branch or tag protection, or create tags: those are the operator's. ## Working here - Set up once per clone: `scripts/dev-setup.sh` (a virtualenv with the pinned tools and git hooks that find them). The `language: system` hooks run `reuse`, `ansible-lint` and `antsibull-changelog` by name, so a hook run without that virtualenv on `PATH` fails. - Agent skills come from holocron through apm: `apm install` (the `apm` CLI is not one of the pinned tools, and `dev-setup.sh` does not run it) deploys them to `.claude/skills` and `.claude/agents`, both gitignored like `apm_modules/`. `apm.yml` and `apm.lock.yaml` are the only tracked files. The entries are unpinned on purpose (see the comment in `apm.yml`); `apm install --update` moves them. They are tooling, so `galaxy.yml` `build_ignore` keeps them out of the Collection. - **Commit with git in a clone, never through the Gitea API.** The hooks (REUSE, yamllint, actionlint, ansible-lint, gitleaks, changelog lint, Conventional Commits) only run in `git commit`; an API commit skips them and CI finds the problem after the push. The first hook run builds the Go hook environments and takes minutes: run commits in the background. `git push` also runs `ansible-test sanity` on HEAD (`scripts/ansible-test-sanity.sh`, the Build job's check, which ruff and the other hooks do not cover); its first run builds virtualenvs and takes minutes. - **This repository stands alone.** No tracked file, issue or pull request text or comment, release note or job output refers to another repository of the maintainer's, its documents, hosts, network or namespaces, or states host sizing. Every comment states its own reason. When bringing content in from another repository, before committing, search the incoming diff for mentions of the source repository, its documents, hostnames, addresses, account namespaces and sibling paths; rewrite comments so they stand alone; say in the pull request what was searched for. No control holds this rule, and it has no expiry. - Feature branch and pull request; `main` and `v*` tags are protected. Never push to `main`. Releases are the operator's: annotated `vX.Y.Z` tags equal to `galaxy.yml`'s version. - Conventional Commits. A PR says what was verified and what was not. - There is no local molecule and no container runtime on the control host: do not install one. Molecule runs in CI, on the repository's own runner (label `kamino-molecule`). - Changes that can affect a consumer need a changelog fragment (`changelogs/fragments/`). New files are covered by `REUSE.toml`; third-party-derived content needs its own annotation. ## Agent skills ### Issue tracker Issues live in Gitea Issues on `mortis/kamino`, used through the `gitea-issues` skill and the Gitea MCP tools. See `docs/agents/issue-tracker.md`. ### Triage labels The five triage roles map onto the repo's scoped `Status/` and `Reviewed/` labels. See `docs/agents/triage-labels.md`. ### Domain docs Single-context: `GLOSSARY.md` and `docs/adr/` at the root, both created lazily. See `docs/agents/domain.md`. ## Workflows (`.gitea/workflows/`) - Never `pull_request_target`. A fork `pull_request` run gets no secrets and a read-only job token; a same-repo pull request does get the org Actions secrets, so nothing but `image.yml` may reference them. Pass ref, repo and name values to scripts through `env:`, never interpolate `${{ github.* }}` into a `run:` block. - Runner labels are `kamino-docker` and `kamino-molecule` only (`.gitea/actionlint.yaml`). Use the `github.*` contexts, which Gitea aliases; actionlint does not know `gitea.*`. - Lint and Build run in the `ci` image. After the checkout they compare the pin files with the checksums baked into the image: a PR that changes `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml` or `.pre-commit-config.yaml` takes the slower path that installs the pinned tools and collections. - Molecule runs on every same-repo pull request, Renovate's included (a new image is tested by its own pin pull request), with no workflow path filter, so that it can be a required check. Fork pull requests are skipped. What a pull request runs is chosen by `scripts/select_molecule_scenarios.py`, run from the base branch's copy (a pull request cannot edit its own rules): only the scenarios of the roles it changes and of the roles that use them (any file naming `mortis.kamino.`, transitively; a test fails a bare or templated role name in an include, import, play `roles:` entry or meta dependency), none for a diff of only its IGNORED paths, a failure for a changed role with no scenario, and every scenario for any other file, for every push to `main`, for manual dispatch and for the nightly run (04:43 UTC, after Renovate's). A new file outside `roles//` runs everything until it is added to IGNORED, which is right only when no scenario reads it. A new commit cancels the pull request's running Molecule run, and the step first removes containers a cancelled run left; two runs never overlap because the runner has a single slot, so raising its capacity needs a lock or a shared concurrency group. - Every scenario sets `scenario.test_sequence` to molecule's default minus the leading `destroy` (the workflow clears stale containers first, and the molecule state lives in the job's own `ANSIBLE_HOME`, so a killed run leaves none behind); copy it into a new scenario. - Molecule discovers `extensions/molecule/*/` and `roles/*/molecule/*/`. The `image-smoke` and `image-smoke-2604` scenarios test the molecule images themselves (24.04 and 26.04); a role scenario that must pass on both takes `image: ${MOLECULE_IMAGE}` or `${MOLECULE_IMAGE_2604}` per platform. ## Images (`images/`) - `ci`, `molecule-ubuntu2404` and `molecule-ubuntu2604`, built by `image.yml` with kaniko on push to `main` (never on pull requests) and pushed to `git.rkdr.net/mortis/`. - The molecule images are one Ubuntu release each, by name: the hosts run 24.04 today and 26.04 is the target, so roles are tested on both. A new release is a new image added by hand (Renovate's major `ubuntu` updates are disabled everywhere); retire an image when no host runs its release. A new image's first consumer pin is a hand-made PR with the digest its first build printed; Renovate follows it after. - Each has a semver `version:` in the workflow's build matrix. A published version tag is never moved and never rebuilt (the job looks it up in the registry first and ends without building): bump the version in the PR that changes the image. A new version is pushed as `` and `latest`; there is no `sha-*` tag, so one digest belongs to exactly one version. - `ansible-test sanity` ignores live in `tests/sanity/ignore-common.txt`; the Build job copies it to the file name of the installed core version in its throwaway worktree (a committed `ignore-.txt` is appended for findings of one version only). - Consumers pin `image:@sha256:` (`lint.yml`, `build.yml`, `molecule.yml`). A build prints the new digest; moving a pin is a reviewed edit, and every build has a new digest. - kaniko runs inside the job container and unpacks the image it builds over it, so each matrix entry names its job container (`job_image: ubuntu:@sha256:...`) and its release must equal the `FROM ubuntu:` release of the image's Dockerfile (`check_image_versions.py pins` fails otherwise). Moving an image to a new release is one edit: the Dockerfile `FROM`, the `job_image` tag and digest, and the version bump. Digest drift within a release is tolerated. A `job_image`-only bump is not an image input: no version bump, nothing rebuilt; the post-merge Images run only reaches the prepare step for published versions, so that is its only exercise. - Image metadata: Gitea's package page shows the description as plain text (no markdown), lists every label, and links source, documentation and licence; it renders no README. So each Dockerfile carries the same label block (`org.opencontainers.image.*` plus `net.rkdr.mortis.purpose/contents/usage`), the build adds `version`, `revision` and `created`, and the readme-style text lives in `docs/images/.md`, which the `documentation` label links to. `check_image_versions.py pins` fails when a label or that file is missing. The docs sit outside the image directories on purpose: editing them is not an image input, so it needs no new version. Editing a label in a Dockerfile is an input and does. - Each pushed layer must stay below 100 MB: Cloudflare rejects larger request bodies with HTTP 413. That is why the `ci` image deletes the Go toolchains from the hook cache and the unused `libpython*.so` of its three baked interpreters (the `/opt/python` layer was 99 MB compressed with them, ci 0.2.26 failed to push). The build prints the compressed size of each layer directory; the registry stores about 9% more, so read that line before adding an interpreter or a hook environment. - `image.yml` is the only workflow that may reference the org Actions secrets (the registry push credential). Never print or use them anywhere else. ## Dependency automation (Renovate) `renovate.json` is run by `.gitea/workflows/renovate.yml` (daily cron and `workflow_dispatch`) on the `kamino-docker` runner, as a Kamino-only bot user: this repository's jobs run only on its own runners, and no credential from anywhere else is used here. Never reuse another Renovate credential here. - **Policy:** minor and patch bumps automerge, majors are manual; the Lint and Build checks are the gate. A new Ubuntu release is a deliberate edit, never a bump. The `job_image` of each matrix entry in `image.yml` never automerges: that job holds the registry push credential. kaniko is pinned by layer digests in `image.yml` and updated by hand. `prHourlyLimit` is 5 (default 2): an `ubuntu` digest move makes two PRs per release (base image and job container), and two runs in a row spent the whole default limit on them, so the hook and image pin PRs waited. - **Two-PR loop for an image input** (`requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `.pre-commit-config.yaml`, `images/**`): PR 1 carries the input change plus the PATCH bump of the image `version:` in `image.yml` (`scripts/bump_image_versions.py []`; `check_image_versions.py bump` then passes; Renovate runs it as a post-upgrade task). The merge builds the image on `main`. PR 2 moves the consumers' pins to the new digest (Renovate's pin-follow rule for the `mortis/*` images; a major version stays manual). - **One Python for the lock, a clone and the ci image:** `.python-version` (a minor version) is the source. `scripts/dev-setup.sh` and `scripts/lock-requirements.sh` require exactly it, the `ci` image builds `/opt/venv` from its baked copy (`ARG PYTHON_VERSION` in `images/ci/Dockerfile`), the lock header records it, and `check_image_versions.py pins` fails when any of them differs. Renovate's `-full` container runs `pip-compile` on its own python (`RENOVATE_BINARY_SOURCE=global`, it ignores the header's version), so that python's minor version must equal `.python-version`: check it when bumping the image in `renovate.yml`. Moving the version is one pull request: `.python-version`, both `ARG PYTHON_VERSION` lines of `images/ci/Dockerfile`, the lock, and the image version bump. - **Python tool pins and their lock:** `requirements-dev.txt` holds the direct pins, `requirements-dev.lock` is their hashed lock (installed with `pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt`; pip refuses an unhashed package and any disagreement between the two). Renovate's `pip-compile` manager bumps a pin and regenerates the lock by replaying the lock's header command; a weekly lock-file-maintenance PR moves transitive packages and is never automerged. By hand: `scripts/lock-requirements.sh [--upgrade]`. The header must hold only options Renovate knows: it refuses `--newline=LF` ("not supported (yet)"), extracts nothing, and proposes no bump, with only a WARN in an otherwise green run. Hook repositories in `.pre-commit-config.yaml` are pinned by commit SHA with a `# frozen: vX.Y.Z` comment. Renovate looks them up with `git ls-remote` (packageRule `overrideDatasource: git-tags` plus `RENOVATE_GITHUB_TOKEN_WARN=false` in `renovate.yml`), because there is no GitHub token and the default `github-tags` lookup is skipped or rate limited. A hook bump is never automerged: `git-tags` has no release timestamps, so `minimumReleaseAge` cannot delay it. After a Renovate config change, test it locally before the merge: `renovate --platform=local` (same version as `renovate.yml`) reads this checkout; a dry run in Actions reads `renovate.json` from `main`. - **Bot-diff gate:** `scripts/check_bot_pr_diff.py` runs in the lint workflow, from `origin/main`'s copy so a pull request cannot weaken it. A `renovate/` head ref may only change version lines (tool pins and their lock entries and hashes, hook `rev:` lines, Dockerfile FROM tags and digests, matrix `version:` lines, `job_image:` pins, consumer image pins); anything else fails, `renovate.json` included. The branch name is attacker-controlled, so this only constrains the bot's own pull requests. - **No Collection release from tooling bumps:** tooling files are in `galaxy.yml` `build_ignore`. A role-visible change needs a changelog fragment and a new `galaxy.yml` version; only the operator tags. - **Denied image namespace:** `check_image_versions.py pins` fails when anything under `.gitea/workflows` mentions the image namespace this repository's CI must not use (the string is in the script). - **Hand edits on a bot branch:** a commit pushed by hand to a `renovate/` branch makes Renovate stop rebasing it, so merge that pull request by hand. - **The runner has a single slot:** the Renovate job (up to 30 minutes) delays Lint, Build and Molecule. - **Open item:** do not enable automerge for bot PRs until a live run has shown that they get Lint and Build.