diff --git a/promptbook/prompts.json b/promptbook/prompts.json index 33520d1..b07d271 100644 --- a/promptbook/prompts.json +++ b/promptbook/prompts.json @@ -272,6 +272,25 @@ ], "formatNotes": "All three. Point the tool at the app deploy path and any Azure IaC first. Prefer concrete manifest/IaC diffs over generic Azure portal steps.", "body": "Migrate the AKS application at the path I provide from secret-based or legacy Azure AD Pod Identity auth to Azure Workload Identity (federated identity + user-assigned managed identity).\n\nReview current state and produce a PR-ready plan + diffs:\n\n1. Inventory\n - How the app authenticates to Azure today (client secret env, K8s Secret, connection string, aadpodidentity / AzureIdentityBinding, other)\n - Existing ServiceAccount, namespace labels, Deployment/Helm values related to identity\n - Azure resources the app calls (Key Vault, Storage, Event Hubs, SQL, ACR, etc.)\n\n2. Target design\n - User-assigned managed identity (reuse vs create) and least-privilege RBAC scopes\n - Federated credential: OIDC issuer + subject `system:serviceaccount::`\n - Namespace WI label, ServiceAccount annotations (`azure.workload.identity/client-id`, …), pod `azure.workload.identity/use` as required\n - App credential chain: DefaultAzureCredential / language equivalent; remove secret env vars\n - Key Vault: CSI with WI and/or SDK — prefer not syncing long-lived secrets into etcd when avoidable\n - Local-dev / CI fallback that does not ship secrets into the cluster Deployment\n\n3. Removals\n - Client secrets / SP passwords in Kubernetes Secrets and CI variable dumps used only for in-cluster auth\n - Legacy `aadpodidbinding`, AzureIdentity, AzureIdentityBinding, and related Helm values for this app\n - Dual paths that leave a secret env var beside WI (SDK must not prefer the secret)\n\n4. Output format\n - Severity-ordered findings (blocker / major / minor)\n - Concrete YAML / Helm / Bicep-or-Terraform patches\n - Identity map table (ns, SA, UAMI client id, federated subject, Azure roles)\n - Ordered migration steps (non-prod first) and rollback notes\n - Validation: issuer/subject match, token from pod, deny test with wrong SA\n - Explicit assumptions if cluster OIDC / WI addon ownership lives outside this repo\n\nDo not invent cluster-wide addon enablement or subscription IDs that are not evidenced in-repo; call out platform prerequisites instead. Prefer Workload Identity over recreating AAD Pod Identity." + }, + { + "id": "harden-spring-actuator-endpoints", + "title": "Harden These Spring Boot Actuator Endpoints", + "whenToUse": "You have a Spring Boot app with Actuator enabled and want a PR-ready lock-down (exposure, auth, probes, and config diffs).", + "tools": [ + "copilot", + "claude-code", + "codex" + ], + "tags": [ + "java", + "spring-boot", + "actuator", + "security", + "review" + ], + "formatNotes": "All three. Point the tool at `application.yml`/`application.properties`, Actuator-related config, and `SecurityFilterChain` / Security config first. Prefer concrete diffs over generic advice.", + "body": "Harden Spring Boot Actuator for the application at the path I provide. Produce a PR-ready lock-down: inventory, severity-ordered findings, and concrete config/security/probe patches.\n\nReview current state and deliver:\n\n1. Inventory\n - Boot version signals (2.x vs 3.x), Actuator dependency presence\n - `management.endpoints.web.exposure.include` / `.exclude`, `base-path`, `management.server.port` / address\n - `management.endpoint.health.show-details` / `show-components`\n - Which endpoints are effectively reachable (health, info, env, heapdump, threaddump, prometheus/metrics, shutdown, custom)\n - Existing Spring Security rules for Actuator (`EndpointRequest`, path matchers, CSRF)\n - Kubernetes/Helm probes and whether management is on a public Service/Ingress\n - Metrics / Prometheus / profiler (e.g. Pyroscope) scrape paths and auth\n\n2. Target design\n - Expose only ops-needed endpoints (typically health + info; metrics/prometheus only with scrape auth)\n - Never leave env / heapdump / threaddump / logfile / shutdown / configprops publicly reachable\n - Prefer a separate management port when the app has a public HTTP surface\n - Health details: `never` anonymously; `when_authorized` only with real operator roles\n - Dedicated management `SecurityFilterChain`; keep CSRF for browser-facing state changes\n - Probes aimed at management health; management not on public Ingress/LoadBalancer\n - Block cloud-metadata leakage via env/info contributors\n\n3. Patches (prefer diffs)\n - `application.yml` / profile-specific properties (Boot 3 exposure keys, base-path, show-details, management port)\n - `SecurityFilterChain` (or XML/adapter equivalent) using `EndpointRequest`\n - Deployment/Service/Ingress or Helm values for probes and port exposure\n - Scrape auth notes (bearer/mTLS) — names only, no real secrets\n\n4. Output format\n - Severity-ordered findings (blocker / major / minor)\n - Exposure matrix: endpoint → anonymous / role / disabled\n - Concrete diffs for each blocker/major\n - Validation steps: curl anonymous vs authenticated, in-cluster probe check, negative tests for env/heapdump/shutdown\n - Residual risks and explicit assumptions if manifests or Security config are missing in-repo\n\nConstraints:\n- Do not invent IdP URLs, passwords, or cluster IPs — use placeholders consistent with repo style.\n- Do not weaken API security to \"fix\" Actuator; do not disable CSRF globally.\n- Keep the diff minimal; no unrelated refactors.\n- Prefer Spring Boot 3 property names when the project is on Boot 3; call out 2.x differences if evidenced.\n\nStart from the files I pointed at (or search for `management.endpoints` and Actuator security). Prefer patches over vague advice." } ] } diff --git a/skillbook/skills.json b/skillbook/skills.json index 19197de..e435742 100644 --- a/skillbook/skills.json +++ b/skillbook/skills.json @@ -273,6 +273,24 @@ ], "formatNotes": "All three. Copilot: path-scoped `.github/instructions/aks-workload-identity.instructions.md` with applyTo for `**/deploy/**`, `**/k8s/**`, `**/*.{yml,yaml,bicep,tf}`, `**/serviceaccount*.yaml`, and app credential wiring files. Claude Code: `.claude/skills/aks-workload-identity-guardrails/SKILL.md` (plus a short CLAUDE.md fact that WI is preferred over pod secrets / aadpodidentity). Codex: nested `deploy/AGENTS.md` or an Identity section in root `AGENTS.md`.", "body": "# Skill: AKS Workload Identity Guardrails\n\n## Goal\nGive every AKS workload a federated identity path: a Kubernetes ServiceAccount mapped to a user-assigned managed identity via Azure Workload Identity, so apps obtain Azure tokens without client secrets in the cluster.\n\n## When to apply\n- New AKS deployments that call Azure AD–protected resources (Key Vault, Storage, Event Hubs, ACR pull via MI, Azure SQL, etc.)\n- Migrations off client secrets, SP passwords, or connection strings stored as Kubernetes Secrets\n- Replacing legacy Azure AD Pod Identity (`aadpodidentity`, AzureIdentity / AzureIdentityBinding)\n- Reviews of Helm/Kustomize that still inject `AZURE_CLIENT_SECRET` or similar\n\n## Baseline rules\n1. **Prefer Workload Identity** (OIDC federation on the AKS cluster + user-assigned MI) over secrets and over AAD Pod Identity.\n2. **One identity intent per workload** (or tightly related set): map ServiceAccount → user-assigned MI; avoid a shared “cluster MI” for unrelated apps.\n3. **Least privilege RBAC** on the MI: grant only the Azure roles/data-plane permissions the app needs on specific resource scopes (RG/resource), never Owner/Contributor at subscription by default.\n4. **Namespace labels**: ensure the namespace opted into WI (`azure.workload.identity/use: \"true\"` on the namespace, per current AKS WI docs your platform follows).\n5. **ServiceAccount**: annotate with client id (and tenant if required by your platform pattern):\n - `azure.workload.identity/client-id: `\n - Optional audience / tenant annotations only when your platform standard requires them.\n6. **Pod**: use that ServiceAccount; label pods that participate with `azure.workload.identity/use: \"true\"` when required by the WI mutating webhook in your cluster version.\n7. **Federated credential** on the user-assigned MI must match the issuer of the AKS OIDC issuer and the subject `system:serviceaccount::` (exact SA name and namespace — typos break auth silently).\n8. **App code**: use Azure Identity SDK `DefaultAzureCredential` / equivalent chain that picks up the WI-injected env (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_FEDERATED_TOKEN_FILE`). Do not hardcode secrets “for local only” into the same Deployment env.\n9. **Key Vault**: prefer CSI Secrets Store with WI, or SDK access with the same MI — do not sync long-lived secret values into etcd if CSI + SDK can avoid it.\n10. **Local / CI fallback**: document Azure CLI / env credential / user auth for laptop and pipeline; keep that path out of the in-cluster Deployment manifest.\n\n## Structure\n1. Infra (Bicep/Terraform/az): user-assigned MI + federated identity credential bound to SA subject + OIDC issuer.\n2. Cluster: WI addon / OIDC issuer enabled (do not invent enablement steps if the platform repo already owns cluster bootstrap).\n3. App manifests: Namespace label → ServiceAccount (annotated) → Deployment/StatefulSet `serviceAccountName` + WI use label → no client-secret env vars.\n4. Azure RBAC assignments scoped to the resources the app actually calls.\n5. README or runbook: how to rotate by swapping MI / federated credential, and how to validate token acquisition.\n\n## Validation\n1. Confirm OIDC issuer URL on the cluster matches the federated credential issuer.\n2. Confirm SA name/namespace in the federated credential subject equal the live ServiceAccount.\n3. From a debug shell in the pod (non-prod): check projected token file exists and Azure SDK / `az login --federated-token` (or equivalent) can obtain an access token for a known resource.\n4. Negative test: wrong SA or missing annotation fails closed (no silent fallback to a shared secret).\n5. PR checklist: no `AZURE_CLIENT_SECRET`, no SP password in Secrets, no `aadpodidbinding` / AzureIdentityBinding leftovers for this app.\n\n## Anti-patterns\n- Storing Azure client secrets or SP passwords in Kubernetes Secrets “temporarily”\n- Re-introducing Azure AD Pod Identity CRDs for new work\n- One shared MI with broad Contributor for every namespace\n- Hardcoding subscription-specific client IDs in app code instead of SA annotation / chart values\n- Mounting the federated token path world-readable or logging token contents\n- Leaving both WI and a client-secret env var so the SDK prefers the secret path\n- Copying federated credential subjects across environments without updating namespace/SA\n\n## Output format\n- Identity map: namespace / SA / UAMI client id / federated subject / Azure roles\n- Manifest and IaC files touched\n- Secrets / aadpodidentity objects to delete\n- Validation commands and residual risks (local-dev, CSI vs SDK, privileged roles)\n" + }, + { + "id": "spring-boot-actuator-hardening", + "title": "Spring Boot Actuator Hardening", + "whenToUse": "Hardening Spring Boot Actuator / management endpoints so health stays usable while sensitive endpoints are not exposed publicly.", + "tools": [ + "copilot", + "claude-code", + "codex" + ], + "tags": [ + "java", + "spring-boot", + "actuator", + "security" + ], + "formatNotes": "All three. Copilot: path-scoped `.github/instructions/spring-boot-actuator-hardening.instructions.md` with applyTo for `**/application*.{yml,yaml,properties}`, `**/Management*Config*.java`, `**/Security*Config*.java`, and `**/actuator/**`. Claude Code: `.claude/skills/spring-boot-actuator-hardening/SKILL.md` (plus a short CLAUDE.md fact that Actuator must not expose env/heapdump/shutdown publicly). Codex: an Actuator / management endpoints section in root `AGENTS.md` or nested `src/main/AGENTS.md`.", + "body": "# Skill: Spring Boot Actuator Hardening\n\n## Goal\nKeep Spring Boot Actuator useful for ops (liveness/readiness, basic info, authenticated metrics) while preventing public or unauthenticated exposure of sensitive management endpoints that leak config, memory, threads, or cloud metadata.\n\n## When to apply\n- New Spring Boot 2.x/3.x services enabling `spring-boot-starter-actuator`\n- Reviews of `management.endpoints.*` / `management.server.*` before production\n- Kubernetes Deployments where probes hit `/actuator/health` (or a custom base-path)\n- Apps that scrape Micrometer/Prometheus metrics or attach continuous profilers\n- Any change that widens `include=*` exposure or moves Actuator onto the public port\n\n## Baseline rules\n1. **Expose only what ops needs.** Prefer `health` and `info` (and `prometheus`/`metrics` only if scrape auth is in place). Never ship `include=*` in production.\n2. **Never expose publicly:** `env`, `heapdump`, `threaddump`, `logfile`, `shutdown`, `configprops`, `beans`, `mappings`, `conditions`, `httptrace`/`httpexchanges`, and similar high-sensitivity endpoints — even \"temporarily\".\n3. **Separate management port when the app has a public HTTP surface.** Use `management.server.port` (and optionally `management.server.address`) so probes/scrapes do not share the user-facing listener. Document the port in Deployment/Service manifests.\n4. **Same-port pitfalls.** If Actuator stays on the app port, treat every exposed path as internet-facing unless a gateway/ingress explicitly blocks `/actuator/**` (or your `management.endpoints.web.base-path`). Prefer deny-by-default at the edge plus app-level auth.\n5. **Spring Boot 3 exposure knobs.** Use `management.endpoints.web.exposure.include` / `.exclude` explicitly; set `management.endpoints.web.base-path` deliberately (default `/actuator`). Do not rely on framework defaults differing across Boot 2→3 upgrades.\n6. **Health details.** Keep `management.endpoint.health.show-details` and `show-components` at `never` for anonymous callers; use `when_authorized` only when Spring Security roles for operators are real and tested.\n7. **Secure sensitive endpoints with Spring Security.** Anything beyond anonymous health/info must require authentication (HTTP basic for scrapers only over mTLS/private network, or OAuth2/JWT roles for humans). Map Actuator under a dedicated `SecurityFilterChain` with `EndpointRequest.to(...)` / `toAnyEndpoint()` rather than ad-hoc path matchers alone.\n8. **Kubernetes probes vs public routes.** Point `livenessProbe`/`readinessProbe` at the management port (or an edge-blocked path). Do not publish the management Service/port on a public LoadBalancer/Ingress. Use a ClusterIP + NetworkPolicy when scrapers live in-cluster.\n9. **Metrics / Pyroscope / profiler scrape auth.** Prometheus scrapes and continuous profiling agents must authenticate or run on a private network path. Do not leave `/actuator/prometheus` or profiler ports open on the public Service. Prefer scrape configs with bearer tokens or mTLS; document the contract in the chart/values.\n10. **CSRF for browser-facing management.** If Actuator is reachable from a browser session (same-site cookies), keep CSRF protection enabled for state-changing endpoint POSTs (e.g. `shutdown`). Machine scrapers should use non-browser auth that is CSRF-exempt by design — do not disable CSRF globally to \"fix\" Actuator.\n11. **Cloud metadata leakage.** The `env` endpoint and over-broad `info` contributors can surface container/cloud metadata, K8s service account paths, and secret-backed env vars. Keep `env` off the exposure list; scrub custom `info` contributors; never mirror `AWS_*/AZURE_*/GCP_*` or mounted token paths into public payloads.\n12. **Shutdown and write endpoints.** Disable or tightly role-gate `shutdown` and any custom write-capable endpoints. Production should not allow remote process death via HTTP without break-glass controls.\n\n## Structure\n1. Dependencies: `spring-boot-starter-actuator` (+ Security, Micrometer registry only as needed).\n2. Config: `application.yml` / profile-specific files with explicit exposure, base-path, health show-details, and optional `management.server.port`.\n3. Security: dedicated `SecurityFilterChain` for management (`EndpointRequest`), separate from the API chain when useful.\n4. Platform: Deployment probes → management port; Service/Ingress must not publish management publicly; scrape auth documented.\n5. Docs/runbook: which endpoints exist, who may call them, and how to verify from inside the cluster.\n\n## Validation\n1. Hit public base URL: `/actuator` (or custom base-path) should not list sensitive links anonymously; unauthenticated `env`/`heapdump`/`threaddump`/`shutdown` → 401/404/403.\n2. Probes succeed against the intended health path on the management port (or private path).\n3. With an operator credential: `health` details appear only when `when_authorized` is configured and the principal has the expected role.\n4. Confirm scrape job works with auth and fails closed without credentials.\n5. Grep config for `include: \"*\"`, `show-details: always`, and exposed `env`/`heapdump`/`shutdown` before merge.\n6. PR checklist: management port (if used) not on public Ingress; no secret values in `info`; CSRF not globally disabled for browser sessions.\n\n## Anti-patterns\n- `management.endpoints.web.exposure.include: \"*\"` in any shared or prod profile\n- `show-details: always` on publicly reachable health\n- Actuator on the public port with no Security filter and no ingress deny\n- Publishing management port via public LoadBalancer \"for convenience\"\n- Leaving `env` enabled so cloud metadata and secret-backed variables leak\n- Disabling CSRF application-wide so `shutdown` works from a browser\n- Relying only on \"security through obscure base-path\" (`/secret-actuator`)\n- Copying local-dev `include=*` settings into the default/prod profile\n\n## Output format\n- Exposure matrix: endpoint → anonymous / authenticated role / disabled\n- Config + `SecurityFilterChain` diffs (and management port if introduced)\n- Probe / Service / Ingress patches\n- Validation commands (curl from inside vs outside the cluster) and residual risks\n" } ] }