Repository navigation
feat: add skill-puller sidecar for dynamic skill loading - #84
Conversation
Design doc for a lightweight sidecar that pulls skills dynamically into a running agent pod. Uses a read-only emptyDir volume mount for kernel-enforced write protection. Supports URL, GitHub, and OCI skill sources. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Pavel Anni <[email protected]>
Adds a lightweight sidecar container that pulls skills at runtime into a shared emptyDir volume mounted read-only by the agent. Supports URL and GitHub sources. Includes per-skill ConfigMap generation in the Makefile and recursive skill discovery in the agent's skill loader to support nested directory layouts. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Pavel Anni <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a skill-puller sidecar: build/runtime artifacts, a Go HTTP server with URL/GitHub pull sources, recursive skill discovery/loading, tests, Dockerfile/Makefile updates, and design/examples/deployment manifests for Kubernetes/OpenShift. ChangesSkill-Puller Sidecar
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
- Bind sidecar to 127.0.0.1 (pod-internal only) - Add SSRF protection: reject private/loopback IPs, restrict to http/https schemes, cap response body at 1 MiB - Validate GitHub ref segments against path traversal - Add request body size limit on pull endpoint - Use atomic write (tmp + rename) for SKILL.md - Rewrite TestGitHubSource_Pull to exercise the actual source - Add SecurityContext to both containers in deployment.yaml - Add agent container probes and resource limits - Add tests for recursive skill discovery, K8s symlink dedup, and recursive LoadContent - Unexport Server fields, sort test assertions Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Pavel Anni <[email protected]>
Sanitize skill.Name before using it in filesystem paths to prevent directory traversal attacks. Validates the name is a clean single path segment and confirms the resolved path stays within the skills directory. Addresses CodeQL finding: "Uncontrolled data used in path expression". Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Pavel Anni <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
examples/skill-puller-sidecar/deployment.yaml (1)
46-52: ⚡ Quick winConsider adding
readOnlyRootFilesystem: truefor defense in depth.Both containers have strong security settings but could be further hardened by setting
readOnlyRootFilesystem: true. Neither container appears to require write access to its root filesystem—the agent serves HTTP and the skill-puller writes only to the mounted/data/skillsvolume.🔒 Proposed security enhancement
- name: agent image: ghcr.io/redhat-et/docsclaw:e54a9c1 args: ["serve", "--skills-dir", "/skills"] ports: - containerPort: 8000 securityContext: runAsNonRoot: true allowPrivilegeEscalation: false + readOnlyRootFilesystem: true capabilities: drop: [ALL] seccompProfile: type: RuntimeDefault- name: skill-puller image: ghcr.io/redhat-et/docsclaw-skill-puller:dev args: ["--skills-dir", "/data/skills", "--port", "9100"] ports: - containerPort: 9100 securityContext: runAsNonRoot: true allowPrivilegeEscalation: false + readOnlyRootFilesystem: true capabilities: drop: [ALL] seccompProfile: type: RuntimeDefaultAlso applies to: 101-107
🤖 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 `@examples/skill-puller-sidecar/deployment.yaml` around lines 46 - 52, The pod spec's container securityContext blocks (look for securityContext with fields runAsNonRoot, allowPrivilegeEscalation, capabilities/drop, seccompProfile) should include readOnlyRootFilesystem: true for defense in depth; update each container's securityContext (both containers referenced around the existing blocks) to add readOnlyRootFilesystem: true while ensuring any required writable paths (e.g., /data/skills) remain mounted as writable volumes so the containers retain necessary write access via volumes rather than the root filesystem.
🤖 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 `@cmd/skill-puller/main.go`:
- Around line 3-18: Replace the use of the standard log.Fatal in main with
structured slog logging: change the import from "log" to "log/slog" (and import
"os" if not present), and when srv.Run() returns an error call
slog.Error("failed to run server", "error", err) followed by os.Exit(1) instead
of log.Fatal(err); update the main function around NewServer and srv.Run to use
slog.Error and exit to preserve the failure behavior.
In `@docs/dev/skill-puller-sidecar-design.md`:
- Around line 38-39: Replace the awkward phrase "agent kernel-enforced cannot
write" with a clear, grammatical form; update the sentence in
docs/dev/skill-puller-sidecar-design.md so it reads something like "the agent
kernel cannot write to the skills path, regardless of what code runs inside it"
(or "the agent kernel, which is enforced, cannot write to the skills path...")
to preserve meaning and improve clarity.
In `@internal/skillpuller/server.go`:
- Around line 112-121: The current handlePull logic uses a deterministic tmpPath
(tmpPath := skillPath + ".tmp") which causes races when concurrent pulls for the
same cleanName overwrite each other's temp files; change the flow to create a
unique per-request temp file inside skillDir (use os.CreateTemp(skillDir,
"skill-*.tmp") or similar) to write the skill content, then fsync/close and
atomically rename that temp file to skillPath with os.Rename, and finally set
the final file permissions to 0644 (or create temp with appropriate mode and
call os.Chmod on the renamed file) while preserving the existing logging/error
handling in handlePull and cleaning up the temp on errors.
In `@internal/skillpuller/source/url.go`:
- Around line 72-99: rejectPrivateHost currently only inspects ips[0], skips
IPv6 private ranges and returns nil on DNS failures; update rejectPrivateHost to
iterate over all addresses returned by net.LookupIP(host) (not just ips[0]) and
check each with ip.IsLoopback()/IsLinkLocal*() and against a unified list of
parsed CIDRs that includes IPv4 private ranges (10/8, 172.16/12, 192.168/16,
169.254/16) plus IPv6 ranges (e.g. fc00::/7, fe80::/10, ::1/128), using
net.ParseCIDR and network.Contains(ip) for each parsed network; also change the
DNS-failure branch so that if net.LookupIP returns an error or zero addresses
you return a non-nil error (deny/abort) instead of nil so DNS lookup failures do
not fail open.
In `@pkg/skills/loader.go`:
- Around line 27-30: The WalkDir callback in pkg/skills/loader.go currently
swallows the incoming err (in filepath.WalkDir's anonymous func) by returning
nil; change the callback to at least log the received err (e.g., log.Printf or
the package's logger) with context including the path and then return the err to
propagate the failure (or return the original err after logging) so filesystem
problems aren't silently ignored during skill discovery.
- Around line 89-98: The WalkDir callback in pkg/skills/loader.go currently
swallows callback errors and does not skip hidden dirs, which can cause wrong
SKILL.md matches; update the filepath.WalkDir callback used around the found
variable so it immediately returns any non-nil err (propagate instead of
swallowing), skip directories whose names begin with ".." (same check used in
Discover) by returning filepath.SkipDir for those directories, and when you find
the target "SKILL.md" for the given name set found to p and return a stop value
consistent with the rest of the code (stop further traversal) so the walk
terminates cleanly; reference the filepath.WalkDir callback, the found variable,
and the "SKILL.md" match logic when making the change.
---
Nitpick comments:
In `@examples/skill-puller-sidecar/deployment.yaml`:
- Around line 46-52: The pod spec's container securityContext blocks (look for
securityContext with fields runAsNonRoot, allowPrivilegeEscalation,
capabilities/drop, seccompProfile) should include readOnlyRootFilesystem: true
for defense in depth; update each container's securityContext (both containers
referenced around the existing blocks) to add readOnlyRootFilesystem: true while
ensuring any required writable paths (e.g., /data/skills) remain mounted as
writable volumes so the containers retain necessary write access via volumes
rather than the root filesystem.
🪄 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: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 51359fa8-840e-4046-80c2-0d163ab438aa
📒 Files selected for processing (16)
Dockerfile.skill-pullerMakefilecmd/skill-puller/main.godocs/dev/skill-puller-sidecar-design.mdexamples/skill-puller-sidecar/README.mdexamples/skill-puller-sidecar/deployment.yamlexamples/skill-puller-sidecar/skills/skill-pull/SKILL.mdinternal/skillpuller/server.gointernal/skillpuller/server_test.gointernal/skillpuller/source/github.gointernal/skillpuller/source/github_test.gointernal/skillpuller/source/source.gointernal/skillpuller/source/url.gointernal/skillpuller/source/url_test.gopkg/skills/loader.gopkg/skills/loader_test.go
| _ = filepath.WalkDir(skillsDir, func(p string, d os.DirEntry, err error) error { | ||
| if err != nil || found != "" { | ||
| return filepath.SkipDir | ||
| } | ||
| if !d.IsDir() && d.Name() == "SKILL.md" && filepath.Base(filepath.Dir(p)) == name { | ||
| found = p | ||
| return filepath.SkipAll | ||
| } | ||
| return nil | ||
| }) |
There was a problem hiding this comment.
Recursive search silently ignores WalkDir errors and hidden dirs.
Similar to Discover, errors passed to the callback are swallowed. Additionally, this walk doesn't skip ..-prefixed directories like Discover does—if a K8s ConfigMap mount is present, you may match the wrong SKILL.md inside ..data/.
Proposed fix: add hidden-dir skip and consistent error handling
_ = filepath.WalkDir(skillsDir, func(p string, d os.DirEntry, err error) error {
if err != nil || found != "" {
return filepath.SkipDir
}
+ if d.IsDir() && strings.HasPrefix(d.Name(), "..") {
+ return filepath.SkipDir
+ }
if !d.IsDir() && d.Name() == "SKILL.md" && filepath.Base(filepath.Dir(p)) == name {
found = p
return filepath.SkipAll
}
return nil
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| _ = filepath.WalkDir(skillsDir, func(p string, d os.DirEntry, err error) error { | |
| if err != nil || found != "" { | |
| return filepath.SkipDir | |
| } | |
| if !d.IsDir() && d.Name() == "SKILL.md" && filepath.Base(filepath.Dir(p)) == name { | |
| found = p | |
| return filepath.SkipAll | |
| } | |
| return nil | |
| }) | |
| _ = filepath.WalkDir(skillsDir, func(p string, d os.DirEntry, err error) error { | |
| if err != nil || found != "" { | |
| return filepath.SkipDir | |
| } | |
| if d.IsDir() && strings.HasPrefix(d.Name(), "..") { | |
| return filepath.SkipDir | |
| } | |
| if !d.IsDir() && d.Name() == "SKILL.md" && filepath.Base(filepath.Dir(p)) == name { | |
| found = p | |
| return filepath.SkipAll | |
| } | |
| return nil | |
| }) |
🤖 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 `@pkg/skills/loader.go` around lines 89 - 98, The WalkDir callback in
pkg/skills/loader.go currently swallows callback errors and does not skip hidden
dirs, which can cause wrong SKILL.md matches; update the filepath.WalkDir
callback used around the found variable so it immediately returns any non-nil
err (propagate instead of swallowing), skip directories whose names begin with
".." (same check used in Discover) by returning filepath.SkipDir for those
directories, and when you find the target "SKILL.md" for the given name set
found to p and return a stop value consistent with the rest of the code (stop
further traversal) so the walk terminates cleanly; reference the
filepath.WalkDir callback, the found variable, and the "SKILL.md" match logic
when making the change.
- Use slog instead of log.Fatal in skill-puller main - Fix awkward phrasing in design doc - Use os.CreateTemp for unique temp files (prevents concurrent write races on same skill name) - Harden rejectPrivateHost: check all resolved IPs, add IPv6 private ranges, fail closed on DNS errors - Log walk errors in skill discovery instead of swallowing - Skip ..data dirs in LoadContent recursive search - Add readOnlyRootFilesystem to both containers Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Pavel Anni <[email protected]>
Build the HTTP request from url.Parse output instead of the raw user input so static analysis can verify the URL was sanitized through scheme and host validation. Fixes code-scanning alert #2 (go/request-forgery). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Pavel Anni <[email protected]>
Summary
skill-puller) that pulls skillsdynamically into a running agent pod via a local HTTP API
emptyDirvolume read-only — enforcementis at the kernel VFS level, not voluntary
bundled skills ConfigMap)
static/,dynamic/)work, with a fix for Kubernetes ConfigMap symlink deduplication
What's included
cmd/skill-puller/,internal/skillpuller/internal/skillpuller/source/(URL, GitHub)Dockerfile.skill-pullerexamples/skill-puller-sidecar/examples/skill-puller-sidecar/skills/skill-pull/SKILL.mddocs/dev/skill-puller-sidecar-design.mdpkg/skills/loader.goTest plan
make build-skill-pullercompilesgo test ./internal/skillpuller/...— 12 tests passgo test ./pkg/skills/...— 19 tests passgolangci-lint run— 0 issues on new codepull works, read-only enforcement confirmed
Assisted-By: Claude (Anthropic AI) [email protected]
Summary by CodeRabbit
New Features
Improvements / Bug Fixes
Documentation
Chores
Tests