Skip to content

feat: resolve policy binary paths at assembly time - #3

Closed
rhuss wants to merge 33 commits into
mainfrom
061-policy-binary-resolution
Closed

rhuss wants to merge 33 commits into
mainfrom
061-policy-binary-resolution

Conversation

@rhuss

@rhuss rhuss commented May 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Remove hardcoded binary paths from embedded package registry policy components (go, rust, node, python YAML files)
  • Add automatic binary resolution at policy assembly time using manifest tool data and a well-known paths table
  • Preserve explicit binaries on components that already define them (claude-code, vertex-ai, git-hosting)

Spec

Feature spec: specs/061-policy-binary-resolution/spec.md

All 9 functional requirements (FR-001 through FR-009) implemented and verified. 164 build package tests pass. Lint clean.

Test plan

  • Unit tests for resolveBinaries() covering package tools, github-release tools, explicit override preservation, missing tools, deduplication, case-insensitive lookup
  • Integration tests in policy_test.go verifying end-to-end assembly with binary resolution
  • make test passes (pre-existing compose_smoke_test failures unrelated to this change)
  • make lint passes

Assisted-By: 🤖 Claude Code

Summary by CodeRabbit

  • New Features

    • Added deterministic OpenShell policy generation from declarative YAML components with automatic binary resolution from build manifests
    • Introduced cc-deck build refresh command for regenerating Containerfile snippets and policies
    • Implemented runtime policy extraction from OCI images for OpenShell workspaces
    • Enabled custom policy components via user-local YAML files
  • Bug Fixes

    • Fixed OpenShell sandbox crash with AF_NETLINK seccomp restriction via compiled LD_PRELOAD shim
  • Documentation

    • Added comprehensive guides for policy components, OCI extraction, and binary resolution

Review Change Stack

rhuss added 30 commits May 22, 2026 15:06
Move OpenShell policy generation from non-deterministic Claude Code
reasoning to declarative YAML component files with a two-tier catalog
(remote GitHub repo + embedded fallback). Capture fetches matching
components, build refresh assembles the policy deterministically.

Assisted-By: 🤖 Claude Code
Add entries for 060 (OpenShell testing findings) and 061 (deterministic
policy generation). Update open threads with testing workarounds and
catalog design questions.

Assisted-By: 🤖 Claude Code
Replace non-deterministic Claude-powered policy generation with
declarative YAML component files and a three-tier catalog system
(embedded, cached catalog, user-local).

Assisted-By: 🤖 Claude Code
Wires up FetchAndCacheCatalog to a new CLI subcommand that fetches
policy components from github.com/cc-deck/openshell-policies and
caches them in openshell/components/ for use by build refresh.

Assisted-By: 🤖 Claude Code
build refresh now fetches catalog components automatically when an
OpenShell target is configured. Use --no-fetch for offline mode.
Removes the standalone catalog-update subcommand.

Assisted-By: 🤖 Claude Code
When re-running capture on a manifest with existing targets, show
current settings and default to keeping them. In --all mode, skip
target prompts entirely. Ensures build refresh always runs after
manifest changes when an OpenShell target is configured.

Assisted-By: 🤖 Claude Code
Deletes build.yaml and config/ before running the wizard so users
can start from scratch without manual cleanup. Combines with --all
for a fully automated fresh capture.

Assisted-By: 🤖 Claude Code
Use absolute cursor positioning to place the note icon at a fixed
column instead of padding-based alignment. Prevents the icon from
shifting as the status text width changes.

Assisted-By: 🤖 Claude Code
Describes extracting policy.yaml from OCI images at ws new time
using go-containerregistry, with build-time layer labeling for
efficient single-layer fetch and fallback layer scanning.

Reverts the host-path auto-resolution approach since the policy
should come from the image, not the build directory.

Assisted-By: 🤖 Claude Code
Assisted-By: 🤖 Claude Code
- Resolve merge conflict markers in go.mod, go.sum, README.md, and
  cli.adoc left from a prior stash operation
- Fix dead assertion in extract_test.go where a closure was assigned
  to _ but never called, making the labels emptiness check unreachable
- Regenerate go.sum via go mod tidy
- Mark remaining unmerged env files as resolved

Assisted-By: 🤖 Claude Code
The merge conflict resolution commit (13bb498) incorrectly introduced
internal/env/ and internal/cmd/env.go files that belong to a different
feature branch. These files reference undefined types (EnvironmentType,
StorageConfig, FileStateStore, etc.) causing build failures. They have
no connection to the 060-oci-policy-extraction feature.

Assisted-By: 🤖 Claude Code
Resolve conflict markers in go.mod (4 blocks), go.sum (12 blocks),
README.md (2 blocks), and cli.adoc (3 blocks) left from a prior stash
pop. Remove stale internal/env/ and internal/cmd/env.go files that
belong to a different feature. Regenerate go.sum via go mod tidy.

Assisted-By: 🤖 Claude Code
When --target openshell is passed to build init, automatically
run the refresh logic (snippet extraction, catalog fetch, policy
assembly) so the setup directory is ready to build without a
separate build refresh step.

Also add review artifacts from 060-oci-policy-extraction.

Assisted-By: 🤖 Claude Code
Makes the flags visible in Claude Code's command picker autocomplete.

Assisted-By: 🤖 Claude Code
Build should only build, not manage workspaces. Replaced auto
ws-new calls in SSH (B9) and OpenShell (C9) sections with
next-steps hints, matching the container section pattern.

