[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M735JN2MA231GA700G4JP7GZ":3,"skill-same:01M735JN2MA231GA700G4JP7GZ":57},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":29,"commitSha":30,"skillDirectory":31,"forksCount":14,"repositoryHtmlUrl":32,"repositoryHomepageUrl":6,"ownerHtmlUrl":33,"ownerBlogUrl":34,"ownerDescription":35,"updatedAt":36,"install":37,"resources":50},"01M735JN2MA231GA700G4JP7GZ","go",null,"How to build a Go service on the platform — project layout, the OpenAPI server generation, verifying the gateway's signed assertion, the build-verify command, and this stack's constraints and pitfalls. Apply when a component's `language` is Go. For a Ballerina service, use `ballerina` instead.","wso2\u002Flabs-agentic-engineer","wso2","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F533043?v=4","01M6CDAFS40T9Y86DYXWE0NJES","WSO2","01M735EE4N2PP2ZR56AX7DNPNP",24,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Fgo\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: go\ndescription: \"How to build a Go service on the platform — project layout, the OpenAPI server generation, verifying the gateway's signed assertion, the build-verify command, and this stack's constraints and pitfalls. Apply when a component's `language` is Go. For a Ballerina service, use `ballerina` instead.\"\nmetadata:\n  aep:\n    kind: org\n    audience: [coding]\n---\n\n# Go\n\nA Go service on this platform: one binary, `net\u002Fhttp` on port 9090, its own\nplatform-provisioned Postgres, built by a CPU-throttled pod that will not\ndownload a toolchain and will not compile C.\n\n## Development flow\n\n1. **Scaffold** — `go.mod` (module path = app folder name, `go 1.25`),\n   `main.go`, `Dockerfile`, per Layout. `workload.yaml` per the component\n   contract.\n2. **Implement** — handlers, store, models. Every rule under Constraints is a\n   build- or runtime-failure if broken, not a style preference. The\n   platform-wide rules (port, no required env vars, error shape, dependency\n   wiring) live in the `aep` skill's component contract, not here.\n3. **Verify** — from the app path:\n   ```bash\n   go mod tidy                   # regenerate go.sum from real checksums\n   go build -o \u002Fdev\u002Fnull .\u002F...   # compile everything\n   go test .\u002F... > \u002Ftmp\u002Fgo-test.txt 2>&1; echo \"rc=$?\"   # read the rc, not the tail\n   ```\n   Commit the `go.sum` this produces. A stdlib-only service produces none —\n   correct and expected; never hand-write one.\n4. **PR** — only once step 3 exits 0.\n\n## Constraints\n\n**Toolchain.** Builder base image is `golang:1.25-alpine` — any other version\nis a hard error at build time. The build pod runs `GOTOOLCHAIN=local` and will\nNOT auto-download a newer Go, so an older image fails `go mod download` with\n`go.mod requires go >= X.Y` even though your local `go build` passed.\n\n**No CGO.** Set `CGO_ENABLED=0`, and pick pure-Go libraries. Under the build\npod's CPU throttle, a dependency that compiles a few MB of C takes 10–20\nminutes and frequently times out.\n\n**Persistence.** Postgres, provisioned by the platform as a\n`platform-resource` dependency the design declares — never a file DB (the pod\nfilesystem is ephemeral) and never a separate `db`\u002F`storage`\u002F`persistence`\ncomponent. Driver is `github.com\u002Fjackc\u002Fpgx\u002Fv5` (pure Go). Connection values\narrive as injected env vars read by name at startup — the `aep` skill's\nDependencies section covers where the names come from. Create schema with\n`IF NOT EXISTS` at startup so re-deploys are idempotent.\n\n**A nil slice binds as SQL `NULL`, not `[]`.** A list field the client omitted\nstays nil, and `NULL` into a `NOT NULL` collection column (`tags TEXT[] NOT\nNULL DEFAULT '{}'`) 500s at runtime. Normalize before insert\n(`if in.Tags == nil { in.Tags = []string{} }`) or omit the column so its\n`DEFAULT` fires — a `DEFAULT` never fires for a column you list with `NULL`.\n\n**Routing.** `net\u002Fhttp` method patterns\n(`mux.HandleFunc(\"PATCH \u002Ftodos\u002F{id}\", …)`). `chi` is fine for grouped routes\nor middleware chains. Not Gin\u002FEcho\u002FFiber — large dep trees, little gain at\n5–20 endpoints.\n\n**Upstreams.** `url.JoinPath(base, \"path\")`, never `base + \"\u002Fpath\"` — an\ninjected address can end in `\u002F`.\n\n**Periodic work.** A background goroutine started in `main`.\n\n## The OpenAPI server\n\nA service whose `design.json` sets `exposesAPI.auth` implements\n`specs\u002Fdesign\u002Fcomponents\u002F\u003Cname>\u002Fopenapi.yaml`. Generate the server from the\ncontract rather than hand-writing routes: the contract is also what the API\ngateway enforces, so generating keeps the two from drifting.\n\n**The gateway has already done the authorization.** It validated the caller's\ntoken and checked the scope each operation declares in that same contract; a\nrequest that failed either never reached this process. So this service holds\n**no operation → scope table**, in any form. Writing one is keeping a second\ncopy of the contract that nothing keeps in sync.\n\n**Generate.** `internal\u002Fgen\u002Foapi-codegen.yaml`:\n\n```yaml\npackage: gen\n# Relative to the directory you RUN the generator from (the App Path), not to\n# this config file. It must land in the package `package:` names, or the build\n# fails on a package\u002Fdirectory mismatch.\noutput: internal\u002Fgen\u002Fserver_gen.go\ngenerate:\n  chi-server: true\n  strict-server: true\n  models: true\noutput-options:\n  name-normalizer: ToCamelCaseWithInitialisms\n  prefer-skip-optional-pointer: true\n```\n\n```bash\ngo run github.com\u002Foapi-codegen\u002Foapi-codegen\u002Fv2\u002Fcmd\u002Foapi-codegen@v2.7.0 \\\n  -config internal\u002Fgen\u002Foapi-codegen.yaml \\\n  ..\u002Fspecs\u002Fdesign\u002Fcomponents\u002F\u003Cname>\u002Fopenapi.yaml\n```\n\nCommit the output. **Nothing you write parses the spec.**\n\n## Who the caller is: the gateway's signed assertion\n\nThe gateway decides *whether* a request may happen. It cannot prove to your code\nthat a request *came through it* — any pod that can open a socket to this\nservice can send whatever headers it likes. So it signs a JWT of the caller it\nauthenticated and puts it on the upstream request, and this service verifies\nthat signature against one certificate the platform publishes per environment.\n\n**Copy the verifier.** From the App Path:\n\n```bash\nmkdir -p internal\u002Fauth\ncp \"$AEP_SKILLS_DIR\u002Fgo\u002Fassets\u002Fgateway_assertion.go\" internal\u002Fauth\u002Fgateway_assertion.go\n```\n\nIf `$AEP_SKILLS_DIR` is unset, copy from `assets\u002F` next to this skill's\n`SKILL.md` (the BFF mirrors that directory to `.claude\u002Fskills\u002Fgo\u002F`). It is\n**verbatim — there is no line to edit**, it imports only the standard library,\nand it adds nothing to `go.mod`.\n\n**Wire it in `main`, and make a half-configured assertion fatal:**\n\n```go\nverifier, err := auth.NewVerifierFromEnv()\nif err != nil {\n\tlog.Fatalf(\"gateway assertion: %v\", err)   \u002F\u002F refuse to start\n}\n\nr := chi.NewRouter()\nr.Use(verifier.Middleware)\nhandler := gen.HandlerWithOptions(gen.NewStrictHandler(srv, nil), gen.ChiServerOptions{BaseRouter: r})\n```\n\n`r.Use` is correct here and there is no ordering trap: the verifier needs\nnothing from the generated wrapper. The platform sets\n`GATEWAY_ASSERTION_CERTIFICATE`, `GATEWAY_ASSERTION_ISSUER` and\n`GATEWAY_ASSERTION_HEADER` on the container. A **partially set** trio is fatal:\na service that starts on half of them cannot tell a real caller from a forged\none, and that is a broken deployment rather than an unconfigured one. All three\n**absent** is the separate, temporary case an environment gateway provisioned\nbefore the backend-JWT keypair existed still lands in — the verifier starts\nwithout verifying anything, says so on every boot, and is tracked for removal in\nissue #789. Do not write code that depends on it.\n\n**Read identity from the verified caller, never from a header.**\n\n| Rule | Why |\n|---|---|\n| **`auth.RequireCaller(ctx)`** in any handler that needs an identity; 401 on its error. | The assertion is the only statement about the caller that a forged request cannot make. |\n| **Never read `X-User-Id`, `X-User-Scopes`, `X-User-Groups` or `Authorization`.** | The first three are unsigned — the gateway sets them, and so can anyone else who reaches this pod directly. `Authorization` is stripped. |\n| **A `security: []` handler reads NO identity at all.** | The gateway serves a public operation with no assertion, so `CallerFrom` is absent there by design. |\n| **Compare a scope with `==` on the whole handle** (`caller.HasScope`). | `strings.Contains` matches `claims:read` inside `claims:read-all`. The gateway compares whole strings too. |\n\n**Reach is the path, never a branch on a scope.** A `\u002Fme\u002F…` handler resolves\nrows through the caller's `sub`; a handler outside `\u002Fme\u002F` reaches every row and\nfilters on nothing (`openapi-conventions`):\n\n```go\n\u002F\u002F GET \u002Fme\u002Fclaims\ncaller, err := auth.RequireCaller(ctx)\n\u002F\u002F …401 on err…\nrows := s.store.ByOwner(caller.UserID)\n\n\u002F\u002F GET \u002Fclaims — a different operation, guarded by claims:read-all\nrows := s.store.All()\n```\n\n`auth.HasScope` never decides which rows come back and is never an operation's\nonly check — both were settled before the handler ran, at the gateway and by\nthe path.\n\nA **single-row** read is the same rule at the other end: when the caller holds\nonly the `own` handle and the row belongs to someone else, answer **404, not\n403** — a caller who may not learn a row exists may not learn it exists from a\nstatus code either (`api-management` owns the rule; this is its Go shape).\n\n**Test through the real router.** Build the wired handler in the test —\n`gen.HandlerWithOptions(…)` with the verifier middleware, not the bare\nhandlers. Mint the test's assertions with a throwaway RSA key and set **all\nthree** variables: `GATEWAY_ASSERTION_CERTIFICATE` to that key's self-signed\ncertificate, and `GATEWAY_ASSERTION_ISSUER` and `GATEWAY_ASSERTION_HEADER` to\nthe values the test's own assertions are minted with. The certificate alone is a\npartial trio, so `NewVerifierFromEnv` returns an error and the test fails before\nit has asserted anything. Nothing in the test talks to a gateway. Write four\ntests, by these names:\n\n- **`TestForgedAssertionIs401`** — the same request signed by a *different* key\n  is rejected, and so is one with its payload edited after signing. This is the\n  one test that proves the trust anchor is the signature and not the header.\n- **`TestHealthIsPublic`** — the `security: []` operation answers 200 with no\n  assertion *and* with forged `X-User-*` headers, and the handler reads neither.\n- **`Test\u003CResource>ListOwnershipAndWidening`** and\n  **`Test\u003CResource>GetOwnershipWidening`** — the `own`\u002F`any` pair: the same\n  operation returns the caller's rows with the `own` handle and every row with\n  the `any` one, and the single-row read 404s on another owner's id.\n\nThere is deliberately no per-operation scope matrix here: that table lives in\nthe contract and is enforced at the gateway, and a copy of it in these tests\nwould pass while the deployed API disagreed. Domain invariants (an\nalready-approved claim, a conflicting transition) get their own test beside\nthese.\n\n## Layout\n\n```\n\u003Capp-path>\u002F\n├── go.mod               # module path matches the app folder name\n├── go.sum               # ONLY with external deps — stdlib-only has none\n├── main.go              # entrypoint — small services keep it all here\n├── internal\u002F\n│   ├── gen\u002F             # oapi-codegen output — generated, committed, never edited\n│   ├── auth\u002F            # gateway_assertion.go, copied VERBATIM from this\n│   │                    #   skill's assets\u002F — stdlib only, nothing to edit\n│   ├── handlers\u002F        # http handlers, one file per resource\n│   ├── store\u002F           # Postgres access\n│   ├── models\u002F          # request\u002Fresponse\u002Fdomain types\n│   └── middleware\u002F      # cross-cutting only (rare)\n├── Dockerfile\n└── workload.yaml\n```\n\n`workload.yaml`'s HTTP endpoint `visibility`: before writing it, read\n`skills\u002Faep`'s `references\u002Fworkload-and-wiring.md` (\"Provider endpoint\nvisibility\") and write the list it gives a provider, one YAML item per value.\n\n**Done when:** the endpoint's `visibility` is exactly that list.\n\n`Dockerfile` — multi-stage, pinned builder, slim runtime:\n\n```dockerfile\nFROM golang:1.25-alpine AS builder\nWORKDIR \u002Fsrc\n# Two branches, and you pick one. A service with ANY dependency — every\n# oapi-codegen service is one — has a go.sum and copies both, as below.\n# A STDLIB-ONLY service has no go.sum; naming a file that does not exist as a\n# COPY source hard-fails the build, so that one is `COPY go.mod .\u002F` instead.\nCOPY go.mod go.sum .\u002F\nRUN go mod download\nCOPY . .\n# Build the main package — `.\u002F` (module root) or `.\u002Fcmd\u002F\u003Cname>`. A real `-o`\n# target takes exactly ONE package; `.\u002F...` is for the `-o \u002Fdev\u002Fnull` verify.\nRUN CGO_ENABLED=0 go build -ldflags='-s -w' -o \u002Fout\u002Fapp .\u002F\n\nFROM alpine:3.20\nRUN apk add --no-cache ca-certificates\nCOPY --from=builder \u002Fout\u002Fapp \u002Fapp\nEXPOSE 9090\nENTRYPOINT [\"\u002Fapp\"]\n```\n\nPostgres — pure-Go `pgx` pool, DSN built from the injected env vars:\n\n```go\nimport \"github.com\u002Fjackc\u002Fpgx\u002Fv5\u002Fpgxpool\"\n\npool, err := pgxpool.New(ctx, os.Getenv(\"\u003CDB_URL_ENV_VAR>\"))\n```\n\n## Pitfalls\n\n| Symptom | Cause | Fix |\n|---|---|---|\n| Build fails `go.mod requires go >= 1.25` | Dockerfile pinned an older Go | `FROM golang:1.25-alpine AS builder` |\n| Build times out compiling a dependency | A cgo dependency compiling C under the build pod's throttle | Swap it for a pure-Go library; `CGO_ENABLED=0` |\n| Data vanishes on every re-deploy | Wrote to a file DB on the pod's ephemeral filesystem | Use the provisioned Postgres |\n| `panic: … connection refused` \u002F empty DSN at startup | Read a guessed env-var name, not the injected one | Read the env-var names the platform injected for the resource dependency |\n| Build fails `cannot write multiple packages to non-directory \u002Fout\u002Fapp` | `go build -o \u002Fout\u002Fapp .\u002F...` on a multi-package module | Build the main package: `.\u002F` or `.\u002Fcmd\u002F\u003Cname>` |\n| `checksum mismatch … SECURITY ERROR` at build | `go.sum` stale or hand-edited | `go mod tidy` locally; commit the result |\n| Build fails `COPY go.mod go.sum .\u002F … go.sum: no such file or directory` | Dockerfile names `go.sum`, stdlib-only service has none | `COPY go.mod .\u002F` only — but a service with any dependency needs both |\n| Every `\u002Fapi` call through the SPA 503s, or the API is not curl-able on the public gateway | The endpoint `visibility` is not the provider list | Write the list `workload-and-wiring` gives a provider |\n| Pod won't start; `panic: listen tcp :8080` | Wrong port | Listen on 9090 |\n| `POST` to an injected upstream returns `405` (or a `301` then a `GET`) | Address ended in `\u002F`, so `base + \"\u002Fpath\"` built `\u002F\u002Fpath`; `ServeMux` 301s to the clean path and the client re-issues it as `GET` | `url.JoinPath(base, \"path\")` |\n| Create\u002FPOST 500s only when an optional list field is omitted (`[]` works) | Nil slice bound as `NULL` into a `NOT NULL` array column; its `DEFAULT` skipped because the INSERT lists it | Normalize nil→empty, or omit the column |\n| Every call 401s right after a deploy | The environment's gateway publishes a different key than the container holds — it was re-provisioned and this component was not redeployed | Redeploy the component; the certificate rides its ReleaseBinding |\n| The service will not start: `…must be set together or not at all` | Some of the three are set, not all | Locally, set all three from a throwaway keypair. In a cell, the environment's gateway needs provisioning |\n| A public operation 401s | A handler for a `security: []` operation called `RequireCaller` | A public handler reads no identity; the gateway sends no assertion with one |\n| Every caller looks anonymous | Read `X-User-Id` instead of the verified caller | `auth.RequireCaller(ctx)` — the headers are unsigned and prove nothing |\n","# Go\n\nA Go service on this platform: one binary, `net\u002Fhttp` on port 9090, its own\nplatform-provisioned Postgres, built by a CPU-throttled pod that will not\ndownload a toolchain and will not compile C.\n\n## Development flow\n\n1. **Scaffold** — `go.mod` (module path = app folder name, `go 1.25`),\n   `main.go`, `Dockerfile`, per Layout. `workload.yaml` per the component\n   contract.\n2. **Implement** — handlers, store, models. Every rule under Constraints is a\n   build- or runtime-failure if broken, not a style preference. The\n   platform-wide rules (port, no required env vars, error shape, dependency\n   wiring) live in the `aep` skill's component contract, not here.\n3. **Verify** — from the app path:\n   ```bash\n   go mod tidy                   # regenerate go.sum from real checksums\n   go build -o \u002Fdev\u002Fnull .\u002F...   # compile everything\n   go test .\u002F... > \u002Ftmp\u002Fgo-test.txt 2>&1; echo \"rc=$?\"   # read the rc, not the tail\n   ```\n   Commit the `go.sum` this produces. A stdlib-only service produces none —\n   correct and expected; never hand-write one.\n4. **PR** — only once step 3 exits 0.\n\n## Constraints\n\n**Toolchain.** Builder base image is `golang:1.25-alpine` — any other version\nis a hard error at build time. The build pod runs `GOTOOLCHAIN=local` and will\nNOT auto-download a newer Go, so an older image fails `go mod download` with\n`go.mod requires go >= X.Y` even though your local `go build` passed.\n\n**No CGO.** Set `CGO_ENABLED=0`, and pick pure-Go libraries. Under the build\npod's CPU throttle, a dependency that compiles a few MB of C takes 10–20\nminutes and frequently times out.\n\n**Persistence.** Postgres, provisioned by the platform as a\n`platform-resource` dependency the design declares — never a file DB (the pod\nfilesystem is ephemeral) and never a separate `db`\u002F`storage`\u002F`persistence`\ncomponent. Driver is `github.com\u002Fjackc\u002Fpgx\u002Fv5` (pure Go). Connection values\narrive as injected env vars read by name at startup — the `aep` skill's\nDependencies section covers where the names come from. Create schema with\n`IF NOT EXISTS` at startup so re-deploys are idempotent.\n\n**A nil slice binds as SQL `NULL`, not `[]`.** A list field the client omitted\nstays nil, and `NULL` into a `NOT NULL` collection column (`tags TEXT[] NOT\nNULL DEFAULT '{}'`) 500s at runtime. Normalize before insert\n(`if in.Tags == nil { in.Tags = []string{} }`) or omit the column so its\n`DEFAULT` fires — a `DEFAULT` never fires for a column you list with `NULL`.\n\n**Routing.** `net\u002Fhttp` method patterns\n(`mux.HandleFunc(\"PATCH \u002Ftodos\u002F{id}\", …)`). `chi` is fine for grouped routes\nor middleware chains. Not Gin\u002FEcho\u002FFiber — large dep trees, little gain at\n5–20 endpoints.\n\n**Upstreams.** `url.JoinPath(base, \"path\")`, never `base + \"\u002Fpath\"` — an\ninjected address can end in `\u002F`.\n\n**Periodic work.** A background goroutine started in `main`.\n\n## The OpenAPI server\n\nA service whose `design.json` sets `exposesAPI.auth` implements\n`specs\u002Fdesign\u002Fcomponents\u002F\u003Cname>\u002Fopenapi.yaml`. Generate the server from the\ncontract rather than hand-writing routes: the contract is also what the API\ngateway enforces, so generating keeps the two from drifting.\n\n**The gateway has already done the authorization.** It validated the caller's\ntoken and checked the scope each operation declares in that same contract; a\nrequest that failed either never reached this process. So this service holds\n**no operation → scope table**, in any form. Writing one is keeping a second\ncopy of the contract that nothing keeps in sync.\n\n**Generate.** `internal\u002Fgen\u002Foapi-codegen.yaml`:\n\n```yaml\npackage: gen\n# Relative to the directory you RUN the generator from (the App Path), not to\n# this config file. It must land in the package `package:` names, or the build\n# fails on a package\u002Fdirectory mismatch.\noutput: internal\u002Fgen\u002Fserver_gen.go\ngenerate:\n  chi-server: true\n  strict-server: true\n  models: true\noutput-options:\n  name-normalizer: ToCamelCaseWithInitialisms\n  prefer-skip-optional-pointer: true\n```\n\n```bash\ngo run github.com\u002Foapi-codegen\u002Foapi-codegen\u002Fv2\u002Fcmd\u002Foapi-codegen@v2.7.0 \\\n  -config internal\u002Fgen\u002Foapi-codegen.yaml \\\n  ..\u002Fspecs\u002Fdesign\u002Fcomponents\u002F\u003Cname>\u002Fopenapi.yaml\n```\n\nCommit the output. **Nothing you write parses the spec.**\n\n## Who the caller is: the gateway's signed assertion\n\nThe gateway decides *whether* a request may happen. It cannot prove to your code\nthat a request *came through it* — any pod that can open a socket to this\nservice can send whatever headers it likes. So it signs a JWT of the caller it\nauthenticated and puts it on the upstream request, and this service verifies\nthat signature against one certificate the platform publishes per environment.\n\n**Copy the verifier.** From the App Path:\n\n```bash\nmkdir -p internal\u002Fauth\ncp \"$AEP_SKILLS_DIR\u002Fgo\u002Fassets\u002Fgateway_assertion.go\" internal\u002Fauth\u002Fgateway_assertion.go\n```\n\nIf `$AEP_SKILLS_DIR` is unset, copy from `assets\u002F` next to this skill's\n`SKILL.md` (the BFF mirrors that directory to `.claude\u002Fskills\u002Fgo\u002F`). It is\n**verbatim — there is no line to edit**, it imports only the standard library,\nand it adds nothing to `go.mod`.\n\n**Wire it in `main`, and make a half-configured assertion fatal:**\n\n```go\nverifier, err := auth.NewVerifierFromEnv()\nif err != nil {\n\tlog.Fatalf(\"gateway assertion: %v\", err)   \u002F\u002F refuse to start\n}\n\nr := chi.NewRouter()\nr.Use(verifier.Middleware)\nhandler := gen.HandlerWithOptions(gen.NewStrictHandler(srv, nil), gen.ChiServerOptions{BaseRouter: r})\n```\n\n`r.Use` is correct here and there is no ordering trap: the verifier needs\nnothing from the generated wrapper. The platform sets\n`GATEWAY_ASSERTION_CERTIFICATE`, `GATEWAY_ASSERTION_ISSUER` and\n`GATEWAY_ASSERTION_HEADER` on the container. A **partially set** trio is fatal:\na service that starts on half of them cannot tell a real caller from a forged\none, and that is a broken deployment rather than an unconfigured one. All three\n**absent** is the separate, temporary case an environment gateway provisioned\nbefore the backend-JWT keypair existed still lands in — the verifier starts\nwithout verifying anything, says so on every boot, and is tracked for removal in\nissue #789. Do not write code that depends on it.\n\n**Read identity from the verified caller, never from a header.**\n\n| Rule | Why |\n|---|---|\n| **`auth.RequireCaller(ctx)`** in any handler that needs an identity; 401 on its error. | The assertion is the only statement about the caller that a forged request cannot make. |\n| **Never read `X-User-Id`, `X-User-Scopes`, `X-User-Groups` or `Authorization`.** | The first three are unsigned — the gateway sets them, and so can anyone else who reaches this pod directly. `Authorization` is stripped. |\n| **A `security: []` handler reads NO identity at all.** | The gateway serves a public operation with no assertion, so `CallerFrom` is absent there by design. |\n| **Compare a scope with `==` on the whole handle** (`caller.HasScope`). | `strings.Contains` matches `claims:read` inside `claims:read-all`. The gateway compares whole strings too. |\n\n**Reach is the path, never a branch on a scope.** A `\u002Fme\u002F…` handler resolves\nrows through the caller's `sub`; a handler outside `\u002Fme\u002F` reaches every row and\nfilters on nothing (`openapi-conventions`):\n\n```go\n\u002F\u002F GET \u002Fme\u002Fclaims\ncaller, err := auth.RequireCaller(ctx)\n\u002F\u002F …401 on err…\nrows := s.store.ByOwner(caller.UserID)\n\n\u002F\u002F GET \u002Fclaims — a different operation, guarded by claims:read-all\nrows := s.store.All()\n```\n\n`auth.HasScope` never decides which rows come back and is never an operation's\nonly check — both were settled before the handler ran, at the gateway and by\nthe path.\n\nA **single-row** read is the same rule at the other end: when the caller holds\nonly the `own` handle and the row belongs to someone else, answer **404, not\n403** — a caller who may not learn a row exists may not learn it exists from a\nstatus code either (`api-management` owns the rule; this is its Go shape).\n\n**Test through the real router.** Build the wired handler in the test —\n`gen.HandlerWithOptions(…)` with the verifier middleware, not the bare\nhandlers. Mint the test's assertions with a throwaway RSA key and set **all\nthree** variables: `GATEWAY_ASSERTION_CERTIFICATE` to that key's self-signed\ncertificate, and `GATEWAY_ASSERTION_ISSUER` and `GATEWAY_ASSERTION_HEADER` to\nthe values the test's own assertions are minted with. The certificate alone is a\npartial trio, so `NewVerifierFromEnv` returns an error and the test fails before\nit has asserted anything. Nothing in the test talks to a gateway. Write four\ntests, by these names:\n\n- **`TestForgedAssertionIs401`** — the same request signed by a *different* key\n  is rejected, and so is one with its payload edited after signing. This is the\n  one test that proves the trust anchor is the signature and not the header.\n- **`TestHealthIsPublic`** — the `security: []` operation answers 200 with no\n  assertion *and* with forged `X-User-*` headers, and the handler reads neither.\n- **`Test\u003CResource>ListOwnershipAndWidening`** and\n  **`Test\u003CResource>GetOwnershipWidening`** — the `own`\u002F`any` pair: the same\n  operation returns the caller's rows with the `own` handle and every row with\n  the `any` one, and the single-row read 404s on another owner's id.\n\nThere is deliberately no per-operation scope matrix here: that table lives in\nthe contract and is enforced at the gateway, and a copy of it in these tests\nwould pass while the deployed API disagreed. Domain invariants (an\nalready-approved claim, a conflicting transition) get their own test beside\nthese.\n\n## Layout\n\n```\n\u003Capp-path>\u002F\n├── go.mod               # module path matches the app folder name\n├── go.sum               # ONLY with external deps — stdlib-only has none\n├── main.go              # entrypoint — small services keep it all here\n├── internal\u002F\n│   ├── gen\u002F             # oapi-codegen output — generated, committed, never edited\n│   ├── auth\u002F            # gateway_assertion.go, copied VERBATIM from this\n│   │                    #   skill's assets\u002F — stdlib only, nothing to edit\n│   ├── handlers\u002F        # http handlers, one file per resource\n│   ├── store\u002F           # Postgres access\n│   ├── models\u002F          # request\u002Fresponse\u002Fdomain types\n│   └── middleware\u002F      # cross-cutting only (rare)\n├── Dockerfile\n└── workload.yaml\n```\n\n`workload.yaml`'s HTTP endpoint `visibility`: before writing it, read\n`skills\u002Faep`'s `references\u002Fworkload-and-wiring.md` (\"Provider endpoint\nvisibility\") and write the list it gives a provider, one YAML item per value.\n\n**Done when:** the endpoint's `visibility` is exactly that list.\n\n`Dockerfile` — multi-stage, pinned builder, slim runtime:\n\n```dockerfile\nFROM golang:1.25-alpine AS builder\nWORKDIR \u002Fsrc\n# Two branches, and you pick one. A service with ANY dependency — every\n# oapi-codegen service is one — has a go.sum and copies both, as below.\n# A STDLIB-ONLY service has no go.sum; naming a file that does not exist as a\n# COPY source hard-fails the build, so that one is `COPY go.mod .\u002F` instead.\nCOPY go.mod go.sum .\u002F\nRUN go mod download\nCOPY . .\n# Build the main package — `.\u002F` (module root) or `.\u002Fcmd\u002F\u003Cname>`. A real `-o`\n# target takes exactly ONE package; `.\u002F...` is for the `-o \u002Fdev\u002Fnull` verify.\nRUN CGO_ENABLED=0 go build -ldflags='-s -w' -o \u002Fout\u002Fapp .\u002F\n\nFROM alpine:3.20\nRUN apk add --no-cache ca-certificates\nCOPY --from=builder \u002Fout\u002Fapp \u002Fapp\nEXPOSE 9090\nENTRYPOINT [\"\u002Fapp\"]\n```\n\nPostgres — pure-Go `pgx` pool, DSN built from the injected env vars:\n\n```go\nimport \"github.com\u002Fjackc\u002Fpgx\u002Fv5\u002Fpgxpool\"\n\npool, err := pgxpool.New(ctx, os.Getenv(\"\u003CDB_URL_ENV_VAR>\"))\n```\n\n## Pitfalls\n\n| Symptom | Cause | Fix |\n|---|---|---|\n| Build fails `go.mod requires go >= 1.25` | Dockerfile pinned an older Go | `FROM golang:1.25-alpine AS builder` |\n| Build times out compiling a dependency | A cgo dependency compiling C under the build pod's throttle | Swap it for a pure-Go library; `CGO_ENABLED=0` |\n| Data vanishes on every re-deploy | Wrote to a file DB on the pod's ephemeral filesystem | Use the provisioned Postgres |\n| `panic: … connection refused` \u002F empty DSN at startup | Read a guessed env-var name, not the injected one | Read the env-var names the platform injected for the resource dependency |\n| Build fails `cannot write multiple packages to non-directory \u002Fout\u002Fapp` | `go build -o \u002Fout\u002Fapp .\u002F...` on a multi-package module | Build the main package: `.\u002F` or `.\u002Fcmd\u002F\u003Cname>` |\n| `checksum mismatch … SECURITY ERROR` at build | `go.sum` stale or hand-edited | `go mod tidy` locally; commit the result |\n| Build fails `COPY go.mod go.sum .\u002F … go.sum: no such file or directory` | Dockerfile names `go.sum`, stdlib-only service has none | `COPY go.mod .\u002F` only — but a service with any dependency needs both |\n| Every `\u002Fapi` call through the SPA 503s, or the API is not curl-able on the public gateway | The endpoint `visibility` is not the provider list | Write the list `workload-and-wiring` gives a provider |\n| Pod won't start; `panic: listen tcp :8080` | Wrong port | Listen on 9090 |\n| `POST` to an injected upstream returns `405` (or a `301` then a `GET`) | Address ended in `\u002F`, so `base + \"\u002Fpath\"` built `\u002F\u002Fpath`; `ServeMux` 301s to the clean path and the client re-issues it as `GET` | `url.JoinPath(base, \"path\")` |\n| Create\u002FPOST 500s only when an optional list field is omitted (`[]` works) | Nil slice bound as `NULL` into a `NOT NULL` array column; its `DEFAULT` skipped because the INSERT lists it | Normalize nil→empty, or omit the column |\n| Every call 401s right after a deploy | The environment's gateway publishes a different key than the container holds — it was re-provisioned and this component was not redeployed | Redeploy the component; the certificate rides its ReleaseBinding |\n| The service will not start: `…must be set together or not at all` | Some of the three are set, not all | Locally, set all three from a throwaway keypair. In a cell, the environment's gateway needs provisioning |\n| A public operation 401s | A handler for a `security: []` operation called `RequireCaller` | A public handler reads no identity; the gateway sends no assertion with one |\n| Every caller looks anonymous | Read `X-User-Id` instead of the verified caller | `auth.RequireCaller(ctx)` — the headers are unsigned and prove nothing |\n",{"name":5,"metadata":24,"description":7},{"aep":25},{"kind":26,"audience":27},"org",[28],"coding","main","e3b5fc8668f26761380b2d4965719f2d8f2eb246","skills\u002Fgo","https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer","https:\u002F\u002Fgithub.com\u002Fwso2","https:\u002F\u002Fwso2.com","Welcome to the WSO2 source code! For info on working with the WSO2 repositories and contributing code, click the link below.","2026-11-11 15:36:27",{"source":8,"skillName":5,"commands":38,"prompt":48,"zipAvailable":49},[39,42,45],{"tool":40,"command":41},"npx","npx skills add wso2\u002Flabs-agentic-engineer --skill go",{"tool":43,"command":44},"bunx","bunx skills add wso2\u002Flabs-agentic-engineer --skill go",{"tool":46,"command":47},"pnpm","pnpm dlx skills add wso2\u002Flabs-agentic-engineer --skill go","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Fgo\u002FSKILL.md",true,[51],{"path":52,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":55,"sourceHtmlUrl":56},"assets\u002Fgateway_assertion.go","SCRIPT","脚本",16996,"https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Fgo\u002Fassets\u002Fgateway_assertion.go",[58,65,72,79,86,93],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M735MP9NFFRPS260G9D16JQX","validation-task","Load when working a VALIDATION task dispatched by WSO2 Labs Agentic Engineer — judging a deployed version against its acceptance criteria.","https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Fvalidation-task\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M735MJ8ZMRZR20A57TMF7R9Q","thunder-authentication","Apply when a component sits on the project's sign-in — a SPA whose users authenticate through the auth platform-resource dependency, or a protected backend those signed-in users call.","https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Fthunder-authentication\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":19},"01M735MFQMY8DY1EM7JKS784D3","task-planning","Use when planning a version's build from a design — the plan turn that writes the build's checklist with planBuild, one item per feature the version carries in build order, after a Foundation item when the version needs one.","https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Ftask-planning\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M735MCJQ4EVH7G4ZFMC682Y4","start","Use when kicking off a project from its idea — the product pass that agrees the feature list and writes the product page, the product-wide page and a stub per feature — or re-running \u002Fstart on a project that already has requirements.","https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Fstart\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":19},"01M735M9R050KT3H34PVXN2MKK","security-design","Write specs\u002Fdesign\u002Fsecurity.json when a design has sign-in, permissions, roles or test users — the permission catalog every API operation is gated on.","https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Fsecurity-design\u002FSKILL.md",[],[],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":19},"01M735M60CTW4S7XMS6XCX9A7Y","resolve-dependency","Use for taking one external dependency from open to resolved — `\u002Fresolve-dependency \u003Cname> [answer]` names it and may carry the provider the user chose; `\u002Fresolve-dependencies` walks every open one in turn. Ask which provider (their suggestions as options; never choose for them), get its interface on disk (found, uploaded from the card, or assumed under the authorization the card records), then derive the config keys.","https:\u002F\u002Fgithub.com\u002Fwso2\u002Flabs-agentic-engineer\u002Fblob\u002Fmain\u002Fskills\u002Fresolve-dependency\u002FSKILL.md",[],[]]