You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d216ce2
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/AUTHORING.md
+87-67Lines changed: 87 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,15 @@
2
2
3
3
This is the procedural guide.
4
4
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.
6
7
7
8
## Point authoring
8
9
9
10
### Files and source of truth
10
11
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.
12
14
A point has one hand-written Go contract and generated wire files:
13
15
14
16
```
@@ -95,7 +97,7 @@ The detailed rules are [DESIGN.md](./DESIGN.md#resolution-ordering-and-lifecycle
95
97
Use `DefineSinglePoint` for a deciding point; the generated `ClientPoint` makes the host reject two executable providers.
96
98
Built-ins yield to executable providers.
97
99
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.
99
101
- 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.
100
102
- Choose fail-open or fail-closed behavior.
101
103
Security and veto points normally fail closed.
@@ -154,54 +156,57 @@ from the inferred service identity.
154
156
155
157
### 3. Generate and validate
156
158
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:
158
161
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 ./...
161
167
```
162
168
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`.
166
173
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:
169
175
170
-
```console
171
-
$ go generate ./extpoints/<area>/<name>/v0/
176
+
```fish
177
+
go generate ./...
172
178
```
173
179
174
-
To reproduce the CI scope use:
180
+
Check that committed output matches fresh generation without rewriting the checkout:
175
181
176
-
```console
177
-
$ go generate ./extpoints/... ./internal/extensions/...
182
+
```fish
183
+
make lint-generate
178
184
```
179
185
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.
181
188
182
189
### 4. Call the point from an engine flow
183
190
184
191
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.
187
195
Call the helper at the engine boundary where its input is complete.
188
196
A security policy point must inspect the authoritative data used by the protected operation so an earlier or partial representation cannot bypass it.
189
197
190
198
### 5. Support separate-binary providers
191
199
192
200
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:
`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.
205
210
See [DESIGN.md#discovery-security](./DESIGN.md#discovery-security).
206
211
207
212
An offered-only process Point does not need `ClientPoint` wiring because the Host
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.
436
441
437
442
### Run out-of-process
438
443
@@ -455,13 +460,31 @@ The daemon writes startup config to stdin and waits for one `ready\n` line on st
455
460
Any other pre-readiness stdout corrupts the handshake and fails launch.
456
461
The daemon captures stderr in its logs.
457
462
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.
461
484
462
485
There is no watchdog yet.
463
486
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).
465
488
466
489
## Author checklist
467
490
@@ -482,19 +505,16 @@ Health checks, reconnect, and restart are future work in [ROADMAP.md](./ROADMAP.
482
505
483
506
## Quick reference
484
507
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`.
Copy file name to clipboardExpand all lines: docs/DESIGN.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,10 @@
3
3
This document is the authoritative description of current behavior and constraints.
4
4
See the [overview](../README.md#how-it-works) and procedural [authoring guide](./AUTHORING.md).
5
5
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.
8
10
9
11
## Contract and startup
10
12
@@ -112,8 +114,7 @@ Errors are attributed to the extension that produced them.
112
114
There is no watchdog, process restart, reconnect, or adoption of extension
113
115
processes from an earlier host.
114
116
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.
117
118
Until a separate extension lifecycle exists, an extension must not own runtime
118
119
state required by containers that are expected to survive their host daemon.
119
120
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
194
195
already served by the daemon; collision fails startup rather than shadowing the
195
196
existing service.
196
197
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.
199
201
200
202
## Separate-process protocol
201
203
202
204
The binary name is its extension id (`<id>.exe` on Windows), and the daemon launches it from the configured extension directory.
203
205
Startup proceeds as follows:
204
206
205
207
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.
207
209
2. The SDK listens on the supplied Unix socket, then writes exactly `ready\n` to stdout.
208
210
Stdout is reserved for this line: any earlier output corrupts the handshake and fails launch.
209
211
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.
250
252
Its host-attested identity is attribution for lookup and policy, not a sandbox,
251
253
permission, or security boundary.
252
254
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.
255
257
- A world-writable directory or binary is skipped with a warning.
256
258
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.
257
259
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.
262
264
- Symlink targets are checked as ordinary files.
263
265
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.
264
266
- 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.
267
269
Packaging should install one non-world-writable binary per extension, named after its id.
268
270
269
271
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
282
284
283
285
As with admission webhooks, each point must explicitly choose fail-open or fail-closed behavior.
284
286
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.
286
288
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