Repository navigation
✨ feat(filter): libpod pod-create, exec, and volume/network/secret inspection (#148) - #190
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 31 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (18)
📝 WalkthroughWalkthroughThis change extends libpod coverage in rule validation and runtime inspection. It classifies more libpod write and exfiltration endpoints, keeps libpod pod, volume, network, and secret create paths body-inspected, and leaves play, kube, and manifest writes as body-blind opt-in paths. It adds libpod-specific config fields and validation for pod-create settings. It adds libpod exec-start inspector wiring and shared exec inspection handling for Docker-compatible and libpod routes. It also adds new libpod request inspectors, tests, and configuration docs. Possibly related PRs
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
app/internal/filter/middleware.go (1)
458-472: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the libpod path predicates instead of repeating the literals.
Each of these three matchers duplicates a path literal that the inspector also re-checks:
libpodPathPrefix+"volumes/create"inlibpod_volume.goline 29,libpodPathPrefix+"networks/create"inlibpod_network.goline 44, andlibpodPathPrefix+"secrets/create"inlibpod_secret.goline 32. The pod-create case already uses a named predicate,isLibpodPodCreatePath. Follow that convention so a future path edit cannot update the matcher and leave the inspector guard behind.♻️ Proposed refactor
func matchesLibpodVolumeInspection(normalizedPath string) bool { - return normalizedPath == libpodPathPrefix+"volumes/create" + return isLibpodVolumeCreatePath(normalizedPath) } func matchesLibpodNetworkInspection(normalizedPath string) bool { - return normalizedPath == libpodPathPrefix+"networks/create" + return isLibpodNetworkCreatePath(normalizedPath) } func matchesLibpodSecretInspection(normalizedPath string) bool { - return normalizedPath == libpodPathPrefix+"secrets/create" + return isLibpodSecretCreatePath(normalizedPath) }Define the predicates next to
isLibpodPodCreatePathand use them in the inspector guards as well.🤖 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/middleware.go` around lines 458 - 472, Extract named predicates for libpod volume, network, and secret create paths alongside isLibpodPodCreatePath, and update matchesLibpodVolumeInspection, matchesLibpodNetworkInspection, and matchesLibpodSecretInspection to use them. Replace the corresponding duplicated path-literal checks in the volume, network, and secret inspectors with the same predicates.app/internal/filter/libpod_network_test.go (2)
79-142: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake the three gate tests table-driven, and normalize the path consistently.
TestLibpodNetworkInspectLibpodCreateOptionsGate,...SubnetsGate, and...IPAMOptionsGateeach duplicate a deny/allow pair. The driver gate in the same file already uses a table. Convert these three to the same shape so a new gate is one row.Line 113 also passes the literal
"/libpod/networks/create"while every other call passesNormalizePath(req.URL.Path). The values are equal today, so behavior is unaffected. UseNormalizePathfor consistency.As per coding guidelines: "Prefer table-driven tests with
testing.Tandhttptest."🤖 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/libpod_network_test.go` around lines 79 - 142, Convert TestLibpodNetworkInspectLibpodCreateOptionsGate, TestLibpodNetworkInspectLibpodCreateSubnetsGate, and TestLibpodNetworkInspectLibpodCreateIPAMOptionsGate into table-driven tests matching the existing driver-gate pattern, with rows covering denied and allowed configurations. Iterate each case with testing.T subtests while preserving the expected reason assertions. In the subnet allowed case, pass NormalizePath(req.URL.Path) instead of the literal path, consistently with the other inspectLibpodCreate calls.Source: Coding guidelines
144-195: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFeed libpod paths into the path-matching fuzz corpus.
FuzzPathMatchfeedsNormalizePathoutput into compiled rules, but it only seeds Docker-style paths. Add libpod seeds (for example/libpod/networks/create,/libpod/exec/{id}/start,/libpod/containers/{name}/exec, and/libpod/volumes/create) so the new matcher behavior remains covered by fuzzing.🤖 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/libpod_network_test.go` around lines 144 - 195, Update the seed setup in FuzzPathMatch to include libpod paths alongside the existing Docker-style seeds, covering /libpod/networks/create, /libpod/exec/{id}/start, /libpod/containers/{name}/exec, and /libpod/volumes/create so NormalizePath output for these routes is exercised by compiled-rule matching.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 `@app/internal/cmd/rules_test.go`:
- Around line 937-1119: The related tests around validateAndCompileRules should
be consolidated into one table-driven test instead of separate standalone
functions. Create a []struct case table covering each allow, reject, and opt-in
scenario, including expected validation success or failure and endpoint/error
assertions, then run each case with t.Run while preserving the existing
validation behavior and checks.
In `@app/internal/cmd/rules.go`:
- Around line 137-144: Update the libpod endpoint classifications to treat
manifest registry pushes as sensitive exfiltration: add sentinels for POST
/libpod/manifests/*/registry/* and POST /libpod/manifests/*/push to
sensitiveExfilEndpoints, then add narrow-rule rejection cases covering both
route patterns so they honor insecure_allow_read_exfiltration.
In `@docs/content/docs/configuration.mdx`:
- Around line 1160-1162: Expand the configuration table entries for
libpod_volume, libpod_network, and libpod_secret to document every active
inherited policy field enforced by their corresponding inspectors, including
custom-driver, IPAM, driver-option, and IPv4 controls. Use the exact
environment-variable and configuration-key symbols defined by the
implementation, rather than listing only the three group-level flags currently
shown.
---
Nitpick comments:
In `@app/internal/filter/libpod_network_test.go`:
- Around line 79-142: Convert TestLibpodNetworkInspectLibpodCreateOptionsGate,
TestLibpodNetworkInspectLibpodCreateSubnetsGate, and
TestLibpodNetworkInspectLibpodCreateIPAMOptionsGate into table-driven tests
matching the existing driver-gate pattern, with rows covering denied and allowed
configurations. Iterate each case with testing.T subtests while preserving the
expected reason assertions. In the subnet allowed case, pass
NormalizePath(req.URL.Path) instead of the literal path, consistently with the
other inspectLibpodCreate calls.
- Around line 144-195: Update the seed setup in FuzzPathMatch to include libpod
paths alongside the existing Docker-style seeds, covering
/libpod/networks/create, /libpod/exec/{id}/start,
/libpod/containers/{name}/exec, and /libpod/volumes/create so NormalizePath
output for these routes is exercised by compiled-rule matching.
In `@app/internal/filter/middleware.go`:
- Around line 458-472: Extract named predicates for libpod volume, network, and
secret create paths alongside isLibpodPodCreatePath, and update
matchesLibpodVolumeInspection, matchesLibpodNetworkInspection, and
matchesLibpodSecretInspection to use them. Replace the corresponding duplicated
path-literal checks in the volume, network, and secret inspectors with the same
predicates.
🪄 Autofix
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: 0d8e797b-3fc6-4b8b-a63b-79c95a3bafa9
⛔ Files ignored due to path filters (1)
CHANGELOG.mdis excluded by!CHANGELOG.md
📒 Files selected for processing (18)
app/internal/cmd/rules.goapp/internal/cmd/rules_test.goapp/internal/cmd/serve.goapp/internal/config/config.goapp/internal/config/filter_options.goapp/internal/config/validate.goapp/internal/filter/exec.goapp/internal/filter/exec_test.goapp/internal/filter/libpod_network.goapp/internal/filter/libpod_network_test.goapp/internal/filter/libpod_pod_create.goapp/internal/filter/libpod_pod_create_test.goapp/internal/filter/libpod_secret.goapp/internal/filter/libpod_secret_test.goapp/internal/filter/libpod_volume.goapp/internal/filter/libpod_volume_test.goapp/internal/filter/middleware.godocs/content/docs/configuration.mdx
…tors
Adds request-body inspection for Podman's libpod-native write endpoints
that had no coverage: POST /libpod/pods/create, POST /libpod/volumes/create,
POST /libpod/networks/create, and POST /libpod/secrets/create.
- libpod_pod_create.go: new inspector gated by allow_host_network (pod-level
netns {nsmode:"host"}), allow_shared_pid_namespace (shared_namespaces
containing "pid"), and allowed_infra_image_registries (reuses the
image_pull registry-allowlist shape). Cross-owner pod-membership checks are
explicitly deferred to a later PR (see the TODO in libpod_pod_create.go).
- libpod_volume.go / libpod_network.go / libpod_secret.go: libpod-shaped
decode structs that reuse the EXISTING volume/network/secret config types
rather than introducing parallel config — libpod's wire shapes differ from
Docker-compat (volume options live under "Options" not "DriverOpts",
network options are snake_case with no swarm-mode fields, secret driver is
a query param not a body field) but the policy question is identical.
- config.go/filter_options.go/validate.go: new
request_body.libpod_pod_create config surface plus
request_body.libpod_volume/libpod_network/libpod_secret keys mapped onto
the pre-existing config types.
- middleware.go: wires the four new inspectors into compileRuntimePolicy,
and extends matchesExecInspection so the existing shared execPolicy also
matches the libpod exec create/start paths (no separate libpod_exec
config — see the follow-up exec.go commit).
All wiring is additive to shared files (config.go, middleware.go, etc.) to
minimize rebase conflict surface with the concurrent libpod container-create
inspector PR.
Refs #148
POST /libpod/containers/{name}/exec and POST /libpod/exec/{id}/start route
to the identical Go handlers the Docker-compat exec paths do (confirmed
against Podman v5.8.1's own route table), so per the #148 design doc
(decision C3) both families now share the SAME execPolicy/ExecOptions and
request_body.exec config — there is no separate libpod_exec block.
- exec.go: execStartIdentifier now also reports which path family (Docker
vs libpod) matched a given exec-start path; inspectExisting dispatches to
the new InspectStartLibpod field for libpod paths instead of InspectStart,
since the two point at different upstream endpoints
(GET /exec/{id}/json vs GET /libpod/exec/{id}/json) and must stay
independently configured so setting one never silently satisfies the
other's fail-closed "no exec inspection configured" guard.
- NewLibpodExecInspector / NewLibpodExecInspectorWithRoundTripper add the
libpod-path variant of the exec-inspect upstream constructor; both it and
the existing Docker constructor now delegate to a shared
newHTTPExecInspector helper.
- serve.go: attachRuntimeInspectors wires
policy.Exec.InspectStartLibpod alongside the existing InspectStart.
Refs #148
Extends the three startup validators driven by bodySensitiveWriteEndpoints / sensitiveExfilEndpoints / bodyInspectionConfiguredForEndpoint to cover the new libpod surface: - bodySensitiveWriteEndpoints gains libpod pod-create, exec create/start, and volume/network/secret create — all of which have real inspectors — plus (design doc decision C2) play/kube, its kube/play alias, kube/apply, and manifest writes, none of which get any request-body inspector in this release (full Kubernetes-YAML/PodSpec modeling is out of scope), so admitting them requires insecure_allow_body_blind_writes exactly like any other uninspected body-sensitive write. - sensitiveExfilEndpoints gains libpod's container archive/export/logs/ attach and image export/get/push read surface, confirmed against Podman v5.8.1's route table rather than assumed from naming symmetry with the Docker-compat entries (libpod has no /attach/ws variant and no plugin API at all). GET /libpod/generate/kube is included here rather than in bodySensitiveWriteEndpoints, deliberately deviating from the design doc's literal placement: Podman registers it as a GET (libpod.GenerateKube) that dumps existing pod/container definitions to YAML, a read/export surface that can leak env vars, not a write. - bodyInspectionConfiguredForEndpoint arms unconditionally true for the four libpod endpoints with real fail-closed inspectors, and shares the existing exec case (keyed on request_body.exec.allowed_commands) across both the Docker-compat and libpod exec paths. Refs #148
- libpod_pod_create_test.go / libpod_volume_test.go / libpod_network_test.go
/ libpod_secret_test.go: gate tables for each new inspector (default-deny
behavior, explicit allow, malformed/oversized body handling, path/method
non-match), plus negative cross-shape tests proving POST /containers/create
and POST /libpod/pods/create bodies never leak into each other's decode —
e.g. libpod's netns.nsmode:"host" has zero effect on the Docker-compat
container-create decision, and Docker's HostConfig.NetworkMode:"host" has
zero effect on the libpod pod-create decision.
- exec_test.go: exec-parity tests proving identical request bodies produce
identical allow/deny verdicts on the Docker-compat and libpod exec paths
through the single shared execPolicy, dispatch tests proving
inspectExisting calls the InspectStart/InspectStartLibpod function
matching the request's own path family (and never the other), and
constructor/round-tripper tests for NewLibpodExecInspector[WithRoundTripper]
including a mock upstream that only accepts GET /libpod/exec/{id}/json to
prove the libpod path is actually used.
Refs #148
Covers the additions to internal/cmd/rules.go from #148: - Allow-with-config success cases for libpod pod-create, exec (shared request_body.exec allowlist), and volume/network/secret create. - Blind-write validator rejection for /libpod/containers/*/exec without a configured allowlist, and for /libpod/play/kube (+ its kube/play alias), /libpod/kube/apply, and /libpod/manifests/* without insecure_allow_body_blind_writes — plus the mirrored allow-with-explicit- opt-in case for play/kube. - Read-exfiltration validator rejection (and explicit-opt-in allow) for the new libpod container/image read surface and GET /libpod/generate/kube. - Direct bodyInspectionConfiguredForEndpoint coverage for every new libpod case, including the shared exec config across both libpod exec create and exec start. Refs #148
…/secret inspection - configuration.mdx: new prose bullets and Request Body Policy Reference / environment-variable rows for request_body.libpod_pod_create, request_body.libpod_volume, request_body.libpod_network, and request_body.libpod_secret; the exec section and reference table now state explicitly that request_body.exec governs both the Docker-compat and libpod exec paths (no separate libpod_exec config); the insecure_allow_body_blind_writes bullet documents the uninspected play/kube/kube-apply/manifest surface and its N-privileged-containers blast radius; insecure_allow_read_exfiltration documents the new libpod read/export surface including GET /libpod/generate/kube. - CHANGELOG.md: Unreleased Added/Docs/Tests entries for #148 PR3+4. Refs #148
POST /libpod/manifests/*/registry/* and the backward-compat POST /libpod/manifests/*/push read local manifest content and hand it to a caller-chosen registry — an exfiltration surface like the existing image/plugin push entries, but they weren't in sensitiveExfilEndpoints, so rules admitting them bypassed insecure_allow_read_exfiltration. Add both sentinels and narrow-rule rejection cases. #148
…secret field The env-var table listed one variable per libpod_volume/libpod_network/ libpod_secret group, and two of those three (allow_endpoint_config, allow_template_drivers) aren't actually consulted by the libpod inspectors. Replace with a row per field each inspector really enforces (allow_custom_drivers/allow_driver_opts for volume; allow_custom_drivers/allow_driver_options/allow_custom_ipam_config/ allow_ipam_options for network; allow_custom_drivers for secret) and call out the inherited fields that have no libpod analog instead of implying they're enforced. #148
…e inspector after rebase
3fb15f8 to
3467e70
Compare
* ✨ feat(dockerresource): add KindLibpodPod/KindLibpodNetwork for #148 ownership+visibility wiring Pods have no Docker-compat equivalent, and libpod network inspect uses lowercase "labels" (plus an occasional single-element array wrap) unlike every other Docker-compat-shaped inspect body — both need their own Kind so ownership/visibility dispatch can route on Kind alone without threading libpod-ness through every call site. - LibpodInspectPath: dedicated /libpod/{kind}/{id}/json builder for the two new kinds, wired into InspectPath's existing switch - DecodeLibpodLabels/decodeLibpodNetworkLabels: lowercase-keyed pod labels, plus array-unwrap-then-decode for network inspect * ✨ feat(ownership): stamp owner labels and check pod cross-owner refs on libpod endpoints Extends mutateOwnershipRequest with libpod cases so POST /libpod/containers/create, /pods/create, /volumes/create, /networks/create, and /secrets/create get the owner label injected when ownership.owner is configured — matching each endpoint's actual wire shape rather than assuming a single convention: - container/pod/network create: lowercase top-level "labels" - volume create: capitalized "Labels" (VolumeCreateOptions has no json tag on that field, so it falls back to the Go field name) - secret create: no JSON body at all — driver/labels are query params, reuses the existing addOwnerLabelToBuildQuery helper Read-side owner filtering (list injection + per-resource inspect/ action dispatch) is extended to every /libpod/ list and inspect path for containers, pods, networks, volumes, and secrets — not just pods — so switching a client from Docker-compat to libpod-native paths can't bypass ownership isolation for reads on existing resources. Closes the cross-owner pod-membership deferral called out in #190: POST /libpod/pods/create requests joining another owner's namespaces are denied, and POST /libpod/containers/create requests targeting another owner's pod (SpecGenerator "pod" field) are denied, reusing the existing container:<ref> namespace-sharing and embedded-resource reference checks against libpod's uniform {"nsmode":"container","value":"<ref>"} namespace shape. Deny reasons for libpod-family requests get the "libpod " prefix, matching the convention libpod's body inspectors already use. * 🧪 test(ownership): cover libpod owner stamping, pod cross-owner denial, and read dispatch Table-driven tests mirroring the existing ownership test patterns: label stamping on every libpod create endpoint (including the capitalized-Labels volume-create deviation and the secret-create query-param path), cross-owner pod-membership denial in both directions (pod-create namespace joins, container-create pod targeting) plus the same-owner allow counterparts, libpod read-path owner-filter dispatch across container/pod/network/volume/secret, exec-identifier resolution, and a negative test proving libpod predicates never fire on Docker-compat paths. * ✨ feat(visibility): filter libpod list/inspect paths, including pods and network array-unwrap Wires every /libpod/ list endpoint into the existing visibility label-filter injection (needsVisibilityLabelFilter), and every inspect/action path (containers, pods, networks, volumes, secrets) into resourceVisible dispatch — pods route through the new KindLibpodPod since they have no Docker-compat equivalent, the rest reuse the existing Docker-compat Kind constants since ownership labels live in the same shape once decoded. Every libpod inspect endpoint is uniformly suffixed "/json" (unlike Docker-compat's mixed bare-path/json-suffixed convention), so the new identifier helpers use suffixedIdentifier rather than singleSegmentIdentifier. Network inspect responses are unwrapped from Podman's occasional single-element-array envelope before label extraction (upstream Inspector round-trip, dockerresource.DecodeLibpodLabels). Hidden-resource deny reasons get the "libpod " prefix for requests under /libpod/, matching the body-inspector convention. * 🧪 test(visibility): cover libpod list/inspect filtering, pod visibility, and network array-unwrap Table-driven tests: visibility label-filter injection on every libpod list endpoint, KindLibpodPod list/inspect visibility (hidden-pod 404, visible-pod forward, rollout-mode would-deny), the "libpod " deny-reason prefix across libpod pod/container and Docker-compat paths, an end-to-end upstreamInspector round-trip for both bare-object and array-wrapped network inspect responses, and a negative test proving libpod predicates never fire on Docker-compat paths. * 📝 docs(148): document libpod owner-label isolation and cross-owner pod checks CHANGELOG: new Unreleased/Added entry after the existing #148 entries, and updates the pod-create entry's "deferred to a later PR" note now that cross-owner pod-membership checks have landed. configuration.mdx: new paragraph under Owner Label Isolation covering the libpod-specific label casing/query-param deviations, KindLibpodPod, and the two-directional cross-owner pod check. * 🧪 test(visibility): fuzz libpod path identifiers, table-drive pod visibility tests - Add FuzzLibpodPathIdentifiers covering libpod_paths.go's identifier helpers: no match outside /libpod/, collection routes never classify as a single-resource identifier, matched identifiers are non-empty and (bar the readSubresourceIdentifier-based container helper) never contain '/'. Wired into the CI fuzz matrix. - Convert TestMiddlewareLibpodPodListAndInspectVisibility and TestMiddlewareLibpodDoesNotAffectDockerCompatVisibilityPaths to table-driven form per repo convention; assertions unchanged. Addresses CodeRabbit comments 3722497023 and 3722497031 on PR #193. * 📝 docs(configuration): close the libpod_pod_create cross-owner deferral note The libpod_pod_create prose bullet and reference table row still said cross-owner pod-membership checks were deferred to a later release. This PR implements them (see the Owner Label Isolation section) — update both to describe the now-enforced behavior instead. Addresses CodeRabbit comment 3722497036 on PR #193.
PRs 3+4 of the #148 train (combined), building on the merged routing groundwork (#189).
What's here
POST /libpod/pods/create): gates pod-level host network (netns {nsmode:"host"}), pod-wide PID sharing (sharecontainingpid— same blast radius as container-level host PID), andallowed_infra_image_registriesfor the infra container image. Newrequest_body.libpod_pod_createconfig block. Cross-owner reference checks intentionally deferred to the ownership PR (TODO anchors in place).execPolicydecode and verdict logic (bodies match Docker's field names), with a libpod-path exec-inspect constructor (GET /libpod/exec/{id}/json). One sharedrequest_body.execconfig covers both API families by design — a split config would be an easy way to configure one and silently forget the other. Parity tests assert identical verdicts for identical bodies on both path families.VolumeRequestBodyConfig/NetworkRequestBodyConfig/SecretRequestBodyConfigtypes underrequest_body.libpod_volume/libpod_network/libpod_secret.bodySensitiveWriteEndpointsgains the libpod write surface includingplay/kube,generate/kube,kube/apply, and manifest writes — those four get NO config surface, so any allow rule for them requiresinsecure_allow_body_blind_writes, and the docs warning now names the kube-play blast radius (one request can provision N privileged containers).sensitiveExfilEndpointsgains libpod export/archive/logs/attach and image get/push. Startup-validator tests cover the new coverage (allow rule forplay/kubewithout the ack fails startup).Verification
go build,go test ./...,golangci-lintgreen; production coverage above the 96% floor; full pre-push hook suite green.Part of #148 (does not close it).
Changelog
request_body.execpolicy.insecure_allow_body_blind_writes.Concerns