Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1370,24 +1370,18 @@ jobs:
done
echo "All ${{ matrix.environment }} manifests rendered successfully."

# The druid catalog chart is a tenant-workload chart (not wired by a
# default ApplicationSet). Render it with synthetic tenant values so its
# templates still pass the same render-assert / schema / misconfiguration
# The catalog charts are tenant workloads, which no default ApplicationSet
# installs. scripts/catalog.py renders each one with the tenant inputs
# beside it, the render `task render` also makes, so
# its templates pass the same render-assert / schema / misconfiguration
# gates as every kustomize root.
- name: Render druid catalog chart
run: |
helm template ci catalog/druid/chart -n druid-ci \
-f catalog/druid/values.yaml \
--set hostedId=ci \
--set environment=${{ matrix.environment }} \
--set secrets.metadata=ci/druid/metadata \
--set secrets.admin=ci/druid/admin \
--set secrets.system=ci/druid/system \
--set secrets.keystore=ci/druid/keystore \
--set s3.indexLogsBucket=ci-druid-indexlogs \
--set s3.deepStorageBucket=ci-druid-deepstorage \
--set s3.msqBucket=ci-druid-msq \
> rendered/catalog_druid_chart.yaml
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version-file: .python-version

- name: Render the catalog charts
run: python3 scripts/catalog.py --env "${{ matrix.environment }}" --out 'rendered/catalog_{name}_chart.yaml'

# Source files are gated by the zero-placeholder job; this asserts the
# RENDERED output too — catching a zero account id, placeholder token, or
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ documents: `task validate` runs it report-only, CI runs it `--blocking`.
## CI

