Skip to content

Commit d216ce2

Browse files
committed
Update docs
Signed-off-by: Paweł Gronowski <git@grono.dev>
1 parent 0b11534 commit d216ce2

2 files changed

Lines changed: 102 additions & 80 deletions

File tree

‎docs/AUTHORING.md‎

Lines changed: 87 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
This is the procedural guide.
44
Read [DESIGN.md](./DESIGN.md) for current rules and the [overview](../README.md#how-it-works) for the main concepts.
5-
No engine hook points are available as implementation references yet, so the snippets below are illustrative.
5+
This guide describes the standalone Go module; snippets with placeholder package names illustrate how to embed it in your application.
6+
The repository does not provide Docker daemon configuration, CLI flags, or engine hook points.
67

78
## Point authoring
89

910
### Files and source of truth
1011

11-
Create `extpoints/<area>/<name>/v0/`.
12+
Create `extpoints/<area>/<name>/v0/` in your own Go module.
13+
This layout is a convention, not a required location.
1214
A point has one hand-written Go contract and generated wire files:
1315

1416
```
@@ -95,7 +97,7 @@ The detailed rules are [DESIGN.md](./DESIGN.md#resolution-ordering-and-lifecycle
9597
Use `DefineSinglePoint` for a deciding point; the generated `ClientPoint` makes the host reject two executable providers.
9698
Built-ins yield to executable providers.
9799
Runtime fallback and failure behavior belongs to the point's call helper and must be stated in its contract.
98-
Omit a built-in point's `ClientPoint` from `clientProviders()` to close it to replacement; a launched declaration is then rejected at client wiring.
100+
Omit a built-in point's `ClientPoint` from `host.WithClientProviders` to close it to internal replacement; a launched declaration requiring that client wiring is then rejected.
99101
- Prefer unary `M(ctx, *Req) (*Resp, error)` methods and explicit phases such as `Update` followed by `Validate`; keep dependencies acyclic and optional when absence is valid.
100102
- Choose fail-open or fail-closed behavior.
101103
Security and veto points normally fail closed.
@@ -154,54 +156,57 @@ from the inferred service identity.
154156

155157
### 3. Generate and validate
156158

157-
Run the pinned toolchain:
159+
Generation needs Go 1.26 or newer, but no `protoc`, plugins, or other `PATH` tools.
160+
In your own module, record the generator as a tool dependency before running the directive:
158161

159-
```console
160-
$ make generate-extensions
162+
```fish
163+
go get -tool github.com/moby/extensions/cmd/mobyextgen
164+
go generate ./extpoints/<area>/<name>/v0/
165+
go mod tidy
166+
go test ./...
161167
```
162168

163-
This regenerates every contract and copies the result back into the tree.
164-
CI runs `make validate-generate-extensions` and fails if committed output does not match a fresh run.
165-
Commit generated output.
169+
Replace `<area>` and `<name>` with your package directory names.
170+
The directive uses the generator version selected by your module's dependency graph.
171+
The tool dependency keeps the generator's dependencies and checksums available after `go mod tidy`.
172+
Commit the generated output along with `go.mod` and `go.sum`.
166173

167-
Generation needs only the Go toolchain: no `protoc`, plugins, or other `PATH` tools.
168-
To regenerate one point use:
174+
When contributing to this repository, regenerate all contracts from the repository root:
169175

170-
```console
171-
$ go generate ./extpoints/<area>/<name>/v0/
176+
```fish
177+
go generate ./...
172178
```
173179

174-
To reproduce the CI scope use:
180+
Check that committed output matches fresh generation without rewriting the checkout:
175181

176-
```console
177-
$ go generate ./extpoints/... ./internal/extensions/...
182+
```fish
183+
make lint-generate
178184
```
179185

180-
The make target pins the Go version to make validation hermetic, not because generation needs a container.
186+
CI runs this check as part of `make lint`, using the Go version from `go.mod` in a container.
187+
The direct `make lint-generate` command uses your local Go toolchain.
181188

182189
### 4. Call the point from an engine flow
183190

184191
Import the contract and call its helper with the host as `extensions.Resolver`.
185-
The daemon's `*host.Host` satisfies that interface.
186-
A point with no providers resolves zero providers and is a safe no-op.
192+
The `*host.Host` returned by `host.New` satisfies that interface.
193+
`Point.All` returns an empty list when there are no providers; `Point.Single` returns an error.
194+
The helper must define whether absence is a safe no-op or a failure.
187195
Call the helper at the engine boundary where its input is complete.
188196
A security policy point must inspect the authoritative data used by the protected operation so an earlier or partial representation cannot bypass it.
189197

190198
### 5. Support separate-binary providers
191199

192200
Steps 1–4 are sufficient for in-process providers.
193-
To support a launched provider, add its generated `ClientPoint` to `clientProviders()` in `daemon/extensions.go`:
201+
To support a launched provider, pass its generated `ClientPoint` when constructing the Host:
194202

195203
```go
196-
func clientProviders() []clientpoint.Registration {
197-
return []clientpoint.Registration{
198-
<name>pb.ClientPoint, // add this
199-
}
200-
}
204+
host.WithClientProviders(mypointpb.ClientPoint),
201205
```
202206

203207
`ClientPoint` builds an in-process caller from the gRPC connection.
204-
This list is the boundary for launched providers: an unlisted declared point is rejected, while any executable extension may provide a listed point.
208+
This list is the wiring boundary for internal calls to launched providers: an unlisted declared point is rejected unless it is offered only for external publication.
209+
Use `host.WithProviderPolicy` to restrict which extensions may provide internally wired points.
205210
See [DESIGN.md#discovery-security](./DESIGN.md#discovery-security).
206211

207212
An offered-only process Point does not need `ClientPoint` wiring because the Host
@@ -319,7 +324,7 @@ func (b *Bridge) Declaration() extensions.Declaration {
319324
```
320325

321326
`Init` receives the extension config and a resolver.
322-
Config is keyed by id in `daemon.json`; declare dependencies and conflicts in the declaration.
327+
The application supplies config keyed by id through `host.WithExtensionConfig`; declare dependencies and conflicts in the declaration.
323328
The broker initializes dependencies before dependents.
324329

325330
### Retain dependencies for later calls
@@ -395,44 +400,44 @@ For an out-of-process extension, wire every dependency point it will call:
395400

396401
```go
397402
srv := sdk.NewServer()
398-
srv.Register(ext, mypointpb.ServerPoint) // include each provided point
403+
if err := srv.Register(ext, mypointpb.ServerPoint); err != nil {
404+
return err
405+
}
399406
srv.Depends(volumedriverpb.ClientPoint) // one per dependency point it will call
400-
srv.Listen(ctx)
407+
return srv.Listen(ctx)
401408
```
402409

403-
The host must offer the same points as dependencies by listing their generated `ServerPoint` in `dependencyProviders()` in `daemon/extensions.go`.
404-
A dependency on an extension-defined point works only when the daemon supports that wiring.
410+
The Host must offer the same points as dependencies by passing their generated `ServerPoint` to `host.WithDependencyProviders`.
411+
A dependency on an extension-defined point works only when the application supplies that wiring.
405412
Cross-process dependency lookup currently exposes one provider; `All` and by-id selection are deferred.
406413

407-
Configure extensions under `extension-config` in `daemon.json`:
414+
Configure extensions when constructing the Host:
408415

409-
```json
410-
{
411-
"extension-config": {
412-
"com.example.myext.v1": { "some_key": "value" }
413-
}
414-
}
416+
```go
417+
host.WithExtensionConfig(map[extensions.ExtensionID]extensions.Config{
418+
"com.example.myext.v1": {"some_key": "value"},
419+
}),
415420
```
416421

417422
The same entry reaches an in-process `Init` or a separate binary through the startup handshake.
423+
The application chooses how to read and validate this configuration; the framework does not read `daemon.json`.
418424

419425
### Run in-process
420426

421-
Register a built-in by adding it to `builtinExtensions()` in `daemon/extensions.go`; select it from daemon config as needed:
427+
Register in-process extensions with `host.WithExtensions`:
422428

423429
```go
424-
func builtinExtensions(cfg *config.Config) []extensions.Extension {
425-
var exts []extensions.Extension
426-
if cfg.SomeFeatureEnabled {
427-
exts = append(exts, somepkg.Extension)
428-
}
429-
return exts
430+
h, err := host.New(ctx,
431+
host.WithExtensions(myext.Extension),
432+
host.WithExtensionConfig(extensionConfig),
433+
)
434+
if err != nil {
435+
return err
430436
}
431437
```
432438

433439
Built-ins use the same registration path as launched binaries.
434-
Their config is delivered by id through
435-
`host.WithExtensionConfig(extensionConfig)`.
440+
Keep `h` for point resolution and call `h.Shutdown` when the application exits, using a context that has not already been canceled.
436441

437442
### Run out-of-process
438443

@@ -455,13 +460,31 @@ The daemon writes startup config to stdin and waits for one `ready\n` line on st
455460
Any other pre-readiness stdout corrupts the handshake and fails launch.
456461
The daemon captures stderr in its logs.
457462

458-
Deploy the binary with the extension id as its name, in the extensions directory, which defaults to `/usr/libexec/docker/moby-extensions/`.
459-
`--extension-dir` overrides it; rootless mode uses the user's libexec home; on Windows use `<id>.exe`.
460-
The daemon discovers and launches binaries at startup.
463+
Deploy the binary with the extension id as its name; on Windows the name is `<id>.exe`.
464+
The embedding application chooses the binary directories and runtime directory:
465+
466+
```go
467+
h, err := host.New(ctx,
468+
host.WithDirs(extensionDir),
469+
host.WithRuntimeDir(runtimeDir),
470+
host.WithClientProviders(mypointpb.ClientPoint),
471+
host.WithExtensionConfig(extensionConfig),
472+
)
473+
if err != nil {
474+
return err
475+
}
476+
```
477+
478+
`host.New` discovers and launches accepted binaries in the supplied directories.
479+
There is no default discovery directory or `--extension-dir` flag in this library.
480+
Use trusted binary directories and a private runtime directory writable only by the Host's user, with a short absolute path for Unix sockets.
481+
Create the private runtime directory before constructing the Host, and supply it whenever launching processes or exposing dependency callbacks.
482+
Keep the construction context alive while launched processes are in use, and call `h.Shutdown` before the application exits.
483+
See [discovery security](./DESIGN.md#discovery-security) before installing binaries.
461484

462485
There is no watchdog yet.
463486
If the process dies, callers get gRPC errors until the daemon restarts.
464-
Health checks, reconnect, and restart are future work in [ROADMAP.md](./ROADMAP.md).
487+
See the [lifecycle limitations](./DESIGN.md#resolution-ordering-and-lifecycle).
465488

466489
## Author checklist
467490

@@ -482,19 +505,16 @@ Health checks, reconnect, and restart are future work in [ROADMAP.md](./ROADMAP.
482505

483506
## Quick reference
484507

485-
| Task | Where | What |
486-
|---|---|---|
487-
| Define a point | `extpoints/<area>/<name>/v0/<name>.go` | Go interface, `pb` messages, `DefinePoint`, helpers |
488-
| Name its wire service | same contract file | inferred `<PointID>.<InterfaceName>` |
489-
| Offer an ordinary point | extension declaration | implement it with `Point.Provide` and name it in `servicev0.Offer` |
490-
| Authorize an internal provider | host functional options | return `host.Allow()` from identity-aware `WithProviderPolicy`; ordinary Point IDs control admission; nil preserves registration |
491-
| Authorize publication | host functional options | return `host.Allow()` for `servicev0.Point.ID()` through `WithProviderPolicy`; supply `WithPointServers` for in-process offers |
492-
| Invoke a published point | external caller | use generated `NewClient(hostConn)` |
493-
| Serve an ordinary point | SDK or dependency wiring | pass its generated `ServerPoint` |
494-
| Wire it | `extpoints/<area>/<name>/v0/<name>.go` | package doc and identical `//go:generate` |
495-
| Generate | `go generate ./extpoints/<area>/<name>/v0/` | regenerate `.proto` and `protogen/` |
496-
| Invoke it | relevant engine flow | call the contract helper with the host resolver |
497-
| Support a binary | `daemon/extensions.go` → `clientProviders()` | add `<name>pb.ClientPoint` |
498-
| Write an extension | anywhere | `extensions.New(Declaration{…})` or `Extension` |
499-
| Run it built-in | `daemon/extensions.go` → `builtinExtensions()` | append the extension value |
500-
| Run it as a binary | `cmd/<name>/main.go` | `sdk.Main(ext, sdk.WithServerPoints(<name>pb.ServerPoint))` |
508+
- Define a Point with a Go interface, `pb` messages, `DefinePoint`, and call helpers in your contract package.
509+
- Generate its `.proto` and `protogen/` files with `go generate`; the wire service name is `<PointID>.<InterfaceName>`.
510+
- Implement an extension with `extensions.New(Declaration{…})` or an `Extension` implementation.
511+
- Register it in-process with `host.WithExtensions`, or serve it in a binary with `sdk.Main` and `sdk.WithServerPoints`.
512+
- Discover binaries with `host.WithDirs` and provide socket storage with `host.WithRuntimeDir`.
513+
- Wire internal calls to binaries with `host.WithClientProviders`.
514+
- Wire calls from binaries to Host providers with `host.WithDependencyProviders` and SDK `Server.Depends`.
515+
- Supply configuration by extension id with `host.WithExtensionConfig`.
516+
- Resolve Points through the Host and call their contract helpers.
517+
- Restrict internal providers with `host.WithProviderPolicy` using ordinary Point IDs.
518+
- Offer implemented Points with `servicev0.Offer`, authorize publication through policy on `servicev0.Point.ID()`, and supply `host.WithPointServers` for in-process offers.
519+
- Call published Points with the generated `NewClient(hostConn)`.
520+
- Release lifecycle resources with `Host.Shutdown`.

‎docs/DESIGN.md‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
This document is the authoritative description of current behavior and constraints.
44
See the [overview](../README.md#how-it-works) and procedural [authoring guide](./AUTHORING.md).
55
Runtime reload, out-of-process health handling, and scoped dependency resolvers are not current behavior.
6-
The framework and runtime protocol are experimental and currently make no
7-
backward-compatibility promise.
6+
The Go API and runtime protocol are experimental and currently make no backward-compatibility promise.
7+
The framework is a standalone Go module embedded through `host.New`.
8+
References to a daemon below mean the embedding application, which supplies configuration, discovery directories, and any public transport endpoint.
9+
Docker configuration files, CLI flags, and engine integration are outside this module.
810

911
## Contract and startup
1012

@@ -112,8 +114,7 @@ Errors are attributed to the extension that produced them.
112114
There is no watchdog, process restart, reconnect, or adoption of extension
113115
processes from an earlier host.
114116
A daemon restart constructs a new Host and a new fixed extension set.
115-
Moby live restore does not retain extension processes, callback sockets, or
116-
in-memory extension state.
117+
The framework provides no integration with Moby live restore to retain extension processes, callback sockets, or in-memory extension state.
117118
Until a separate extension lifecycle exists, an extension must not own runtime
118119
state required by containers that are expected to survive their host daemon.
119120
The generic Host makes no universal guarantee that an abrupt host crash kills
@@ -194,16 +195,17 @@ service inventory. A name cannot collide with another extension or a service
194195
already served by the daemon; collision fails startup rather than shadowing the
195196
existing service.
196197

197-
These services use the raw gRPC endpoint beside the daemon's own gRPC services.
198-
Authorization plugins gate the REST API, not this endpoint; an exposed service must enforce any access control it needs.
198+
The embedding application chooses the gRPC endpoint used for publication; the framework does not create a Docker API endpoint.
199+
An exposed service must enforce any access control it needs.
200+
In a Moby integration, REST authorization plugins must not be assumed to protect a separate gRPC endpoint.
199201

200202
## Separate-process protocol
201203

202204
The binary name is its extension id (`<id>.exe` on Windows), and the daemon launches it from the configured extension directory.
203205
Startup proceeds as follows:
204206

205207
1. The daemon writes JSON to stdin with `endpoint`, `protocolVersion`, `config`, and, when dependencies are offered, `callbackEndpoint`.
206-
The current protocol version is `1`; `config` is the parsed `daemon.json` entry for the id.
208+
The current protocol version is `1`; `config` is the entry supplied through `host.WithExtensionConfig` for the id.
207209
2. The SDK listens on the supplied Unix socket, then writes exactly `ready\n` to stdout.
208210
Stdout is reserved for this line: any earlier output corrupts the handshake and fails launch.
209211
The daemon also drains later stdout so it cannot block the process.
@@ -250,8 +252,8 @@ executable, often as root; each accepted binary remains trusted host code.
250252
Its host-attested identity is attribution for lookup and policy, not a sandbox,
251253
permission, or security boundary.
252254

253-
- `--extension-dir`, or the default `/usr/libexec/docker/moby-extensions`, is trusted.
254-
Treat it as a root-owned program directory: only package managers or operators should install files there, and unprivileged users must not be able to write to it.
255+
- Directories supplied through `host.WithDirs` are trusted; the framework has no default discovery directory.
256+
Treat each as a root-owned program directory: only package managers or operators should install files there, and unprivileged users must not be able to write to it.
255257
- A world-writable directory or binary is skipped with a warning.
256258
A binary or directory owned by anyone other than root or the daemon user is also skipped because its owner could rewrite daemon-executed code.
257259
Only executable files with valid extension-id names are launched; stray tools and build leftovers are not executed.
@@ -262,8 +264,8 @@ permission, or security boundary.
262264
- Symlink targets are checked as ordinary files.
263265
Where ownership cannot be determined from file metadata, notably on Windows, the owner check is not enforced; ACL and group policy remain the operator's responsibility.
264266
- One accepted extension that cannot launch, describe, initialize, or coexist with the set fails daemon startup.
265-
Because the default directory is scanned automatically, a broken or incompatible binary there blocks startup until removed.
266-
- In rootless mode, the daemon and libexec directory belong to the user, so "trusted" means trusted by that user; the world-writable check still applies.
267+
Because every configured directory is scanned at Host construction, a broken or incompatible binary there blocks startup until removed or its directory is no longer configured.
268+
- When running as an unprivileged user, "trusted" means trusted by that user; the world-writable check still applies.
267269
Packaging should install one non-world-writable binary per extension, named after its id.
268270

269271
There is no sandbox or separate permission model after acceptance.
@@ -282,6 +284,6 @@ WASM and OPA-style hosts suit sandboxed, reloadable pure computation, not mounts
282284

283285
As with admission webhooks, each point must explicitly choose fail-open or fail-closed behavior.
284286
Security and veto points generally fail closed; transport or diagnostic points may choose otherwise.
285-
The framework is built in-tree, with external-binary discovery and packaging on the same extension-facing Go API.
287+
The framework is a standalone Go module, with external-binary discovery and in-process registration on the same extension-facing Go API.
286288
Transport is a host assembly choice: direct Go and gRPC use the same point interface.
287-
Keeping the startup protocol small and the framework in-tree leaves room for extraction or convergence after production experience instead of freezing an unproven public contract.
289+
Keeping the startup protocol small and the API experimental leaves room for changes after integration experience instead of freezing an unproven public contract.

0 commit comments

Comments
 (0)