Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func main() {
"Secret name containing tls.crt and tls.key for sandbox mTLS client auth")
flag.StringVar(&cfg.ImagePullPolicy, "sandbox-image-pull-policy", cfg.ImagePullPolicy,
"Image pull policy for sandbox pod containers (Always, IfNotPresent, Never); empty uses K8s default")
flag.StringVar(&cfg.SATokenAudience, "sa-token-audience", cfg.SATokenAudience,
"Audience for the projected ServiceAccount token injected into sandbox pods")
flag.Int64Var(&cfg.SATokenTTLSecs, "sa-token-ttl-secs", cfg.SATokenTTLSecs,
"Expiration (seconds) for the projected ServiceAccount token")
flag.Parse()

if cfg.Tenant == "" {
Expand Down
4 changes: 4 additions & 0 deletions internal/driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type Config struct {
TLSCASecret string // Secret name containing ca.crt for gateway TLS verification
TLSClientSecret string // Secret name containing tls.crt and tls.key for mTLS client auth
ImagePullPolicy string // Policy for sandbox pod containers (Always, IfNotPresent, Never); empty means K8s default
SATokenAudience string // audience for the projected SA token volume
SATokenTTLSecs int64 // expiration seconds for the projected SA token
}

func DefaultConfig() Config {
Expand All @@ -18,5 +20,7 @@ func DefaultConfig() Config {
SupervisorImage: "quay.io/azaalouk/openshell-supervisor:latest",
SupervisorBinaryPath: "/openshell-sandbox",
SupervisorMountPath: "/opt/openshell/bin",
SATokenAudience: "openshell-gateway",
SATokenTTLSecs: 3600,
}
}
5 changes: 5 additions & 0 deletions internal/driver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ func TestDefaultConfig(t *testing.T) {
{"SupervisorImage", cfg.SupervisorImage, "quay.io/azaalouk/openshell-supervisor:latest"},
{"SupervisorBinaryPath", cfg.SupervisorBinaryPath, "/openshell-sandbox"},
{"SupervisorMountPath", cfg.SupervisorMountPath, "/opt/openshell/bin"},
{"SATokenAudience", cfg.SATokenAudience, "openshell-gateway"},
}

for _, tt := range tests {
if tt.got != tt.want {
t.Errorf("DefaultConfig().%s = %q, want %q", tt.field, tt.got, tt.want)
}
}

if cfg.SATokenTTLSecs != 3600 {
t.Errorf("DefaultConfig().SATokenTTLSecs = %d, want 3600", cfg.SATokenTTLSecs)
}
}

func TestConfigZeroValue(t *testing.T) {
Expand Down
26 changes: 25 additions & 1 deletion internal/driver/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ func (p *K8sProvisioner) buildSandboxSpec(sb *pb.DriverSandbox) map[string]inter
"readOnly": true,
})
}
if p.cfg.SATokenAudience != "" {
agentVolumeMounts = append(agentVolumeMounts, map[string]interface{}{
"name": "openshell-sa-token",
"mountPath": "/var/run/secrets/openshell",
"readOnly": true,
})
}

container := map[string]interface{}{
"name": "agent",
Expand Down Expand Up @@ -329,6 +336,23 @@ func (p *K8sProvisioner) buildSandboxSpec(sb *pb.DriverSandbox) map[string]inter
},
})
}
if p.cfg.SATokenAudience != "" {
volumes = append(volumes, map[string]interface{}{
"name": "openshell-sa-token",
"projected": map[string]interface{}{
"sources": []interface{}{
map[string]interface{}{
"serviceAccountToken": map[string]interface{}{
"audience": p.cfg.SATokenAudience,
"expirationSeconds": p.cfg.SATokenTTLSecs,
"path": "token",
},
},
},
"defaultMode": int64(0400),
},
})
}

