Skip to content

feat: grant core + grants schema + validation (#117)#123

Merged
pedromvgomes merged 3 commits into
mainfrom
feature/grant-core
Jun 15, 2026
Merged

feat: grant core + grants schema + validation (#117)#123
pedromvgomes merged 3 commits into
mainfrom
feature/grant-core

Conversation

@pedromvgomes

Copy link
Copy Markdown
Contributor

Part of #117. Foundational slice of ADR-0025 (the Grant capability), landing in dependency order ahead of the two provider slices.

What this slice ships (slice A — grant core + schema + validation)

No provider behavior yet — this is the abstraction, the manifest schema, and the credential-free inforge validate pass.

  • internal/grant — the Grantable interface (Grant(...) stub + credential-free FieldNames(perm) (values, files)), Permission (ro|rw), Fields/FileMaterial, the grant.For(type) lookup, and the {FIELD} template machinery (ParseTemplate / Template.{Fields,HasLiteral,Interpolate}). Database publishes value fields {USER,PASSWORD,HOST,PORT,DBNAME}; PKIResource publishes file fields {CERT} (verify/ro) and {CERT,KEY} (issue/rw). FieldNames is credential- and instance-independent, so validation is real and testable without pulling in pgx or the PKI generate command — the Grant(...) bodies are clearly-marked stubs for slices B/C.
  • Schemagrants: added to the service manifest (ServiceSpec + schemas/service.json): a list of {resource: <type>/<name>, permission: ro|rw, outputs: map[ENV]=template}, sitting with pki:/ingress:.
  • PKI resource type (declarative only)types.PKIResourceSpec + schemas/pkiresource.json + loader/validate enumeration for regional|global/pki/<name>/manifest.yaml (root-only, scope from folder). This is the one refinement to the proposed A/B/C split (confirmed before coding): slice A's pki/* grant-validation bullets (target-exists, root-only, cross-region) require the validator to resolve PKI-resource folders, so the declarative type lands here. The pki.enc.yaml sidecar, inforge pki generate, and the Grant/projection behavior stay in slice C.
  • inforge validatecheckGrants implements every ADR "Validation" bullet credential-free: target resolves to a supported Grantable of the right shape; permission ∈ {ro,rw}; every {FIELD} is published for that permission; a file field must stand alone; output env names avoid reserved INFORGE_*/MTLS_* (reusing meshcert.DescriptorFiles()) and don't collide with environment.yaml keys or each other across grants. Cross-region boundary falls out of target resolution (shared regional set + global/ prefix), mirroring ref:. Plus checkPKIResource rejects a non-root-only PKI resource.

The bootstrapper is untouched (the point of the value/file field-kind split). Grants are not wired into deploy in this slice.

Follow-on slices

  • B — Database Grantable: per-service NeonRole + ro/rw Postgres GRANTs over a CGO-free pgx owner connection; removes DatabaseOutputs.ConnectionURL (breaking — migrates ref:database/*.connectionUrl consumers).
  • C — PKI resource Grantable: age-encrypted pki.enc.yaml sidecar, inforge pki generate, the verify/issue file-field Grant + file-output projection.

Tests / gates

  • Table-driven unit tests for internal/grant (template parse/interpolate, field names, For, permission) and validate.checkGrants / checkPKIResource (all error paths + valid cases incl. global targets); the ok validate fixture gains a regional PKI resource and grants on the api service to exercise the end-to-end path.
  • go build ./..., go test -race ./..., golangci-lint run ./... all clean.

Docs: internal/CONTEXT.md glossary (Grant/Grantable/PKI resource/Field/Output) already merged with ADR-0025; AGENTS.md gains a Grants section.

@pedromvgomes pedromvgomes added the pki Service-mesh + daemon PKI work label Jun 15, 2026
- checkGrants: default arm so a future Grantable wired into grant.For
  without a switch resolver fails loudly instead of skipping validation
- globalHasResources: count PKI resources (a global PKI-only slice with no
  providers block must still fail the guard)
- checkGrants: skip field-publication checks for an unresolved target so a
  wrong resource name yields one clear error, not a misleading cascade
- checkGrants: reject an output template that interpolates no field (a
  dropped-brace typo would otherwise validate as a constant)
- extract reservedEnvNameErrs shared by the environment.yaml and grant-output
  checks; fix the doc comment that overstated the reserved MTLS_* namespace
@pedromvgomes pedromvgomes merged commit bef5e77 into main Jun 15, 2026
2 checks passed
@pedromvgomes pedromvgomes deleted the feature/grant-core branch June 15, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pki Service-mesh + daemon PKI work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant