From 39f1da33fa9233c74c76974d5793e96e046e9fa2 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Fri, 27 Nov 2026 13:36:02 +0000 Subject: [PATCH 1/3] docs: organize the docs landing page by task, and add a kcp workspaces guide Phase 1 of the task-oriented docs plan: docs/README.md now leads with Get started (capture path and coordination path), Make changes, Operate, and Understand and reference. Guides that are still missing link to their best existing source. Add docs/kcp-workspaces.md: mirror kcp workspaces and name commit authors from a shard's shared audit stream, written as a top-to-bottom read for a newcomer. Co-Authored-By: Claude Opus 5.5 --- .docs-lint-scope | 1 + docs/README.md | 138 ++++-- docs/configuration.md | 3 + docs/future/task-oriented-docs-and-website.md | 16 +- docs/kcp-workspaces.md | 402 ++++++++++++++++++ 5 files changed, 513 insertions(+), 47 deletions(-) create mode 100644 docs/kcp-workspaces.md diff --git a/.docs-lint-scope b/.docs-lint-scope index ec9a4e473..4149046b1 100644 --- a/.docs-lint-scope +++ b/.docs-lint-scope @@ -38,6 +38,7 @@ docs/bi-directional.md docs/README.md docs/github-setup-guide.md docs/attribution-setup-guide.md +docs/kcp-workspaces.md docs/audit-setup/cluster/readme.md docs/sops-age-guide.md docs/commit-signing.md diff --git a/docs/README.md b/docs/README.md index fddd72d90..afc343268 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,45 +1,103 @@ # Documentation -This repository has two kinds of markdown: - -- stable user/operator guides -- maintainer notes, design docs, and working plans - -If you only want the supported product docs, start with the files below. - -## Start here - -- [`../README.md`](../README.md): product overview and supported workflows -- [`quickstart.md`](quickstart.md): installation and your first Git commit -- [`demo/commit-window.md`](demo/commit-window.md): two resources and a `CommitRequest` -- [`configuration.md`](configuration.md): core configuration objects, every setting, and how - they fit together -- [`commit-messages.md`](commit-messages.md): the three commit message templates and their context -- [`api-first-publication.md`](api-first-publication.md): why API edits drive publication, how - replay handles remote changes, and how commit windows and push timing fit together -- [`installing-apps-as-krm.md`](installing-apps-as-krm.md): installing an app is adding a KRM - document: Flux `HelmRelease`, Argo CD `Application`, KRO, and core resources all mirror and edit alike -- [`commit-signing.md`](commit-signing.md): how valid Git signatures map to platform verification -- [`github-setup-guide.md`](github-setup-guide.md): GitHub repository and credential setup -- [`azure-devops-getting-started.md`](azure-devops-getting-started.md): Azure DevOps repository and credential setup -- [`attribution-setup-guide.md`](attribution-setup-guide.md): naming real Kubernetes users as commit - authors via kube-apiserver audit delivery -- [`sops-age-guide.md`](sops-age-guide.md): Secret encryption with SOPS + age -- [`security-model.md`](security-model.md): controller access, trust boundaries, and the Git - credentials Secret shape -- [`rbac.md`](rbac.md): the two ClusterRoles (plus the optional applier grants), and how to stop the - reverser enumerating Secrets -- [`bi-directional.md`](bi-directional.md): when Flux or Argo CD applies a folder GitOps Reverser - writes, and why every other setup needs nothing -- [`bi-directional-flux.md`](bi-directional-flux.md): the complete Flux setup for such a folder -- [`bi-directional-argocd.md`](bi-directional-argocd.md): the complete Argo CD setup for such a folder -- [`alternatives.md`](alternatives.md): nearby tools and when another approach fits better -- [`UPGRADING.md`](UPGRADING.md): breaking changes and migration steps, newest first -- [`../CONTRIBUTING.md`](../CONTRIBUTING.md): contributor workflow and validation commands -- [`style-guide.md`](style-guide.md): how docs here are written, including the no-em-dash rule and - the American-English decision -- [`../test/e2e/E2E_DEBUGGING.md`](../test/e2e/E2E_DEBUGGING.md): e2e troubleshooting, reuse, - and `.stamps` +GitOps Reverser turns changes made through the Kubernetes API into commits in a Git repository. +These pages are organized by what you want to do. If you are new, read the +[product overview](../README.md) first, then follow **Get started** from the top. + +Not sure this is the right tool? [Alternatives](alternatives.md) compares nearby tools and says when +another approach fits better. + +## 1. Get started + +Pick a setup path with one question: **does Flux or Argo CD apply the same folder GitOps Reverser +writes?** If yes, follow [coordinate changes from Kubernetes and Git](#coordinate-changes-from-kubernetes-and-git), +even when you only want to record cluster changes for now. An applier that keeps deploying that +folder needs coordination either way. If no, follow [capture cluster state in Git](#capture-cluster-state-in-git). + +### Capture cluster state in Git + +The shortest path to a commit in Git, with no applier and no Git push webhook. It captures the +selected cluster state; batching and restarts mean Git history is not a complete record of every +event. + +1. **Install GitOps Reverser and see a first commit:** [quick start](quickstart.md). +2. **Connect your Git host:** [GitHub](github-setup-guide.md) or + [Azure DevOps](azure-devops-getting-started.md). +3. **Start capturing a team's resources:** choose the source cluster, namespaces, resources, + repository, branch, and folder. The [configuration overview](configuration.md#how-the-objects-fit-together) + shows how the objects fit, and [one tenant, end to end](configuration.md#one-tenant-end-to-end) + walks a team through it. To adopt an existing repository, start on a + [scratch branch](configuration.md#seeing-what-a-target-will-do-before-it-does-it) and choose a + [deletion policy](configuration.md#deletion-policy-specprunemode) before going live. +4. **Optional: record who made each change:** [attribute commits to Kubernetes users](attribution-setup-guide.md) + through API-server audit delivery. It needs control over the API server's audit settings; + [the k3s example](audit-setup/cluster/readme.md) shows a complete configuration. + +### Coordinate changes from Kubernetes and Git + +For a folder that Flux or Argo CD also applies. Start with the capture path above, then: + +1. **Understand why coordination is needed:** [bi-directional GitOps](bi-directional.md). +2. **Configure the applier:** [Flux](bi-directional-flux.md) or [Argo CD](bi-directional-argocd.md). +3. **React promptly to Git pushes:** configure the Git host's push webhook and a `GitReceiver`, as + in [telling GitOps Reverser that somebody else pushed](bi-directional.md#telling-gitops-reverser-that-somebody-else-pushed). + The [`GitReceiver` reference](configuration.md#gitreceiver) lists the supported hosts. +4. **Optional: record who made each change**, as in the capture path. + +### Supporting guides + +Use these where your setup needs them: + +- [Encrypt Secrets with SOPS and age](sops-age-guide.md) +- [Sign commits](commit-signing.md) +- [Narrow the controller's permissions](rbac.md) +- [Mirror kcp workspaces](kcp-workspaces.md), including commit authors from kcp's shared audit stream +- [Helm chart values](../charts/gitops-reverser/README.md) + +## 2. Make changes + +- **Make a change through Kubernetes:** create, update, or delete a selected resource and follow it + into Git. The [quick start's test step](quickstart.md#4-test-it) is the smallest example. +- **Group changes and explain why:** [the commit window demo](demo/commit-window.md) collects two + edits and saves them as one commit with a `CommitRequest`. [Commit messages](commit-messages.md) + covers the templates. +- **Choose what to capture:** [installing apps as KRM](installing-apps-as-krm.md) shows that a Flux + `HelmRelease`, an Argo CD `Application`, or a KRO instance mirrors and edits like any other + resource. +- **Work alongside other people on the same branch:** [API-first publication](api-first-publication.md) + explains how edits from several authors and targets become commits, and what happens when another + writer moves the branch. +- **Make a change through Git:** with an applier configured, a push reaches the cluster as described + in [the life of an apply](bi-directional.md#the-life-of-an-apply). + +## 3. Operate + +- **Monitor health and resource usage:** [interpreting metrics](interpreting-metrics.md), including + [suggested alerts](interpreting-metrics.md#suggested-alerts). +- **Investigate a missing or unexpected change:** start from the resource's conditions + (`kubectl describe`), then the [metrics for the watch-to-push pipeline](interpreting-metrics.md#pipeline-watch-to-push) + and the [operational boundaries](architecture.md#operational-boundaries). +- **Upgrade an installation:** [UPGRADING.md](UPGRADING.md) lists breaking changes and migration + steps, newest first. + +## 4. Understand and reference + +- [Architecture](architecture.md): how a Kubernetes edit reaches Git, how a Git edit reaches the + cluster, and the boundaries around safety and recovery. +- [Configuration](configuration.md): every object, field, default, and controller setting. +- [Security model](security-model.md): credentials, permissions, trust boundaries, and the Git + credentials Secret shape. +- [RBAC](rbac.md): the two ClusterRoles, the optional applier grants, and how to stop the controller + listing Secrets. +- [Definitions](definitions.md): the vocabulary these pages use. +- [Helm chart](../charts/gitops-reverser/README.md): installation options and values. + +## Contributing + +- [CONTRIBUTING.md](../CONTRIBUTING.md): contributor workflow and validation commands. +- [Style guide](style-guide.md): how these docs are written, including the no-em-dash rule and the + American-English decision. +- [e2e debugging](../test/e2e/E2E_DEBUGGING.md): e2e troubleshooting, reuse, and `.stamps`. ## Maintainer notes diff --git a/docs/configuration.md b/docs/configuration.md index 2acd36a61..c67a55f1d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -3565,6 +3565,9 @@ Use an annotation that the producing control plane sets consistently as source m routing metadata only: it keeps the audit fact and the watch event in the same source-cluster partition, so a user from one logical cluster can never be credited for a matching object in another. +For kcp, where the annotation is `kcp.io/cluster` and its value is a workspace's logical cluster +name, see [mirror kcp workspaces](kcp-workspaces.md). + Valkey/Redis is **optional**: when `--redis-addr` is set, watch resume cursors are stored so restarts pick up where they left off; when left empty, watches cold-replay from scratch on restart instead. The Helm chart defaults to **configured-author** (`attribution.enabled: false`): the audit webhook is diff --git a/docs/future/task-oriented-docs-and-website.md b/docs/future/task-oriented-docs-and-website.md index ca295f635..47ee57e27 100644 --- a/docs/future/task-oriented-docs-and-website.md +++ b/docs/future/task-oriented-docs-and-website.md @@ -1,7 +1,8 @@ # Task-oriented documentation and a static website -Status: proposed documentation and website plan. The navigation, page splits, and website described -here are future work. +Status: phase 1 (navigation) is done: [the documentation landing page](../README.md) is organized +under the four categories below. The page splits, the missing guides, and the website are future +work. ## Goal @@ -117,7 +118,7 @@ even where source material does. Proposed guides are named by task, not by filen | Guide or source | Destination | State and action | | --- | --- | --- | -| `docs/README.md` | Documentation landing page | Exists: rewrite around the four categories | +| `docs/README.md` | Documentation landing page | Exists: organized around the four categories; link each new guide as it lands | | Root `README.md` | Homepage | Exists: reuse the product explanation and demo | | `alternatives.md` | Homepage: is this right for me? | Exists: link from adoption guidance | | `quickstart.md` | Get started: capture | Exists: verify a first commit without an applier claim or push webhook | @@ -129,6 +130,7 @@ even where source material does. Proposed guides are named by task, not by filen | `bi-directional.md` | Get started: coordination overview | Needs split: keep the setup decision and common behavior; extract receiver setup into the push-notification guide and the everyday Git edit into Make changes | | `bi-directional-flux.md`, `bi-directional-argocd.md` | Get started: applier setup | Exists: link receiver setup and verify both directions | | `sops-age-guide.md`, `commit-signing.md` | Get started: supporting guides | Exists | +| `kcp-workspaces.md` | Get started: supporting guides | Exists: kcp workspace mirroring and shared-stream attribution | | Normal Kubernetes change | Make changes | Missing: expand the quick-start example into create, update, delete, and refusal outcomes | | `demo/commit-window.md` | Make changes: group and explain | Exists: the worked task guide | | `commit-messages.md` | Reference, linked from grouped changes | Exists: template reference | @@ -245,10 +247,10 @@ against these requirements and their maintenance cost. ## Implementation phases -**Phase 1: Navigation.** Rewrite `docs/README.md` under the four categories from the inventory, -with both setup paths under Get started. Link `docs/INDEX.md` as the maintainer entry point. Keep -the lifecycle folders and source citations; navigation provides the new structure without moving -files. +**Phase 1: Navigation. Done.** `docs/README.md` lists the inventory under the four categories, with +both setup paths under Get started, and links `docs/INDEX.md` as the maintainer entry point. A +missing guide is linked to its best existing source until it is written. The lifecycle folders and +source citations are unchanged. **Phase 2: Reading paths.** diff --git a/docs/kcp-workspaces.md b/docs/kcp-workspaces.md new file mode 100644 index 000000000..a6236f070 --- /dev/null +++ b/docs/kcp-workspaces.md @@ -0,0 +1,402 @@ +# Mirror kcp workspaces + +This guide mirrors the resources of one or more [kcp](https://www.kcp.io) workspaces into Git, and +optionally names the workspace user who made each change as the commit author. It is for a +platform administrator who runs kcp and installs GitOps Reverser beside it. + +The guide has two parts, and you can stop after the first: + +- **Mirror a workspace** ([step 1](#1-connect-each-workspace)). Each workspace is reached through + its own `KubeProvider`, like any other remote cluster. Nothing about it is kcp-specific, and every + commit is authored by the configured committer. +- **Name each change's author** ([steps 2–4](#2-turn-on-the-shared-audit-endpoint)). This is where + kcp differs from an ordinary cluster: one kcp shard sends the audit events of all its workspaces + in a single stream, so GitOps Reverser has to tell from each event which workspace it came from. + +## Before you start + +- GitOps Reverser runs in an ordinary Kubernetes cluster, installed following the + [quick start](quickstart.md). This guide calls it the **control cluster**. All GitOps Reverser + objects (`GitTarget`, `KubeProvider`, `WatchRule`, and the rest) live there, so a workspace needs + none of its CRDs. +- For each workspace you mirror, you have a credential whose RBAC in that workspace can read the + namespaces and types you want in Git. + +For commit authors you also need: + +- Attribution enabled, with a place to keep author facts until the matching change arrives: + Redis/Valkey, or `memory` for a single replica. See + [step 1 of the attribution guide](attribution-setup-guide.md#1-enable-the-receiver). +- Access to the audit configuration of every kcp shard: the kcp-operator's `RootShard` and `Shard` + objects, or the shard's own flags. + +## Words this guide uses + +- **Workspace:** a kcp tenant's own Kubernetes API, with its own namespaces, objects, and CRDs. + Every workspace is backed by a **logical cluster**. +- **Logical cluster name:** the short, opaque identifier of a workspace, such as + `2nhnb6jpthl8l7z5`. It is distinct from the workspace **path**, such as `root:shop`, which is + readable and is what `kubectl ws` navigates. This guide uses the logical cluster name everywhere. +- **Audit route:** the label GitOps Reverser files each author fact under. A `KubeProvider` reads + the facts of exactly one route, its `spec.attribution.auditRoute`. +- **Shared audit endpoint:** `/audit-webhook` with no route in the path. It reads each event's + route from an annotation on the event, so one stream can carry many workspaces. The + configuration reference calls it the bare endpoint. The ordinary, + **named** endpoint `/audit-webhook/` files every event it receives under that one route. + +## How the pieces fit + +```mermaid +flowchart LR + user["Workspace user
kubectl apply"] --> fp["kcp front-proxy"] + fp --> shard["kcp shard
serves many workspaces"] + shard -- "one audit stream
each event tagged kcp.io/cluster" --> bare["GitOps Reverser
shared /audit-webhook"] + kp["KubeProvider shop-workspace
auditRoute: 2nhnb6jpthl8l7z5"] -- "watch via
/clusters/2nhnb6jpthl8l7z5" --> fp + bare -- "fact filed under
route 2nhnb6jpthl8l7z5" --> join["join: watch event + audit fact"] + kp --> join + join --> git["Git commit
author alice@example.com"] +``` + +GitOps Reverser names an author by joining two streams that arrive separately: + +1. The **watch event**: the change itself, read from the workspace through its `KubeProvider`. +2. The **audit fact**: who made the change, built from the shard's audit event. + +The kcp shard tags every audit event with the logical cluster name of the workspace it served, in +the `kcp.io/cluster` annotation. The shared endpoint files each event under that name as its +route. So the join works exactly when a workspace's `KubeProvider` carries that workspace's +logical cluster name as its `spec.attribution.auditRoute`. + +When the two differ, nothing fails. Mirroring stays complete, and every commit through that +provider is authored `unknown (attribution unresolved)`. Most of the steps below exist to keep the +two values equal, and [the troubleshooting table](#when-commits-are-authored-unknown-attribution-unresolved) +shows how to compare them. + +## Find the workspace's logical cluster name + +kcp stores it in the `Workspace` object's `spec.cluster`, which you read from the parent workspace: + +```bash +kubectl ws :root +kubectl get workspace shop -o jsonpath='{.spec.cluster}{"\n"}' +``` + +The examples below use `2nhnb6jpthl8l7z5` for the `root:shop` workspace. Repeat the steps for each +workspace you mirror. + +## 1. Connect each workspace + +Create a kubeconfig whose `server` is the front-proxy address with `/clusters/` appended. Store it in a Secret in the control cluster, and create a `KubeProvider` beside it: + +```yaml +apiVersion: v1 +kind: Secret +metadata: + name: shop-workspace-kubeconfig + namespace: team-shop +stringData: + value: | + apiVersion: v1 + kind: Config + clusters: + - name: shop + cluster: + server: https://kcp-front-proxy.example.com:6443/clusters/2nhnb6jpthl8l7z5 + certificate-authority-data: + users: + - name: gitops-reverser + user: + token: + contexts: + - name: shop + context: {cluster: shop, user: gitops-reverser} + current-context: shop +--- +apiVersion: configbutler.ai/v1alpha3 +kind: KubeProvider +metadata: + name: shop-workspace + namespace: team-shop +spec: + secretRef: + name: shop-workspace-kubeconfig + attribution: + auditRoute: 2nhnb6jpthl8l7z5 # the workspace's logical cluster name + allowedGitTargets: + - consumerNamespaces: + from: Same + sourceNamespaces: [storefront] +``` + +`allowedGitTargets` is the provider's grant: `GitTarget`s in its own namespace (`team-shop`) may +mirror the `storefront` namespace of the workspace through it. The +[grants section of the configuration reference](configuration.md#the-grants) explains the other +shapes. + +kcp also accepts the path in the URL (`/clusters/root:shop`), and mirroring works either way. Using +the logical cluster name in both the URL and `auditRoute` leaves one value to check. Setting +`auditRoute` now costs nothing while attribution is off, and saves a second edit later. + +The kubeconfig must embed its credentials. One that runs an exec plugin, skips TLS verification, or +names a file is refused, as described under [`KubeProvider`](configuration.md#kubeprovider). + +Then point a `GitTarget` at the provider and select what to mirror with a `WatchRule`. Both live in +the control cluster. The `GitBranch` named here is one you created as in the +[quick start](quickstart.md) or [`config/samples/`](../config/samples/): + +```yaml +apiVersion: configbutler.ai/v1alpha3 +kind: GitTarget +metadata: + name: shop + namespace: team-shop +spec: + gitBranchRef: + name: shop-main + kubeProviderRef: + name: shop-workspace + path: workspaces/shop +--- +apiVersion: configbutler.ai/v1alpha3 +kind: WatchRule +metadata: + name: shop-configmaps + namespace: team-shop +spec: + gitTargetRef: + name: shop + rules: + - apiGroups: [""] + apiVersions: ["v1"] + resources: ["configmaps"] + sourceNamespace: storefront # a namespace inside the workspace +``` + +Three things differ from a cluster with its own API server: + +- **Namespaces are on two sides.** The `GitTarget` and `WatchRule` live in `team-shop` in the + control cluster. The namespace they mirror, `storefront`, lives in the workspace. That is why the + rule names it with [`rules[].sourceNamespace`](configuration.md#watching-a-different-source-namespace), + and why the grant lists it. +- **Each workspace is its own API.** Two workspaces can serve different versions of a CRD with the + same name, and each `KubeProvider` discovers its own. Nothing is shared between providers. +- **Keep all providers of one workspace in one namespace.** An audit route belongs to one + namespace of the control cluster: the namespace of the oldest provider carrying it. A provider in + another namespace carrying the same logical cluster name reports `Stalled=True` with reason + `AuditRouteConflict`. See + [audit route and `AuditFactsReceived`](configuration.md#audit-route-and-auditfactsreceived). + +Mirroring works at this point, and every commit is authored by the configured committer. If that is +all you need, you are done. The next steps add the commit author. + +## 2. Turn on the shared audit endpoint + +Set the annotation key in the chart values, together with attribution: + +```yaml +attribution: + enabled: true + auditRouteAnnotationKey: kcp.io/cluster +``` + +The chart passes it to the operator as +`--author-attribution-audit-route-annotation-key=kcp.io/cluster`. That turns on the shared +`/audit-webhook` endpoint, which reads each event's route from its `kcp.io/cluster` annotation. One +batch from a shard can therefore hold events for many workspaces, and each is filed under its own +route. + +If you also attribute changes made in the control cluster itself, keep its API server on its named +route, `/audit-webhook/.local`, as in the +[attribution guide](attribution-setup-guide.md#2-configure-delivery-on-every-api-server). Its +events carry no `kcp.io/cluster` annotation, and the shared endpoint drops an event without one +instead of guessing a route. + +## 3. Deliver every shard's audit stream + +Every shard sends its own stream, so configure each one: the `RootShard` and every `Shard`. + +Build the webhook kubeconfig as in the +[attribution guide](attribution-setup-guide.md#2-configure-delivery-on-every-api-server), with +mutual TLS, `tls-server-name`, and an address the shard can reach. The Service name below works +when the shard runs in the control cluster. End the `server` URL at the shared endpoint, with no +route after it: + +```yaml +server: https://gitops-reverser-audit.gitops-reverser.svc:9444/audit-webhook +tls-server-name: gitops-reverser-audit.gitops-reverser.svc +``` + +Appending a route would file every event of the stream under that one route, whichever workspace +it came from. + +With the kcp-operator, store that kubeconfig in a Secret in the shard's namespace under the key +`kubeconfig`, store the audit policy in a ConfigMap, and reference both from `spec.audit`: + +```yaml +apiVersion: operator.kcp.io/v1alpha1 +kind: RootShard # and the same block on every Shard +metadata: + name: root + namespace: kcp +spec: + audit: + policy: + configMap: + name: kcp-audit-policy + key: policy.yaml + webhook: + configSecretName: kcp-audit-webhook + mode: batch + batchMaxWait: 1s + batchMaxSize: 400 +``` + +A shard run without the kcp-operator takes the kube-apiserver audit flags that the attribution +guide lists. + +Two settings matter more than on an ordinary API server: + +- **Keep `batchMaxWait` below `--author-attribution-grace`** (default `3s`). A watch event waits at + most that long for its fact. A batch held longer than the grace delivers facts after their watch + events have already been committed without an author. +- **The policy covers every workspace on the shard.** Start from the + [tuned policy](../test/e2e/cluster/audit/policy.yaml) and its notes under + [choose the audit policy](attribution-setup-guide.md#choose-the-audit-policy). A type the policy + excludes can never be attributed in any workspace. + +## 4. Verify + +Check that the provider's route is the workspace's logical cluster name. `-o wide` adds the `ROUTE` +column: + +```bash +kubectl -n team-shop get kubeprovider shop-workspace -o wide +``` + +Then, inside the workspace and with an ordinary user's credentials, change an object the +`WatchRule` selects: + +```bash +kubectl ws :root:shop +kubectl -n storefront create configmap attribution-check --from-literal=check=first +``` + +The commit lands once the target's commit window closes, about 5 seconds after the last change by +default. Pull the branch and check that the author is that user and the committer is unchanged: + +```bash +git pull +git log -1 --format=fuller +``` + +The provider's `FACTSRECEIVED` column turns `True` once the first fact on its route arrives. It is +a latch: it records that the route has delivered at least once, not that it still does. Delete the +test ConfigMap afterward. + +## When commits are authored `unknown (attribution unresolved)` + +Start from the provider's `AuditFactsReceived` reason, then the audit metrics described in +[interpreting metrics](interpreting-metrics.md): + +| What you see | Cause | Fix | +|---|---|---| +| `AuditFactsReceived=Unknown`, reason `RouteUnused` | Audit arrives, and none of it names this provider's route. Usually `spec.attribution.auditRoute` differs from the workspace's `spec.cluster` | Compare the `ROUTE` column with `kubectl get workspace -o jsonpath='{.spec.cluster}'` in the parent workspace | +| `AuditFactsReceived=Unknown`, reason `NoAuditDelivery` | No audit request has reached the operator on any route | Check the shard's `spec.audit.webhook`, its Secret, and network reach to port 9444 | +| A steady rate of `audit_events_total{audit_route="unrecognized"}` | Events name a logical cluster no `KubeProvider` carries | Harmless for a workspace you do not mirror. Otherwise a mistyped `auditRoute` | +| A rising rate of `audit_events_total{outcome="missing_cluster_annotation"}` | Something posts to the shared endpoint without the annotation | Usually the control cluster's API server pointed at `/audit-webhook`. Give it its named route | +| The shard's webhook gets HTTP 400 | The shared endpoint is off: `attribution.auditRouteAnnotationKey` is unset | Set it ([step 2](#2-turn-on-the-shared-audit-endpoint)) | +| `Stalled=True`, reason `AuditRouteConflict` | A provider in another namespace already holds this logical cluster name | Keep one workspace's providers in one namespace | + +## How kcp tags the shared audit stream + +You do not need this section to set things up. It explains why routing on `kcp.io/cluster` is +reliable, for readers who want to check. + +A kcp shard is one API server process that serves many workspaces. Like any API server it has one +audit backend, so it sends one audit stream holding the events of every workspace it serves. To +make that stream separable, the shard adds three audit annotations to every event whose request it +resolved to a logical cluster: + +| Annotation | Value | +|---|---| +| `kcp.io/cluster` | the logical cluster name | +| `tenancy.kcp.io/workspace` | the logical cluster name as well | +| `kcp.io/path` | the canonical workspace path, or empty when the shard could not read it | + +A request filter on the shard adds them after it has resolved the `/clusters/<...>` part of the +URL to a logical cluster (`WithAuditEventClusterAnnotation` in kcp's +`pkg/server/filters/filters.go`). An event as the webhook receives it looks like this (trimmed): + +```json +{ + "apiVersion": "audit.k8s.io/v1", + "kind": "Event", + "stage": "ResponseComplete", + "verb": "update", + "user": { "username": "alice@example.com" }, + "objectRef": { "resource": "configmaps", "namespace": "storefront", "name": "checkout-limits" }, + "annotations": { + "authorization.k8s.io/decision": "allow", + "kcp.io/cluster": "2nhnb6jpthl8l7z5", + "tenancy.kcp.io/workspace": "2nhnb6jpthl8l7z5", + "kcp.io/path": "root:shop" + } +} +``` + +These are the event's own `annotations`: the map where every API server also records annotations +such as `authorization.k8s.io/decision`, beside `user` and `objectRef`. They describe the request, +so they are present whatever the request touched, including a `delete` that carries no object +body. They never appear inside `requestObject` or `responseObject`. + +GitOps Reverser routes on `kcp.io/cluster` for three reasons: + +- It is set on every event of a workspace request, while `kcp.io/path` can be empty. +- An audit route must be a lowercase, DNS-subdomain-shaped value, which the schema of + `spec.attribution.auditRoute` checks. A logical cluster name fits; a path such as `root:shop` + has a colon, and the API server refuses it. +- It is the same value the kubeconfig URL uses, so one string identifies the workspace across the + whole `KubeProvider`. + +### The same key on objects is a different thing + +kcp also writes `kcp.io/cluster` into the `metadata.annotations` of every object it returns. That is +the copy you see in `kubectl get -o yaml` inside a workspace, and it records which logical cluster +the object was read from. + +GitOps Reverser never routes on that copy. It strips the annotation, by exact key, before writing +an object to Git: it is an address, and a manifest carrying it would point at one workspace +wherever it was applied later. Other `kcp.io/` keys on an object are kept, because they are not +known to be bookkeeping. + +## The trust boundary + +The shared endpoint trusts the shard. Audit ingress checks the client certificate against the +shared audit CA, and any sender holding that credential can submit facts under any route. That is +the [shared audit-ingress trust model](../SECURITY.md#shared-audit-ingress-trust-model): suitable +when one privileged control plane, here kcp, serves every participating source and protects the +credential. + +A workspace user cannot cross that boundary from inside a workspace. A client cannot set an audit +annotation: the shard writes the route from the logical cluster it served the request in. Whoever +holds the shard's client credential can submit any route, so protect it like the shard's own keys. +Run a separate GitOps Reverser when one tenant must not be able to influence another tenant's +commit authors, even through that credential. + +## Saving from inside a workspace + +A workspace user can save their open commit window with a `CommitRequest` created in the workspace +itself, once the `CommitRequest` CRD is installed there and the provider serves it. See +[serving the `CommitRequest`s of a source cluster](configuration.md#serving-the-commitrequests-of-a-source-cluster). +The request is authored from its own audit event, so it reaches GitOps Reverser through the same +shard stream and the same route as the user's other changes. + +## Reference + +- [`KubeProvider`](configuration.md#kubeprovider): credentials, grants, and the audit route. +- [Route a shared audit stream by event annotation](configuration.md#route-a-shared-audit-stream-by-event-annotation): + the rejection rules of the shared endpoint. +- [Attribute commits to Kubernetes users](attribution-setup-guide.md): the receiver, the webhook + kubeconfig, and the audit policy. +- [Interpreting metrics](interpreting-metrics.md): `audit_events_total` and its `audit_route` label. From cbe2dd8f43d1a6d5d664d2285d539fa36afebbae Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Fri, 27 Nov 2026 15:12:54 +0000 Subject: [PATCH 2/3] docs: add team onboarding and push webhook guides, and align vocabulary Add two phase-2 task guides from the task-oriented docs plan: docs/team-onboarding.md (start mirroring a team's resources) and docs/push-webhook.md (point the Git host's push webhook at a GitReceiver), and link both from the docs landing page. Add push webhook, push event, delivery, audit webhook, and named/bare endpoint to docs/definitions.md, and use "bare endpoint", "author attribution", and "mirror" consistently across the touched pages. Co-Authored-By: Claude Opus 5.5 --- .docs-lint-scope | 2 + docs/README.md | 26 +- docs/architecture.md | 4 +- docs/definitions.md | 27 ++ docs/future/task-oriented-docs-and-website.md | 33 +- docs/interpreting-metrics.md | 4 +- docs/kcp-workspaces.md | 33 +- docs/push-webhook.md | 250 ++++++++++++++ docs/team-onboarding.md | 322 ++++++++++++++++++ 9 files changed, 649 insertions(+), 52 deletions(-) create mode 100644 docs/push-webhook.md create mode 100644 docs/team-onboarding.md diff --git a/.docs-lint-scope b/.docs-lint-scope index 4149046b1..9e6298fd7 100644 --- a/.docs-lint-scope +++ b/.docs-lint-scope @@ -39,6 +39,8 @@ docs/README.md docs/github-setup-guide.md docs/attribution-setup-guide.md docs/kcp-workspaces.md +docs/push-webhook.md +docs/team-onboarding.md docs/audit-setup/cluster/readme.md docs/sops-age-guide.md docs/commit-signing.md diff --git a/docs/README.md b/docs/README.md index afc343268..cdc3ea605 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,37 +12,33 @@ another approach fits better. Pick a setup path with one question: **does Flux or Argo CD apply the same folder GitOps Reverser writes?** If yes, follow [coordinate changes from Kubernetes and Git](#coordinate-changes-from-kubernetes-and-git), even when you only want to record cluster changes for now. An applier that keeps deploying that -folder needs coordination either way. If no, follow [capture cluster state in Git](#capture-cluster-state-in-git). +folder needs coordination either way. If no, follow [mirror cluster state into Git](#mirror-cluster-state-into-git). -### Capture cluster state in Git +### Mirror cluster state into Git -The shortest path to a commit in Git, with no applier and no Git push webhook. It captures the +The shortest path to a commit in Git, with no applier and no Git push webhook. It mirrors the selected cluster state; batching and restarts mean Git history is not a complete record of every event. 1. **Install GitOps Reverser and see a first commit:** [quick start](quickstart.md). 2. **Connect your Git host:** [GitHub](github-setup-guide.md) or [Azure DevOps](azure-devops-getting-started.md). -3. **Start capturing a team's resources:** choose the source cluster, namespaces, resources, - repository, branch, and folder. The [configuration overview](configuration.md#how-the-objects-fit-together) - shows how the objects fit, and [one tenant, end to end](configuration.md#one-tenant-end-to-end) - walks a team through it. To adopt an existing repository, start on a - [scratch branch](configuration.md#seeing-what-a-target-will-do-before-it-does-it) and choose a - [deletion policy](configuration.md#deletion-policy-specprunemode) before going live. +3. **Start mirroring a team's resources:** [onboard a team](team-onboarding.md): the repository, + branch, folder, namespaces, and resources it mirrors, and how to adopt an existing repository + on a scratch branch first. 4. **Optional: record who made each change:** [attribute commits to Kubernetes users](attribution-setup-guide.md) through API-server audit delivery. It needs control over the API server's audit settings; [the k3s example](audit-setup/cluster/readme.md) shows a complete configuration. ### Coordinate changes from Kubernetes and Git -For a folder that Flux or Argo CD also applies. Start with the capture path above, then: +For a folder that Flux or Argo CD also applies. Start with the path above, then: 1. **Understand why coordination is needed:** [bi-directional GitOps](bi-directional.md). 2. **Configure the applier:** [Flux](bi-directional-flux.md) or [Argo CD](bi-directional-argocd.md). -3. **React promptly to Git pushes:** configure the Git host's push webhook and a `GitReceiver`, as - in [telling GitOps Reverser that somebody else pushed](bi-directional.md#telling-gitops-reverser-that-somebody-else-pushed). - The [`GitReceiver` reference](configuration.md#gitreceiver) lists the supported hosts. -4. **Optional: record who made each change**, as in the capture path. +3. **React promptly to Git pushes:** [point the Git host's push webhook at GitOps Reverser](push-webhook.md), + then push a test change and watch it apply. +4. **Optional: record who made each change**, as in the path above. ### Supporting guides @@ -61,7 +57,7 @@ Use these where your setup needs them: - **Group changes and explain why:** [the commit window demo](demo/commit-window.md) collects two edits and saves them as one commit with a `CommitRequest`. [Commit messages](commit-messages.md) covers the templates. -- **Choose what to capture:** [installing apps as KRM](installing-apps-as-krm.md) shows that a Flux +- **Choose what to mirror:** [installing apps as KRM](installing-apps-as-krm.md) shows that a Flux `HelmRelease`, an Argo CD `Application`, or a KRO instance mirrors and edits like any other resource. - **Work alongside other people on the same branch:** [API-first publication](api-first-publication.md) diff --git a/docs/architecture.md b/docs/architecture.md index e5837df0a..6d6b0a0ec 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -181,7 +181,7 @@ selectable transport, Redis Streams by default and an in-process ring with Redis as the shared store across replicas. **Audit is an optional attribution lookup.** When attribution is enabled, kube-apiserver posts audit -events to `/audit-webhook/` (or a configured annotation-routed shared endpoint). The route +events to `/audit-webhook/` (or the bare endpoint, routed by an event annotation). The route is `KubeProvider.spec.attribution.auditRoute`, which defaults to `.`. The operator appends a minimal fact to that route's per-type fact stream; every process watching the type follows that stream into a bounded, TTL'd in-process index, and a watch event joins against the @@ -2004,7 +2004,7 @@ Current limitations: over it is not mirrored, and the next apply restores it; until then the cluster runs the older value. See [the apply window](design/apply-trigger.md#the-apply-window). - **Audit ingress uses a shared-CA trust boundary.** Named `/audit-webhook/` routes and the - annotation-routed shared endpoint both require a client certificate signed by the audit CA, but that + annotation-routed bare endpoint both require a client certificate signed by the audit CA, but that certificate is not bound to one audit route. This is an accepted privileged-control-plane assumption, not tenant isolation; see [SECURITY.md](../SECURITY.md#shared-audit-ingress-trust-model). - **`deletecollection`** is reconciled by the watch (each item arrives as its own `DELETED`, or the diff --git a/docs/definitions.md b/docs/definitions.md index 40bb7d678..85894e572 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -332,6 +332,19 @@ clusters, and in prose "the receiver" is fine. A delivery to it is a hint to loo about the branch: it wakes the branch worker of each provider for the repository and branch it names, and the worker reads the remote itself. +**Push webhook.** The Git host's webhook for pushes, configured in the repository's or the +organization's settings and pointed at a receiver's `status.webhookPath`. Say "push webhook" for the +host-side configuration and the capability as a whole. Not "push notification" or "push hook". + +**Push event.** The Git host's own name for what a push webhook reports: one push, naming a +repository, a branch, and the commit it moved to. GitHub, GitLab and Gitea all call it that. + +**Delivery.** One request a push webhook sends to a receiver, carrying one push event. Its signature +is checked before its body is read, and a verified delivery is only a hint (see **Receiver**). +`receiver_deliveries_total` counts deliveries by `outcome`, and `GitBranch.status.lastPushNoticeAt` +records when one last reached the branch. The **audit webhook** sends requests too; call those +audit requests, so "delivery" stays with the push webhook. + ## Attribution The word alone is ambiguous, so it is never used alone. There are two: @@ -355,6 +368,18 @@ is the `` segment in `/audit-webhook/`, and defaults to the `KubeP a provider there carries it, otherwise the namespace of the oldest provider carrying it. A provider elsewhere that carries it is not used (`AuditRouteConflict`), so no namespace reads another's facts. +**Audit webhook.** The kube-apiserver's audit webhook backend, configured to post audit events to the +operator's audit listener. It authenticates with a client certificate, where a push webhook signs +its body, which is why the two never share a listener. A bare "webhook" is ambiguous wherever both +could be meant: say which. + +**Named endpoint, bare endpoint.** The two paths the audit listener serves. A **named endpoint**, +`/audit-webhook/`, files every event it receives under that route. The **bare endpoint**, +`/audit-webhook` with no route, serves a **shared audit stream**: one producer's events for many +source clusters, such as a kcp shard's. It reads each event's route from the event annotation +`--author-attribution-audit-route-annotation-key` names, drops an event without one, and is off until +that flag is set. The stream is shared; the endpoint is bare. Not "shared endpoint". + **Grace window.** The bounded wait for a matching fact before a watch event ships credited to the committer instead. @@ -546,3 +571,5 @@ outage. | trigger, apply trigger (for an applier claim) | applier claim | the resource does not declare when to apply, and "trigger" already names watch-plan, API-surface and Argo Events triggers | | quiet branch | flush | no apply waits for a branch with nothing pending; it goes after a flush | | consumer (for what applies a `GitRepository`) | what applies it, `alsoAppliedBy` | consumer names the object a grant admits | +| push notification, push hook | push webhook, delivery | the host configures a push webhook, and it sends deliveries | +| shared endpoint (for `/audit-webhook`) | bare endpoint | the stream is what is shared; the endpoint is the path with no route | diff --git a/docs/future/task-oriented-docs-and-website.md b/docs/future/task-oriented-docs-and-website.md index 47ee57e27..2dacdc3d4 100644 --- a/docs/future/task-oriented-docs-and-website.md +++ b/docs/future/task-oriented-docs-and-website.md @@ -25,14 +25,14 @@ GitOps Reverser writes? If yes, follow the bi-directional path even when the imm to record cluster changes. An existing deployment loop needs coordination regardless of whether anyone plans to edit Git manually. -**Capture cluster state in Git.** This path reaches a verified commit without an applier claim or -a Git push webhook. Describe it as capturing selected cluster state: batching and restart recovery +**Mirror cluster state into Git.** This path reaches a verified commit without an applier claim or +a Git push webhook. Describe it as mirroring selected cluster state: batching and restart recovery mean Git history is not a complete record of every event. - **Install GitOps Reverser.** For a cluster administrator: prerequisites, credentials, permissions, - installation, a first captured change, verification, and cleanup. Keep the default path usable + installation, a first mirrored change, verification, and cleanup. Keep the default path usable without audit attribution. -- **Start capturing a team's resources.** For a platform administrator or team owner: choose the +- **Start mirroring a team's resources.** For a platform administrator or team owner: choose the source cluster, namespaces, resource selection, repository, branch, and folder. Cover adopting an existing repository through a scratch branch, supported layouts, deletion policy, and cross-namespace access. @@ -49,7 +49,7 @@ steps above. Explain who controls applying the folder and what happens when the operator is unavailable. - **React promptly to Git pushes.** Configure the Git host's push webhook and a `GitReceiver`. See the dedicated scope below. -- **Verify both directions.** Capture a Kubernetes edit, then push a Git edit and verify the +- **Verify both directions.** Mirror a Kubernetes edit, then push a Git edit and verify the coordinated apply. Installation happens at the platform level; onboarding repeats for each team or destination. Keep @@ -121,13 +121,14 @@ even where source material does. Proposed guides are named by task, not by filen | `docs/README.md` | Documentation landing page | Exists: organized around the four categories; link each new guide as it lands | | Root `README.md` | Homepage | Exists: reuse the product explanation and demo | | `alternatives.md` | Homepage: is this right for me? | Exists: link from adoption guidance | -| `quickstart.md` | Get started: capture | Exists: verify a first commit without an applier claim or push webhook | -| Team onboarding | Get started: capture | Missing: extract selection, sharing, and repository adoption from `configuration.md` and the root README; ask whether an applier deploys the folder | -| `github-setup-guide.md` | Get started: Git host | Exists: link to push-notification setup | -| `azure-devops-getting-started.md` | Get started: Git host | Exists: state the push-notification limit described below | +| `quickstart.md` | Get started: mirror | Exists: verify a first commit without an applier claim or push webhook | +| `team-onboarding.md` | Get started: mirror | Exists: grants, branch, folder, selection, scratch-branch adoption, deletion policy; asks whether an applier deploys the folder | +| `github-setup-guide.md` | Get started: Git host | Exists: link to the push webhook guide | +| `push-webhook.md` | Get started: coordination | Exists: receiver listener, route, `GitReceiver`, GitHub webhook, verification, rotation, and the Azure DevOps limit | +| `azure-devops-getting-started.md` | Get started: Git host | Exists: state the push webhook limit described below | | `attribution-setup-guide.md` | Get started: record who | Exists: keep its outcome and eligibility opening | | `audit-setup/cluster/readme.md` | Get started: record who | Exists: publish as the k3s example the attribution guide links | -| `bi-directional.md` | Get started: coordination overview | Needs split: keep the setup decision and common behavior; extract receiver setup into the push-notification guide and the everyday Git edit into Make changes | +| `bi-directional.md` | Get started: coordination overview | Needs split: keep the setup decision and common behavior; extract receiver setup into the push webhook guide and the everyday Git edit into Make changes | | `bi-directional-flux.md`, `bi-directional-argocd.md` | Get started: applier setup | Exists: link receiver setup and verify both directions | | `sops-age-guide.md`, `commit-signing.md` | Get started: supporting guides | Exists | | `kcp-workspaces.md` | Get started: supporting guides | Exists: kcp workspace mirroring and shared-stream attribution | @@ -136,7 +137,7 @@ even where source material does. Proposed guides are named by task, not by filen | `commit-messages.md` | Reference, linked from grouped changes | Exists: template reference | | Collaboration on a shared branch | Make changes | Missing: publication semantics and multi-author examples | | `api-first-publication.md` | Reference, linked from collaboration | Exists: shared publication contract | -| `installing-apps-as-krm.md` | Make changes | Exists: expanded example of choosing which declarations to capture | +| `installing-apps-as-krm.md` | Make changes | Exists: expanded example of choosing which declarations to mirror | | `interpreting-metrics.md` | Operate: monitor | Exists: shared metric reference | | Symptom-driven troubleshooting | Operate | Missing: gather diagnostic paths from configuration and metrics | | Stable upgrade procedure | Operate | Missing: steps and verification linking to release entries | @@ -150,10 +151,10 @@ even where source material does. Proposed guides are named by task, not by filen | API and command reference | Reference | Needs split: consolidate field and flag descriptions, find uncovered surfaces | | `INDEX.md`, `components.md`, `CONTRIBUTING.md`, `style-guide.md` | Maintainer entry point | Exists: link to repository pages | -## Push notifications as an explicit setup activity +## The push webhook as an explicit setup activity The outcome is "react promptly to Git pushes." Webhook setup is part of the normal bi-directional -path; capture-only installations complete setup without it. A Git-side commit leaves the cluster +path; an installation whose folder no applier applies completes setup without it. A Git-side commit leaves the cluster behind until the coordinated apply runs. Prompt notification shortens that interval and the opportunity for further Kubernetes edits to overlap the incoming change. @@ -172,7 +173,7 @@ stays authoritative for fields and delivery diagnostics. It covers: 3. Configure a GitHub push webhook with that URL and secret. Verify current host instructions when writing the walkthrough; link the GitLab, Gitea, and `generic-hmac` variants from the reference. 4. Follow the documented Flux or Argo CD rules for existing applier webhooks. Name audit delivery - and Git push notifications as separate webhook purposes. + and push webhooks as separate webhook purposes. 5. Push a known change and check host delivery, `GitBranch.status.lastPushNoticeAt`, the observed remote commit, and the applier's result. A successful HTTP response alone does not prove apply. 6. Diagnose unreachable endpoints, rejected signatures, repository URL mismatches, and unmatched @@ -254,9 +255,9 @@ source citations are unchanged. **Phase 2: Reading paths.** -- Capture-only installation through a first verified commit, as the shortest complete path. +- Mirror-only installation through a first verified commit, as the shortest complete path. - The missing onboarding, normal-change, collaboration, troubleshooting, and upgrade guides. -- The bi-directional path: applier setup, push notifications with a GitHub example, the Azure +- The bi-directional path: applier setup, the push webhook with a GitHub example, the Azure DevOps limit, and verification of both directions. - The marked splits and the attribution ordering. - Bring each source the manifest will publish under the prose gate. Measured on 2026-10-26, these diff --git a/docs/interpreting-metrics.md b/docs/interpreting-metrics.md index 9d4498661..0c3608789 100644 --- a/docs/interpreting-metrics.md +++ b/docs/interpreting-metrics.md @@ -971,8 +971,8 @@ sum by (outcome) (rate(gitopsreverser_audit_eventlist_duration_seconds_count[5m] **Per-event census.** `audit_events_total` increments exactly once per decoded event. `category` is the coarse bucket of `outcome` (carried as its own label so the health invariant is a simple -selector). `audit_route` is the route the event was posted under, `/audit-webhook/` or the -shared endpoint's annotation, when some `KubeProvider` declares it; `unrecognized` when none does, +selector). `audit_route` is the route the event was posted under, `/audit-webhook/` or, on the +bare endpoint, the event's annotation, when some `KubeProvider` declares it; `unrecognized` when none does, and `none` for an event that names no route. A route is producer-chosen text, so only declared ones become label values. A fresh pod reads every route as `unrecognized` until its `KubeProvider`s have reconciled, which takes seconds. diff --git a/docs/kcp-workspaces.md b/docs/kcp-workspaces.md index a6236f070..71ef04649 100644 --- a/docs/kcp-workspaces.md +++ b/docs/kcp-workspaces.md @@ -9,7 +9,7 @@ The guide has two parts, and you can stop after the first: - **Mirror a workspace** ([step 1](#1-connect-each-workspace)). Each workspace is reached through its own `KubeProvider`, like any other remote cluster. Nothing about it is kcp-specific, and every commit is authored by the configured committer. -- **Name each change's author** ([steps 2–4](#2-turn-on-the-shared-audit-endpoint)). This is where +- **Name each change's author** ([steps 2–4](#2-turn-on-the-bare-endpoint)). This is where kcp differs from an ordinary cluster: one kcp shard sends the audit events of all its workspaces in a single stream, so GitOps Reverser has to tell from each event which workspace it came from. @@ -24,7 +24,7 @@ The guide has two parts, and you can stop after the first: For commit authors you also need: -- Attribution enabled, with a place to keep author facts until the matching change arrives: +- Author attribution enabled, with a place to keep author facts until the matching change arrives: Redis/Valkey, or `memory` for a single replica. See [step 1 of the attribution guide](attribution-setup-guide.md#1-enable-the-receiver). - Access to the audit configuration of every kcp shard: the kcp-operator's `RootShard` and `Shard` @@ -39,9 +39,8 @@ For commit authors you also need: readable and is what `kubectl ws` navigates. This guide uses the logical cluster name everywhere. - **Audit route:** the label GitOps Reverser files each author fact under. A `KubeProvider` reads the facts of exactly one route, its `spec.attribution.auditRoute`. -- **Shared audit endpoint:** `/audit-webhook` with no route in the path. It reads each event's - route from an annotation on the event, so one stream can carry many workspaces. The - configuration reference calls it the bare endpoint. The ordinary, +- **Bare endpoint:** `/audit-webhook` with no route in the path. It reads each event's route from + an annotation on the event, so one shared audit stream can carry many workspaces. The ordinary, **named** endpoint `/audit-webhook/` files every event it receives under that one route. ## How the pieces fit @@ -50,7 +49,7 @@ For commit authors you also need: flowchart LR user["Workspace user
kubectl apply"] --> fp["kcp front-proxy"] fp --> shard["kcp shard
serves many workspaces"] - shard -- "one audit stream
each event tagged kcp.io/cluster" --> bare["GitOps Reverser
shared /audit-webhook"] + shard -- "one audit stream
each event tagged kcp.io/cluster" --> bare["GitOps Reverser
bare /audit-webhook"] kp["KubeProvider shop-workspace
auditRoute: 2nhnb6jpthl8l7z5"] -- "watch via
/clusters/2nhnb6jpthl8l7z5" --> fp bare -- "fact filed under
route 2nhnb6jpthl8l7z5" --> join["join: watch event + audit fact"] kp --> join @@ -63,7 +62,7 @@ GitOps Reverser names an author by joining two streams that arrive separately: 2. The **audit fact**: who made the change, built from the shard's audit event. The kcp shard tags every audit event with the logical cluster name of the workspace it served, in -the `kcp.io/cluster` annotation. The shared endpoint files each event under that name as its +the `kcp.io/cluster` annotation. The bare endpoint files each event under that name as its route. So the join works exactly when a workspace's `KubeProvider` carries that workspace's logical cluster name as its `spec.attribution.auditRoute`. @@ -136,7 +135,7 @@ shapes. kcp also accepts the path in the URL (`/clusters/root:shop`), and mirroring works either way. Using the logical cluster name in both the URL and `auditRoute` leaves one value to check. Setting -`auditRoute` now costs nothing while attribution is off, and saves a second edit later. +`auditRoute` now costs nothing while author attribution is off, and saves a second edit later. The kubeconfig must embed its credentials. One that runs an exec plugin, skips TLS verification, or names a file is refused, as described under [`KubeProvider`](configuration.md#kubeprovider). @@ -190,9 +189,9 @@ Three things differ from a cluster with its own API server: Mirroring works at this point, and every commit is authored by the configured committer. If that is all you need, you are done. The next steps add the commit author. -## 2. Turn on the shared audit endpoint +## 2. Turn on the bare endpoint -Set the annotation key in the chart values, together with attribution: +Set the annotation key in the chart values, together with author attribution: ```yaml attribution: @@ -201,7 +200,7 @@ attribution: ``` The chart passes it to the operator as -`--author-attribution-audit-route-annotation-key=kcp.io/cluster`. That turns on the shared +`--author-attribution-audit-route-annotation-key=kcp.io/cluster`. That turns on the bare `/audit-webhook` endpoint, which reads each event's route from its `kcp.io/cluster` annotation. One batch from a shard can therefore hold events for many workspaces, and each is filed under its own route. @@ -209,7 +208,7 @@ route. If you also attribute changes made in the control cluster itself, keep its API server on its named route, `/audit-webhook/.local`, as in the [attribution guide](attribution-setup-guide.md#2-configure-delivery-on-every-api-server). Its -events carry no `kcp.io/cluster` annotation, and the shared endpoint drops an event without one +events carry no `kcp.io/cluster` annotation, and the bare endpoint drops an event without one instead of guessing a route. ## 3. Deliver every shard's audit stream @@ -219,7 +218,7 @@ Every shard sends its own stream, so configure each one: the `RootShard` and eve Build the webhook kubeconfig as in the [attribution guide](attribution-setup-guide.md#2-configure-delivery-on-every-api-server), with mutual TLS, `tls-server-name`, and an address the shard can reach. The Service name below works -when the shard runs in the control cluster. End the `server` URL at the shared endpoint, with no +when the shard runs in the control cluster. End the `server` URL at the bare endpoint, with no route after it: ```yaml @@ -304,8 +303,8 @@ Start from the provider's `AuditFactsReceived` reason, then the audit metrics de | `AuditFactsReceived=Unknown`, reason `RouteUnused` | Audit arrives, and none of it names this provider's route. Usually `spec.attribution.auditRoute` differs from the workspace's `spec.cluster` | Compare the `ROUTE` column with `kubectl get workspace -o jsonpath='{.spec.cluster}'` in the parent workspace | | `AuditFactsReceived=Unknown`, reason `NoAuditDelivery` | No audit request has reached the operator on any route | Check the shard's `spec.audit.webhook`, its Secret, and network reach to port 9444 | | A steady rate of `audit_events_total{audit_route="unrecognized"}` | Events name a logical cluster no `KubeProvider` carries | Harmless for a workspace you do not mirror. Otherwise a mistyped `auditRoute` | -| A rising rate of `audit_events_total{outcome="missing_cluster_annotation"}` | Something posts to the shared endpoint without the annotation | Usually the control cluster's API server pointed at `/audit-webhook`. Give it its named route | -| The shard's webhook gets HTTP 400 | The shared endpoint is off: `attribution.auditRouteAnnotationKey` is unset | Set it ([step 2](#2-turn-on-the-shared-audit-endpoint)) | +| A rising rate of `audit_events_total{outcome="missing_cluster_annotation"}` | Something posts to the bare endpoint without the annotation | Usually the control cluster's API server pointed at `/audit-webhook`. Give it its named route | +| The shard's webhook gets HTTP 400 | The bare endpoint is off: `attribution.auditRouteAnnotationKey` is unset | Set it ([step 2](#2-turn-on-the-bare-endpoint)) | | `Stalled=True`, reason `AuditRouteConflict` | A provider in another namespace already holds this logical cluster name | Keep one workspace's providers in one namespace | ## How kcp tags the shared audit stream @@ -372,7 +371,7 @@ known to be bookkeeping. ## The trust boundary -The shared endpoint trusts the shard. Audit ingress checks the client certificate against the +The bare endpoint trusts the shard. Audit ingress checks the client certificate against the shared audit CA, and any sender holding that credential can submit facts under any route. That is the [shared audit-ingress trust model](../SECURITY.md#shared-audit-ingress-trust-model): suitable when one privileged control plane, here kcp, serves every participating source and protects the @@ -396,7 +395,7 @@ shard stream and the same route as the user's other changes. - [`KubeProvider`](configuration.md#kubeprovider): credentials, grants, and the audit route. - [Route a shared audit stream by event annotation](configuration.md#route-a-shared-audit-stream-by-event-annotation): - the rejection rules of the shared endpoint. + the rejection rules of the bare endpoint. - [Attribute commits to Kubernetes users](attribution-setup-guide.md): the receiver, the webhook kubeconfig, and the audit policy. - [Interpreting metrics](interpreting-metrics.md): `audit_events_total` and its `audit_route` label. diff --git a/docs/push-webhook.md b/docs/push-webhook.md new file mode 100644 index 000000000..3723712d3 --- /dev/null +++ b/docs/push-webhook.md @@ -0,0 +1,250 @@ +# React promptly to Git pushes + +This guide makes GitOps Reverser notice a push by somebody else within seconds, by pointing the Git +host's push webhook at it. It is for a platform administrator whose folder Flux or Argo CD also +applies, following the [bi-directional path](README.md#coordinate-changes-from-kubernetes-and-git). +It ends with a test push whose apply you watch reach the cluster. + +## Why it matters + +When someone pushes to a branch GitOps Reverser writes, the cluster runs the old content until the +coordinated apply runs. While it waits, more Kubernetes edits can pile up on top of a branch that +has already moved. A push webhook shortens that wait from minutes to seconds. + +Without one, GitOps Reverser still finds the push, only later: + +| How it finds out | When | +| --- | --- | +| A push webhook, which this guide sets up | Seconds after the push | +| Its own next push is rejected because the branch moved | At the next publication, which needs a Kubernetes edit to happen | +| The periodic refresh | Within `--git-refresh-interval` (`10m`) plus the 5-minute reconcile tick | + +Flux's or Argo CD's own polling does not help here: in a coordinated folder GitOps Reverser decides +when the applier applies, so the applier waits for it. + +**Skip this guide when nothing applies the folder.** If no applier applies the folder back to the +cluster, a push by somebody else is found at the next publication and replayed safely. There the +webhook brings two smaller gains. GitOps Reverser learns of the push sooner. And when the push lands +on an idle branch, the next publication is a little faster: the delivery fetches the new commit +ahead of time, so the publication's push is accepted on the first attempt, instead of being +rejected and then fetching and pushing again. (On a busy branch, the delivery publishes right away +and that push is rejected as before.) +[What the network saving measures](api-first-publication.md#what-the-network-saving-measures) +counts the requests. + +### Two kinds of webhook + +GitOps Reverser serves two unrelated webhook endpoints. Keep them apart when you read logs and +configure routes: + +| | Push webhook (this guide) | Audit webhook ([author attribution](attribution-setup-guide.md)) | +| --- | --- | --- | +| Sent by | The Git host, on a push | The Kubernetes API server, on every request | +| Tells GitOps Reverser | The branch moved | Who made a change | +| Authenticated by | An HMAC signature or token over the body | A client certificate (mutual TLS) | +| Listener | Port `9292`, plain HTTP behind your TLS route | Port `9444`, TLS | + +## Before you start + +- A `GitProvider`, `GitBranch`, and `GitTarget` that already write the branch. A delivery wakes only + a branch that some `GitTarget` writes. +- A way to expose an HTTP Service to your Git host over HTTPS: an Ingress controller or a Gateway, + with a certificate the host trusts. +- Admin rights on the repository (or the organization) to add a webhook. + +The examples use GitHub, a provider for `git@github.com:acme/platform.git` in namespace `team-a`, and +the chart installed as `gitops-reverser` in namespace `gitops-reverser`. + +## 1. Turn on the receiver listener + +The listener is off by default. Turn it on in the chart: + +```bash +helm upgrade gitops-reverser oci://ghcr.io/configbutler/charts/gitops-reverser \ + --namespace gitops-reverser --reuse-values \ + --set servers.receiver.enabled=true +``` + +The chart passes `--receiver-bind-address=:9292` and adds a `gitops-reverser-receiver` Service on +port `80`. Check it: + +```bash +kubectl -n gitops-reverser get service gitops-reverser-receiver +``` + +## 2. Expose it over HTTPS + +The listener speaks plain HTTP, so put a route in front of it that terminates TLS, the same way +Flux's `webhook-receiver` is usually exposed. Every delivery path starts with `/git-push/`, so you +can route only that prefix. With an Ingress (adjust the class, host, and certificate to your +cluster): + +```yaml +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: gitops-reverser-receiver + namespace: gitops-reverser +spec: + ingressClassName: nginx + tls: + - hosts: [hooks.example.com] + secretName: hooks-example-com-tls + rules: + - host: hooks.example.com + http: + paths: + - path: /git-push/ + pathType: Prefix + backend: + service: + name: gitops-reverser-receiver + port: + number: 80 +``` + +Exposing the route is safe: a request reaches nothing unless it carries a valid signature for a +path a `GitReceiver` publishes, and every other request gets the same `404`. + +## 3. Create the token and the `GitReceiver` + +Generate a long random token, store it under the key `token`, and create a `GitReceiver` beside it: + +```bash +kubectl -n team-a create secret generic platform-receiver \ + --from-literal=token="$(openssl rand -hex 32)" +``` + +```yaml +apiVersion: configbutler.ai/v1alpha3 +kind: GitReceiver +metadata: + name: platform + namespace: team-a +spec: + type: github # github | gitlab | gitea | generic-hmac + secretRef: + name: platform-receiver +``` + +No `GitProvider` names the receiver. A verified delivery wakes every `GitProvider`, in any +namespace, whose `spec.url` names the repository the delivery reports. So one `GitReceiver` serves +a GitHub organization webhook or a GitHub App, which deliver for many repositories through one URL. +The `token` key is the one a Flux `Receiver` Secret uses, so you can copy an existing Secret over. + +Read the webhook path the receiver publishes. `-o wide` adds the `PATH` column: + +```bash +kubectl -n team-a get gitreceiver platform -o wide +``` + +`READY` is `True` once the token is readable and the listener is on. The path looks like +`/git-push/3f9a…c41e`: 64 hex characters derived from the token, so only whoever holds the token can +find it. While the Secret is missing, the path stays empty and the receiver looks again every +30 seconds. + +## 4. Add the webhook on the Git host + +On GitHub, open the repository's **Settings → Webhooks → Add webhook** (or the organization's, for +every repository at once) and fill in: + +| Field | Value | +| --- | --- | +| Payload URL | `https://hooks.example.com` followed by the receiver's path | +| Content type | `application/json` (`application/x-www-form-urlencoded` also works) | +| Secret | The token from step 3 | +| Which events | Just the `push` event | +| Active | Checked | + +GitHub sends a `ping` when you save. The receiver answers `202` and ignores it, so a green check +next to the ping in **Recent Deliveries** proves that the route and the secret both work. + +For other hosts, use the same steps with the matching `spec.type`. The +[`GitReceiver` reference](configuration.md#gitreceiver) lists which header each type verifies and +which payload fields name the repository: + +- **GitLab:** `type: gitlab`. Put the token in the webhook's **Secret token** field. +- **Gitea:** `type: gitea`. Put the token in the webhook's **Secret** field. +- **Azure DevOps** has no receiver type. GitOps Reverser finds Azure DevOps pushes through the + fallback paths in + [why it matters](#why-it-matters), with their latency. Prompt notification needs a relay of your + own that re-signs each delivery as `generic-hmac`; no tested relay is documented yet. + +## 5. Settle the applier's own webhook + +Flux and Argo CD may already receive a push webhook for this repository. What to do with it +depends on the applier: + +- **Flux:** remove the Flux `Receiver` for this repository. GitOps Reverser's receiver replaces it, + and GitOps Reverser asks Flux to apply when the branch is ready. See + [the Flux setup](bi-directional-flux.md). +- **Argo CD:** its `/api/webhook` can stay. With automated sync off, an Argo CD refresh only + compares and applies nothing. See [the Argo CD setup](bi-directional-argocd.md). + +## 6. Verify with a test push + +Push a small change to the branch from Git, as a person would: edit a file in the folder and push +it, or commit through the host's web editor. + +1. **The host delivered it.** In the webhook's **Recent Deliveries**, the push has response `202`. +2. **GitOps Reverser received it.** The `GitBranch` records when a delivery last reached it: + + ```bash + kubectl -n team-a get gitbranch main -o jsonpath='{.status.lastPushNoticeAt}{"\n"}' + ``` + +3. **It saw the new commit.** The `GitBranch`'s `COMMIT` column shows the commit you pushed: + + ```bash + kubectl -n team-a get gitbranch main + ``` + +4. **The applier applied it.** The applier claim's `OPERATION` column moves through `Requested` and + `Running` to `Succeeded`, and `-o wide` shows the commit it applied: + + ```bash + kubectl -n team-a get fluxclaim -o wide # or: get argocdclaim -o wide + ``` + +Then check the object you changed in the cluster. A `202` alone does not prove the apply: it only +says the delivery was verified. + +## When a push is not noticed + +Start at the host's delivery log, then the `GitBranch`, then the receiver's metric +`gitopsreverser_receiver_deliveries_total`, whose `outcome` label separates the causes: + +| What you see | Cause | Fix | +| --- | --- | --- | +| The host reports a timeout or connection error | The route does not reach the receiver | Check the Ingress or Gateway, its certificate, and that the `gitops-reverser-receiver` Service has an endpoint | +| The host gets `404` | Wrong path or wrong secret; both answer `404` on purpose | The operator's log says which. Compare the URL with `kubectl get gitreceiver -o wide`, and the host's secret with the Secret's `token` | +| `404` right after a token change | Rotating the token moved the path | Update the webhook URL as well as its secret | +| `202`, but `lastPushNoticeAt` stays empty, and the metric counts `unknown_repository` | The delivery names the repository by a URL no `GitProvider` matches, such as an SSH host alias | Spell the provider's `spec.url` with the hostname the Git host uses, such as `github.com`. Scheme, user, `.git`, and letter case do not matter; the host and path do | +| `202`, metric counts `unknown_branch` | No `GitTarget` writes that branch through a matching provider | Expected for other branches. For yours, check that a `GitTarget` names the `GitBranch` | +| `lastPushNoticeAt` is set, but nothing is applied | The delivery arrived; the apply is the next step | Read the applier claim's `status.operation` and the `GitTarget`'s `ApplierClaimReady` condition | +| The host gets `429` or `413` | More than 8 deliveries at once, or a body over 2 MiB | Nothing to fix; the periodic refresh finds the push | +| `GitReceiver` `READY=False` | `SecretNotFound`, `SecretMalformed` (no `token` key), or `ListenerDisabled` | Fix the Secret, or [turn the listener on](#1-turn-on-the-receiver-listener) | + +`unknown_repository` and `unknown_branch` are routine on an organization or GitHub App webhook, +which delivers for every repository and branch. + +## Rotate the token + +1. Write a new value into the Secret's `token` key. +2. Wait for the new `PATH` on the `GitReceiver`, published at its next reconcile (within about + 5 minutes). The old path stops serving at once, because every delivery reads the token afresh. +3. Update both the webhook URL and its secret on the host. + +Pushes made between steps 2 and 3 are found by the periodic refresh. GitHub's **Redeliver** button +also sends a missed delivery again. + +## Reference + +- [`GitReceiver`](configuration.md#gitreceiver): fields, verification per host type, routing, and + every response code. +- [Push receiver settings](configuration.md#push-receiver-settings): the listener flag and chart + values. +- [Telling GitOps Reverser that somebody else pushed](bi-directional.md#telling-gitops-reverser-that-somebody-else-pushed): + how a delivery feeds the apply decision. +- [Interpreting metrics](interpreting-metrics.md#apply-requests-and-the-push-receiver): the + receiver and apply metrics, with alert queries. diff --git a/docs/team-onboarding.md b/docs/team-onboarding.md new file mode 100644 index 000000000..ed444f589 --- /dev/null +++ b/docs/team-onboarding.md @@ -0,0 +1,322 @@ +# Start mirroring a team's resources + +This guide takes one team from nothing to its resources landing in a folder of the team's +repository, ending at a first commit you can inspect. It is for a platform administrator onboarding +a team on an existing installation, and for the team owner who then decides what to mirror. + +It assumes GitOps Reverser is installed. If it is not, follow the [quick start](quickstart.md) +first. You can repeat this guide for every team on the same installation. + +## First: does Flux or Argo CD apply the folder? + +Ask this before you pick the folder. If Flux or Argo CD applies the folder this team's resources +will be written to, the two tools need coordinating, or each commit GitOps Reverser makes is applied +back over edits still in flight. In that case, finish this guide on a +[scratch branch](#adopt-an-existing-repository-safely) that nothing deploys, then follow +[bi-directional GitOps](bi-directional.md) before you point the team at the deployed folder. + +If nothing applies the folder, or Flux and Argo CD apply only other folders, this guide is all you +need. + +## The six choices + +Onboarding a team means making six choices. Each one is an object, and each object has an owner: + +| Choice | Example in this guide | Object | Usually owned by | +| --- | --- | --- | --- | +| The repository and its credential | `git@github.com:acme/platform.git` | `GitProvider` + Secret | Platform | +| The source cluster | The control cluster, which the operator runs in | `KubeProvider` | Platform | +| The branch | `main` | `GitBranch` | Platform for a shared branch, the team for its own | +| The folder | `teams/team-a` | `GitTarget` | Team | +| The namespaces | `team-a` | `WatchRule` and the provider's grant | Team, within the platform's grant | +| The resource types | Deployments, Services, ConfigMaps | `WatchRule` | Team | + +![A platform namespace holds the shared GitProvider with its credentials Secret, a KubeProvider and +a GitReceiver; each team namespace has its own WatchRule and GitTarget writing its own branch of that +repository, and a push event is routed by repository and branch to the GitTarget that writes +it](images/config-platform-shared.excalidraw.svg) + +The objects that hold credentials (`GitProvider`, `KubeProvider`) stay in the platform's namespace +with their Secrets. The team's objects live in the team's namespace and reach the shared ones by +reference. A shared object admits only the namespaces its **grants** list, so the platform decides +what each team may use, and the team decides what to do with it. + +The examples use these names: + +- `platform`: the platform team's namespace, holding the repository credential. +- `gitops-reverser`: the chart's release namespace, holding the chart's `local` `KubeProvider`. +- `team-a`: the team's namespace, which is also the namespace it wants mirrored. + +## 1. Platform: connect the repository + +Skip this step if a `GitProvider` for the repository exists; add the grant from step 3 to it +instead. Otherwise create the credential Secret as in the [quick start](quickstart.md) or the +[GitHub guide](github-setup-guide.md), in `platform`, and a `GitProvider` beside it: + +```yaml +apiVersion: configbutler.ai/v1alpha3 +kind: GitProvider +metadata: + name: platform-repo + namespace: platform +spec: + url: git@github.com:acme/platform.git + secretRef: + name: git-creds + allowedGitBranches: + - consumerNamespaces: {from: Same} + branchPatterns: [main] +``` + +`allowedGitBranches` has no default: without a grant, not even the provider's own namespace may use +the credential. This grant lets a `GitBranch` in `platform` hold `main`. + +## 2. Platform: hold the branch, and let the team write through it + +One `GitBranch` holds a repository branch for everybody who writes it. For a shared branch such as +`main`, the platform owns it and lists who may write through it: + +```yaml +apiVersion: configbutler.ai/v1alpha3 +kind: GitBranch +metadata: + name: main + namespace: platform +spec: + gitProviderRef: + name: platform-repo + branch: main + allowedGitTargets: + - consumerNamespaces: {from: Same} + - consumerNamespaces: {from: Names, names: [team-a]} +``` + +Add each new team to the `names` list. Check that the branch is held: + +```bash +kubectl -n platform get gitbranch main +``` + +`READY` is `True` once the credential could open a push session on the repository. `False` with +reason `PushSessionFailed` means the Secret is missing, wrong, or lacks push permission. + +**A branch of the team's own** is the alternative: a grant on the `GitProvider` such as +`branchPatterns: ["teams/{consumer.namespace}/*"]` lets the team create its own `GitBranch` and +decide who shares it. [One tenant, end to end](configuration.md#one-tenant-end-to-end) shows that +shape. + +## 3. Platform: let the team mirror its namespace + +The `KubeProvider` decides which namespaces' `GitTarget`s may read the cluster, and which source +namespaces they may read. The chart's `local` provider is configured through Helm values. A list you +set is the whole policy, so keep the release namespace's own grant if anything there still uses it: + +```yaml +# values.yaml +kubeProvider: + allowedGitTargets: + - consumerNamespaces: {from: Same} + sourceNamespaces: ["{consumer.namespace}"] + - consumerNamespaces: {from: Names, names: [team-a]} + sourceNamespaces: ["{consumer.namespace}"] +``` + +```bash +helm upgrade gitops-reverser oci://ghcr.io/configbutler/charts/gitops-reverser \ + --namespace gitops-reverser --reuse-values -f values.yaml +``` + +`{consumer.namespace}` is the namespace of the `GitTarget` asking, so `team-a` may mirror `team-a` +and nothing else. Two other common shapes: + +- **Many teams at once:** `from: Selector` with a namespace label the platform controls, such as + `platform.example.com/tenant: "true"`. Keep labeling namespaces a platform permission, so a + team cannot grant itself access. +- **A remote cluster:** a `KubeProvider` of your own with a kubeconfig Secret, carrying the same + grant in its `spec.allowedGitTargets`. See + [creating and managing a `KubeProvider`](configuration.md#creating-and-managing-a-kubeprovider). + +[The grants](configuration.md#the-grants) explains every shape, and +[RBAC](rbac.md) explains what the operator's own identity can read. + +## 4. Platform: let the team create its objects + +The chart ships no Role for people who create GitOps Reverser objects. Give the team one in its +namespace, for example: + +```yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: gitops-reverser-editor + namespace: team-a +rules: + - apiGroups: [configbutler.ai] + resources: [gittargets, watchrules, commitrequests] + verbs: [get, list, watch, create, update, patch, delete] +``` + +Bind it to the team's group with a `RoleBinding`. Add `gitbranches` when the team owns its own +branch. + +## 5. Team: choose the folder + +A `GitTarget` names the folder, the branch, and the source cluster: + +```yaml +apiVersion: configbutler.ai/v1alpha3 +kind: GitTarget +metadata: + name: apps + namespace: team-a +spec: + gitBranchRef: + name: main + namespace: platform + kubeProviderRef: + name: local + namespace: gitops-reverser + path: teams/team-a +``` + +- `spec.path` is relative to the repository root. Two `GitTarget`s on one branch cannot write the + same or nested folders; the later one reports `TargetConflict`. +- `spec.gitBranchRef` and `spec.kubeProviderRef` are immutable. To change either, create a new + `GitTarget` and delete the old one. +- `spec.prune.mode` decides when a document leaves Git. The default, `OnEvent`, removes a document + when its resource is deleted, and never on a guess. See + [the deletion policy](#choose-the-deletion-policy). + +The [`GitTarget` reference](configuration.md#gittarget) covers commit timing, messages, encryption, +and placement. + +## 6. Team: choose what to mirror + +A `WatchRule` selects the resource types, and optionally labels, that the target mirrors from the +team's namespace: + +```yaml +apiVersion: configbutler.ai/v1alpha3 +kind: WatchRule +metadata: + name: apps + namespace: team-a +spec: + gitTargetRef: + name: apps + rules: + - apiGroups: ["apps"] + resources: [deployments] + - apiGroups: [""] + resources: [services, configmaps] +``` + +Each rule item watches the `WatchRule`'s own namespace unless it names another in +`sourceNamespace`, which the provider's grant must allow. `objectSelector` narrows a rule to objects +with matching labels. + +Mirror the resources that express intent, and leave out what controllers generate from them: a +`Deployment` and not its `ReplicaSet`s and `Pod`s, a Flux `HelmRelease` and not the workloads it +renders. GitOps Reverser cannot tell an authored object from a generated one. See +[choosing what to capture](installing-apps-as-krm.md#the-design-decision-capture-intent-not-the-rendered-output). + +## 7. Verify the first commit + +Check the team's objects: + +```bash +kubectl -n team-a get gittarget,watchrule +kubectl -n team-a wait --for=condition=Validated gittarget/apps --timeout=60s +``` + +`Validated` means the grants admit the target. The rule's `READY` turns `True` once its watches +run. Then pull the branch: the first commit holds the selected resources that already exist in +`team-a`, under `teams/team-a`. Create a ConfigMap and a second commit follows within seconds: + +```bash +kubectl -n team-a create configmap onboarding-check --from-literal=check=1 +``` + +Delete it afterward; under the default deletion policy, that removes its file in a third commit. + +## Adopt an existing repository safely + +When the folder already holds manifests, see what GitOps Reverser does with them before it writes +`main`. Point a preview target at a **scratch branch** that nothing deploys, started from `main`: + +```yaml +apiVersion: configbutler.ai/v1alpha3 +kind: GitBranch +metadata: + name: preview + namespace: platform +spec: + gitProviderRef: + name: platform-repo + branch: gitops-preview/team-a + parentBranch: main + allowedGitTargets: + - consumerNamespaces: {from: Names, names: [team-a]} +``` + +The `GitProvider`'s grant must allow `gitops-preview/*` as well. A `GitTarget` naming this branch +compares the cluster with the folder on `main`, and creates `gitops-preview/team-a` only when it has +something to commit. Read those commits as a normal diff: which files changed, which documents were +added, and where new ones were placed. When you are satisfied, delete the preview `GitTarget` and +create the one for `main`. The preview cannot disturb the folder on `main`, because a `GitTarget` +cannot change branch. + +What it can edit depends on how the folder is written: + +| The folder holds | What GitOps Reverser does | +| --- | --- | +| Plain Kubernetes manifests | Updates existing documents in place, and adds new ones | +| A supported Kustomize layout | Edits source manifests, image and replica declarations, and `configMapGenerator` inputs; adds and removes resources | +| A Flux `HelmRelease` or Argo CD `Application` | Mirrors the declaration, including chart versions and inline values | +| Helm templates, or a layout it cannot edit safely | Refuses the folder before writing anything: `Stalled=True`, with the reason in `GitPathAccepted` | + +The [Kustomize support in the target path](configuration.md#kustomize-support-in-the-target-path) +section lists the exact subset. To inspect a repository without a cluster, use the +`manifest-analyzer` CLI. + +### Choose the deletion policy + +A document can leave Git for two reasons: the resource was deleted, or a fresh snapshot of the +cluster no longer contains it. `spec.prune.mode` treats them separately: + +| Mode | A resource is deleted | A document has no resource in the snapshot | Use it for | +| --- | --- | --- | --- | +| `OnEvent` (default) | Removed | Kept | Adopting a folder: files that match nothing in the cluster stay | +| `Always` | Removed | Removed | A folder that should match the cluster exactly | +| `Never` | Kept | Kept | An archive that only ever gains documents | + +Start with `OnEvent` when the folder already holds files. `Always` deletes every file the snapshot +does not account for, so a watch rule narrower than you meant becomes deleted manifests. +[The deletion policy reference](configuration.md#deletion-policy-specprunemode) explains the risk in +full. + +## When nothing is committed + +Start at the `GitTarget`'s `READY` reason, then the `WatchRule`'s: + +| Reason | On | Cause | +| --- | --- | --- | +| `BranchNotAllowed` | `GitBranch` | No grant on the `GitProvider` allows the branch for this namespace | +| `PushSessionFailed` | `GitBranch` | The credential cannot push: Secret, host keys, or permissions | +| `BranchConflict` | `GitBranch` | Another `GitBranch` already holds this repository branch. Reference that one | +| `NamespaceNotAuthorized` | `GitTarget` | The `GitBranch` or the `KubeProvider` has no grant admitting the team's namespace | +| `KubeProviderNotFound` | `GitTarget` | `spec.kubeProviderRef` names no provider. Check the namespace | +| `TargetConflict` | `GitTarget` | Another target on the branch writes the same or a nested folder | +| `UnsupportedContent`, or `GitPathAccepted=False` | `GitTarget` | The folder holds something it cannot edit safely. The message names the file | +| `SourceNamespaceNotAllowed` | `WatchRule` | A rule item names a namespace the provider's grant does not allow | + +[Why a `GitTarget` is not committing](configuration.md#why-a-gittarget-is-not-committing) walks +through every condition. + +## Next steps + +- [Record who made each change](attribution-setup-guide.md), so commits name the Kubernetes user + as author. +- [Group related changes into one commit](demo/commit-window.md) with a `CommitRequest`. +- [Encrypt Secrets with SOPS and age](sops-age-guide.md) before mirroring `Secret`s. +- If Flux or Argo CD applies the folder: [bi-directional GitOps](bi-directional.md). From df91e35ea3249d1d0fda3c74856aba57700c7189 Mon Sep 17 00:00:00 2001 From: Simon Koudijs Date: Fri, 27 Nov 2026 15:28:56 +0000 Subject: [PATCH 3/3] docs: address review comments on the push webhook and onboarding guides - definitions.md: a delivery is verified before its body is parsed (the bounded body is read first), the metric carries its exported name, and a push webhook proves itself with a shared token (GitLab sends the token, it does not sign the body). - push-webhook.md: show how to read the token back for the Git host, and continue from the Flux and Argo CD guides' GitBranch `platform-main`. - team-onboarding.md: an existing GitProvider needs the allowedGitBranches grant from step 1, and its own name in place of `platform-repo`. Co-Authored-By: Claude Opus 5.5 --- docs/definitions.md | 14 +++++++------- docs/push-webhook.md | 17 ++++++++++++----- docs/team-onboarding.md | 7 ++++--- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/definitions.md b/docs/definitions.md index 85894e572..69be15022 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -339,11 +339,11 @@ host-side configuration and the capability as a whole. Not "push notification" o **Push event.** The Git host's own name for what a push webhook reports: one push, naming a repository, a branch, and the commit it moved to. GitHub, GitLab and Gitea all call it that. -**Delivery.** One request a push webhook sends to a receiver, carrying one push event. Its signature -is checked before its body is read, and a verified delivery is only a hint (see **Receiver**). -`receiver_deliveries_total` counts deliveries by `outcome`, and `GitBranch.status.lastPushNoticeAt` -records when one last reached the branch. The **audit webhook** sends requests too; call those -audit requests, so "delivery" stays with the push webhook. +**Delivery.** One request a push webhook sends to a receiver, carrying one push event. It is +verified before its body is parsed, and a verified delivery is only a hint (see **Receiver**). +`gitopsreverser_receiver_deliveries_total` counts deliveries by `outcome`, and +`GitBranch.status.lastPushNoticeAt` records when one last reached the branch. The **audit webhook** +sends requests too; call those audit requests, so "delivery" stays with the push webhook. ## Attribution @@ -369,8 +369,8 @@ a provider there carries it, otherwise the namespace of the oldest provider carr elsewhere that carries it is not used (`AuditRouteConflict`), so no namespace reads another's facts. **Audit webhook.** The kube-apiserver's audit webhook backend, configured to post audit events to the -operator's audit listener. It authenticates with a client certificate, where a push webhook signs -its body, which is why the two never share a listener. A bare "webhook" is ambiguous wherever both +operator's audit listener. It authenticates with a client certificate, where a push webhook proves +itself with a shared token, which is why the two never share a listener. A bare "webhook" is ambiguous wherever both could be meant: say which. **Named endpoint, bare endpoint.** The two paths the audit listener serves. A **named endpoint**, diff --git a/docs/push-webhook.md b/docs/push-webhook.md index 3723712d3..a227fedf1 100644 --- a/docs/push-webhook.md +++ b/docs/push-webhook.md @@ -52,8 +52,9 @@ configure routes: with a certificate the host trusts. - Admin rights on the repository (or the organization) to add a webhook. -The examples use GitHub, a provider for `git@github.com:acme/platform.git` in namespace `team-a`, and -the chart installed as `gitops-reverser` in namespace `gitops-reverser`. +The examples use GitHub and continue from [the Flux](bi-directional-flux.md) or +[Argo CD setup](bi-directional-argocd.md): the `GitBranch` `platform-main` in namespace `team-a`, and +the chart installed as `gitops-reverser` in namespace `gitops-reverser`. Use your own names. ## 1. Turn on the receiver listener @@ -152,10 +153,16 @@ every repository at once) and fill in: | --- | --- | | Payload URL | `https://hooks.example.com` followed by the receiver's path | | Content type | `application/json` (`application/x-www-form-urlencoded` also works) | -| Secret | The token from step 3 | +| Secret | The token from step 3 (see below) | | Which events | Just the `push` event | | Active | Checked | +Read the token back from the Secret to paste it: + +```bash +kubectl -n team-a get secret platform-receiver -o jsonpath='{.data.token}' | base64 -d; echo +``` + GitHub sends a `ping` when you save. The receiver answers `202` and ignores it, so a green check next to the ping in **Recent Deliveries** proves that the route and the secret both work. @@ -190,13 +197,13 @@ it, or commit through the host's web editor. 2. **GitOps Reverser received it.** The `GitBranch` records when a delivery last reached it: ```bash - kubectl -n team-a get gitbranch main -o jsonpath='{.status.lastPushNoticeAt}{"\n"}' + kubectl -n team-a get gitbranch platform-main -o jsonpath='{.status.lastPushNoticeAt}{"\n"}' ``` 3. **It saw the new commit.** The `GitBranch`'s `COMMIT` column shows the commit you pushed: ```bash - kubectl -n team-a get gitbranch main + kubectl -n team-a get gitbranch platform-main ``` 4. **The applier applied it.** The applier claim's `OPERATION` column moves through `Requested` and diff --git a/docs/team-onboarding.md b/docs/team-onboarding.md index ed444f589..dd7a86d7c 100644 --- a/docs/team-onboarding.md +++ b/docs/team-onboarding.md @@ -49,9 +49,10 @@ The examples use these names: ## 1. Platform: connect the repository -Skip this step if a `GitProvider` for the repository exists; add the grant from step 3 to it -instead. Otherwise create the credential Secret as in the [quick start](quickstart.md) or the -[GitHub guide](github-setup-guide.md), in `platform`, and a `GitProvider` beside it: +Skip this step if a `GitProvider` for the repository exists: add the `allowedGitBranches` grant +below to it, and use its name wherever this guide says `platform-repo`. Otherwise create the +credential Secret as in the [quick start](quickstart.md) or the [GitHub guide](github-setup-guide.md), +in `platform`, and a `GitProvider` beside it: ```yaml apiVersion: configbutler.ai/v1alpha3