Skip to content

feat: add skill-puller sidecar for dynamic skill loading - #84

Merged
pavelanni merged 6 commits into
mainfrom
feature/skill-puller-sidecar
Jun 2, 2026
Merged

pavelanni merged 6 commits into
mainfrom
feature/skill-puller-sidecar

Conversation

@pavelanni

@pavelanni pavelanni commented Jun 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a lightweight sidecar container (skill-puller) that pulls skills
    dynamically into a running agent pod via a local HTTP API
  • The agent mounts the shared emptyDir volume read-only — enforcement
    is at the kernel VFS level, not voluntary
  • Supports URL and GitHub skill sources (OCI deferred to follow-up)
  • Includes per-skill ConfigMap generation in the Makefile (replaces the
    bundled skills ConfigMap)
  • Makes skill discovery recursive so nested layouts (static/, dynamic/)
    work, with a fix for Kubernetes ConfigMap symlink deduplication

What's included

Component Path
Sidecar binary cmd/skill-puller/, internal/skillpuller/
Source backends internal/skillpuller/source/ (URL, GitHub)
Dockerfile Dockerfile.skill-puller
Example deployment examples/skill-puller-sidecar/
Agent-side skill examples/skill-puller-sidecar/skills/skill-pull/SKILL.md
Design doc docs/dev/skill-puller-sidecar-design.md
Recursive skill discovery pkg/skills/loader.go

Test plan

  • make build-skill-puller compiles
  • go test ./internal/skillpuller/... — 12 tests pass
  • go test ./pkg/skills/... — 19 tests pass
  • golangci-lint run — 0 issues on new code
  • Local smoke test: pulled Red Hat skill from GitHub via curl
  • OpenShift deployment: static skills mount correctly, dynamic
    pull works, read-only enforcement confirmed
  • Review with Kimi (GLM)

Assisted-By: Claude (Anthropic AI) [email protected]

Summary by CodeRabbit

  • New Features

    • Skill-puller sidecar for dynamic skill discovery and on-demand installation
    • HTTP API to pull/list skills from external sources (URL and GitHub) plus health endpoint
    • Pulled skills stored in a shared volume readable by the agent
  • Improvements / Bug Fixes

    • Skill discovery now finds nested skills and avoids duplicate k8s mount copies
    • Content loading falls back to recursive lookup when needed
  • Documentation

    • Design doc, example deployment, and usage README for the sidecar
  • Chores

    • Container image and Makefile build target added for the skill-puller
  • Tests

    • New tests covering pulling, listing, parsing, and security edge cases

pavelanni added 2 commits June 1, 2026 15:41
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]>
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 038d4fe0-36e9-49a2-9474-e3ea18a2c0d3

📥 Commits

Reviewing files that changed from the base of the PR and between d8ba09e and 6c9d3c9.

📒 Files selected for processing (1)
  • internal/skillpuller/source/url.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/skillpuller/source/url.go

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Skill-Puller Sidecar

Layer / File(s) Summary
Build and Docker image
Dockerfile.skill-puller, Makefile, cmd/skill-puller/main.go
Multi-stage Dockerfile for a static Go binary, Makefile build-skill-puller target, and CLI entrypoint cmd/skill-puller/main.go.
Source abstractions and fetchers
internal/skillpuller/source/source.go, internal/skillpuller/source/url.go, internal/skillpuller/source/github.go, internal/skillpuller/source/*_test.go
Adds Source/Skill/PullOptions and implements URLSource (SSRF checks, size limits, name extraction) and GitHubSource (ref→raw URL conversion, name inference). Unit tests validate URL/github parsing and fetching.
HTTP server and handlers
internal/skillpuller/server.go, internal/skillpuller/server_test.go
Implements /skills/pull (body limit, source dispatch, name sanitization, atomic SKILL.md write), /skills/list, /healthz, Run() with graceful shutdown, and comprehensive handler tests including path-traversal checks.
Recursive discovery and loader
pkg/skills/loader.go, pkg/skills/loader_test.go
Discover() now recursively finds SKILL.md (skips ..* k8s patterns) and may override description from skill.yaml; LoadContent() gains a recursive fallback. Tests cover nested discovery, symlinked ..data duplication, and deep-load fallback.
Design, examples, and deployment
docs/dev/skill-puller-sidecar-design.md, examples/skill-puller-sidecar/*
Design doc and README describing sidecar architecture, API, volume mounts, hot-reload responsibilities; deployment manifest for agent+skill-puller pod, shared emptyDir, probes, and example skill-pull SKILL.md.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • redhat-et/docsclaw#21: Both PRs modify pkg/skills/loader.go’s discovery/metadata behavior and skill.yaml handling.
  • redhat-et/docsclaw#41: Overlaps on pkg/skills/loader.go changes to skill discovery and metadata parsing.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the PR: adding a skill-puller sidecar component for dynamic skill loading. It is concise, specific, and directly reflects the primary change.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feature/skill-puller-sidecar

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

Comment thread internal/skillpuller/server.go Fixed
Comment thread internal/skillpuller/server.go Fixed
Comment thread internal/skillpuller/source/url.go Dismissed
- 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]>
Comment thread internal/skillpuller/server.go Fixed
Comment thread internal/skillpuller/server.go Fixed
Comment thread internal/skillpuller/server.go Fixed
Comment thread internal/skillpuller/server.go Fixed
@pavelanni
pavelanni marked this pull request as ready for review June 1, 2026 22:02
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]>

@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: 6

🧹 Nitpick comments (1)
examples/skill-puller-sidecar/deployment.yaml (1)

46-52: ⚡ Quick win

Consider adding readOnlyRootFilesystem: true for 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/skills volume.

🔒 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: RuntimeDefault

Also 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

📥 Commits

Reviewing files that changed from the base of the PR and between d77d359 and 9ae7f73.

📒 Files selected for processing (16)
  • Dockerfile.skill-puller
  • Makefile
  • cmd/skill-puller/main.go
  • docs/dev/skill-puller-sidecar-design.md
  • examples/skill-puller-sidecar/README.md
  • examples/skill-puller-sidecar/deployment.yaml
  • examples/skill-puller-sidecar/skills/skill-pull/SKILL.md
  • internal/skillpuller/server.go
  • internal/skillpuller/server_test.go
  • internal/skillpuller/source/github.go
  • internal/skillpuller/source/github_test.go
  • internal/skillpuller/source/source.go
  • internal/skillpuller/source/url.go
  • internal/skillpuller/source/url_test.go
  • pkg/skills/loader.go
  • pkg/skills/loader_test.go

Comment thread cmd/skill-puller/main.go Resolved
Comment thread docs/dev/skill-puller-sidecar-design.md Resolved
Comment thread internal/skillpuller/server.go Resolved
Comment thread internal/skillpuller/source/url.go Resolved
Comment thread pkg/skills/loader.go Resolved
Comment thread pkg/skills/loader.go
Comment on lines +89 to +98
_ = 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
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
_ = 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.

pavelanni added 2 commits June 1, 2026 19:06
- 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]>
@pavelanni
pavelanni merged commit 02db400 into main Jun 2, 2026
4 checks passed
@pavelanni
pavelanni deleted the feature/skill-puller-sidecar branch June 2, 2026 00:07
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.

2 participants