Skip to content

🔒 security(filter): enforce endpoint-config policy symmetrically at create and connect - #136

Merged
scttbnsn merged 12 commits into
dev/v1.5from
fix/endpoint-config-symmetry
Jul 11, 2026
Merged

scttbnsn merged 12 commits into
dev/v1.5from
fix/endpoint-config-symmetry

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Closes the create/connect endpoint-config asymmetry found while root-causing a real production incident (drydock recreating a macvlan+static-IP container through sockguard defaults).

  • POST /containers/create now inspects NetworkingConfig.EndpointsConfig — static IPs, MAC addresses, links, and driver opts are gated by the existing request_body.network.allow_endpoint_config flag (default unchanged: false), identically to /networks/{id}/connect. Previously the same config passed create uninspected, making the connect-side gate a bypassable no-op.
  • The deprecated root-level create MacAddress field is now gated too (the daemon still honors it on the primary endpoint — same bypass class).
  • Aliases are no longer gated at either endpoint. Compose sets a service-name alias on every endpoint, so alias-gating broke every multi-network compose recreate while providing no real boundary (it was never enforced at create). Links remain gated.
  • Docs corrected where they overstated the old guarantee; drydock preset configs annotated (macvlan/static-IP/MAC-pinning operators need allow_endpoint_config: true); conformance suite now covers the real incident shape plus the drydock ≥1.5.3 vs pre-1.5.3 payload difference.

Why this shape

Decided via two independent design reviews then synthesized: keeping the default at false preserves the documented static-IP/MAC posture, while symmetric enforcement turns the flag into a real control instead of connect-only theater. Flipping the default was rejected (withdraws a documented protection); gating aliases at create was rejected (breaks ordinary compose clients).

Migration note

Deployments that were (knowingly or not) pinning static IPs/MACs via the create payload's endpoint config will start seeing denials — that path was an unchecked bypass of the documented policy. Set request_body.network.allow_endpoint_config: true to allow it.

Verification

  • TDD red-first throughout; go build / go vet / golangci-lint clean; go test -race ./... all green
  • Production coverage 96.6% (CI methodology), above the 96% floor
  • Adversarially reviewed by a multi-agent verification pass (which found the root-level MacAddress bypass fixed here)

Companion drydock PR (rollback hardening + no longer forwarding auto-assigned MACs) is on CodesWhat/drydock.

Changelog

  • 🔒 Security: Enforced request_body.network.allow_endpoint_config symmetrically for endpoint config on POST /networks/{id}/connect and POST /containers/create (NetworkingConfig.EndpointsConfig), with endpoint aliases always allowed.
  • 🔒 Security: Default-deny for endpoint static IPs, non-empty MAC addresses, links, and driver options; deprecated root-level MacAddress is also denied by default (empty string remains allowed).
  • 🔧 Changed: Wired Network.AllowEndpointConfig into container-create filter options (ContainerCreateOptions.AllowEndpointConfig) so connect/create can’t diverge.
  • 🔧 Changed: Refactored connect/create endpoint-config denial logic behind shared helpers; aliases are excluded from denial checks (to preserve the alias exception).
  • ✨ Added: Container-create inspection gates for NetworkingConfig.EndpointsConfig and legacy root MacAddress, including deterministic key iteration and nil endpoint skipping.
  • ✨ Added: Unit tests + regression tests for default deny/allow behavior, multi-network inspection, nil endpoint handling, legacy-root MacAddress semantics, and new fuzz coverage (FuzzContainerCreatePolicyInspectEndpointConfig).
  • ✨ Added: Drydock preset conformance updates for macvlan/static-IP denial, legacy-drydock create vs connect behavior, aliases-only escape-hatch expectations, and operator override testing.
  • 🐛 Fixed: Closed the create-vs-connect endpoint-config bypass by aligning enforcement paths and denial reasoning.