Assisted-By: 🤖 Claude Code
go-containerregistry's name.ParseReference normalizes
"localhost/repo:tag" to "docker.io/localhost/repo:tag" by default.
The daemon.ImageSave call uses ref.Name() (normalized), which
breaks podman lookups for local images.

Fix by passing name.WithDefaultRegistry("") to preserve the
original reference as-is.

Assisted-By: 🤖 Claude Code
The /cc-deck.build command was running podman build directly,
bypassing the CLI's post-build label stamping. Now calls
cc-deck build run which handles both the build and the
dev.cc-deck.policy-layer label injection.

Assisted-By: 🤖 Claude Code
Without WithBufferedOpener, go-containerregistry calls ImageSave
(full image export) for every layer access during the fallback
scan. For a 57-layer image this caused a 53-second delay.
Buffering exports the image once and reads layers from memory.

Assisted-By: 🤖 Claude Code
For local daemon images, first open unbuffered (config-only, fast)
to check for the policy layer label. If labeled, fetch just that
one layer without ever exporting the full image.

Only fall back to buffered mode (single full export) when the
label is missing and a reverse layer scan is needed. This avoids
loading multi-GB images into memory when the label is present.

For remote registry images, all access remains lazy (per-layer
fetch), so only inspected layers are downloaded.

Assisted-By: 🤖 Claude Code
Replace go-containerregistry daemon.Image (which calls ImageSave,
exporting the full image) with runtime create + cp for local
images. This reads directly from the overlay filesystem and
completes in under a second for any image size.

The go-containerregistry path is kept for remote registry images,
where lazy per-layer fetch is already efficient.

Assisted-By: 🤖 Claude Code
The allowed_domains loop was writing group names (e.g., "github")
as literal hostnames in the policy, overwriting correct catalog
entries that had real domains with binaries and access rules.

Now: catalog/embedded components take precedence. Groups not
covered by a component are expanded via the network.Resolver
to actual domains. Literal domains (with dots) pass through
unchanged.

Added 5 tests covering: catalog precedence, group expansion,
literal domains, unknown groups, and mixed entries.

Assisted-By: 🤖 Claude Code
The Rust, Go, Node, and Python policy components were missing
the binaries field. Without it, OpenShell blocks all processes
from accessing those registries (CONNECT tunnel 403).

Added binary paths for cargo, go, npm/node/npx, pip/uv covering
common install locations (/usr/bin, /usr/local/bin, /sandbox/).

Assisted-By: 🤖 Claude Code
rhuss added 3 commits May 24, 2026 08:49
Replace hardcoded binary paths in embedded policy components (go, rust,
node, python) with automatic resolution from the build manifest's tools
section. Package-installed tools resolve to /usr/bin/<name>, github-release
tools use their install_path, and a well-known paths table adds common
alternative locations. Components with explicit binaries are preserved as
overrides.

Assisted-By: 🤖 Claude Code
@coderabbitai

coderabbitai Bot commented May 24, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds deterministic policy assembly from YAML components, automatic binary resolution, OCI policy extraction with image-label fast path and layer-scan fallback, an OpenShell getifaddrs LD_PRELOAD shim, a build refresh command, wiring in CLI/build/workspace flows, extensive tests, and updated docs/specs. Removes legacy Specify scripts/templates.

Changes

OpenShell deterministic policy, OCI extraction, and shim

Layer / File(s) Summary
End-to-end implementation, wiring, tests, and docs
cc-deck/internal/build/*, cc-deck/internal/oci/*, cc-deck/internal/ws/*, cc-deck/internal/cmd/build.go, cc-deck/internal/build/templates/containerfile/04-openshell-extras.tmpl, cc-deck/internal/build/policies/*.yaml, docs/..., specs/..., .playwright-mcp/*, others
Implements component-based policy assembly and binary resolution, OCI policy extraction and image labeling, OpenShell getifaddrs shim and preload, CLI build refresh and stamping, tests across build/oci/ws, and comprehensive documentation/spec updates; removes legacy Specify scripts/templates.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Build as cc-deck build run/refresh
  participant Emb as Embedded Components
  participant Catalog as Cached Catalog
  participant Local as User-Local Policies
  participant OCI as oci.Label/Extract
  participant WS as ws new --type openshell

  User->>Build: build refresh
  Build->>Emb: load components
  Build->>Catalog: overlay components (if cached)
  Build->>Local: apply overrides
  Build-->>Build: assemble deterministic policy.yaml
  User->>Build: build run --target openshell
  Build->>OCI: StampPolicyLabel(image, policy layer)
  User->>WS: ws new --image=<ref>
  WS->>OCI: ExtractFileFromImage(ref, policy.yaml)
  OCI-->>WS: policy bytes (label fast path or scan)
  WS-->>User: sandbox created with policy
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Poem

A rabbit compiled a policy stew,
With YAML herbs and binaries too;
It labeled the layers, hopped to the repo,
Pulled policy clean with a single echo.
Shim on the wind, getifaddrs tamed—
Determinism won; the burrow acclaimed! 🐇✨

✨ 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 061-policy-binary-resolution

@rhuss

rhuss commented May 24, 2026

Copy link
Copy Markdown
Collaborator Author

Merged locally to main

@rhuss rhuss closed this May 24, 2026
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