podSpec := map[string]interface{}{
"initContainers": []interface{}{initContainer},
Expand Down Expand Up @@ -390,7 +414,7 @@ func (p *K8sProvisioner) buildFullEnvList(
gatewayEnv["OPENSHELL_TLS_KEY"] = "/tls/client/tls.key"
}

gatewayEnv["OPENSHELL_K8S_SA_TOKEN_FILE"] = "/var/run/secrets/kubernetes.io/serviceaccount/token"
gatewayEnv["OPENSHELL_K8S_SA_TOKEN_FILE"] = "/var/run/secrets/openshell/token"
gatewayEnv["OPENSHELL_LOG_LEVEL"] = "debug"
gatewayEnv["ANTHROPIC_BASE_URL"] = "https://inference.local"
gatewayEnv["OPENAI_BASE_URL"] = "https://inference.local/v1"
Expand Down
48 changes: 42 additions & 6 deletions internal/driver/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ func TestBuildSandboxSpec_SupervisorInitContainer(t *testing.T) {

// Verify volume mounts on agent container.
agentMounts := agentC["volumeMounts"].([]interface{})
if len(agentMounts) != 1 {
t.Fatalf("expected 1 volume mount on agent, got %d", len(agentMounts))
if len(agentMounts) != 2 {
t.Fatalf("expected 2 volume mounts on agent, got %d", len(agentMounts))
}
mount := agentMounts[0].(map[string]interface{})
if mount["name"] != "supervisor-bin" {
Expand All @@ -257,11 +257,21 @@ func TestBuildSandboxSpec_SupervisorInitContainer(t *testing.T) {
if mount["readOnly"] != true {
t.Error("expected readOnly=true on agent volume mount")
}
saMount := agentMounts[1].(map[string]interface{})
if saMount["name"] != "openshell-sa-token" {
t.Errorf("expected mount name openshell-sa-token, got %v", saMount["name"])
}
if saMount["mountPath"] != "/var/run/secrets/openshell" {
t.Errorf("expected mountPath /var/run/secrets/openshell, got %v", saMount["mountPath"])
}
if saMount["readOnly"] != true {
t.Error("expected readOnly=true on SA token volume mount")
}

// Verify volumes.
volumes, ok := podSpec["volumes"].([]interface{})
if !ok || len(volumes) == 0 {
t.Fatal("missing volumes")
if !ok || len(volumes) < 2 {
t.Fatalf("expected at least 2 volumes, got %d", len(volumes))
}
vol := volumes[0].(map[string]interface{})
if vol["name"] != "supervisor-bin" {
Expand All @@ -270,6 +280,32 @@ func TestBuildSandboxSpec_SupervisorInitContainer(t *testing.T) {
if _, ok := vol["emptyDir"]; !ok {
t.Error("expected emptyDir volume")
}
saVol := volumes[1].(map[string]interface{})
if saVol["name"] != "openshell-sa-token" {
t.Errorf("expected volume name openshell-sa-token, got %v", saVol["name"])
}
projected, ok := saVol["projected"].(map[string]interface{})
if !ok {
t.Fatal("expected projected volume")
}
sources, ok := projected["sources"].([]interface{})
if !ok || len(sources) == 0 {
t.Fatal("expected projected sources")
}
src := sources[0].(map[string]interface{})
saToken, ok := src["serviceAccountToken"].(map[string]interface{})
if !ok {
t.Fatal("expected serviceAccountToken source")
}
if saToken["audience"] != cfg.SATokenAudience {
t.Errorf("expected audience %s, got %v", cfg.SATokenAudience, saToken["audience"])
}
if saToken["expirationSeconds"] != cfg.SATokenTTLSecs {
t.Errorf("expected expirationSeconds %d, got %v", cfg.SATokenTTLSecs, saToken["expirationSeconds"])
}
if saToken["path"] != "token" {
t.Errorf("expected path token, got %v", saToken["path"])
}
}

func TestBuildSandboxSpec_Labels(t *testing.T) {
Expand Down Expand Up @@ -488,8 +524,8 @@ func TestBuildSandboxSpec_SATokenEnv(t *testing.T) {
env := e.(map[string]interface{})
if env["name"] == "OPENSHELL_K8S_SA_TOKEN_FILE" {
found = true
if env["value"] != "/var/run/secrets/kubernetes.io/serviceaccount/token" {
t.Errorf("expected SA token path, got %v", env["value"])
if env["value"] != "/var/run/secrets/openshell/token" {
t.Errorf("expected /var/run/secrets/openshell/token, got %v", env["value"])
}
break
}
Expand Down
Loading