Documentation
¶
Overview ¶
Package openshell runs AgentRun workloads in NVIDIA OpenShell sandboxes.
The operator never creates OpenShell's Kubernetes objects itself: it talks to the OpenShell gateway over its Go SDK, and the gateway's Kubernetes compute driver creates the agent-sandbox Sandbox CR, the supervisor and workload pods, and their network fence in the gateway's sandbox namespace. This package owns the translation from agent-orca CRDs to a sandbox spec and policy, so upstream schema changes stay contained here.
Index ¶
- Constants
- Variables
- func BindCredentials(eps []ToolEndpoint, creds []*ToolCredential, ...) ([]ToolEndpoint, []*ToolCredential, error)
- func BuildSpec(in SpecInput) *osv1.SandboxSpec
- func CompilePolicy(routerHost string, sb *agentorcav1alpha1.SandboxSpec, tools []ToolEndpoint) *osv1.SandboxPolicy
- func DescribeCredentials(creds []*ToolCredential) string
- func Profile(namespace string, cred *ToolCredential) *osv1.ProviderProfile
- func ProfileID(namespace, source string) string
- func Provider(namespace, runName string, cred *ToolCredential, ...) *osv1.Provider
- func ProviderName(namespace, runName, source string) string
- func SandboxName(namespace, runName string, attempt int) string
- type Config
- type CredentialKey
- type Gateway
- type Outcome
- type PodLogFunc
- type SDKGateway
- func (g *SDKGateway) Create(ctx context.Context, name string, spec *osv1.SandboxSpec, ...) (*osv1.Sandbox, error)
- func (g *SDKGateway) Delete(ctx context.Context, name string) error
- func (g *SDKGateway) DeleteProviders(ctx context.Context, labels map[string]string) error
- func (g *SDKGateway) EnsureProfile(ctx context.Context, profile *osv1.ProviderProfile) error
- func (g *SDKGateway) EnsureProvider(ctx context.Context, provider *osv1.Provider) error
- func (g *SDKGateway) Get(ctx context.Context, name string) (*osv1.Sandbox, error)
- func (g *SDKGateway) MainProcessLogs(ctx context.Context, sb *osv1.Sandbox) (string, error)
- func (g *SDKGateway) SandboxNamespace() string
- type SpecInput
- type ToolCredential
- type ToolEndpoint
Constants ¶
const ( LabelRunName = "agentorca.io/run" LabelRunNamespace = "agentorca.io/run-namespace" )
Labels set on every sandbox the operator creates, so a sandbox found on the gateway can be traced back to its AgentRun.
const ( SupervisorComponentLabel = "openshell.ai/component" SupervisorComponentValue = "supervisor" SandboxIDLabel = "openshell.ai/sandbox-id" )
Supervisor pod labels set by the OpenShell Kubernetes driver. The supervisor opens the workload's outbound connections, so it is the peer the router NetworkPolicy admits.
const CredentialsEnvVar = "AGENTORCA_TOOL_CREDENTIALS"
CredentialsEnvVar names the non-secret env var describing the credentialed tools, so an agent can build its MCP clients without hardcoding env names.
Variables ¶
var RouterPorts = []uint32{8080, 8082}
RouterPorts are the model-router ports the workload may reach: the OpenAI-compatible API and the Gemini-compatible API.
Functions ¶
func BindCredentials ¶
func BindCredentials(eps []ToolEndpoint, creds []*ToolCredential, providerName func(*ToolCredential) string) ([]ToolEndpoint, []*ToolCredential, error)
BindCredentials marks the tool endpoints that a credential binds to, and drops credentials whose endpoint is not in eps (its host was excluded). Credentials of excluded tools must not be passed in. It returns the endpoints and the credentials still in use. When two sources bind the same endpoint, the first wins: an endpoint can carry only one binding.
func BuildSpec ¶
func BuildSpec(in SpecInput) *osv1.SandboxSpec
BuildSpec returns the sandbox spec for a run: the agent image as the workload, the agent command as the sandbox's main process, and the compiled policy.
func CompilePolicy ¶
func CompilePolicy(routerHost string, sb *agentorcav1alpha1.SandboxSpec, tools []ToolEndpoint) *osv1.SandboxPolicy
CompilePolicy builds the sandbox policy for an agent. The model-router is always reachable; every other destination must be listed in sb.Egress or come from tools. The policy is deterministic for a given input.
func DescribeCredentials ¶
func DescribeCredentials(creds []*ToolCredential) string
DescribeCredentials renders CredentialsEnvVar: for each credentialed tool, its URL and each auth header as a template over the placeholder env var, e.g. {"Authorization": "Bearer ${AGENTORCA_GITHUB_TOKEN}"}. It holds no secrets.
func Profile ¶
func Profile(namespace string, cred *ToolCredential) *osv1.ProviderProfile
Profile returns the endpointless profile declaring cred's env vars. It has no endpoints so the only credential boundary is the sandbox policy's credential_binding, which names exactly the tool's MCP endpoint.
func ProfileID ¶
ProfileID is the gateway profile for a credential source in a namespace. It is shared by every run that uses the source.
func Provider ¶
func Provider(namespace, runName string, cred *ToolCredential, values, labels map[string]string) *osv1.Provider
Provider returns the run's provider instance holding cred's values, keyed by env var. labels identify the run, for cleanup.
func ProviderName ¶
ProviderName is the run's provider instance for a credential source. It is stable across a run's retries, so a retry reuses (and refreshes) it.
func SandboxName ¶
SandboxName returns the gateway name for one attempt of a run's sandbox. The gateway caps sandbox names at 19 characters and names are unique per workspace, while AgentRun names are only unique per namespace, so the name is a short hash. It is stable within an attempt, which makes Create idempotent across reconciles, and changes per retry so a retry never collides with the previous attempt's sandbox while the gateway is still deleting it.
Types ¶
type Config ¶
type Config struct {
// Address is the gateway gRPC address, e.g. "openshell.openshell.svc:8080".
Address string
// Workspace is the gateway workspace sandboxes are created in.
Workspace string
// SandboxNamespace is the namespace the gateway creates sandbox pods in. The
// router NetworkPolicy admits the run's supervisor pod from this namespace.
SandboxNamespace string
// CertFile, KeyFile and CAFile configure mTLS to the gateway.
CertFile string
KeyFile string
CAFile string
// TokenFile optionally holds a bearer token (OIDC gateways).
TokenFile string
// Insecure disables TLS verification. Development only.
Insecure bool
}
Config holds the operator's connection settings for the OpenShell gateway.
func ConfigFromEnv ¶
ConfigFromEnv reads the gateway settings from OPENSHELL_* environment variables. ok is false when OPENSHELL_GATEWAY_ADDRESS is unset, meaning sandbox support is disabled.
type CredentialKey ¶
type CredentialKey struct {
// EnvVar is the workload env var holding the placeholder.
EnvVar string
// Header is the HTTP header the value goes in, and Prefix what precedes it.
Header string
Prefix string
// SecretName and SecretKey locate the value in the tool's namespace.
SecretName string
SecretKey string
}
CredentialKey is one secret header value.
type Gateway ¶
type Gateway interface {
// Create creates a sandbox. It returns the existing sandbox when one with the
// same name already exists, so a reconcile retry is idempotent.
Create(ctx context.Context, name string, spec *osv1.SandboxSpec, labels map[string]string) (*osv1.Sandbox, error)
// Get returns the sandbox, or an error satisfying osv1.IsNotFound.
Get(ctx context.Context, name string) (*osv1.Sandbox, error)
// Delete deletes the sandbox. A missing sandbox is not an error.
Delete(ctx context.Context, name string) error
// MainProcessLogs returns the tail of the workload's main-process output.
MainProcessLogs(ctx context.Context, sb *osv1.Sandbox) (string, error)
// SandboxNamespace is the Kubernetes namespace the gateway creates sandbox pods in.
SandboxNamespace() string
// EnsureProfile creates the provider profile, or updates it when its
// declared credentials changed.
EnsureProfile(ctx context.Context, profile *osv1.ProviderProfile) error
// EnsureProvider creates the provider, or updates its credentials.
EnsureProvider(ctx context.Context, provider *osv1.Provider) error
// DeleteProviders deletes every provider carrying all of labels.
DeleteProviders(ctx context.Context, labels map[string]string) error
}
Gateway is the slice of the OpenShell gateway API the AgentRun controller uses, bound to one workspace.
type Outcome ¶
type Outcome int
Outcome is a sandbox's run state as the AgentRun controller sees it.
type PodLogFunc ¶
PodLogFunc reads a container's logs from a pod. The gateway does not relay main-process output, so the operator reads it from the workload pod directly.
type SDKGateway ¶
type SDKGateway struct {
// contains filtered or unexported fields
}
SDKGateway implements Gateway over the OpenShell Go SDK.
func NewGateway ¶
func NewGateway(sandboxes osv1.SandboxInterface, providers osv1.ProviderInterface, workspace, sandboxNamespace string, podLogs PodLogFunc) *SDKGateway
NewGateway binds a sandbox client to a workspace. With a nil podLogs, MainProcessLogs returns an error.
func (*SDKGateway) Create ¶
func (g *SDKGateway) Create(ctx context.Context, name string, spec *osv1.SandboxSpec, labels map[string]string) (*osv1.Sandbox, error)
Create implements Gateway.
func (*SDKGateway) Delete ¶
func (g *SDKGateway) Delete(ctx context.Context, name string) error
Delete implements Gateway.
func (*SDKGateway) DeleteProviders ¶
DeleteProviders implements Gateway.
func (*SDKGateway) EnsureProfile ¶
func (g *SDKGateway) EnsureProfile(ctx context.Context, profile *osv1.ProviderProfile) error
EnsureProfile implements Gateway.
func (*SDKGateway) EnsureProvider ¶
EnsureProvider implements Gateway. The provider's profile is looked up in the gateway workspace EnsureProfile imports into; an empty ProfileWorkspace would mean the global scope.
func (*SDKGateway) MainProcessLogs ¶
MainProcessLogs implements Gateway.
func (*SDKGateway) SandboxNamespace ¶
func (g *SDKGateway) SandboxNamespace() string
SandboxNamespace implements Gateway.
type SpecInput ¶
type SpecInput struct {
Agent *agentorcav1alpha1.Agent
// RouterHost is the router Service hostname the workload's base URL names.
RouterHost string
// Env is the agent process environment, including the router base URL and
// the per-run router credential.
Env map[string]string
// Tools are the tool endpoints the agent may reach directly, already
// filtered by spec.runtime.sandbox.tools and bound to credential providers.
Tools []ToolEndpoint
// Providers are the provider instances to attach to the sandbox.
Providers []string
}
SpecInput is everything BuildSpec needs to describe a run's sandbox.
type ToolCredential ¶
type ToolCredential struct {
// Source owns the credential: the MCPServer the tool was generated from, or
// the tool itself. Tools from one MCPServer share one credential.
Source string
// Tool is the first tool (in spec.tools order) that declared the credential.
Tool string
// URL is the MCP server URL, and Host/Port its endpoint the credential binds to.
URL string
Host string
Port uint32
Keys []CredentialKey
}
ToolCredential is the static secret material a tool sends to its MCP server.
func ToolCredentials ¶
func ToolCredentials(tool *agentorcav1alpha1.Tool, source string) *ToolCredential
ToolCredentials returns the static credentials of a remote MCP tool, or nil when the tool has none. OAuth tools are skipped: their access token rotates, and a snapshot would go stale mid-run. Secret references to other namespaces are skipped, matching the router, which mounts only same-namespace Secrets. source is the credential owner (see ToolCredential.Source).
type ToolEndpoint ¶
type ToolEndpoint struct {
Tool string
Host string
Port uint32
// CredentialProvider, when set, binds the named provider's static
// credentials to this endpoint (see BindCredentials).
CredentialProvider string
}
ToolEndpoint is one network destination of one of the Agent's tools.
func FilterToolEndpoints ¶
func FilterToolEndpoints(sb *agentorcav1alpha1.SandboxSpec, eps []ToolEndpoint) []ToolEndpoint
FilterToolEndpoints applies spec.runtime.sandbox.tools to the Agent's tool endpoints.
func ToolEndpoints ¶
func ToolEndpoints(tool *agentorcav1alpha1.Tool, extraEgress ...agentorcav1alpha1.EgressRule) []ToolEndpoint
ToolEndpoints returns the network destinations of one Tool that a sandboxed agent may reach: its networkEgress rules that name a host (plus extraEgress, e.g. its MCPServer's networkEgress), and the URL of a remote MCP server. Port-only egress rules are skipped because sandbox policy is per host, and loopback URLs because they name the router pod's own sidecars and the sandbox can never reach loopback destinations.