- PR and push to main trigger `.github/workflows/ci.yml` (lint → validate per environment → PR summary)
- The validate job renders every kustomize root plus the druid catalog chart, then gates the rendered output: render-assert (no unfilled sentinels), kubeconform strict (native schemas + datreeio CRDs-catalog, each read at a commit the shared `scripts/kubeconform-scan.sh` pins, no ignore-missing-schemas), and `trivy config` (misconfiguration scan, MEDIUM+ hard-fails; scoped justified exceptions live in `.trivyignore.yaml`)
- The validate job renders every kustomize root plus the druid catalog chart, then gates the rendered output. A catalog chart is rendered through `scripts/catalog.py`, with the tenant inputs in `catalog/<name>/ci-values.yaml`; `task render` and `check-serviceaccount-bindings.py` render it the same way. The gates: render-assert (no unfilled sentinels), kubeconform strict (native schemas + datreeio CRDs-catalog, each read at a commit the shared `scripts/kubeconform-scan.sh` pins, no ignore-missing-schemas), and `trivy config` (misconfiguration scan, MEDIUM+ hard-fails; scoped justified exceptions live in `.trivyignore.yaml`)
- Standalone jobs on every PR: `helm-render` (templates every addon against its appset-pinned chart with base + each env's values — an unknown key fails here, not fleet-wide at sync), `policy-admission` (renders the whole fleet into its real destination namespaces and runs `kyverno apply` against the Deny-tier best-practice/pod-security policies, so an addon landing in a namespace the policies don't exclude fails here instead of being denied at admission on a vended enforce cluster — also asserts all six exclusion lists stay identical, that every namespace the fleet lands a workload in is on that list, that each overlay carries its tier's `validationActions`, and that a deliberately non-compliant canary is denied by every validation, which is what proves the run evaluated anything), `appsets` (ApplicationSet schema + documented sync-wave ordering), `appset-render` (renders every template string an ApplicationSet carries the way the ArgoCD ApplicationSet controller does — Go text/template + sprig, `missingkey=error`: the Karpenter EC2NodeClass patch against fixture create/adopt/legacy cluster Secrets, the argo-workflows/loki/tempo bucket injection against with- and without-bucket fixtures, and the `addons-ai-platform.yaml` prune `templatePatch` against every element plus both `autoPrune` arms — so a control-flow edit that breaks a per-cluster render, or a prune nobody meant to change, fails here instead of at sync), `secrets` (gitleaks over the working tree), plus the dashboard, fork-safety, and Kyverno policy gates
- `charts` (Pinned chart archives) runs `scripts/render-addons.py --fetch` and keeps every pinned chart archive, each beside a `.sha256` record of the digest it was verified against, in an Actions cache of `~/.cache/eks-gitops/charts` keyed on `applicationsets/*.yaml` and `scripts/registry.py`. The cache is restored and saved as separate steps, and the save runs whatever the fetch did: a complete set goes under that key, and a set a failed fetch left incomplete under a `charts-partial-` key carrying the same pins hash, the run and its attempt. No incomplete set's key begins with the key the rendering jobs restore, so the prefix match a restore falls back to cannot hand one a partial set; the `charts` job's own restore-keys take the newest partial set for the same pins first. Requests to `public.ecr.aws` are spaced by `REQUEST_SPACING_SECONDS` in `scripts/registry.py`, above ECR Public's one-pull-a-second anonymous quota. `charts` and `image-vulnerabilities`, the two jobs that read `public.ecr.aws` in bulk, first assume the role the `ECR_PUBLIC_PULL_ROLE_ARN` repository secret names over GitHub OIDC and log in to `public.ecr.aws`, so ECR Public meters their pulls by that role's AWS account rather than by the runner's shared address; a run for a pull request from a fork, or with the secret unset, skips the login and reads anonymously. The ARN carries an AWS account id and this repository's Actions logs are public, so it is a secret (a variable is printed unmasked), at repository level (the role trusts this repo's `pull_request` and `ref:refs/heads/main` OIDC subjects, and an environment would change the subject); the first step that receives it runs the vendored `scripts/mask-aws-ids.sh` as its first command, fails the job while the name still exists as a variable, and `configure-aws-credentials` runs with `mask-aws-account-id: true`. trivy reads the login from the docker config, and `scripts/registry.py` sends it to a token realm only when the realm and the registry being read are both the host it was stored for, and reads a registry that refuses it anonymously, saying so once on stderr. These two are the only jobs granted `id-token`, each at job level. Every job that renders a pinned chart waits on it (`needs: charts`) and restores that cache, so a registry is read once per pin set; `scripts/registry.py` hands out a cached archive only while it still hashes to its record. A chart read exits 1 when the registry answered and ruled the pin out, and 2 when the registry could not be read. Each of these jobs, and each scheduled job in `chart-provenance.yml` that reads upstream through the client, sets a `timeout-minutes` above `CALL_BOUND_SECONDS` in `scripts/registry.py`: the deadline one client call runs to, its token request included, plus the one socket read a body still arriving at that deadline can have under way. `docs/runbooks/render-gate-failures.md` covers a red run
- `workflow-id-masking` runs `scripts/check-workflow-id-masking.py`, its `--self-test`, and `scripts/mask-aws-ids.sh --self-test`. The gate holds every workflow to reading an AWS account id or role ARN only as a secret, whole, masked by the mask script as the first command of the first step that receives it, never from a variable, an input, a matrix value or a literal, with `mask-aws-account-id: true` on every `configure-aws-credentials` step and a leftover-variable guard (`vars.NAME != ''`) beside every secret read. The gate, the mask script and the core that script runs (`scripts/mask-aws-ids.py`) are landing-zone's, vendored byte for byte: `scripts/vendored.json` records the repository, path, commit and SHA-256 of each, and the gate fails when the bytes stop matching, so a change lands there first and is re-vendored here with the record moved in the same commit. What is particular to this repository is its policy, `scripts/workflow-id-masking.toml`: the floor a scan must meet, the self-test's cases anchored in these workflows, and `ECR_PUBLIC_PULL_ROLE_ARN` as the one id allowed at repository level (`[repository_level_ids]`); any other id must be an environment secret with a refuse-inherited-config job, as landing-zone's are. ruff excludes the vendored Python, and `scripts/tests/test_workflow_id_masking.py` holds that exclusion to the record and runs both self-tests under the coverage run
Expand Down
18 changes: 3 additions & 15 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,9 @@ tasks:
echo "Rendering $dir ..."
kustomize build --enable-helm "$dir" > "rendered/${name}.yaml" || exit 1
done
# Druid catalog chart with synthetic tenant values — same render CI
# gates (see .github/workflows/ci.yml).
echo "Rendering catalog/druid/chart ..."
helm template ci catalog/druid/chart -n druid-ci \
-f catalog/druid/values.yaml \
--set hostedId=ci \
--set environment={{.ENVIRONMENT}} \
--set secrets.metadata=ci/druid/metadata \
--set secrets.admin=ci/druid/admin \
--set secrets.system=ci/druid/system \
--set secrets.keystore=ci/druid/keystore \
--set s3.indexLogsBucket=ci-druid-indexlogs \
--set s3.deepStorageBucket=ci-druid-deepstorage \
--set s3.msqBucket=ci-druid-msq \
> rendered/catalog-druid-chart.yaml
# The catalog charts, rendered with their tenant inputs: the same
# render CI's validate job makes (see .github/workflows/ci.yml).
python3 scripts/catalog.py --env {{.ENVIRONMENT}} --out 'rendered/catalog-{name}-chart.yaml' || exit 1
echo "All {{.ENVIRONMENT}} overlays rendered to rendered/"

clean:
Expand Down
18 changes: 18 additions & 0 deletions catalog/druid/ci-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# The inputs a tenant's Application supplies when it installs this chart, as
# synthetic values. No ApplicationSet in this repository deploys the chart, so
# every render made here stands in for a tenant's, and this file is what it
# stands in with. scripts/catalog.py reads it beside values.yaml for every
# render: CI's validate job, `task render` and check-serviceaccount-bindings.py.
# `environment` is set per render.
hostedId: ci

secrets:
metadata: ci/druid/metadata
admin: ci/druid/admin
system: ci/druid/system
keystore: ci/druid/keystore

s3:
indexLogsBucket: ci-druid-indexlogs
deepStorageBucket: ci-druid-deepstorage
msqBucket: ci-druid-msq
151 changes: 151 additions & 0 deletions scripts/catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"""catalog.py — the catalog's own charts, and the one way this repository renders them.

A chart under catalog/<name>/chart is a workload a tenant installs. No
ApplicationSet in this repository deploys one, so ArgoCD never renders it from
here, and every render made here stands in for a tenant's. What it stands in with
is catalog/<name>/ci-values.yaml, the inputs a tenant's Application supplies,
read beside the chart's own values.yaml.

This module is the one place that turns those into a `helm template` command.
CI's validate job and `task render` write the render through main();
check-serviceaccount-bindings.py reads it through render().
Written out separately, the command drifted: three renderers each spelled it,
and one of them passed a single input of the nine. With one definition, what
one gate checks is what the others check.

The population is every directory matching CHART_GLOB, derived rather than
listed, so a second catalog chart is rendered by everything that renders the
first.

Exit status: 0 when every chart rendered, 1 when a chart failed to render or has
no tenant inputs, and 2 (CANNOT_RUN) when helm is missing, a render ran out of
time, or no chart matched CHART_GLOB.
"""

from __future__ import annotations

import argparse
import subprocess
import sys
from collections.abc import Sequence
from dataclasses import dataclass
from pathlib import Path

import gatelib

ROOT = Path(__file__).resolve().parent.parent
CHART_GLOB = "catalog/*/chart"

# Beside each chart's values.yaml: the inputs a tenant's Application supplies.
TENANT_INPUTS = "ci-values.yaml"

# The release every render uses. Each chart renders into <name>-ci, a namespace
# no cluster this catalog reaches runs a tenant in.
RELEASE = "ci"

# Seconds one `helm template` of a chart in this tree may take. It reads only the
# working tree, so running past this is a hang rather than a slow network.
RENDER_TIMEOUT = 120


class RenderFailed(Exception):
"""The chart, as this tree has it, does not render: a finding about the tree."""


class CannotRender(Exception):
"""helm did not finish, so nothing was decided about the chart."""


@dataclass(frozen=True)
class CatalogChart:
root: Path
chart_dir: Path

@property
def name(self) -> str:
return self.chart_dir.parent.name

@property
def path(self) -> str:
return self.chart_dir.relative_to(self.root).as_posix()

@property
def namespace(self) -> str:
return f"{self.name}-{RELEASE}"

@property
def value_files(self) -> list[Path]:
return [self.chart_dir.parent / "values.yaml", self.chart_dir.parent / TENANT_INPUTS]


def discover(root: Path = ROOT) -> list[CatalogChart]:
return [CatalogChart(root, d) for d in sorted(root.glob(CHART_GLOB)) if d.is_dir()]


def template_command(chart: CatalogChart, env: str) -> list[str]:
cmd = ["helm", "template", RELEASE, str(chart.chart_dir), "--namespace", chart.namespace]
for values in chart.value_files:
cmd += ["-f", str(values)]
return cmd + ["--set", f"environment={env}"]


def render(chart: CatalogChart, env: str) -> str:
"""The chart's manifests for `env`, rendered with its tenant inputs."""
missing = [v.relative_to(chart.root).as_posix() for v in chart.value_files if not v.is_file()]
if missing:
raise RenderFailed(
f"{', '.join(missing)} does not exist. A catalog chart renders here with "
f"values.yaml and the tenant inputs in {TENANT_INPUTS}, both beside it."
)
try:
proc = subprocess.run(
template_command(chart, env), capture_output=True, text=True, timeout=RENDER_TIMEOUT
)
except subprocess.TimeoutExpired as exc:
raise CannotRender(
f"helm template ran past the {RENDER_TIMEOUT}s a render of {chart.path} is allowed"
) from exc
if proc.returncode != 0:
raise RenderFailed((proc.stderr.strip() or proc.stdout.strip())[:1200])
return proc.stdout


def main(argv: Sequence[str] | None = None) -> int:
ap = argparse.ArgumentParser(description="Render every catalog chart with its tenant inputs.")
ap.add_argument("--env", required=True, help="the environment value each render sets")
ap.add_argument(
"--out",
required=True,
help="where each render is written, with {name} for the chart, "
"e.g. rendered/catalog-{name}-chart.yaml",
)
args = ap.parse_args(argv)
if "{name}" not in args.out:
ap.error("--out must contain {name}, or every chart would be written to one file")

gatelib.require("helm")
charts = discover()
if not charts:
print(f"Cannot run: no chart matched {CHART_GLOB}, so nothing was rendered.")
return gatelib.CANNOT_RUN

failed = 0
for chart in charts:
try:
manifests = render(chart, args.env)
except CannotRender as exc:
print(f"Cannot run: {exc}.")
return gatelib.CANNOT_RUN
except RenderFailed as exc:
print(f"FAIL {chart.path} did not render for {args.env}:\n{exc}")
failed += 1
continue
out = Path(args.out.format(name=chart.name))
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(manifests)
print(f"rendered {chart.path} for {args.env} to {out}")
return 1 if failed else 0


if __name__ == "__main__":
sys.exit(main())
Loading