Concerns

  • Ensure alias exception remains consistent across all code paths (connect vs container-create) and matches conformance expectations.
  • Confirm legacy root MacAddress behavior is exactly as intended (empty allowed, non-empty denied when flag is false).
  • Validate older Drydock version behavior (including orphaned-container edge case) matches the documented rollback/audit guidance.
  • Check fuzz/regression coverage fully targets all gated fields (static IP, MAC, links, driver opts) and assertion robustness (no brittle reason-string coupling).

scttbnsn added 9 commits July 11, 2026 13:10
Aliases were denied at POST /networks/*/connect (unless
allow_endpoint_config) but never enforced at container-create's primary
network, so the check was bypassable and low-value. Docker Compose sets
Aliases: [serviceName] on every endpoint it creates, so gating them broke
every multi-network Compose recreate under the default policy. Links stays
gated — it's a materially different, higher-privilege primitive.

Extracts the field checks (static IP, MAC, Links, DriverOpts) into a shared
denyEndpointConfigReason(ep, allow, subject) helper so the same logic can be
reused by the upcoming container-create endpoint-config check.
…iner create

POST /containers/create never inspected NetworkingConfig.EndpointsConfig,
while POST /networks/*/connect already gated static IP/MAC/DriverOpts there
unless allow_endpoint_config — a client (or a legitimate updater like
drydock recreating a macvlan+static-IP container) could put the identical
config on create's primary network and sail through unchecked. Real
incident: drydock's connect call for the extra network got denied, but the
create call for the primary network was never checked at all — a pure
policy bypass, not a hardening gap.

containerCreateRequest now decodes NetworkingConfig.EndpointsConfig; a new
containerCreatePolicy.allowEndpointConfig field (from the same
AllowEndpointConfig knob network already exposes) reuses
denyEndpointConfigReason across every EndpointsConfig entry, iterated in
sorted key order for deterministic denial messages. Also updates the
network.go mutation-kill test that pinned the old combined Aliases+Links
arithmetic, which no longer exists after the prior commit's alias fix.
…policy

