kcp icon indicating copy to clipboard operation
kcp copied to clipboard

feat: automated AI pen testing harness for kcp security validation

Open mjudeikis-bot opened this issue 8 months ago • 1 comments

Problem

kcp has complex authorization boundaries — logical clusters, APIExports, permission claims, virtual workspaces, RBAC layers. Manual security reviews catch some issues but miss subtle cross-tenant escalation paths, especially with new features. We need automated, repeatable security testing driven by an LLM that can explore the attack surface systematically.

Proposed Setup

Infrastructure

  • External kcp instance (publicly reachable, not localhost)
  • Two kubeconfigs representing different security principals:

1. user.kubeconfig — regular tenant user

  • Has access to their own workspace(s)
  • No APIBindings, no provider capabilities
  • Should NOT be able to see or affect other workspaces
  • Should NOT be able to access APIExport endpoints directly

2. provider.kubeconfig — API provider user

  • Owns an APIExport with permission claims
  • Has provider workspace access
  • Should NOT be able to access consumer/user workspaces
  • Should NOT be able to escalate to root or other tenants

AI Pen Testing Flow

1. Boot kcp instance + bootstrap both principals
2. Feed kubeconfigs + kcp API surface docs to LLM agent
3. LLM systematically attempts all angles below
4. LLM documents every finding with: request, response, expected vs actual behavior
5. Generate security report

Testing Angles

🔐 Authorization boundary testing

  • [ ] Can user read resources from another tenant's workspace?
  • [ ] Can user call APIExport virtual workspace endpoints they haven't bound?
  • [ ] Can provider list workspaces of consumers who have bound their API?
  • [ ] Can either principal access root: or system: workspace resources?
  • [ ] Does removing an APIBinding immediately revoke access (or is there a grace window)?

🏷️ Label & annotation abuse

  • [ ] Can forged kcp.io/path annotations be used to spoof cluster identity?
  • [ ] Are permission claim labels (claimed.internal.apis.kcp.io/*) writable by non-admin users?
  • [ ] Can label selectors on virtual workspace LIST be crafted to enumerate cross-tenant resources?
  • [ ] Can annotations be set to influence scheduling or shard placement?

🔑 Permission claim escalation

  • [ ] Can a provider craft a PermissionClaim that grants access to resources beyond the claimed GVR?
  • [ ] Can a user accept a binding that gives the provider more access than intended?
  • [ ] Can permission claim labels be added/removed directly (bypassing admission)?
  • [ ] What happens when a permission claim references a non-existent identity hash?

🌐 Virtual workspace path traversal

  • [ ] Can a user access /services/apiexport/<other-export>/clusters/* without binding?
  • [ ] Can path segments be URL-encoded or double-encoded to bypass routing guards?
  • [ ] Can the cluster: prefix in URLs be manipulated to access unexpected shards?
  • [ ] Are wildcard list/watch (clusters/*) guarded against unauthenticated callers?

🔄 Lifecycle & race conditions

  • [ ] Create binding → immediately delete export → what resources remain accessible?
  • [ ] Rapid create/delete workspace cycles — does garbage collection leak resources?
  • [ ] Concurrent APIBinding accept from two users on same export — any state corruption?
  • [ ] Delete workspace while LLM agent is actively reading from it — graceful or panic?

🛠️ API machinery abuse

  • [ ] Server-side apply with manager field spoofing across workspace boundaries
  • [ ] PATCH requests with strategic merge on cross-workspace referenced objects
  • [ ] Subresource access (/status, /scale, /exec) on claimed resources — authorization correct?
  • [ ] Impersonation headers (Impersonate-User) — are they blocked for non-admin users?
  • [ ] Dry-run requests — do they bypass authorization checks?

🕵️ Information disclosure

  • [ ] Does error response from unauthorized request leak resource existence?
  • [ ] Do 403 vs 404 responses reveal whether a workspace/resource exists?
  • [ ] Can discovery endpoints (/apis, /api) expose cross-tenant API groups?
  • [ ] Do audit logs contain sensitive data that could be read via claimed log access?

📡 Network & transport

  • [ ] Are kcp shard endpoints exposed with weak TLS config?
  • [ ] Can a user influence which shard handles their request (shard-pinning attacks)?
  • [ ] SSRF via workspace URLs pointing to internal kcp shard addresses?

Related

  • Security issues #63–#69 (found in manual audit, Feb 2026)
  • Issue #3942 (quickstart bootstrap — reuse for test env setup)

/assign @mjudeikis

mjudeikis-bot avatar Mar 27 '26 10:03 mjudeikis-bot

Issues go stale after 90d of inactivity. After a furter 30 days, they will turn rotten. Mark the issue as fresh with /remove-lifecycle stale.

If this issue is safe to close now please do so with /close.

/lifecycle stale

kcp-ci-bot avatar Nov 09 '26 20:11 kcp-ci-bot