Repository navigation
bug(K8s): sandbox create does not validate name against Kubernetes naming constraints #2115
Description
Agent Diagnostic
- Loaded
openshell-cliskill and explored the sandbox creation flow across CLI, gateway, and Kubernetes driver. - Traced the name through the code: CLI passes
--nameto the gateway'sCreateSandboxgRPC call. The gateway'svalidate_sandbox_spec(crates/openshell-server/src/grpc/validation.rs:93) checks name length and--substring but does not validate character set. - The gateway calls
validate_sandbox_createon the Kubernetes driver (crates/openshell-driver-kubernetes/src/driver.rs:344), which validates GPU requirements and driver config but not the name. - The name reaches
create_sandboxatdriver.rs:474where it is used directly asmetadata.nameon theSandboxCRD object. Kubernetes rejects it with an RFC 1123 validation error. - The Docker driver already handles this —
sanitize_docker_name(crates/openshell-driver-docker/src/lib.rs:2958) lowercases and replaces invalid characters before creating the container, so names likemy_sandboxandMySandboxwork fine on Docker. The Kubernetes driver has no equivalent sanitization or validation. - Auto-generated names (petname, e.g.
crack-krait) are always valid. Only user-provided--namevalues trigger this.
Description
openshell sandbox create --name "my_sandbox" on the Kubernetes driver passes the name through gateway validation (which only checks length and --), through the Kubernetes driver's validate_sandbox_create (which only checks GPU and driver config), and fails at the Kubernetes API because underscores are not valid in Kubernetes resource names.
The same names work fine on the Docker driver because sanitize_docker_name (crates/openshell-driver-docker/src/lib.rs:2958) lowercases the name and replaces invalid characters with - before creating the container. The Kubernetes driver should either validate and reject early, or sanitize the name to be Kubernetes-compatible, matching the level of input handling the Docker driver already provides.
The Kubernetes driver's validate_sandbox_create (crates/openshell-driver-kubernetes/src/driver.rs:344) already validates GPU requirements and driver config — adding a name check against Kubernetes naming constraints here would catch invalid names before they reach the API.
Reproduction Steps
- Deploy OpenShell on a Kubernetes cluster (kind, minikube, etc.) using the Helm chart
- Run
openshell sandbox create --from base --name "my_sandbox" -- echo test - Observe the Kubernetes API rejection
- Also try
openshell sandbox create --from base --name "MySandbox" -- echo test - Compare: the same names work on a Docker-backed gateway
Environment
- OS: macOS (Darwin 25.5.0, Apple Silicon)
- OpenShell CLI: 0.0.70
- Gateway: 0.0.75-dev.2 (Helm chart 0.0.0-dev)
- Kubernetes: v1.31.0 (kind with Podman)
- Compute driver: kubernetes
- I pointed my agent at the repo and had it investigate this issue
- I loaded relevant skills (e.g.,
debug-openshell-cluster,debug-inference,openshell-cli) - My agent could not resolve this — the diagnostic above explains why - (my agent could just fix it by providing a new name, but it is a good practice to perform validation on the client side to the extent possible before send req to the server)
Activity
[-]bug(kubernetes): sandbox create does not validate name against Kubernetes naming constraints[/-][+]bug(K8s): sandbox create does not validate name against Kubernetes naming constraints[/+]2000krysztof commentedon Jul 13, 2026
I would like to work on this issue.
TaylorMutch commentedon Jul 13, 2026
@2000krysztof I approved your vouch, thanks for volunteering!
Hokonoken commentedon Jul 14, 2026
Welcome @2000krysztof, and good luck with this one! I looked into it earlier, so a few edge cases that might be worth covering, if they help:
^[a-z0-9]([a-z0-9-]*[a-z0-9])?$) rather than a full subdomain. The sandbox name is the leading hostname label in service routing (the routing host is{sandbox}.{base_domain}, and service endpoints are keyed{sandbox}--{service}), so a dotted-but-otherwise-valid subdomain name would still break routing.validate_sandbox_create, so the friendly error precedes the raw RFC-1123 API error the issue is about.--service separator to the routing layer rather than banning it in name validation (it's cross-driver), unless you find a concrete reason to reject it here.Happy to share the two unit tests I drafted (a valid-name case and an invalid dotted/too-long case) if useful — otherwise, all yours.
2000krysztof commentedon Jul 14, 2026
@Hokonoken I think that 63 characters is fine for this, because it gives enough of a margine. I would be happy to take a look at your tests that you made.
Hokonoken commentedon Jul 15, 2026
Here they are — two unit tests plus the small validator they exercise, so the block is self-contained. Take them as-is or adapt freely, no attribution needed.
I re-ran both today on current
main(e6f319c7): the only adaptation needed was the call site, sincevalidate_sandbox_createnow starts withself.validate_driver_config_for_sandbox(sandbox)— I putvalidate_sandbox_name(&sandbox.name)?;as the first line before it. Both tests pass there (cargo test -p openshell-driver-kubernetes sandbox_name_validation).Two deliberate choices encoded in the reject list, in case you want to change them:
dotted.nameis rejected even though the Kubernetes API would accept it formetadata.name— that's the label-vs-subdomain point from my earlier comment.--rejection (a--bpasses): Kubernetes accepts it, and the{sandbox}--{service}separator collision felt like the routing layer's call rather than the driver's, but that one is arguable either way.Good luck with the PR!
2000krysztof commentedon Jul 15, 2026
@Hokonoken Thank you for the code snippet I will add some of these things into my solution.