RequestBodyConfig.ToFilterOptions now copies c.Network.AllowEndpointConfig
into the constructed ContainerCreateOptions after building it from
ContainerCreateRequestBodyConfig. One existing flag
(request_body.network.allow_endpoint_config) governs both the
/networks/*/connect and the new /containers/create endpoint-config gates —
no new YAML key, so a config that already sets allow_endpoint_config for
connect automatically covers create's NetworkingConfig too.
…cident

The network-connect preset case was a trivial {"Container":"abc"} body that
never exercised EndpointConfig at all. Replaces/extends it with the shape
that actually broke: an aliases-only secondary-network connect (what every
multi-network Compose recreate sends, and what the alias-gating fix now
lets through by default — the regression test that would have caught the
incident) and the real macvlan+static-IP connect body drydock issues, which
must stay denied without allow_endpoint_config. A new
TestDrydockPresetNetworkConnectAllowEndpointConfigEscapeHatch proves the
documented opt-out actually admits that same body once the flag is set, on
both drydock presets.
… symmetry fix

security.mdx and configuration.mdx (network group row, container_create
group row, and the allow_endpoint_config env-var row) previously claimed a
flat "endpoint static IP/MAC/alias/driver options" guarantee for
POST /networks/*/connect only. Corrected: Aliases are always allowed at both
endpoints (never gated); allow_endpoint_config now enforces static
IP/MAC/links/driver options identically at POST /networks/*/connect AND
POST /containers/create's NetworkingConfig.EndpointsConfig, via the same
single flag.

Also adds operator guidance to the drydock.yaml / drydock-with-compose.yaml
preset headers: macvlan/static-IP/custom-MAC/endpoint-DriverOpts recreates
need allow_endpoint_config: true, while alias-only multi-network compose
recreates now work by default with no config change.
Unreleased entry: container-create now enforces the same endpoint-config
gate connect already had (closes a bypass), aliases are no longer gated at
either endpoint (a deliberate relaxation Compose needed), and a migration
note for deployments relying on the pre-existing create-side gap.
…r create

Docker's container-create body still honors a deprecated top-level
MacAddress field (pre-API-1.44), applying it to the primary network
endpoint exactly like NetworkingConfig.EndpointsConfig[*].MacAddress
does. denyNetworkingConfigReason only inspected the EndpointsConfig
form, so with allow_endpoint_config=false a client could still pin a
MAC via the legacy root field — the same asymmetric-bypass class this
inspector exists to close. Gate it with the same allow_endpoint_config
flag and denial message.
….5.3

drydock >=1.5.3 rolls back cleanly on a connect/create denial (removes
the half-created replacement, restores the name) so the container
stays on its old image — only older drydock versions could leave an
orphaned Created container. Reword the network endpoint-config
comments in drydock.yaml and drydock-with-compose.yaml to reflect that
while keeping the allow_endpoint_config guidance for macvlan/static-IP/
MAC-pinning setups.
…e shapes

drydock >=1.5.3 only forwards a MacAddress when the user explicitly
configured one, so its default-policy recreate is Aliases-only with no
MacAddress — clarify that on the existing passing case. Add two denied-
by-default cases for the pre-1.5.3 shape (which clones the operational
MAC off inspect and forwards it on every recreate): Aliases+MacAddress
on connect, and the same combination on create via
NetworkingConfig.EndpointsConfig. Documents that older drydock versions
still fail against the current default policy and need either the
drydock upgrade or allow_endpoint_config: true.
@vercel

vercel Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sockguard-website Ready Ready Preview, Comment Jul 11, 2026 7:10pm

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a55fe496-19a0-4234-9d6f-9a249ee05fa5

📥 Commits

Reviewing files that changed from the base of the PR and between 589d80e and 4915db2.

📒 Files selected for processing (2)
  • app/internal/filter/container_create_test.go
  • docs/content/docs/configuration.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/internal/filter/container_create_test.go
  • docs/content/docs/configuration.mdx

📝 Walkthrough

Walkthrough

The network endpoint-configuration policy now applies to both network connect requests and container creation endpoint settings. Container-create inspection checks endpoint fields and legacy root MAC addresses, while aliases remain allowed by default. Configuration wiring, regression tests, preset conformance tests, and documentation cover the shared policy and its override.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/endpoint-config-symmetry

Comment @coderabbitai help to get the list of available commands.

@scttbnsn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/internal/filter/container_create_test.go (1)

722-927: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a fuzz test for the new endpoint-config parsing/denial path.

denyNetworkingConfigReason/denyRootMacAddressReason parse attacker-controlled NetworkingConfig.EndpointsConfig JSON to detect specific field shapes. Only fixed-table unit tests are added here; no fuzz coverage for this new filter-matching logic.

As per coding guidelines, app/**/*_test.go should "Use fuzz tests for filter matching and config parsing."

