ConfigHub · Durable config for coding agents
Docs / examples/walkthroughs/story-31-oci-config-bundles.md Source on GitHub →

New 12-Factor & Immutable OCI Config Bundles (Kubernetes 1.36+ Image Volumes)

Editing a Kubernetes ConfigMap in place in etcd creates silent fleet drift: any newly autoscaled or restarted pod boots immediately with the new config while existing pods keep running the old one, and etcd caps ConfigMaps at 1 MiB. When an app follows three simple rules (New 12-Factor: read YAML from --config /etc/<app>/<app>.yaml, print defaults via --print-default-config, and validate without side effects via --validate-config), cub bundle build (Zero Hub — no hub or cluster required) validates every file, blocks leaked secrets, and packs an immutable sha256-pinned OCI bundle for Kubernetes 1.36+ volumes[].image.

Quick start

You need: the ConfigHub plugin (Zero Hub) and a service implementing --config, --print-default-config, and --validate-config (20-line Go example below). (cub bundle ... remains a silent compatibility alias.)

By handAsk your agent
Wire validator hookcub bundle init --dir config --mount /etc/oncall-router --validate-cmd "go run ./main.go --validate-config --config config/oncall-router.yaml" (step 2)"Create .confighub-bundle.yaml for /etc/oncall-router so every edit runs --validate-config automatically."
Validate before packagingcub bundle validate (step 3)"Validate the YAML with --validate-config and reject any leaked secrets."
Build immutable OCI bundlecub bundle build --out dist/oncall-router-bundle.oci · cub bundle inspect dist/oncall-router-bundle.oci (step 4)"Build a deterministic OCI bundle from config/ and print its sha256: digest."
Generate K8s 1.36+ PodSpeccub bundle podspec --app oncall-router --ref ghcr.io/acme/oncall-router-config@sha256:... --mount /etc/oncall-router (step 5)"Generate a hardened Kubernetes 1.36+ volumes[].image PodSpec mounting this OCI bundle read-only at /etc/oncall-router."

Without ConfigHub: editing a ConfigMap in place drifts autoscaled pods mid-rollout, bad config shows up only after containers crash-loop, and custom OCI build scripts break digest reproducibility.

Deeper dive

Show the full walkthrough

Human

What you need

The ConfigHub plugin (Zero Hub) and Go 1.22+ (or any binary with --config, --print-default-config, and --validate-config). No hub, Kubernetes cluster, or registry login is required to build and inspect the local OCI bundle.

Steps

  1. Write a 20-line Go service (oncall-router) that reads structured YAML from --config /etc/oncall-router/oncall-router.yaml, prints defaults via --print-default-config, and checks config via --validate-config:
    mkdir -p ~/oci-bundle-demo/config && cd ~/oci-bundle-demo
    cat > main.go <<'EOF'
    package main
    
    import (
    	"flag"
    	"fmt"
    	"os"
    	"strings"
    )
    
    const defaultYAML = "default_channel: \"#ops-triage\"\nescalation_minutes: 15\n"
    
    func main() {
    	cfg := flag.String("config", "/etc/oncall-router/oncall-router.yaml", "config file")
    	printDef := flag.Bool("print-default-config", false, "emit default YAML")
    	validate := flag.Bool("validate-config", false, "validate config without starting")
    	flag.Parse()
    	if *printDef { fmt.Print(defaultYAML); return }
    	raw, err := os.ReadFile(*cfg)
    	if err != nil || !strings.Contains(string(raw), "default_channel:") || strings.Contains(string(raw), "escalation_minutes: -") {
    		fmt.Fprintf(os.Stderr, "invalid config %s\n", *cfg); os.Exit(1)
    	}
    	if *validate { fmt.Println("config valid"); return }
    	fmt.Printf("loaded %d bytes from %s\n", len(raw), *cfg)
    }
    EOF
  2. Generate config/oncall-router.yaml and create .confighub-bundle.yaml. Setting validate_cmd makes ConfigHub's PostToolUse hook automatically run --validate-config after every agent edit:
    cd ~/oci-bundle-demo
    go run ./main.go --print-default-config > config/oncall-router.yaml
    cub bundle init \
      --dir config \
      --mount /etc/oncall-router \
      --validate-cmd "go run ./main.go --validate-config --config config/oncall-router.yaml"
    cat .confighub-bundle.yaml
  3. Confirm valid YAML passes, an invalid value (escalation_minutes: -5) fails before build, and restore valid defaults:
    cd ~/oci-bundle-demo
    cub bundle validate
    printf 'default_channel: "#ops-triage"\nescalation_minutes: -5\n' > config/oncall-router.yaml
    cub bundle validate || echo "caught invalid config before build"
    go run ./main.go --print-default-config > config/oncall-router.yaml
    cub bundle validate
  4. Build a deterministic OCI Image Layout and verify its manifest, file list, and sha256: digest:
    cd ~/oci-bundle-demo
    cub bundle build --out dist/oncall-router-bundle.oci
    cub bundle inspect dist/oncall-router-bundle.oci
  5. Generate a hardened Kubernetes 1.36+ volumes[].image PodSpec mounting the digest-pinned OCI bundle read-only at /etc/oncall-router:
    cd ~/oci-bundle-demo
    DIGEST=$(cub bundle inspect dist/oncall-router-bundle.oci --digest-only)
    cub bundle podspec \
      --app oncall-router \
      --image ghcr.io/acme/oncall-router@sha256:example \
      --ref "ghcr.io/acme/oncall-router-config@${DIGEST}" \
      --mount /etc/oncall-router > k8s-podspec.yaml
    cat k8s-podspec.yaml

Undo it

Delete ~/oci-bundle-demo. Nothing was pushed to a registry or applied to a cluster.

Agent

When packaging config into an immutable OCI bundle:

  • Follow the three-rule New 12-Factor contract: --config /etc/<app>/<app>.yaml, --print-default-config, and side-effect-free --validate-config.
  • Set validate_cmd in .confighub-bundle.yaml so every config edit auto-validates.
  • Run cub bundle validate before cub bundle build, never pack secrets into an OCI bundle, and pin volumes[].image.reference to @sha256:....
  • Keep Pod Security Standards intact (runAsNonRoot: true, allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, capabilities.drop: [ALL], readOnly: true).

Testing

Build a 20-line New 12-Factor Go service supporting --config, --print-default-config, and --validate-config, scaffold .confighub-bundle.yaml, catch a bad config with cub bundle validate, build a deterministic OCI Config Bundle, and emit a hardened Kubernetes 1.36+ volumes[].image PodSpec.

This proves: a New 12-Factor service wired with .confighub-bundle.yaml and cub bundle builds a deterministic OCI bundle and hardened Kubernetes 1.36+ volumes[].image PodSpec with zero in-place ConfigMap drift.