🧪 Sketch of a fuzz test seeded from existing table cases
func FuzzContainerCreatePolicyInspectEndpointConfig(f *testing.F) {
	seeds := []string{
		`{"Image":"x","NetworkingConfig":{"EndpointsConfig":{"macvlan0":{"IPAMConfig":{"IPv4Address":"172.30.0.10"}}}}}`,
		`{"Image":"x","NetworkingConfig":{"EndpointsConfig":{"app-net":{"Aliases":["web"]}}}}`,
		`{"Image":"x","MacAddress":"02:42:ac:1e:00:0a"}`,
	}
	for _, s := range seeds {
		f.Add(s)
	}
	f.Fuzz(func(t *testing.T, body string) {
		req := httptest.NewRequest(http.MethodPost, "/containers/create", bytes.NewBufferString(body))
		_, _ = newContainerCreatePolicy(ContainerCreateOptions{}).inspect(nil, req, "/containers/create")
	})
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/internal/filter/container_create_test.go` around lines 722 - 927, Add a
fuzz test for the container-create endpoint configuration parsing and denial
flow, using FuzzContainerCreatePolicyInspectEndpointConfig near the existing
inspect tests. Seed it with representative static-IP, aliases-only, and root
MacAddress payloads, then invoke
newContainerCreatePolicy(ContainerCreateOptions{}).inspect with arbitrary
request bodies and ensure the fuzz target completes without panicking.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/content/docs/configuration.mdx`:
- Line 249: The container_create documentation currently omits the legacy
top-level MacAddress behavior. Update the network group's allow_endpoint_config
documentation to state that POST /containers/create also gates the deprecated
top-level MacAddress field, alongside NetworkingConfig.EndpointsConfig.

---

Nitpick comments:
In `@app/internal/filter/container_create_test.go`:
- Around line 722-927: Add a fuzz test for the container-create endpoint
configuration parsing and denial flow, using
FuzzContainerCreatePolicyInspectEndpointConfig near the existing inspect tests.
Seed it with representative static-IP, aliases-only, and root MacAddress
payloads, then invoke newContainerCreatePolicy(ContainerCreateOptions{}).inspect
with arbitrary request bodies and ensure the fuzz target completes without
panicking.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 554c5d24-871e-4e17-8151-71ce4701cad0

📥 Commits

Reviewing files that changed from the base of the PR and between 874aa4b and 1030470.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (13)
  • app/configs/drydock-with-compose.yaml
  • app/configs/drydock.yaml
  • app/internal/config/filter_options.go
  • app/internal/config/filter_options_test.go
  • app/internal/filter/container_create.go
  • app/internal/filter/container_create_test.go
  • app/internal/filter/container_create_types.go
  • app/internal/filter/drydock_preset_conformance_test.go
  • app/internal/filter/mutation_kill_test.go
  • app/internal/filter/network.go
  • app/internal/filter/network_test.go
  • docs/content/docs/configuration.mdx
  • docs/content/docs/security.mdx

Comment thread docs/content/docs/configuration.mdx Resolved
Rollback on a denied endpoint-config request is best-effort, not
guaranteed — if the rollback itself fails, drydock logs it to the
update-operation history/audit log without a push notification.
@scttbnsn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@scttbnsn

Copy link
Copy Markdown
Contributor Author

Added the fuzz test in 4915db2: FuzzContainerCreatePolicyInspectEndpointConfig, seeded from the static-IP, aliases-only, root MacAddress, and case-variant-key table cases. 15s smoke run, 367k execs, no crashers.

@scttbnsn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@scttbnsn
scttbnsn merged commit 5214c33 into dev/v1.5 Jul 11, 2026
46 checks passed
@scttbnsn
scttbnsn deleted the fix/endpoint-config-symmetry branch July 11, 2026 19:31
scttbnsn added a commit to CodesWhat/drydock that referenced this pull request Jul 13, 2026
…e-pinning on recreate (#503)

> [!IMPORTANT]
> **Consolidated into v1.5.2-rc.5.** Merge after branch-protection
approval, then dispatch `release-cut.yml` for `v1.5.2-rc.5` and restart
the patch soak. The separate v1.5.3 train is retired. Companion PR:
CodesWhat/sockguard#136.

Root-caused from a real incident bundle
(`drydock-npm-macvlan-incident-20260709`): a multi-network
nginx-proxy-manager recreate behind sockguard's default-deny policy left
an orphaned `Created` replacement squatting the canonical name, the
original renamed `nginx-proxy-manager-old-…-old-…` (nested), silently
broken ~4 weeks.

## Fixes

- **Orphaned replacement recovery.** `createContainer` lost the created
handle when a post-create network connect threw, so rollback couldn't
remove the orphan and the rename-back 409'd. New
`created-container-candidate` channel attaches the handle to the thrown
error (connect failure *and* start-after-create failure); all rollback
consumers (executor, self-update, health monitor, backup API, compose
rollback-restore) recover and best-effort stop+remove it before
restoring the original name.
- **Rollback-cascade guard.** A container already named
`-old-<epoch-ms>` refuses further updates with a "needs manual cleanup"
error naming the true canonical name (nested suffixes stripped), instead
of renaming again on top of the unresolved failure. Applies to regular
and self-updates, and runs ahead of the dry-run check so dry-run
surfaces the stuck state instead of masking it.
- **MAC addresses are no longer re-pinned.** The recreate path copied
each endpoint's operational `MacAddress` from inspect, permanently
pinning daemon-assigned MACs (stale after IP changes, rejected by
MAC-denying socket proxies). A MAC is now forwarded only when explicitly
configured (`Config.MacAddress`, or `DesiredMacAddress` if daemons ever
expose it), attributed only to the primary network (`NetworkMode:
"default"` translated to `bridge`, mirroring moby's `IsDefault()`); the
deprecated root-level create field is retained only for explicit MACs as
an API<1.44 back-compat carrier.
- **Locally-built images** (no `RepoDigests`) skip registry lookups
instead of 401-ing into the nightly error count.
- Digest-throttle warning no longer prints `with domain undefined` for
unprefixed Docker Hub references.
- Docs: socket-proxy requirements for static-IP/MAC recreates (Tecnativa
`POST=1`+`NETWORKS=1`; sockguard `allow_endpoint_config`, create-side
from sockguard v1.5.0), FAQ entry for `-old-<timestamp>` leftovers,
CHANGELOG known-limitations (rollback-failure is audit-log-only;
per-network `mac_address` on non-primary networks can't be preserved).

## Verification

Two adversarial verification workflows (20 + 21 agents: dimension
reviewers → independent refuters per finding → end-to-end completeness
critic) plus a final deep-reasoner pass over the last delta. Each round
confirmed real defects that were then fixed (round 1: 6 confirmed incl.
the original fix not resolving the incident due to auto-MAC forwarding;
round 2: 7 confirmed incl. compose rollback-restore dropping the orphan
and MAC fan-out to every network; final pass: 3 incl. the `NetworkMode
"default"` mismatch and an old-daemon MAC regression). Full pre-push
gate green: 100% app+ui coverage, tsc, biome, qlty.

Version files use the workflow-required base `1.5.2`; CHANGELOG heading
`## [1.5.2-rc.5] — 2026-07-13`.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Changelog

- ✨ Added orphaned replacement-container candidate detection and
best-effort stop/force-remove cleanup across Docker update, self-update,
health-monitor rollback, backup rollback, and Compose rollback.
- ✨ Added rollback-cascade protection to prevent further
update/recreation when container names match the `-old-<timestamp>`
rollback suffix pattern (including nested cases), including dry-run
behavior.
- 🔧 Changed Docker container recreation MAC handling to preserve only
explicitly configured MACs on the primary network; auto-assigned
endpoint MACs are dropped, with legacy `Config.MacAddress`
compatibility.
- ✨ Added local-image tracking (`image.isLocalImage`) to skip registry
lookups for locally built/loaded images.
- 🐛 Fixed orphan/candidate cleanup flows when failures occur after
`createContainer` (connect/start failures) by attaching
created-container handles to thrown errors and cleaning them up during
rollback.
- 🐛 Fixed Docker Hub digest-throttle warning formatting for unprefixed
`docker.io` references.
- 🐛 Fixed primary-network resolution when Docker reports
`HostConfig.NetworkMode: "default"`.
- ✨ Updated socket-proxy documentation and added FAQ guidance + rollback
remediation notes.
- ✨ Consolidated release updates/version files for `1.5.2-rc.5`.

## Concerns

- Ensure the release is merged only after the v1.5.2
GA/branch-protection approval path, and verify `release-cut.yml`
dispatch + patch-soak restart.
- Double-check that rollback-named container prevention fully covers
nested `-old-<timestamp>` suffixes without false positives.
- Verify MAC precedence rules (auto-assigned vs desired vs legacy)
across multi-network and “empty-string legacy MAC” scenarios.
- Confirm Compose rollback candidate cleanup targets the correct
candidate and does not double-remove.
- Ensure `isLocalImage` is set/synced correctly so registry lookups are
skipped only for truly local images.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

This branch was successfully deployed

1 active deployment
Preview — 4915db25 Deployed Jul 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant