Skip to content

An open-source, faster Devin alternative

TypeScript

remove projects, wireup per secret allowedhost

Brian Reardon287a3c1a0802
diff --git a/cmd/oc/internal/commands/project.go b/cmd/oc/internal/commands/project.go
index cc59d333..816ef8c7 100644
--- a/cmd/oc/internal/commands/project.go
+++ b/cmd/oc/internal/commands/project.go
@@ -9,35 +9,27 @@ import (
"github.com/spf13/cobra"
)
-type projectInfo struct {
+type secretStoreInfo struct {
ID string `json:"id"`
OrgID string `json:"orgId"`
Name string `json:"name"`
- Template string `json:"template"`
- CpuCount int `json:"cpuCount"`
- MemoryMB int `json:"memoryMB"`
- TimeoutSec int `json:"timeoutSec"`
EgressAllowlist []string `json:"egressAllowlist"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
-var projectCmd = &cobra.Command{
- Use: "project",
- Short: "Manage projects",
+var secretStoreCmd = &cobra.Command{
+ Use: "secret-store",
+ Short: "Manage secret stores",
}
-var projectCreateCmd = &cobra.Command{
+var secretStoreCreateCmd = &cobra.Command{
Use: "create",
- Short: "Create a new project",
+ Short: "Create a new secret store",
RunE: func(cmd *cobra.Command, args []string) error {
c := client.FromContext(cmd.Context())
name, _ := cmd.Flags().GetString("name")
- template, _ := cmd.Flags().GetString("template")
- cpu, _ := cmd.Flags().GetInt("cpu")
- memory, _ := cmd.Flags().GetInt("memory")
- timeout, _ := cmd.Flags().GetInt("timeout")
allowlist, _ := cmd.Flags().GetStringSlice("egress-allowlist")
if name == "" {
@@ -45,65 +37,54 @@ var projectCreateCmd = &cobra.Command{
}
body := map[string]interface{}{"name": name}
- if template != "" {
- body["template"] = template
- }
- if cpu > 0 {
- body["cpuCount"] = cpu
- }
- if memory > 0 {
- body["memoryMB"] = memory
- }
- if timeout > 0 {
- body["timeoutSec"] = timeout
- }
if len(allowlist) > 0 {
body["egressAllowlist"] = allowlist
}
- var project projectInfo
- if err := c.Post(cmd.Context(), "/projects", body, &project); err != nil {
+ var store secretStoreInfo
+ if err := c.Post(cmd.Context(), "/secret-stores", body, &store); err != nil {
return err
}
- printer.Print(project, func() {
- fmt.Printf("Created project %s (id: %s)\n", project.Name, project.ID)
+ printer.Print(store, func() {
+ fmt.Printf("Created secret store %s (id: %s)\n", store.Name, store.ID)
})
return nil
},
}
-var projectListCmd = &cobra.Command{
+var secretStoreListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
- Short: "List projects",
+ Short: "List secret stores",
RunE: func(cmd *cobra.Command, args []string) error {
c := client.FromContext(cmd.Context())
- var projects []projectInfo
- if err := c.Get(cmd.Context(), "/projects", &projects); err != nil {
+ var stores []secretStoreInfo
+ if err := c.Get(cmd.Context(), "/secret-stores", &stores); err != nil {
return err
}
- printer.Print(projects, func() {
- if len(projects) == 0 {
- fmt.Println("No projects found.")
+ printer.Print(stores, func() {
+ if len(stores) == 0 {
+ fmt.Println("No secret stores found.")
return
}
- headers := []string{"ID", "NAME", "TEMPLATE", "CPU", "MEM", "TIMEOUT", "CREATED"}
+ headers := []string{"ID", "NAME", "EGRESS ALLOWLIST", "CREATED"}
var rows [][]string
- for _, p := range projects {
- created := p.CreatedAt
- if t, err := time.Parse(time.RFC3339Nano, p.CreatedAt); err == nil {
+ for _, s := range stores {
+ created := s.CreatedAt
+ if t, err := time.Parse(time.RFC3339Nano, s.CreatedAt); err == nil {
created = time.Since(t).Truncate(time.Second).String() + " ago"
}
+ egress := "(all)"
+ if len(s.EgressAllowlist) > 0 {
+ egress = strings.Join(s.EgressAllowlist, ", ")
+ }
rows = append(rows, []string{
- p.ID,
- p.Name,
- p.Template,
- fmt.Sprintf("%d", p.CpuCount),
- fmt.Sprintf("%dMB", p.MemoryMB),
- fmt.Sprintf("%ds", p.TimeoutSec),
+ s.ID,
+ s.Name,
+ egress,
created,
})
}
@@ -113,36 +94,32 @@ var projectListCmd = &cobra.Command{
},
}
-var projectGetCmd = &cobra.Command{
- Use: "get <project-id>",
- Short: "Get project details",
+var secretStoreGetCmd = &cobra.Command{
+ Use: "get <store-id>",
+ Short: "Get secret store details",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c := client.FromContext(cmd.Context())
- var project projectInfo
- if err := c.Get(cmd.Context(), "/projects/"+args[0], &project); err != nil {
+ var store secretStoreInfo
+ if err := c.Get(cmd.Context(), "/secret-stores/"+args[0], &store); err != nil {
return err
}
- printer.Print(project, func() {
- fmt.Printf("ID: %s\n", project.ID)
- fmt.Printf("Name: %s\n", project.Name)
- fmt.Printf("Template: %s\n", project.Template)
- fmt.Printf("CPU: %d\n", project.CpuCount)
- fmt.Printf("Memory: %dMB\n", project.MemoryMB)
- fmt.Printf("Timeout: %ds\n", project.TimeoutSec)
- if len(project.EgressAllowlist) > 0 {
- fmt.Printf("Egress: %s\n", strings.Join(project.EgressAllowlist, ", "))
+ printer.Print(store, func() {
+ fmt.Printf("ID: %s\n", store.ID)
+ fmt.Printf("Name: %s\n", store.Name)
+ if len(store.EgressAllowlist) > 0 {
+ fmt.Printf("Egress: %s\n", strings.Join(store.EgressAllowlist, ", "))
}
})
return nil
},
}
-var projectUpdateCmd = &cobra.Command{
- Use: "update <project-id>",
- Short: "Update a project",
+var secretStoreUpdateCmd = &cobra.Command{
+ Use: "update <store-id>",
+ Short: "Update a secret store",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c := client.FromContext(cmd.Context())
@@ -152,77 +129,51 @@ var projectUpdateCmd = &cobra.Command{
v, _ := cmd.Flags().GetString("name")
body["name"] = v
}
- if cmd.Flags().Changed("template") {
- v, _ := cmd.Flags().GetString("template")
- body["template"] = v
- }
- if cmd.Flags().Changed("cpu") {
- v, _ := cmd.Flags().GetInt("cpu")
- body["cpuCount"] = v
- }
- if cmd.Flags().Changed("memory") {
- v, _ := cmd.Flags().GetInt("memory")
- body["memoryMB"] = v
- }
- if cmd.Flags().Changed("timeout") {
- v, _ := cmd.Flags().GetInt("timeout")
- body["timeoutSec"] = v
- }
if cmd.Flags().Changed("egress-allowlist") {
v, _ := cmd.Flags().GetStringSlice("egress-allowlist")
body["egressAllowlist"] = v
}
if len(body) == 0 {
- return fmt.Errorf("no fields to update (use --name, --template, --cpu, --memory, --timeout, --egress-allowlist)")
+ return fmt.Errorf("no fields to update (use --name, --egress-allowlist)")
}
- var project projectInfo
- if err := c.PutJSON(cmd.Context(), "/projects/"+args[0], body, &project); err != nil {
+ var store secretStoreInfo
+ if err := c.PutJSON(cmd.Context(), "/secret-stores/"+args[0], body, &store); err != nil {
return err
}
- printer.Print(project, func() {
- fmt.Printf("Updated project %s\n", project.Name)
+ printer.Print(store, func() {
+ fmt.Printf("Updated secret store %s\n", store.Name)
})
return nil
},
}
-var projectDeleteCmd = &cobra.Command{
- Use: "delete <project-id>",
- Short: "Delete a project and all its secrets",
+var secretStoreDeleteCmd = &cobra.Command{
+ Use: "delete <store-id>",
+ Short: "Delete a secret store and all its secrets",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c := client.FromContext(cmd.Context())
- if err := c.Delete(cmd.Context(), "/projects/"+args[0]); err != nil {
+ if err := c.Delete(cmd.Context(), "/secret-stores/"+args[0]); err != nil {
return err
}
- fmt.Printf("Project %s deleted.\n", args[0])
+ fmt.Printf("Secret store %s deleted.\n", args[0])
return nil
},
}
func init() {
- // project create flags
- projectCreateCmd.Flags().String("name", "", "Project name (required)")
- projectCreateCmd.Flags().String("template", "", "Default template")
- projectCreateCmd.Flags().Int("cpu", 0, "Default CPU count")
- projectCreateCmd.Flags().Int("memory", 0, "Default memory in MB")
- projectCreateCmd.Flags().Int("timeout", 0, "Default timeout in seconds")
- projectCreateCmd.Flags().StringSlice("egress-allowlist", nil, "Allowed egress hosts")
-
- // project update flags (same as create)
- projectUpdateCmd.Flags().String("name", "", "Project name")
- projectUpdateCmd.Flags().String("template", "", "Default template")
- projectUpdateCmd.Flags().Int("cpu", 0, "Default CPU count")
- projectUpdateCmd.Flags().Int("memory", 0, "Default memory in MB")
- projectUpdateCmd.Flags().Int("timeout", 0, "Default timeout in seconds")
- projectUpdateCmd.Flags().StringSlice("egress-allowlist", nil, "Allowed egress hosts")
-
- projectCmd.AddCommand(projectCreateCmd)
- projectCmd.AddCommand(projectListCmd)
- projectCmd.AddCommand(projectGetCmd)
- projectCmd.AddCommand(projectUpdateCmd)
- projectCmd.AddCommand(projectDeleteCmd)
+ secretStoreCreateCmd.Flags().String("name", "", "Store name (required)")
+ secretStoreCreateCmd.Flags().StringSlice("egress-allowlist", nil, "Allowed egress hosts")
+
+ secretStoreUpdateCmd.Flags().String("name", "", "Store name")
+ secretStoreUpdateCmd.Flags().StringSlice("egress-allowlist", nil, "Allowed egress hosts")
+
+ secretStoreCmd.AddCommand(secretStoreCreateCmd)
+ secretStoreCmd.AddCommand(secretStoreListCmd)
+ secretStoreCmd.AddCommand(secretStoreGetCmd)
+ secretStoreCmd.AddCommand(secretStoreUpdateCmd)
+ secretStoreCmd.AddCommand(secretStoreDeleteCmd)
}
diff --git a/cmd/oc/internal/commands/root.go b/cmd/oc/internal/commands/root.go
index 1974b2b6..eeab3138 100644
--- a/cmd/oc/internal/commands/root.go
+++ b/cmd/oc/internal/commands/root.go
@@ -49,7 +49,7 @@ func init() {
rootCmd.AddCommand(checkpointCmd)
rootCmd.AddCommand(patchCmd)
rootCmd.AddCommand(previewCmd)
- rootCmd.AddCommand(projectCmd)
+ rootCmd.AddCommand(secretStoreCmd)
rootCmd.AddCommand(secretCmd)
rootCmd.AddCommand(configCmd)
diff --git a/cmd/oc/internal/commands/secret.go b/cmd/oc/internal/commands/secret.go
index 4ab9aa7b..7f0b434e 100644
--- a/cmd/oc/internal/commands/secret.go
+++ b/cmd/oc/internal/commands/secret.go
@@ -12,26 +12,30 @@ import (
var secretCmd = &cobra.Command{
Use: "secret",
- Short: "Manage project secrets",
+ Short: "Manage secrets in a secret store",
}
var secretSetCmd = &cobra.Command{
- Use: "set <project-id> <name> [value]",
- Short: "Set a secret on a project (encrypted at rest)",
- Long: `Set a secret on a project. The value is encrypted at rest and injected
-as an environment variable into sandboxes created with this project.
+ Use: "set <store-id> <name> [value]",
+ Short: "Set a secret in a store (encrypted at rest)",
+ Long: `Set a secret in a secret store. The value is encrypted at rest and injected
+as an environment variable into sandboxes created with this store.
Value can be provided as:
- oc secret set <project-id> KEY value # inline
- oc secret set <project-id> KEY --from-stdin # from stdin (pipe-friendly)
- echo "val" | oc secret set <project-id> KEY --from-stdin`,
+ oc secret set <store-id> KEY value # inline
+ oc secret set <store-id> KEY --from-stdin # from stdin
+ oc secret set <store-id> KEY value --allowed-hosts api.x.com # with host restriction
+
+When --allowed-hosts is set, the secret is only substituted in outbound
+HTTPS requests to matching hosts. Supports wildcards (*.example.com).`,
Args: cobra.RangeArgs(2, 3),
RunE: func(cmd *cobra.Command, args []string) error {
c := client.FromContext(cmd.Context())
- projectID := args[0]
+ storeID := args[0]
name := args[1]
fromStdin, _ := cmd.Flags().GetBool("from-stdin")
+ allowedHosts, _ := cmd.Flags().GetStringSlice("allowed-hosts")
var value string
if fromStdin {
@@ -54,59 +58,80 @@ Value can be provided as:
return fmt.Errorf("secret value cannot be empty")
}
- body := map[string]string{"value": value}
+ body := map[string]interface{}{"value": value}
+ if len(allowedHosts) > 0 {
+ body["allowedHosts"] = allowedHosts
+ }
+
var result map[string]string
- if err := c.PutJSON(cmd.Context(), fmt.Sprintf("/projects/%s/secrets/%s", projectID, name), body, &result); err != nil {
+ if err := c.PutJSON(cmd.Context(), fmt.Sprintf("/secret-stores/%s/secrets/%s", storeID, name), body, &result); err != nil {
return err
}
- fmt.Printf("Secret %s set on project %s\n", name, projectID)
+ if len(allowedHosts) > 0 {
+ fmt.Printf("Secret %s set on store %s (allowed hosts: %s)\n", name, storeID, strings.Join(allowedHosts, ", "))
+ } else {
+ fmt.Printf("Secret %s set on store %s\n", name, storeID)
+ }
return nil
},
}
+type secretEntryInfo struct {
+ Name string `json:"name"`
+ AllowedHosts []string `json:"allowedHosts"`
+}
+
var secretListCmd = &cobra.Command{
- Use: "list <project-id>",
+ Use: "list <store-id>",
Aliases: []string{"ls"},
- Short: "List secret names for a project (values are never shown)",
+ Short: "List secrets in a store (values are never shown)",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c := client.FromContext(cmd.Context())
- var names []string
- if err := c.Get(cmd.Context(), fmt.Sprintf("/projects/%s/secrets", args[0]), &names); err != nil {
+ var entries []secretEntryInfo
+ if err := c.Get(cmd.Context(), fmt.Sprintf("/secret-stores/%s/secrets", args[0]), &entries); err != nil {
return err
}
- printer.Print(names, func() {
- if len(names) == 0 {
+ printer.Print(entries, func() {
+ if len(entries) == 0 {
fmt.Println("No secrets found.")
return
}
- for _, name := range names {
- fmt.Println(name)
+ headers := []string{"NAME", "ALLOWED HOSTS"}
+ var rows [][]string
+ for _, e := range entries {
+ hosts := "(all)"
+ if len(e.AllowedHosts) > 0 {
+ hosts = strings.Join(e.AllowedHosts, ", ")
+ }
+ rows = append(rows, []string{e.Name, hosts})
}
+ printer.Table(headers, rows)
})
return nil
},
}
var secretDeleteCmd = &cobra.Command{
- Use: "delete <project-id> <name>",
- Short: "Delete a secret from a project",
+ Use: "delete <store-id> <name>",
+ Short: "Delete a secret from a store",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
c := client.FromContext(cmd.Context())
- if err := c.DeleteIgnoreNotFound(cmd.Context(), fmt.Sprintf("/projects/%s/secrets/%s", args[0], args[1])); err != nil {
+ if err := c.DeleteIgnoreNotFound(cmd.Context(), fmt.Sprintf("/secret-stores/%s/secrets/%s", args[0], args[1])); err != nil {
return err
}
- fmt.Printf("Secret %s deleted from project %s\n", args[1], args[0])
+ fmt.Printf("Secret %s deleted from store %s\n", args[1], args[0])
return nil
},
}
func init() {
secretSetCmd.Flags().Bool("from-stdin", false, "Read secret value from stdin")
+ secretSetCmd.Flags().StringSlice("allowed-hosts", nil, "Hosts where this secret can be substituted (e.g. api.anthropic.com)")
secretCmd.AddCommand(secretSetCmd)
secretCmd.AddCommand(secretListCmd)
diff --git a/internal/api/projects.go b/internal/api/projects.go
index 669f5f7b..0525a0e1 100644
--- a/internal/api/projects.go
+++ b/internal/api/projects.go
@@ -2,6 +2,7 @@ package api
import (
"net/http"
+ "strings"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
@@ -9,16 +10,14 @@ import (
"github.com/opensandbox/opensandbox/internal/auth"
)
-func (s *Server) createProject(c echo.Context) error {
+// ── Secret Stores ─────────────────────────────────────────────────────────────
+
+func (s *Server) createSecretStore(c echo.Context) error {
if s.store == nil {
return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
}
var req struct {
Name string `json:"name"`
- Template string `json:"template"`
- CpuCount int `json:"cpuCount"`
- MemoryMB int `json:"memoryMB"`
- TimeoutSec int `json:"timeoutSec"`
EgressAllowlist []string `json:"egressAllowlist"`
}
if err := c.Bind(&req); err != nil {
@@ -33,14 +32,14 @@ func (s *Server) createProject(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- project, err := s.store.CreateProject(c.Request().Context(), orgID, req.Name, req.Template, req.CpuCount, req.MemoryMB, req.TimeoutSec, req.EgressAllowlist)
+ store, err := s.store.CreateSecretStore(c.Request().Context(), orgID, req.Name, req.EgressAllowlist)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
- return c.JSON(http.StatusCreated, project)
+ return c.JSON(http.StatusCreated, store)
}
-func (s *Server) listProjects(c echo.Context) error {
+func (s *Server) listSecretStores(c echo.Context) error {
if s.store == nil {
return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
}
@@ -49,14 +48,14 @@ func (s *Server) listProjects(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projects, err := s.store.ListProjects(c.Request().Context(), orgID)
+ stores, err := s.store.ListSecretStores(c.Request().Context(), orgID)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
- return c.JSON(http.StatusOK, projects)
+ return c.JSON(http.StatusOK, stores)
}
-func (s *Server) getProject(c echo.Context) error {
+func (s *Server) getSecretStore(c echo.Context) error {
if s.store == nil {
return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
}
@@ -65,19 +64,19 @@ func (s *Server) getProject(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
- project, err := s.store.GetProject(c.Request().Context(), orgID, projectID)
+ store, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID)
if err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
- return c.JSON(http.StatusOK, project)
+ return c.JSON(http.StatusOK, store)
}
-func (s *Server) updateProject(c echo.Context) error {
+func (s *Server) updateSecretStore(c echo.Context) error {
if s.store == nil {
return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
}
@@ -86,51 +85,42 @@ func (s *Server) updateProject(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
var req struct {
Name *string `json:"name"`
- Template *string `json:"template"`
- CpuCount *int `json:"cpuCount"`
- MemoryMB *int `json:"memoryMB"`
- TimeoutSec *int `json:"timeoutSec"`
EgressAllowlist []string `json:"egressAllowlist"`
}
if err := c.Bind(&req); err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid request"})
}
- // Fetch existing project to merge partial updates
- existing, err := s.store.GetProject(c.Request().Context(), orgID, projectID)
+ existing, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID)
if err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
name := existing.Name
- template := existing.Template
- cpuCount := existing.CpuCount
- memoryMB := existing.MemoryMB
- timeoutSec := existing.TimeoutSec
allowlist := existing.EgressAllowlist
- if req.Name != nil { name = *req.Name }
- if req.Template != nil { template = *req.Template }
- if req.CpuCount != nil { cpuCount = *req.CpuCount }
- if req.MemoryMB != nil { memoryMB = *req.MemoryMB }
- if req.TimeoutSec != nil { timeoutSec = *req.TimeoutSec }
- if req.EgressAllowlist != nil { allowlist = req.EgressAllowlist }
+ if req.Name != nil {
+ name = *req.Name
+ }
+ if req.EgressAllowlist != nil {
+ allowlist = req.EgressAllowlist
+ }
- project, err := s.store.UpdateProject(c.Request().Context(), orgID, projectID, name, template, cpuCount, memoryMB, timeoutSec, allowlist)
+ store, err := s.store.UpdateSecretStore(c.Request().Context(), orgID, storeID, name, allowlist)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
- return c.JSON(http.StatusOK, project)
+ return c.JSON(http.StatusOK, store)
}
-func (s *Server) deleteProject(c echo.Context) error {
+func (s *Server) deleteSecretStore(c echo.Context) error {
if s.store == nil {
return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
}
@@ -139,20 +129,20 @@ func (s *Server) deleteProject(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
- if err := s.store.DeleteProject(c.Request().Context(), orgID, projectID); err != nil {
+ if err := s.store.DeleteSecretStore(c.Request().Context(), orgID, storeID); err != nil {
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
}
return c.NoContent(http.StatusNoContent)
}
-// ── Project Secrets ───────────────────────────────────────────────────────────
+// ── Secret Store Entries ──────────────────────────────────────────────────────
-func (s *Server) setProjectSecret(c echo.Context) error {
+func (s *Server) setSecretEntry(c echo.Context) error {
if s.store == nil {
return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
}
@@ -161,34 +151,41 @@ func (s *Server) setProjectSecret(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
name := c.Param("name")
if name == "" {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "secret name required"})
}
- // Verify project belongs to org
- if _, err := s.store.GetProject(c.Request().Context(), orgID, projectID); err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ if _, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID); err != nil {
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
var req struct {
- Value string `json:"value"`
+ Value string `json:"value"`
+ AllowedHosts []string `json:"allowedHosts"`
}
if err := c.Bind(&req); err != nil || req.Value == "" {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "secret value required: {\"value\": \"...\"}"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "secret value required: {\"value\": \"...\", \"allowedHosts\": [...]}"})
}
- if err := s.store.SetProjectSecret(c.Request().Context(), projectID, name, []byte(req.Value)); err != nil {
+ for _, h := range req.AllowedHosts {
+ h = strings.TrimSpace(h)
+ if h == "" {
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "allowedHosts entries cannot be empty"})
+ }
+ }
+
+ if err := s.store.SetSecretEntry(c.Request().Context(), storeID, name, []byte(req.Value), req.AllowedHosts); err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
return c.JSON(http.StatusOK, map[string]string{"name": name, "status": "set"})
}
-func (s *Server) deleteProjectSecret(c echo.Context) error {
+func (s *Server) deleteSecretEntry(c echo.Context) error {
if s.store == nil {
return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
}
@@ -197,23 +194,23 @@ func (s *Server) deleteProjectSecret(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
name := c.Param("name")
- if _, err := s.store.GetProject(c.Request().Context(), orgID, projectID); err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ if _, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID); err != nil {
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
- if err := s.store.DeleteProjectSecret(c.Request().Context(), projectID, name); err != nil {
+ if err := s.store.DeleteSecretEntry(c.Request().Context(), storeID, name); err != nil {
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
}
return c.NoContent(http.StatusNoContent)
}
-func (s *Server) listProjectSecrets(c echo.Context) error {
+func (s *Server) listSecretEntries(c echo.Context) error {
if s.store == nil {
return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "database not configured"})
}
@@ -222,22 +219,18 @@ func (s *Server) listProjectSecrets(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
- if _, err := s.store.GetProject(c.Request().Context(), orgID, projectID); err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ if _, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID); err != nil {
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
- secrets, err := s.store.ListProjectSecretNames(c.Request().Context(), projectID)
+ entries, err := s.store.ListSecretEntries(c.Request().Context(), storeID)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
- names := make([]string, len(secrets))
- for i, s := range secrets {
- names[i] = s.Name
- }
- return c.JSON(http.StatusOK, names)
+ return c.JSON(http.StatusOK, entries)
}
diff --git a/internal/api/router.go b/internal/api/router.go
index 64002b38..d2078c99 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -189,17 +189,17 @@ func NewServer(mgr sandbox.Manager, ptyMgr *sandbox.PTYManager, apiKey string, o
api.DELETE("/templates/:name", s.deleteTemplate)
api.POST("/sandboxes/:sandboxId/save-as-template", s.dashboardSaveAsTemplate)
- // Projects
- api.POST("/projects", s.createProject)
- api.GET("/projects", s.listProjects)
- api.GET("/projects/:id", s.getProject)
- api.PUT("/projects/:id", s.updateProject)
- api.DELETE("/projects/:id", s.deleteProject)
-
- // Project secrets
- api.PUT("/projects/:id/secrets/:name", s.setProjectSecret)
- api.DELETE("/projects/:id/secrets/:name", s.deleteProjectSecret)
- api.GET("/projects/:id/secrets", s.listProjectSecrets)
+ // Secret stores
+ api.POST("/secret-stores", s.createSecretStore)
+ api.GET("/secret-stores", s.listSecretStores)
+ api.GET("/secret-stores/:id", s.getSecretStore)
+ api.PUT("/secret-stores/:id", s.updateSecretStore)
+ api.DELETE("/secret-stores/:id", s.deleteSecretStore)
+
+ // Secret store entries
+ api.PUT("/secret-stores/:id/secrets/:name", s.setSecretEntry)
+ api.DELETE("/secret-stores/:id/secrets/:name", s.deleteSecretEntry)
+ api.GET("/secret-stores/:id/secrets", s.listSecretEntries)
// Workers (server mode only — queries worker registry)
api.GET("/workers", s.listWorkers)
diff --git a/internal/api/sandbox.go b/internal/api/sandbox.go
index 41714f6a..51869831 100644
--- a/internal/api/sandbox.go
+++ b/internal/api/sandbox.go
@@ -60,44 +60,37 @@ func (s *Server) createSandbox(c echo.Context) error {
}
}
- // Resolve project: inherit config defaults + decrypt and merge secrets
- if cfg.Project != "" && s.store != nil && hasOrg {
- project, err := s.store.GetProjectByName(ctx, orgID, cfg.Project)
+ // Resolve secret store: decrypt secrets + inherit egress config
+ if cfg.SecretStore != "" && s.store != nil && hasOrg {
+ store, err := s.store.GetSecretStoreByName(ctx, orgID, cfg.SecretStore)
if err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{
- "error": "project not found: " + cfg.Project,
+ "error": "secret store not found: " + cfg.SecretStore,
})
}
- // Project config serves as defaults — request fields override
- if cfg.Template == "" {
- cfg.Template = project.Template
- }
- if cfg.CpuCount == 0 {
- cfg.CpuCount = project.CpuCount
- }
- if cfg.MemoryMB == 0 {
- cfg.MemoryMB = project.MemoryMB
- }
- if cfg.Timeout == 0 {
- cfg.Timeout = project.TimeoutSec
- }
+ cfg.EgressAllowlist = store.EgressAllowlist
- // Decrypt project secrets and merge into envs (request envs override project secrets)
- secrets, err := s.store.DecryptProjectSecrets(ctx, project.ID)
+ secrets, err := s.store.DecryptSecretEntries(ctx, store.ID)
if err != nil {
- log.Printf("api: decrypt project secrets failed for %s: %v", cfg.Project, err)
+ log.Printf("api: decrypt secrets failed for store %s: %v", cfg.SecretStore, err)
return c.JSON(http.StatusInternalServerError, map[string]string{
- "error": "failed to decrypt project secrets",
+ "error": "failed to decrypt secrets",
})
}
if len(secrets) > 0 {
if cfg.Envs == nil {
cfg.Envs = make(map[string]string)
}
- for k, v := range secrets {
- if _, exists := cfg.Envs[k]; !exists {
- cfg.Envs[k] = v
+ for _, secret := range secrets {
+ if _, exists := cfg.Envs[secret.Name]; !exists {
+ cfg.Envs[secret.Name] = secret.Value
+ }
+ if len(secret.AllowedHosts) > 0 {
+ if cfg.SecretAllowedHosts == nil {
+ cfg.SecretAllowedHosts = make(map[string][]string)
+ }
+ cfg.SecretAllowedHosts[secret.Name] = secret.AllowedHosts
}
}
}
diff --git a/internal/controlplane/projects.go b/internal/controlplane/projects.go
index ac811dd7..4debd399 100644
--- a/internal/controlplane/projects.go
+++ b/internal/controlplane/projects.go
@@ -2,6 +2,7 @@ package controlplane
import (
"net/http"
+ "strings"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
@@ -9,13 +10,11 @@ import (
"github.com/opensandbox/opensandbox/internal/auth"
)
-func (s *Server) createProject(c echo.Context) error {
+// ── Secret Stores ─────────────────────────────────────────────────────────────
+
+func (s *Server) createSecretStore(c echo.Context) error {
var req struct {
Name string `json:"name"`
- Template string `json:"template"`
- CpuCount int `json:"cpuCount"`
- MemoryMB int `json:"memoryMB"`
- TimeoutSec int `json:"timeoutSec"`
EgressAllowlist []string `json:"egressAllowlist"`
}
if err := c.Bind(&req); err != nil {
@@ -30,194 +29,185 @@ func (s *Server) createProject(c echo.Context) error {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- project, err := s.store.CreateProject(c.Request().Context(), orgID, req.Name, req.Template, req.CpuCount, req.MemoryMB, req.TimeoutSec, req.EgressAllowlist)
+ store, err := s.store.CreateSecretStore(c.Request().Context(), orgID, req.Name, req.EgressAllowlist)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
- return c.JSON(http.StatusCreated, project)
+ return c.JSON(http.StatusCreated, store)
}
-func (s *Server) listProjects(c echo.Context) error {
+func (s *Server) listSecretStores(c echo.Context) error {
orgID, ok := auth.GetOrgID(c)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projects, err := s.store.ListProjects(c.Request().Context(), orgID)
+ stores, err := s.store.ListSecretStores(c.Request().Context(), orgID)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
- return c.JSON(http.StatusOK, projects)
+ return c.JSON(http.StatusOK, stores)
}
-func (s *Server) getProject(c echo.Context) error {
+func (s *Server) getSecretStore(c echo.Context) error {
orgID, ok := auth.GetOrgID(c)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
- project, err := s.store.GetProject(c.Request().Context(), orgID, projectID)
+ store, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID)
if err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
- return c.JSON(http.StatusOK, project)
+ return c.JSON(http.StatusOK, store)
}
-func (s *Server) updateProject(c echo.Context) error {
+func (s *Server) updateSecretStore(c echo.Context) error {
orgID, ok := auth.GetOrgID(c)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
var req struct {
Name *string `json:"name"`
- Template *string `json:"template"`
- CpuCount *int `json:"cpuCount"`
- MemoryMB *int `json:"memoryMB"`
- TimeoutSec *int `json:"timeoutSec"`
EgressAllowlist []string `json:"egressAllowlist"`
}
if err := c.Bind(&req); err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid request"})
}
- // Fetch existing project to merge partial updates
- existing, err := s.store.GetProject(c.Request().Context(), orgID, projectID)
+ existing, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID)
if err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
name := existing.Name
- template := existing.Template
- cpuCount := existing.CpuCount
- memoryMB := existing.MemoryMB
- timeoutSec := existing.TimeoutSec
allowlist := existing.EgressAllowlist
- if req.Name != nil { name = *req.Name }
- if req.Template != nil { template = *req.Template }
- if req.CpuCount != nil { cpuCount = *req.CpuCount }
- if req.MemoryMB != nil { memoryMB = *req.MemoryMB }
- if req.TimeoutSec != nil { timeoutSec = *req.TimeoutSec }
- if req.EgressAllowlist != nil { allowlist = req.EgressAllowlist }
+ if req.Name != nil {
+ name = *req.Name
+ }
+ if req.EgressAllowlist != nil {
+ allowlist = req.EgressAllowlist
+ }
- project, err := s.store.UpdateProject(c.Request().Context(), orgID, projectID, name, template, cpuCount, memoryMB, timeoutSec, allowlist)
+ store, err := s.store.UpdateSecretStore(c.Request().Context(), orgID, storeID, name, allowlist)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
- return c.JSON(http.StatusOK, project)
+ return c.JSON(http.StatusOK, store)
}
-func (s *Server) deleteProject(c echo.Context) error {
+func (s *Server) deleteSecretStore(c echo.Context) error {
orgID, ok := auth.GetOrgID(c)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
- if err := s.store.DeleteProject(c.Request().Context(), orgID, projectID); err != nil {
+ if err := s.store.DeleteSecretStore(c.Request().Context(), orgID, storeID); err != nil {
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
}
return c.NoContent(http.StatusNoContent)
}
-// ── Project Secrets ───────────────────────────────────────────────────────────
+// ── Secret Store Entries ──────────────────────────────────────────────────────
-func (s *Server) setProjectSecret(c echo.Context) error {
+func (s *Server) setSecretEntry(c echo.Context) error {
orgID, ok := auth.GetOrgID(c)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
name := c.Param("name")
if name == "" {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "secret name required"})
}
- // Verify project belongs to org
- if _, err := s.store.GetProject(c.Request().Context(), orgID, projectID); err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ if _, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID); err != nil {
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
- // Read secret value from JSON body
var req struct {
- Value string `json:"value"`
+ Value string `json:"value"`
+ AllowedHosts []string `json:"allowedHosts"`
}
if err := c.Bind(&req); err != nil || req.Value == "" {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "secret value required: {\"value\": \"...\"}"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "secret value required: {\"value\": \"...\", \"allowedHosts\": [...]}"})
}
- body := []byte(req.Value)
- if err := s.store.SetProjectSecret(c.Request().Context(), projectID, name, body); err != nil {
+ // Validate allowedHosts format
+ for _, h := range req.AllowedHosts {
+ h = strings.TrimSpace(h)
+ if h == "" {
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "allowedHosts entries cannot be empty"})
+ }
+ }
+
+ if err := s.store.SetSecretEntry(c.Request().Context(), storeID, name, []byte(req.Value), req.AllowedHosts); err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
return c.JSON(http.StatusOK, map[string]string{"name": name, "status": "set"})
}
-func (s *Server) deleteProjectSecret(c echo.Context) error {
+func (s *Server) deleteSecretEntry(c echo.Context) error {
orgID, ok := auth.GetOrgID(c)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
name := c.Param("name")
- // Verify project belongs to org
- if _, err := s.store.GetProject(c.Request().Context(), orgID, projectID); err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ if _, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID); err != nil {
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
- if err := s.store.DeleteProjectSecret(c.Request().Context(), projectID, name); err != nil {
+ if err := s.store.DeleteSecretEntry(c.Request().Context(), storeID, name); err != nil {
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
}
return c.NoContent(http.StatusNoContent)
}
-func (s *Server) listProjectSecrets(c echo.Context) error {
+func (s *Server) listSecretEntries(c echo.Context) error {
orgID, ok := auth.GetOrgID(c)
if !ok {
return c.JSON(http.StatusUnauthorized, map[string]string{"error": "auth required"})
}
- projectID, err := uuid.Parse(c.Param("id"))
+ storeID, err := uuid.Parse(c.Param("id"))
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid project ID"})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid store ID"})
}
- // Verify project belongs to org
- if _, err := s.store.GetProject(c.Request().Context(), orgID, projectID); err != nil {
- return c.JSON(http.StatusNotFound, map[string]string{"error": "project not found"})
+ if _, err := s.store.GetSecretStore(c.Request().Context(), orgID, storeID); err != nil {
+ return c.JSON(http.StatusNotFound, map[string]string{"error": "secret store not found"})
}
- secrets, err := s.store.ListProjectSecretNames(c.Request().Context(), projectID)
+ entries, err := s.store.ListSecretEntries(c.Request().Context(), storeID)
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
- names := make([]string, len(secrets))
- for i, s := range secrets {
- names[i] = s.Name
- }
- return c.JSON(http.StatusOK, names)
+ return c.JSON(http.StatusOK, entries)
}
diff --git a/internal/controlplane/server.go b/internal/controlplane/server.go
index ac3aa986..67e1818e 100644
--- a/internal/controlplane/server.go
+++ b/internal/controlplane/server.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"log"
"net/http"
+ "strings"
"time"
"github.com/labstack/echo/v4"
@@ -64,17 +65,17 @@ func NewServer(store *db.Store, jwtIssuer *auth.JWTIssuer, registry *WorkerRegis
// Workers
api.GET("/workers", s.listWorkers)
- // Projects
- api.POST("/projects", s.createProject)
- api.GET("/projects", s.listProjects)
- api.GET("/projects/:id", s.getProject)
- api.PUT("/projects/:id", s.updateProject)
- api.DELETE("/projects/:id", s.deleteProject)
+ // Secret stores
+ api.POST("/secret-stores", s.createSecretStore)
+ api.GET("/secret-stores", s.listSecretStores)
+ api.GET("/secret-stores/:id", s.getSecretStore)
+ api.PUT("/secret-stores/:id", s.updateSecretStore)
+ api.DELETE("/secret-stores/:id", s.deleteSecretStore)
- // Project secrets
- api.PUT("/projects/:id/secrets/:name", s.setProjectSecret)
- api.DELETE("/projects/:id/secrets/:name", s.deleteProjectSecret)
- api.GET("/projects/:id/secrets", s.listProjectSecrets)
+ // Secret store entries
+ api.PUT("/secret-stores/:id/secrets/:name", s.setSecretEntry)
+ api.DELETE("/secret-stores/:id/secrets/:name", s.deleteSecretEntry)
+ api.GET("/secret-stores/:id/secrets", s.listSecretEntries)
return s
}
@@ -99,7 +100,7 @@ func (s *Server) createSandbox(c echo.Context) error {
CpuCount int `json:"cpuCount"`
Metadata map[string]string `json:"metadata"`
NetworkEnabled bool `json:"networkEnabled"`
- Project string `json:"project"` // project name — resolves config + secrets
+ SecretStore string `json:"secretStore"` // secret store name — resolves secrets + egress config
}
if err := c.Bind(&req); err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid request: " + err.Error()})
@@ -120,52 +121,41 @@ func (s *Server) createSandbox(c echo.Context) error {
return c.JSON(http.StatusTooManyRequests, map[string]string{"error": "concurrent sandbox limit reached"})
}
- // Resolve project: inherit config defaults + decrypt and merge secrets
- var projectID *string
+ // Resolve secret store: decrypt secrets + inherit egress allowlist
var egressAllowlist []string
- if req.Project != "" {
- project, err := s.store.GetProjectByName(c.Request().Context(), orgID, req.Project)
+ var secretAllowedHosts map[string]string // env var name → comma-separated hosts (for proto)
+ if req.SecretStore != "" {
+ store, err := s.store.GetSecretStoreByName(c.Request().Context(), orgID, req.SecretStore)
if err != nil {
- return c.JSON(http.StatusBadRequest, map[string]string{"error": "project not found: " + req.Project})
+ return c.JSON(http.StatusBadRequest, map[string]string{"error": "secret store not found: " + req.SecretStore})
}
- pid := project.ID.String()
- projectID = &pid
- // Project config serves as defaults — request fields override
- if req.TemplateID == "" {
- req.TemplateID = project.Template
- }
- if req.CpuCount == 0 {
- req.CpuCount = project.CpuCount
- }
- if req.MemoryMB == 0 {
- req.MemoryMB = project.MemoryMB
- }
- if req.Timeout == 0 {
- req.Timeout = project.TimeoutSec
- }
-
- // Inherit egress allowlist from project
- egressAllowlist = project.EgressAllowlist
+ egressAllowlist = store.EgressAllowlist
- // Decrypt project secrets and merge into envs (request envs override project secrets)
- secrets, err := s.store.DecryptProjectSecrets(c.Request().Context(), project.ID)
+ // Decrypt secrets and merge into envs (request envs override store secrets)
+ secrets, err := s.store.DecryptSecretEntries(c.Request().Context(), store.ID)
if err != nil {
- log.Printf("controlplane: decrypt project secrets failed for %s: %v", req.Project, err)
- return c.JSON(http.StatusInternalServerError, map[string]string{"error": "failed to decrypt project secrets"})
+ log.Printf("controlplane: decrypt secrets failed for store %s: %v", req.SecretStore, err)
+ return c.JSON(http.StatusInternalServerError, map[string]string{"error": "failed to decrypt secrets"})
}
if len(secrets) > 0 {
if req.Envs == nil {
req.Envs = make(map[string]string)
}
- for k, v := range secrets {
- if _, exists := req.Envs[k]; !exists {
- req.Envs[k] = v
+ for _, secret := range secrets {
+ if _, exists := req.Envs[secret.Name]; !exists {
+ req.Envs[secret.Name] = secret.Value
+ }
+ // Build per-secret host restrictions for proto
+ if len(secret.AllowedHosts) > 0 {
+ if secretAllowedHosts == nil {
+ secretAllowedHosts = make(map[string]string)
+ }
+ secretAllowedHosts[secret.Name] = strings.Join(secret.AllowedHosts, ",")
}
}
}
}
- _ = projectID // TODO: store on sandbox_sessions.project_id
// Select region (explicit, or from Fly-Region header, or default)
region := req.Region
@@ -199,13 +189,14 @@ func (s *Server) createSandbox(c echo.Context) error {
client := pb.NewSandboxWorkerClient(conn)
grpcResp, err := client.CreateSandbox(ctx, &pb.CreateSandboxRequest{
- Template: req.TemplateID,
- Timeout: int32(req.Timeout),
- Envs: req.Envs,
- MemoryMb: int32(req.MemoryMB),
- CpuCount: int32(req.CpuCount),
- NetworkEnabled: req.NetworkEnabled,
- EgressAllowlist: egressAllowlist,
+ Template: req.TemplateID,
+ Timeout: int32(req.Timeout),
+ Envs: req.Envs,
+ MemoryMb: int32(req.MemoryMB),
+ CpuCount: int32(req.CpuCount),
+ NetworkEnabled: req.NetworkEnabled,
+ EgressAllowlist: egressAllowlist,
+ SecretAllowedHosts: secretAllowedHosts,
})
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "worker create failed: " + err.Error()})
diff --git a/internal/db/migrations/015_secret_allowed_hosts.up.sql b/internal/db/migrations/015_secret_allowed_hosts.up.sql
new file mode 100644
index 00000000..2c267f54
--- /dev/null
+++ b/internal/db/migrations/015_secret_allowed_hosts.up.sql
@@ -0,0 +1,35 @@
+-- Replace projects with secret stores: simpler entity that just holds secrets + egress config.
+-- Projects bundled too much (template, cpu, mem, timeout) — those belong on sandbox creation.
+
+-- Create secret stores
+CREATE TABLE IF NOT EXISTS secret_stores (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ org_id UUID NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ egress_allowlist TEXT[] NOT NULL DEFAULT '{}',
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ UNIQUE(org_id, name)
+);
+CREATE INDEX IF NOT EXISTS idx_secret_stores_org ON secret_stores(org_id);
+
+-- Create secret store entries with per-secret host restrictions
+CREATE TABLE IF NOT EXISTS secret_store_entries (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ store_id UUID NOT NULL REFERENCES secret_stores(id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ encrypted_value BYTEA NOT NULL,
+ allowed_hosts TEXT[] NOT NULL DEFAULT '{}',
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ UNIQUE(store_id, name)
+);
+CREATE INDEX IF NOT EXISTS idx_secret_store_entries_store ON secret_store_entries(store_id);
+
+-- Drop old project tables (secrets first due to FK)
+DROP TABLE IF EXISTS project_secrets;
+DROP TABLE IF EXISTS projects;
+
+-- Update sandbox_sessions: replace project_id with secret_store_id
+ALTER TABLE sandbox_sessions DROP COLUMN IF EXISTS project_id;
+ALTER TABLE sandbox_sessions ADD COLUMN IF NOT EXISTS secret_store_id UUID REFERENCES secret_stores(id);
diff --git a/internal/db/store.go b/internal/db/store.go
index bc67e1b4..d4283960 100644
--- a/internal/db/store.go
+++ b/internal/db/store.go
@@ -1249,174 +1249,169 @@ func (s *Store) DeletePreviewURLsBySandbox(ctx context.Context, sandboxID string
return urls, nil
}
-// ── Projects ──────────────────────────────────────────────────────────────────
+// ── Secret Stores ─────────────────────────────────────────────────────────────
-// Project represents a project that groups sandboxes and holds secrets.
-type Project struct {
+// SecretStore represents a named collection of secrets scoped to an org.
+type SecretStore struct {
ID uuid.UUID `json:"id"`
OrgID uuid.UUID `json:"orgId"`
Name string `json:"name"`
- Template string `json:"template"`
- CpuCount int `json:"cpuCount"`
- MemoryMB int `json:"memoryMB"`
- TimeoutSec int `json:"timeoutSec"`
EgressAllowlist []string `json:"egressAllowlist"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
-// ProjectSecret represents an encrypted secret belonging to a project.
-type ProjectSecret struct {
- ID uuid.UUID `json:"id"`
- ProjectID uuid.UUID `json:"projectId"`
- Name string `json:"name"`
- CreatedAt time.Time `json:"createdAt"`
- UpdatedAt time.Time `json:"updatedAt"`
+// SecretEntry represents an encrypted secret in a store (values are never returned to clients).
+type SecretEntry struct {
+ ID uuid.UUID `json:"id"`
+ StoreID uuid.UUID `json:"storeId"`
+ Name string `json:"name"`
+ AllowedHosts []string `json:"allowedHosts"`
+ CreatedAt time.Time `json:"createdAt"`
+ UpdatedAt time.Time `json:"updatedAt"`
}
-// CreateProject creates a new project for an org.
-func (s *Store) CreateProject(ctx context.Context, orgID uuid.UUID, name, template string, cpuCount, memoryMB, timeoutSec int, allowlist []string) (*Project, error) {
- if template == "" {
- template = "default"
- }
- if cpuCount <= 0 {
- cpuCount = 1
- }
- if memoryMB <= 0 {
- memoryMB = 1024
- }
- if timeoutSec <= 0 {
- timeoutSec = 300
- }
- if allowlist == nil {
- allowlist = []string{}
+// DecryptedSecret holds a plaintext secret value and its host restrictions.
+type DecryptedSecret struct {
+ Name string
+ Value string
+ AllowedHosts []string
+}
+
+// CreateSecretStore creates a new secret store for an org.
+func (s *Store) CreateSecretStore(ctx context.Context, orgID uuid.UUID, name string, egressAllowlist []string) (*SecretStore, error) {
+ if egressAllowlist == nil {
+ egressAllowlist = []string{}
}
- var p Project
+ var ss SecretStore
err := s.pool.QueryRow(ctx,
- `INSERT INTO projects (org_id, name, template, cpu_count, memory_mb, timeout_sec, egress_allowlist)
- VALUES ($1, $2, $3, $4, $5, $6, $7)
- RETURNING id, org_id, name, template, cpu_count, memory_mb, timeout_sec, egress_allowlist, created_at, updated_at`,
- orgID, name, template, cpuCount, memoryMB, timeoutSec, allowlist,
- ).Scan(&p.ID, &p.OrgID, &p.Name, &p.Template, &p.CpuCount, &p.MemoryMB, &p.TimeoutSec, &p.EgressAllowlist, &p.CreatedAt, &p.UpdatedAt)
+ `INSERT INTO secret_stores (org_id, name, egress_allowlist)
+ VALUES ($1, $2, $3)
+ RETURNING id, org_id, name, egress_allowlist, created_at, updated_at`,
+ orgID, name, egressAllowlist,
+ ).Scan(&ss.ID, &ss.OrgID, &ss.Name, &ss.EgressAllowlist, &ss.CreatedAt, &ss.UpdatedAt)
if err != nil {
- return nil, fmt.Errorf("create project: %w", err)
+ return nil, fmt.Errorf("create secret store: %w", err)
}
- return &p, nil
+ return &ss, nil
}
-// GetProject returns a project by ID, scoped to an org.
-func (s *Store) GetProject(ctx context.Context, orgID, projectID uuid.UUID) (*Project, error) {
- var p Project
+// GetSecretStore returns a secret store by ID, scoped to an org.
+func (s *Store) GetSecretStore(ctx context.Context, orgID, storeID uuid.UUID) (*SecretStore, error) {
+ var ss SecretStore
err := s.pool.QueryRow(ctx,
- `SELECT id, org_id, name, template, cpu_count, memory_mb, timeout_sec, egress_allowlist, created_at, updated_at
- FROM projects WHERE id = $1 AND org_id = $2`,
- projectID, orgID,
- ).Scan(&p.ID, &p.OrgID, &p.Name, &p.Template, &p.CpuCount, &p.MemoryMB, &p.TimeoutSec, &p.EgressAllowlist, &p.CreatedAt, &p.UpdatedAt)
+ `SELECT id, org_id, name, egress_allowlist, created_at, updated_at
+ FROM secret_stores WHERE id = $1 AND org_id = $2`,
+ storeID, orgID,
+ ).Scan(&ss.ID, &ss.OrgID, &ss.Name, &ss.EgressAllowlist, &ss.CreatedAt, &ss.UpdatedAt)
if err != nil {
- return nil, fmt.Errorf("get project: %w", err)
+ return nil, fmt.Errorf("get secret store: %w", err)
}
- return &p, nil
+ return &ss, nil
}
-// GetProjectByName returns a project by name, scoped to an org.
-func (s *Store) GetProjectByName(ctx context.Context, orgID uuid.UUID, name string) (*Project, error) {
- var p Project
+// GetSecretStoreByName returns a secret store by name, scoped to an org.
+func (s *Store) GetSecretStoreByName(ctx context.Context, orgID uuid.UUID, name string) (*SecretStore, error) {
+ var ss SecretStore
err := s.pool.QueryRow(ctx,
- `SELECT id, org_id, name, template, cpu_count, memory_mb, timeout_sec, egress_allowlist, created_at, updated_at
- FROM projects WHERE org_id = $1 AND name = $2`,
+ `SELECT id, org_id, name, egress_allowlist, created_at, updated_at
+ FROM secret_stores WHERE org_id = $1 AND name = $2`,
orgID, name,
- ).Scan(&p.ID, &p.OrgID, &p.Name, &p.Template, &p.CpuCount, &p.MemoryMB, &p.TimeoutSec, &p.EgressAllowlist, &p.CreatedAt, &p.UpdatedAt)
+ ).Scan(&ss.ID, &ss.OrgID, &ss.Name, &ss.EgressAllowlist, &ss.CreatedAt, &ss.UpdatedAt)
if err != nil {
- return nil, fmt.Errorf("get project by name: %w", err)
+ return nil, fmt.Errorf("get secret store by name: %w", err)
}
- return &p, nil
+ return &ss, nil
}
-// ListProjects returns all projects for an org.
-func (s *Store) ListProjects(ctx context.Context, orgID uuid.UUID) ([]Project, error) {
+// ListSecretStores returns all secret stores for an org.
+func (s *Store) ListSecretStores(ctx context.Context, orgID uuid.UUID) ([]SecretStore, error) {
rows, err := s.pool.Query(ctx,
- `SELECT id, org_id, name, template, cpu_count, memory_mb, timeout_sec, egress_allowlist, created_at, updated_at
- FROM projects WHERE org_id = $1 ORDER BY name`,
+ `SELECT id, org_id, name, egress_allowlist, created_at, updated_at
+ FROM secret_stores WHERE org_id = $1 ORDER BY name`,
orgID,
)
if err != nil {
- return nil, fmt.Errorf("list projects: %w", err)
+ return nil, fmt.Errorf("list secret stores: %w", err)
}
defer rows.Close()
- var projects []Project
+ var stores []SecretStore
for rows.Next() {
- var p Project
- if err := rows.Scan(&p.ID, &p.OrgID, &p.Name, &p.Template, &p.CpuCount, &p.MemoryMB, &p.TimeoutSec, &p.EgressAllowlist, &p.CreatedAt, &p.UpdatedAt); err != nil {
+ var ss SecretStore
+ if err := rows.Scan(&ss.ID, &ss.OrgID, &ss.Name, &ss.EgressAllowlist, &ss.CreatedAt, &ss.UpdatedAt); err != nil {
return nil, err
}
- projects = append(projects, p)
+ stores = append(stores, ss)
}
- return projects, nil
+ return stores, nil
}
-// UpdateProject updates a project's configuration.
-func (s *Store) UpdateProject(ctx context.Context, orgID, projectID uuid.UUID, name, template string, cpuCount, memoryMB, timeoutSec int, allowlist []string) (*Project, error) {
- if allowlist == nil {
- allowlist = []string{}
+// UpdateSecretStore updates a secret store's configuration.
+func (s *Store) UpdateSecretStore(ctx context.Context, orgID, storeID uuid.UUID, name string, egressAllowlist []string) (*SecretStore, error) {
+ if egressAllowlist == nil {
+ egressAllowlist = []string{}
}
- var p Project
+ var ss SecretStore
err := s.pool.QueryRow(ctx,
- `UPDATE projects SET name = $3, template = $4, cpu_count = $5, memory_mb = $6, timeout_sec = $7, egress_allowlist = $8, updated_at = now()
+ `UPDATE secret_stores SET name = $3, egress_allowlist = $4, updated_at = now()
WHERE id = $1 AND org_id = $2
- RETURNING id, org_id, name, template, cpu_count, memory_mb, timeout_sec, egress_allowlist, created_at, updated_at`,
- projectID, orgID, name, template, cpuCount, memoryMB, timeoutSec, allowlist,
- ).Scan(&p.ID, &p.OrgID, &p.Name, &p.Template, &p.CpuCount, &p.MemoryMB, &p.TimeoutSec, &p.EgressAllowlist, &p.CreatedAt, &p.UpdatedAt)
+ RETURNING id, org_id, name, egress_allowlist, created_at, updated_at`,
+ storeID, orgID, name, egressAllowlist,
+ ).Scan(&ss.ID, &ss.OrgID, &ss.Name, &ss.EgressAllowlist, &ss.CreatedAt, &ss.UpdatedAt)
if err != nil {
- return nil, fmt.Errorf("update project: %w", err)
+ return nil, fmt.Errorf("update secret store: %w", err)
}
- return &p, nil
+ return &ss, nil
}
-// DeleteProject deletes a project and all its secrets (cascading).
-func (s *Store) DeleteProject(ctx context.Context, orgID, projectID uuid.UUID) error {
- tag, err := s.pool.Exec(ctx, `DELETE FROM projects WHERE id = $1 AND org_id = $2`, projectID, orgID)
+// DeleteSecretStore deletes a secret store and all its entries (cascading).
+func (s *Store) DeleteSecretStore(ctx context.Context, orgID, storeID uuid.UUID) error {
+ tag, err := s.pool.Exec(ctx, `DELETE FROM secret_stores WHERE id = $1 AND org_id = $2`, storeID, orgID)
if err != nil {
- return fmt.Errorf("delete project: %w", err)
+ return fmt.Errorf("delete secret store: %w", err)
}
if tag.RowsAffected() == 0 {
- return fmt.Errorf("project not found")
+ return fmt.Errorf("secret store not found")
}
return nil
}
-// ── Project Secrets ───────────────────────────────────────────────────────────
+// ── Secret Store Entries ──────────────────────────────────────────────────────
-// SetProjectSecret creates or updates a secret on a project. The value is encrypted at rest.
-func (s *Store) SetProjectSecret(ctx context.Context, projectID uuid.UUID, name string, value []byte) error {
+// SetSecretEntry creates or updates a secret in a store. The value is encrypted at rest.
+func (s *Store) SetSecretEntry(ctx context.Context, storeID uuid.UUID, name string, value []byte, allowedHosts []string) error {
if s.encryptor == nil {
return fmt.Errorf("encryption not configured (set OPENSANDBOX_SECRET_ENCRYPTION_KEY)")
}
+ if allowedHosts == nil {
+ allowedHosts = []string{}
+ }
encrypted, err := s.encryptor.Encrypt(value)
if err != nil {
return fmt.Errorf("encrypt secret: %w", err)
}
_, err = s.pool.Exec(ctx,
- `INSERT INTO project_secrets (project_id, name, encrypted_value)
- VALUES ($1, $2, $3)
- ON CONFLICT (project_id, name) DO UPDATE SET encrypted_value = $3, updated_at = now()`,
- projectID, name, encrypted,
+ `INSERT INTO secret_store_entries (store_id, name, encrypted_value, allowed_hosts)
+ VALUES ($1, $2, $3, $4)
+ ON CONFLICT (store_id, name) DO UPDATE SET encrypted_value = $3, allowed_hosts = $4, updated_at = now()`,
+ storeID, name, encrypted, allowedHosts,
)
if err != nil {
- return fmt.Errorf("set project secret: %w", err)
+ return fmt.Errorf("set secret entry: %w", err)
}
return nil
}
-// DeleteProjectSecret removes a secret from a project.
-func (s *Store) DeleteProjectSecret(ctx context.Context, projectID uuid.UUID, name string) error {
+// DeleteSecretEntry removes a secret from a store.
+func (s *Store) DeleteSecretEntry(ctx context.Context, storeID uuid.UUID, name string) error {
tag, err := s.pool.Exec(ctx,
- `DELETE FROM project_secrets WHERE project_id = $1 AND name = $2`,
- projectID, name,
+ `DELETE FROM secret_store_entries WHERE store_id = $1 AND name = $2`,
+ storeID, name,
)
if err != nil {
- return fmt.Errorf("delete project secret: %w", err)
+ return fmt.Errorf("delete secret entry: %w", err)
}
if tag.RowsAffected() == 0 {
return fmt.Errorf("secret not found")
@@ -1424,57 +1419,62 @@ func (s *Store) DeleteProjectSecret(ctx context.Context, projectID uuid.UUID, na
return nil
}
-// ListProjectSecretNames returns the names (not values) of all secrets on a project.
-func (s *Store) ListProjectSecretNames(ctx context.Context, projectID uuid.UUID) ([]ProjectSecret, error) {
+// ListSecretEntries returns all entries in a store (names and allowed hosts, no values).
+func (s *Store) ListSecretEntries(ctx context.Context, storeID uuid.UUID) ([]SecretEntry, error) {
rows, err := s.pool.Query(ctx,
- `SELECT id, project_id, name, created_at, updated_at
- FROM project_secrets WHERE project_id = $1 ORDER BY name`,
- projectID,
+ `SELECT id, store_id, name, allowed_hosts, created_at, updated_at
+ FROM secret_store_entries WHERE store_id = $1 ORDER BY name`,
+ storeID,
)
if err != nil {
- return nil, fmt.Errorf("list project secrets: %w", err)
+ return nil, fmt.Errorf("list secret entries: %w", err)
}
defer rows.Close()
- var secrets []ProjectSecret
+ var entries []SecretEntry
for rows.Next() {
- var ps ProjectSecret
- if err := rows.Scan(&ps.ID, &ps.ProjectID, &ps.Name, &ps.CreatedAt, &ps.UpdatedAt); err != nil {
+ var se SecretEntry
+ if err := rows.Scan(&se.ID, &se.StoreID, &se.Name, &se.AllowedHosts, &se.CreatedAt, &se.UpdatedAt); err != nil {
return nil, err
}
- secrets = append(secrets, ps)
+ entries = append(entries, se)
}
- return secrets, nil
+ return entries, nil
}
-// DecryptProjectSecrets returns all secrets for a project as plaintext name→value pairs.
+// DecryptSecretEntries returns all secrets in a store as plaintext with host restrictions.
// Used server-side when creating a sandbox to pass decrypted values to the worker.
-func (s *Store) DecryptProjectSecrets(ctx context.Context, projectID uuid.UUID) (map[string]string, error) {
+func (s *Store) DecryptSecretEntries(ctx context.Context, storeID uuid.UUID) ([]DecryptedSecret, error) {
if s.encryptor == nil {
return nil, fmt.Errorf("encryption not configured")
}
rows, err := s.pool.Query(ctx,
- `SELECT name, encrypted_value FROM project_secrets WHERE project_id = $1`,
- projectID,
+ `SELECT name, encrypted_value, allowed_hosts FROM secret_store_entries WHERE store_id = $1`,
+ storeID,
)
if err != nil {
- return nil, fmt.Errorf("query project secrets: %w", err)
+ return nil, fmt.Errorf("query secret entries: %w", err)
}
defer rows.Close()
- secrets := make(map[string]string)
+ var secrets []DecryptedSecret
for rows.Next() {
var name string
var encrypted []byte
- if err := rows.Scan(&name, &encrypted); err != nil {
+ var allowedHosts []string
+ if err := rows.Scan(&name, &encrypted, &allowedHosts); err != nil {
return nil, err
}
plaintext, err := s.encryptor.Decrypt(encrypted)
if err != nil {
return nil, fmt.Errorf("decrypt secret %q: %w", name, err)
}
- secrets[name] = string(plaintext)
+ secrets = append(secrets, DecryptedSecret{
+ Name: name,
+ Value: string(plaintext),
+ AllowedHosts: allowedHosts,
+ })
}
return secrets, nil
}
diff --git a/internal/firecracker/manager.go b/internal/firecracker/manager.go
index aeb73814..3955f9e7 100644
--- a/internal/firecracker/manager.go
+++ b/internal/firecracker/manager.go
@@ -70,17 +70,18 @@ type SandboxMeta struct {
type SecretsProxyIntegration interface {
// CreateSealedEnvs generates sealed tokens for env vars, registers a proxy session,
// and returns the full env map (sealed tokens + proxy config vars) to inject into the VM.
- CreateSealedEnvs(sandboxID, guestIP, gatewayIP string, envVars map[string]string, allowlist, secretHosts []string) map[string]string
+ // secretAllowedHosts maps env var name → allowed hosts for that secret (nil = all allowed hosts).
+ CreateSealedEnvs(sandboxID, guestIP, gatewayIP string, envVars map[string]string, allowlist []string, secretAllowedHosts map[string][]string) map[string]string
// UnregisterSession removes the proxy session for the given guest IP.
UnregisterSession(guestIP string)
// GetSessionTokens returns the sealed token → real value map for persisting during hibernate.
GetSessionTokens(guestIP string) map[string]string
// GetSessionAllowlist returns the egress allowlist for persisting during hibernate.
GetSessionAllowlist(guestIP string) []string
- // GetSessionSecretHosts returns the secret hosts list for persisting during hibernate.
- GetSessionSecretHosts(guestIP string) []string
+ // GetSessionTokenHosts returns the per-token host restrictions for persisting during hibernate.
+ GetSessionTokenHosts(guestIP string) map[string][]string
// ReregisterSession re-creates a proxy session from a persisted token map (used on wake).
- ReregisterSession(sandboxID, guestIP string, tokens map[string]string, allowlist, secretHosts []string)
+ ReregisterSession(sandboxID, guestIP string, tokens map[string]string, allowlist []string, tokenHosts map[string][]string)
// CACertPEM returns the CA certificate PEM for injection into the VM trust store.
CACertPEM() []byte
}
@@ -435,7 +436,7 @@ func (m *Manager) createWithID(ctx context.Context, id string, cfg types.Sandbox
// them back to real values on outbound HTTPS requests.
envsToInject := cfg.Envs
if m.secretsProxy != nil && len(cfg.Envs) > 0 {
- sealedEnvs := m.secretsProxy.CreateSealedEnvs(id, netCfg.GuestIP, netCfg.HostIP, cfg.Envs, cfg.EgressAllowlist, nil)
+ sealedEnvs := m.secretsProxy.CreateSealedEnvs(id, netCfg.GuestIP, netCfg.HostIP, cfg.Envs, cfg.EgressAllowlist, cfg.SecretAllowedHosts)
if sealedEnvs != nil {
envsToInject = sealedEnvs
// Redirect VM HTTPS traffic through the proxy
diff --git a/internal/firecracker/snapshot.go b/internal/firecracker/snapshot.go
index c9e5adb6..220c7b43 100644
--- a/internal/firecracker/snapshot.go
+++ b/internal/firecracker/snapshot.go
@@ -40,10 +40,10 @@ type SnapshotMeta struct {
SnapshotedAt time.Time `json:"snapshotedAt,omitempty"`
// SealedTokens maps sealed token → real value for re-registering the proxy session on wake.
SealedTokens map[string]string `json:"sealedTokens,omitempty"`
- // ProxyAllowlist and ProxySecretHosts are persisted so the proxy session
+ // ProxyAllowlist and ProxyTokenHosts are persisted so the proxy session
// can be fully restored with the same restrictions after hibernate → wake.
- ProxyAllowlist []string `json:"proxyAllowlist,omitempty"`
- ProxySecretHosts []string `json:"proxySecretHosts,omitempty"`
+ ProxyAllowlist []string `json:"proxyAllowlist,omitempty"`
+ ProxyTokenHosts map[string][]string `json:"proxyTokenHosts,omitempty"`
}
// doHibernate pauses a running VM, creates a full memory snapshot, and kicks off
@@ -135,7 +135,7 @@ func (m *Manager) doHibernate(ctx context.Context, vm *VMInstance, checkpointSto
if m.secretsProxy != nil && vm.network != nil {
meta.SealedTokens = m.secretsProxy.GetSessionTokens(vm.network.GuestIP)
meta.ProxyAllowlist = m.secretsProxy.GetSessionAllowlist(vm.network.GuestIP)
- meta.ProxySecretHosts = m.secretsProxy.GetSessionSecretHosts(vm.network.GuestIP)
+ meta.ProxyTokenHosts = m.secretsProxy.GetSessionTokenHosts(vm.network.GuestIP)
}
metaJSON, err := json.Marshal(meta)
if err != nil {
@@ -505,7 +505,7 @@ func (m *Manager) doWake(ctx context.Context, sandboxID, checkpointKey string, c
// Re-register secrets proxy session if token map was persisted
if m.secretsProxy != nil && len(meta.SealedTokens) > 0 {
- m.secretsProxy.ReregisterSession(sandboxID, netCfg.GuestIP, meta.SealedTokens, meta.ProxyAllowlist, meta.ProxySecretHosts)
+ m.secretsProxy.ReregisterSession(sandboxID, netCfg.GuestIP, meta.SealedTokens, meta.ProxyAllowlist, meta.ProxyTokenHosts)
if err := AddProxyRedirect(netCfg); err != nil {
log.Printf("firecracker: warning: proxy redirect failed for %s on wake: %v", sandboxID, err)
}
@@ -1877,7 +1877,7 @@ func (m *Manager) warmForkFromCheckpoint(ctx context.Context, checkpointID strin
// Secrets proxy integration: seal env vars and set up proxy redirect
envsToInject := cfg.Envs
if m.secretsProxy != nil && len(cfg.Envs) > 0 {
- sealedEnvs := m.secretsProxy.CreateSealedEnvs(newID, netCfg.GuestIP, netCfg.HostIP, cfg.Envs, cfg.EgressAllowlist, nil)
+ sealedEnvs := m.secretsProxy.CreateSealedEnvs(newID, netCfg.GuestIP, netCfg.HostIP, cfg.Envs, cfg.EgressAllowlist, cfg.SecretAllowedHosts)
if sealedEnvs != nil {
envsToInject = sealedEnvs
if err := AddProxyRedirect(netCfg); err != nil {
@@ -2357,7 +2357,7 @@ func (m *Manager) createFromGoldenSnapshot(ctx context.Context, id string, cfg t
// Secrets proxy integration: seal env vars and set up proxy redirect
envsToInject := cfg.Envs
if m.secretsProxy != nil && len(cfg.Envs) > 0 {
- sealedEnvs := m.secretsProxy.CreateSealedEnvs(id, netCfg.GuestIP, netCfg.HostIP, cfg.Envs, cfg.EgressAllowlist, nil)
+ sealedEnvs := m.secretsProxy.CreateSealedEnvs(id, netCfg.GuestIP, netCfg.HostIP, cfg.Envs, cfg.EgressAllowlist, cfg.SecretAllowedHosts)
if sealedEnvs != nil {
envsToInject = sealedEnvs
if err := AddProxyRedirect(netCfg); err != nil {
diff --git a/internal/secretsproxy/proxy.go b/internal/secretsproxy/proxy.go
index b8bac8f2..2743fcda 100644
--- a/internal/secretsproxy/proxy.go
+++ b/internal/secretsproxy/proxy.go
@@ -55,11 +55,27 @@ const (
// Session holds the sealed→real token mapping for one sandbox.
type Session struct {
- SandboxID string
- Secrets map[string]string // "osb_sealed_xxx" → real value
- Allowlist []string // nil = all hosts allowed; supports "*." prefix wildcards
- SecretHosts []string // hosts where token replacement is performed; nil = replace on all allowed hosts
- ExpiresAt time.Time
+ SandboxID string
+ Secrets map[string]string // "osb_sealed_xxx" → real value
+ TokenHosts map[string][]string // sealed token → allowed hosts; nil/empty entry = all allowed hosts
+ Allowlist []string // nil = all hosts allowed; supports "*." prefix wildcards
+ ExpiresAt time.Time
+}
+
+// secretsForHost returns the subset of sealed tokens that are allowed to be replaced for this host.
+// Tokens with no host restriction (empty/nil entry in TokenHosts) are always included.
+func (s *Session) secretsForHost(host string) map[string]string {
+ if len(s.TokenHosts) == 0 {
+ return s.Secrets // no per-token restrictions
+ }
+ filtered := make(map[string]string, len(s.Secrets))
+ for token, real := range s.Secrets {
+ hosts := s.TokenHosts[token]
+ if len(hosts) == 0 || hostAllowed(host, hosts) {
+ filtered[token] = real
+ }
+ }
+ return filtered
}
// SecretsProxy is an HTTP CONNECT proxy that intercepts HTTPS traffic from
@@ -146,32 +162,32 @@ func (p *SecretsProxy) GetSessionAllowlist(guestIP string) []string {
return session.Allowlist
}
-// GetSessionSecretHosts returns the secret hosts list for the given guest IP's session.
-func (p *SecretsProxy) GetSessionSecretHosts(guestIP string) []string {
+// GetSessionTokenHosts returns the per-token host restrictions for the given guest IP's session.
+func (p *SecretsProxy) GetSessionTokenHosts(guestIP string) map[string][]string {
p.mu.RLock()
session := p.sessions[guestIP]
p.mu.RUnlock()
if session == nil {
return nil
}
- return session.SecretHosts
+ return session.TokenHosts
}
// ReregisterSession creates a new proxy session from a previously persisted token map.
// Used on wake to restore the proxy session without re-generating tokens.
-func (p *SecretsProxy) ReregisterSession(sandboxID, guestIP string, tokens map[string]string, allowlist, secretHosts []string) {
+func (p *SecretsProxy) ReregisterSession(sandboxID, guestIP string, tokens map[string]string, allowlist []string, tokenHosts map[string][]string) {
session := &Session{
- SandboxID: sandboxID,
- Secrets: tokens,
- Allowlist: allowlist,
- SecretHosts: secretHosts,
- ExpiresAt: time.Now().Add(defaultSessionTTL),
+ SandboxID: sandboxID,
+ Secrets: tokens,
+ TokenHosts: tokenHosts,
+ Allowlist: allowlist,
+ ExpiresAt: time.Now().Add(defaultSessionTTL),
}
p.mu.Lock()
p.sessions[guestIP] = session
p.mu.Unlock()
- log.Printf("secrets-proxy: re-registered session sandbox=%s ip=%s secrets=%d allowlist=%d secretHosts=%d",
- sandboxID, guestIP, len(tokens), len(allowlist), len(secretHosts))
+ log.Printf("secrets-proxy: re-registered session sandbox=%s ip=%s secrets=%d allowlist=%d tokenHosts=%d",
+ sandboxID, guestIP, len(tokens), len(allowlist), len(tokenHosts))
}
// CreateSealedEnvs generates sealed tokens for the given env vars, registers a
@@ -180,8 +196,8 @@ func (p *SecretsProxy) ReregisterSession(sandboxID, guestIP string, tokens map[s
// Returns nil if envVars is empty.
//
// allowlist controls which hosts the sandbox can reach (nil = all).
-// secretHosts controls which hosts get token replacement (nil = all allowed hosts).
-func (p *SecretsProxy) CreateSealedEnvs(sandboxID, guestIP, gatewayIP string, envVars map[string]string, allowlist, secretHosts []string) map[string]string {
+// secretAllowedHosts maps env var name → allowed hosts for that secret (nil = all allowed hosts).
+func (p *SecretsProxy) CreateSealedEnvs(sandboxID, guestIP, gatewayIP string, envVars map[string]string, allowlist []string, secretAllowedHosts map[string][]string) map[string]string {
if len(envVars) == 0 {
return nil
}
@@ -195,11 +211,22 @@ func (p *SecretsProxy) CreateSealedEnvs(sandboxID, guestIP, gatewayIP string, en
tokenMap[token] = realValue
}
+ // Build per-token host restrictions from per-env-var restrictions
+ var tokenHosts map[string][]string
+ if len(secretAllowedHosts) > 0 {
+ tokenHosts = make(map[string][]string, len(secretAllowedHosts))
+ for envVar, token := range sealed {
+ if hosts, ok := secretAllowedHosts[envVar]; ok && len(hosts) > 0 {
+ tokenHosts[token] = hosts
+ }
+ }
+ }
+
p.RegisterSession(guestIP, &Session{
- SandboxID: sandboxID,
- Secrets: tokenMap,
- Allowlist: allowlist,
- SecretHosts: secretHosts,
+ SandboxID: sandboxID,
+ Secrets: tokenMap,
+ TokenHosts: tokenHosts,
+ Allowlist: allowlist,
})
// Build the complete env map for the VM
@@ -317,11 +344,11 @@ func (p *SecretsProxy) handleConn(conn net.Conn) {
return
}
- // Determine if we should replace tokens for this host
- shouldReplace := shouldReplaceTokens(targetHost, session)
+ // Filter secrets to only those allowed for this host
+ hostSecrets := session.secretsForHost(targetHost)
- log.Printf("secrets-proxy: audit sandbox=%s src=%s host=%s action=connect secrets=%d replace=%v",
- session.SandboxID, clientIP, targetHost, len(session.Secrets), shouldReplace)
+ log.Printf("secrets-proxy: audit sandbox=%s src=%s host=%s action=connect secrets=%d filtered=%d",
+ session.SandboxID, clientIP, targetHost, len(session.Secrets), len(hostSecrets))
// Acknowledge the CONNECT tunnel
conn.Write([]byte("HTTP/1.1 200 Connection Established\r\n\r\n"))
@@ -356,9 +383,9 @@ func (p *SecretsProxy) handleConn(conn net.Conn) {
}
defer upstreamConn.Close()
- if shouldReplace && len(session.Secrets) > 0 {
+ if len(hostSecrets) > 0 {
// HTTP-aware proxy: parse requests, replace tokens in headers + body
- p.proxyHTTPRequests(clientTLS, upstreamConn, session, targetHost)
+ p.proxyHTTPRequests(clientTLS, upstreamConn, hostSecrets, targetHost)
} else {
// No replacement needed — raw bidirectional pipe (faster)
p.proxyRaw(clientTLS, upstreamConn)
@@ -414,18 +441,9 @@ func checkPrivateIP(host string) error {
return nil
}
-// shouldReplaceTokens returns true if token replacement should be performed for this host.
-// If SecretHosts is set, only replace on those hosts. Otherwise replace on all allowed hosts.
-func shouldReplaceTokens(host string, session *Session) bool {
- if len(session.SecretHosts) == 0 {
- return true // no restriction — replace on all hosts
- }
- return hostAllowed(host, session.SecretHosts)
-}
-
// proxyHTTPRequests performs HTTP-aware proxying with token replacement in
// both headers and body.
-func (p *SecretsProxy) proxyHTTPRequests(clientTLS *tls.Conn, upstreamTLS *tls.Conn, session *Session, targetHost string) {
+func (p *SecretsProxy) proxyHTTPRequests(clientTLS *tls.Conn, upstreamTLS *tls.Conn, secrets map[string]string, targetHost string) {
clientReader := bufio.NewReader(clientTLS)
upstreamReader := bufio.NewReader(upstreamTLS)
@@ -439,14 +457,14 @@ func (p *SecretsProxy) proxyHTTPRequests(clientTLS *tls.Conn, upstreamTLS *tls.C
clientTLS.SetReadDeadline(time.Time{})
// Replace tokens in request headers
- replaceHeaderTokens(req.Header, session.Secrets)
+ replaceHeaderTokens(req.Header, secrets)
// Replace tokens in request body
if req.Body != nil && req.ContentLength != 0 {
// Buffer the replaced body to compute correct Content-Length.
// Sealed tokens (43 bytes) may differ in size from real values,
// so the original Content-Length would be wrong after replacement.
- replacer := newStreamReplacer(req.Body, session.Secrets)
+ replacer := newStreamReplacer(req.Body, secrets)
replaced, err := io.ReadAll(replacer)
req.Body.Close()
if err != nil {
diff --git a/internal/secretsproxy/replacer_test.go b/internal/secretsproxy/replacer_test.go
index fa613b05..3e87d832 100644
--- a/internal/secretsproxy/replacer_test.go
+++ b/internal/secretsproxy/replacer_test.go
@@ -224,27 +224,50 @@ func TestIsPrivateIP(t *testing.T) {
}
}
-func TestShouldReplaceTokens(t *testing.T) {
+func TestSecretsForHost(t *testing.T) {
+ allSecrets := map[string]string{
+ "osb_sealed_aaa": "real-a",
+ "osb_sealed_bbb": "real-b",
+ }
+
tests := []struct {
- name string
- host string
- secretHosts []string
- want bool
+ name string
+ host string
+ tokenHosts map[string][]string
+ wantCount int
}{
- {"nil secret hosts replaces all", "anything.com", nil, true},
- {"empty secret hosts replaces all", "anything.com", []string{}, true},
- {"exact match", "api.anthropic.com", []string{"api.anthropic.com"}, true},
- {"no match", "evil.com", []string{"api.anthropic.com"}, false},
- {"wildcard match", "api.anthropic.com", []string{"*.anthropic.com"}, true},
- {"wildcard no match", "evil.com", []string{"*.anthropic.com"}, false},
+ {"nil token hosts returns all", "anything.com", nil, 2},
+ {"empty token hosts returns all", "anything.com", map[string][]string{}, 2},
+ {"exact match filters correctly", "api.anthropic.com", map[string][]string{
+ "osb_sealed_aaa": {"api.anthropic.com"},
+ }, 2}, // aaa matches, bbb has no restriction so included
+ {"no match filters out", "evil.com", map[string][]string{
+ "osb_sealed_aaa": {"api.anthropic.com"},
+ "osb_sealed_bbb": {"api.anthropic.com"},
+ }, 0},
+ {"wildcard match", "api.anthropic.com", map[string][]string{
+ "osb_sealed_aaa": {"*.anthropic.com"},
+ "osb_sealed_bbb": {"*.anthropic.com"},
+ }, 2},
+ {"wildcard no match", "evil.com", map[string][]string{
+ "osb_sealed_aaa": {"*.anthropic.com"},
+ "osb_sealed_bbb": {"*.anthropic.com"},
+ }, 0},
+ {"mixed restrictions", "api.anthropic.com", map[string][]string{
+ "osb_sealed_aaa": {"api.anthropic.com"},
+ "osb_sealed_bbb": {"other.com"},
+ }, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- session := &Session{SecretHosts: tt.secretHosts}
- got := shouldReplaceTokens(tt.host, session)
- if got != tt.want {
- t.Errorf("shouldReplaceTokens(%q, %v) = %v, want %v", tt.host, tt.secretHosts, got, tt.want)
+ session := &Session{
+ Secrets: allSecrets,
+ TokenHosts: tt.tokenHosts,
+ }
+ got := session.secretsForHost(tt.host)
+ if len(got) != tt.wantCount {
+ t.Errorf("secretsForHost(%q) returned %d secrets, want %d", tt.host, len(got), tt.wantCount)
}
})
}
diff --git a/internal/worker/grpc_server.go b/internal/worker/grpc_server.go
index 7a957dee..60632396 100644
--- a/internal/worker/grpc_server.go
+++ b/internal/worker/grpc_server.go
@@ -92,6 +92,24 @@ func (s *GRPCServer) Stop() {
s.server.GracefulStop()
}
+// parseSecretAllowedHosts converts the proto map (env var → comma-separated hosts)
+// to the internal map (env var → host slice). Returns nil if input is empty.
+func parseSecretAllowedHosts(m map[string]string) map[string][]string {
+ if len(m) == 0 {
+ return nil
+ }
+ result := make(map[string][]string, len(m))
+ for name, hosts := range m {
+ if hosts != "" {
+ result[name] = strings.Split(hosts, ",")
+ }
+ }
+ if len(result) == 0 {
+ return nil
+ }
+ return result
+}
+
func (s *GRPCServer) CreateSandbox(ctx context.Context, req *pb.CreateSandboxRequest) (*pb.CreateSandboxResponse, error) {
cfg := types.SandboxConfig{
Template: req.Template,
@@ -103,7 +121,8 @@ func (s *GRPCServer) CreateSandbox(ctx context.Context, req *pb.CreateSandboxReq
ImageRef: req.ImageRef,
Port: int(req.Port),
SandboxID: req.SandboxId, // use server-assigned ID if provided
- EgressAllowlist: req.EgressAllowlist,
+ EgressAllowlist: req.EgressAllowlist,
+ SecretAllowedHosts: parseSecretAllowedHosts(req.SecretAllowedHosts),
}
// Warm fork: if checkpoint_id is set, try snapshot-based fork first.
diff --git a/pkg/types/sandbox.go b/pkg/types/sandbox.go
index 5d92b055..b4d150d9 100644
--- a/pkg/types/sandbox.go
+++ b/pkg/types/sandbox.go
@@ -46,12 +46,16 @@ type SandboxConfig struct {
// When set, the sandbox boots from these drives instead of the standard base image.
TemplateRootfsKey string `json:"templateRootfsKey,omitempty"`
TemplateWorkspaceKey string `json:"templateWorkspaceKey,omitempty"`
- // Project name — resolves config defaults + secrets from the project.
- Project string `json:"project,omitempty"`
+ // SecretStore name — resolves secrets from the named secret store.
+ SecretStore string `json:"secretStore,omitempty"`
// EgressAllowlist restricts outbound HTTPS from the sandbox to these hosts.
// Supports exact matches ("api.anthropic.com") and wildcards ("*.openai.com").
// Empty = all hosts allowed (no restriction).
EgressAllowlist []string `json:"egressAllowlist,omitempty"`
+ // SecretAllowedHosts maps env var name → allowed hosts for that secret.
+ // Secrets are only substituted in requests to matching hosts.
+ // Missing key or empty slice = substitute on all allowed hosts.
+ SecretAllowedHosts map[string][]string `json:"secretAllowedHosts,omitempty"`
// SandboxID allows pre-determining the sandbox ID for async creation.
// If empty, a new ID is generated automatically.
SandboxID string `json:"-"`
diff --git a/proto/worker/worker.pb.go b/proto/worker/worker.pb.go
index a98108ed..5813f7ae 100644
--- a/proto/worker/worker.pb.go
+++ b/proto/worker/worker.pb.go
@@ -88,8 +88,12 @@ type CreateSandboxRequest struct {
// Supports exact ("api.anthropic.com") and wildcard ("*.openai.com") patterns.
// Empty = all hosts allowed.
EgressAllowlist []string `protobuf:"bytes,13,rep,name=egress_allowlist,json=egressAllowlist,proto3" json:"egress_allowlist,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ // Per-secret host restrictions: env var name → comma-separated allowed hosts.
+ // Secrets are only substituted in requests to matching hosts.
+ // Empty value or missing key = substitute on all allowed hosts.
+ SecretAllowedHosts map[string]string `protobuf:"bytes,14,rep,name=secret_allowed_hosts,json=secretAllowedHosts,proto3" json:"secret_allowed_hosts,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *CreateSandboxRequest) Reset() {
@@ -213,6 +217,13 @@ func (x *CreateSandboxRequest) GetEgressAllowlist() []string {
return nil
}
+func (x *CreateSandboxRequest) GetSecretAllowedHosts() map[string]string {
+ if x != nil {
+ return x.SecretAllowedHosts
+ }
+ return nil
+}
+
type CreateSandboxResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
SandboxId string `protobuf:"bytes,1,opt,name=sandbox_id,json=sandboxId,proto3" json:"sandbox_id,omitempty"`
@@ -2587,7 +2598,7 @@ var File_proto_worker_worker_proto protoreflect.FileDescriptor
const file_proto_worker_worker_proto_rawDesc = "" +
"\n" +
- "\x19proto/worker/worker.proto\x12\x06worker\"\xaa\x04\n" +
+ "\x19proto/worker/worker.proto\x12\x06worker\"\xd9\x05\n" +
"\x14CreateSandboxRequest\x12\x1a\n" +
"\btemplate\x18\x01 \x01(\tR\btemplate\x12\x18\n" +
"\atimeout\x18\x02 \x01(\x05R\atimeout\x12:\n" +
@@ -2603,9 +2614,13 @@ const file_proto_worker_worker_proto_rawDesc = "" +
"\rcheckpoint_id\x18\v \x01(\tR\fcheckpointId\x12\x1d\n" +
"\n" +
"sandbox_id\x18\f \x01(\tR\tsandboxId\x12)\n" +
- "\x10egress_allowlist\x18\r \x03(\tR\x0fegressAllowlist\x1a7\n" +
+ "\x10egress_allowlist\x18\r \x03(\tR\x0fegressAllowlist\x12f\n" +
+ "\x14secret_allowed_hosts\x18\x0e \x03(\v24.worker.CreateSandboxRequest.SecretAllowedHostsEntryR\x12secretAllowedHosts\x1a7\n" +
"\tEnvsEntry\x12\x10\n" +
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
+ "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\x1aE\n" +
+ "\x17SecretAllowedHostsEntry\x12\x10\n" +
+ "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
"\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"N\n" +
"\x15CreateSandboxResponse\x12\x1d\n" +
"\n" +
@@ -2832,7 +2847,7 @@ func file_proto_worker_worker_proto_rawDescGZIP() []byte {
}
var file_proto_worker_worker_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
-var file_proto_worker_worker_proto_msgTypes = make([]protoimpl.MessageInfo, 47)
+var file_proto_worker_worker_proto_msgTypes = make([]protoimpl.MessageInfo, 48)
var file_proto_worker_worker_proto_goTypes = []any{
(ExecOutputChunk_Stream)(0), // 0: worker.ExecOutputChunk.Stream
(*CreateSandboxRequest)(nil), // 1: worker.CreateSandboxRequest
@@ -2880,65 +2895,67 @@ var file_proto_worker_worker_proto_goTypes = []any{
(*RestoreCheckpointRequest)(nil), // 43: worker.RestoreCheckpointRequest
(*RestoreCheckpointResponse)(nil), // 44: worker.RestoreCheckpointResponse
nil, // 45: worker.CreateSandboxRequest.EnvsEntry
- nil, // 46: worker.ExecCommandRequest.EnvsEntry
- nil, // 47: worker.ExecSessionCreateRequest.EnvsEntry
+ nil, // 46: worker.CreateSandboxRequest.SecretAllowedHostsEntry
+ nil, // 47: worker.ExecCommandRequest.EnvsEntry
+ nil, // 48: worker.ExecSessionCreateRequest.EnvsEntry
}
var file_proto_worker_worker_proto_depIdxs = []int32{
45, // 0: worker.CreateSandboxRequest.envs:type_name -> worker.CreateSandboxRequest.EnvsEntry
- 6, // 1: worker.ListSandboxesResponse.sandboxes:type_name -> worker.GetSandboxResponse
- 46, // 2: worker.ExecCommandRequest.envs:type_name -> worker.ExecCommandRequest.EnvsEntry
- 0, // 3: worker.ExecOutputChunk.stream:type_name -> worker.ExecOutputChunk.Stream
- 17, // 4: worker.ListDirResponse.entries:type_name -> worker.DirEntry
- 22, // 5: worker.PTYInput.resize:type_name -> worker.PTYResize
- 47, // 6: worker.ExecSessionCreateRequest.envs:type_name -> worker.ExecSessionCreateRequest.EnvsEntry
- 36, // 7: worker.ExecSessionListResponse.sessions:type_name -> worker.ExecSessionInfoEntry
- 1, // 8: worker.SandboxWorker.CreateSandbox:input_type -> worker.CreateSandboxRequest
- 3, // 9: worker.SandboxWorker.DestroySandbox:input_type -> worker.DestroySandboxRequest
- 5, // 10: worker.SandboxWorker.GetSandbox:input_type -> worker.GetSandboxRequest
- 7, // 11: worker.SandboxWorker.ListSandboxes:input_type -> worker.ListSandboxesRequest
- 9, // 12: worker.SandboxWorker.ExecCommand:input_type -> worker.ExecCommandRequest
- 9, // 13: worker.SandboxWorker.ExecCommandStream:input_type -> worker.ExecCommandRequest
- 12, // 14: worker.SandboxWorker.ReadFile:input_type -> worker.ReadFileRequest
- 14, // 15: worker.SandboxWorker.WriteFile:input_type -> worker.WriteFileRequest
- 16, // 16: worker.SandboxWorker.ListDir:input_type -> worker.ListDirRequest
- 19, // 17: worker.SandboxWorker.CreatePTY:input_type -> worker.CreatePTYRequest
- 21, // 18: worker.SandboxWorker.PTYStream:input_type -> worker.PTYInput
- 32, // 19: worker.SandboxWorker.ExecSessionCreate:input_type -> worker.ExecSessionCreateRequest
- 34, // 20: worker.SandboxWorker.ExecSessionList:input_type -> worker.ExecSessionListRequest
- 37, // 21: worker.SandboxWorker.ExecSessionKill:input_type -> worker.ExecSessionKillRequest
- 24, // 22: worker.SandboxWorker.HibernateSandbox:input_type -> worker.HibernateSandboxRequest
- 26, // 23: worker.SandboxWorker.WakeSandbox:input_type -> worker.WakeSandboxRequest
- 28, // 24: worker.SandboxWorker.SaveAsTemplate:input_type -> worker.SaveAsTemplateRequest
- 41, // 25: worker.SandboxWorker.CreateCheckpoint:input_type -> worker.CreateCheckpointRequest
- 43, // 26: worker.SandboxWorker.RestoreCheckpoint:input_type -> worker.RestoreCheckpointRequest
- 30, // 27: worker.SandboxWorker.BuildTemplate:input_type -> worker.BuildTemplateRequest
- 39, // 28: worker.SandboxWorker.GetSandboxStats:input_type -> worker.GetSandboxStatsRequest
- 2, // 29: worker.SandboxWorker.CreateSandbox:output_type -> worker.CreateSandboxResponse
- 4, // 30: worker.SandboxWorker.DestroySandbox:output_type -> worker.DestroySandboxResponse
- 6, // 31: worker.SandboxWorker.GetSandbox:output_type -> worker.GetSandboxResponse
- 8, // 32: worker.SandboxWorker.ListSandboxes:output_type -> worker.ListSandboxesResponse
- 10, // 33: worker.SandboxWorker.ExecCommand:output_type -> worker.ExecCommandResponse
- 11, // 34: worker.SandboxWorker.ExecCommandStream:output_type -> worker.ExecOutputChunk
- 13, // 35: worker.SandboxWorker.ReadFile:output_type -> worker.ReadFileResponse
- 15, // 36: worker.SandboxWorker.WriteFile:output_type -> worker.WriteFileResponse
- 18, // 37: worker.SandboxWorker.ListDir:output_type -> worker.ListDirResponse
- 20, // 38: worker.SandboxWorker.CreatePTY:output_type -> worker.CreatePTYResponse
- 23, // 39: worker.SandboxWorker.PTYStream:output_type -> worker.PTYOutput
- 33, // 40: worker.SandboxWorker.ExecSessionCreate:output_type -> worker.ExecSessionCreateResponse
- 35, // 41: worker.SandboxWorker.ExecSessionList:output_type -> worker.ExecSessionListResponse
- 38, // 42: worker.SandboxWorker.ExecSessionKill:output_type -> worker.ExecSessionKillResponse
- 25, // 43: worker.SandboxWorker.HibernateSandbox:output_type -> worker.HibernateSandboxResponse
- 27, // 44: worker.SandboxWorker.WakeSandbox:output_type -> worker.WakeSandboxResponse
- 29, // 45: worker.SandboxWorker.SaveAsTemplate:output_type -> worker.SaveAsTemplateResponse
- 42, // 46: worker.SandboxWorker.CreateCheckpoint:output_type -> worker.CreateCheckpointResponse
- 44, // 47: worker.SandboxWorker.RestoreCheckpoint:output_type -> worker.RestoreCheckpointResponse
- 31, // 48: worker.SandboxWorker.BuildTemplate:output_type -> worker.BuildTemplateResponse
- 40, // 49: worker.SandboxWorker.GetSandboxStats:output_type -> worker.GetSandboxStatsResponse
- 29, // [29:50] is the sub-list for method output_type
- 8, // [8:29] is the sub-list for method input_type
- 8, // [8:8] is the sub-list for extension type_name
- 8, // [8:8] is the sub-list for extension extendee
- 0, // [0:8] is the sub-list for field type_name
+ 46, // 1: worker.CreateSandboxRequest.secret_allowed_hosts:type_name -> worker.CreateSandboxRequest.SecretAllowedHostsEntry
+ 6, // 2: worker.ListSandboxesResponse.sandboxes:type_name -> worker.GetSandboxResponse
+ 47, // 3: worker.ExecCommandRequest.envs:type_name -> worker.ExecCommandRequest.EnvsEntry
+ 0, // 4: worker.ExecOutputChunk.stream:type_name -> worker.ExecOutputChunk.Stream
+ 17, // 5: worker.ListDirResponse.entries:type_name -> worker.DirEntry
+ 22, // 6: worker.PTYInput.resize:type_name -> worker.PTYResize
+ 48, // 7: worker.ExecSessionCreateRequest.envs:type_name -> worker.ExecSessionCreateRequest.EnvsEntry
+ 36, // 8: worker.ExecSessionListResponse.sessions:type_name -> worker.ExecSessionInfoEntry
+ 1, // 9: worker.SandboxWorker.CreateSandbox:input_type -> worker.CreateSandboxRequest
+ 3, // 10: worker.SandboxWorker.DestroySandbox:input_type -> worker.DestroySandboxRequest
+ 5, // 11: worker.SandboxWorker.GetSandbox:input_type -> worker.GetSandboxRequest
+ 7, // 12: worker.SandboxWorker.ListSandboxes:input_type -> worker.ListSandboxesRequest
+ 9, // 13: worker.SandboxWorker.ExecCommand:input_type -> worker.ExecCommandRequest
+ 9, // 14: worker.SandboxWorker.ExecCommandStream:input_type -> worker.ExecCommandRequest
+ 12, // 15: worker.SandboxWorker.ReadFile:input_type -> worker.ReadFileRequest
+ 14, // 16: worker.SandboxWorker.WriteFile:input_type -> worker.WriteFileRequest
+ 16, // 17: worker.SandboxWorker.ListDir:input_type -> worker.ListDirRequest
+ 19, // 18: worker.SandboxWorker.CreatePTY:input_type -> worker.CreatePTYRequest
+ 21, // 19: worker.SandboxWorker.PTYStream:input_type -> worker.PTYInput
+ 32, // 20: worker.SandboxWorker.ExecSessionCreate:input_type -> worker.ExecSessionCreateRequest
+ 34, // 21: worker.SandboxWorker.ExecSessionList:input_type -> worker.ExecSessionListRequest
+ 37, // 22: worker.SandboxWorker.ExecSessionKill:input_type -> worker.ExecSessionKillRequest
+ 24, // 23: worker.SandboxWorker.HibernateSandbox:input_type -> worker.HibernateSandboxRequest
+ 26, // 24: worker.SandboxWorker.WakeSandbox:input_type -> worker.WakeSandboxRequest
+ 28, // 25: worker.SandboxWorker.SaveAsTemplate:input_type -> worker.SaveAsTemplateRequest
+ 41, // 26: worker.SandboxWorker.CreateCheckpoint:input_type -> worker.CreateCheckpointRequest
+ 43, // 27: worker.SandboxWorker.RestoreCheckpoint:input_type -> worker.RestoreCheckpointRequest
+ 30, // 28: worker.SandboxWorker.BuildTemplate:input_type -> worker.BuildTemplateRequest
+ 39, // 29: worker.SandboxWorker.GetSandboxStats:input_type -> worker.GetSandboxStatsRequest
+ 2, // 30: worker.SandboxWorker.CreateSandbox:output_type -> worker.CreateSandboxResponse
+ 4, // 31: worker.SandboxWorker.DestroySandbox:output_type -> worker.DestroySandboxResponse
+ 6, // 32: worker.SandboxWorker.GetSandbox:output_type -> worker.GetSandboxResponse
+ 8, // 33: worker.SandboxWorker.ListSandboxes:output_type -> worker.ListSandboxesResponse
+ 10, // 34: worker.SandboxWorker.ExecCommand:output_type -> worker.ExecCommandResponse
+ 11, // 35: worker.SandboxWorker.ExecCommandStream:output_type -> worker.ExecOutputChunk
+ 13, // 36: worker.SandboxWorker.ReadFile:output_type -> worker.ReadFileResponse
+ 15, // 37: worker.SandboxWorker.WriteFile:output_type -> worker.WriteFileResponse
+ 18, // 38: worker.SandboxWorker.ListDir:output_type -> worker.ListDirResponse
+ 20, // 39: worker.SandboxWorker.CreatePTY:output_type -> worker.CreatePTYResponse
+ 23, // 40: worker.SandboxWorker.PTYStream:output_type -> worker.PTYOutput
+ 33, // 41: worker.SandboxWorker.ExecSessionCreate:output_type -> worker.ExecSessionCreateResponse
+ 35, // 42: worker.SandboxWorker.ExecSessionList:output_type -> worker.ExecSessionListResponse
+ 38, // 43: worker.SandboxWorker.ExecSessionKill:output_type -> worker.ExecSessionKillResponse
+ 25, // 44: worker.SandboxWorker.HibernateSandbox:output_type -> worker.HibernateSandboxResponse
+ 27, // 45: worker.SandboxWorker.WakeSandbox:output_type -> worker.WakeSandboxResponse
+ 29, // 46: worker.SandboxWorker.SaveAsTemplate:output_type -> worker.SaveAsTemplateResponse
+ 42, // 47: worker.SandboxWorker.CreateCheckpoint:output_type -> worker.CreateCheckpointResponse
+ 44, // 48: worker.SandboxWorker.RestoreCheckpoint:output_type -> worker.RestoreCheckpointResponse
+ 31, // 49: worker.SandboxWorker.BuildTemplate:output_type -> worker.BuildTemplateResponse
+ 40, // 50: worker.SandboxWorker.GetSandboxStats:output_type -> worker.GetSandboxStatsResponse
+ 30, // [30:51] is the sub-list for method output_type
+ 9, // [9:30] is the sub-list for method input_type
+ 9, // [9:9] is the sub-list for extension type_name
+ 9, // [9:9] is the sub-list for extension extendee
+ 0, // [0:9] is the sub-list for field type_name
}
func init() { file_proto_worker_worker_proto_init() }
@@ -2956,7 +2973,7 @@ func file_proto_worker_worker_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_worker_worker_proto_rawDesc), len(file_proto_worker_worker_proto_rawDesc)),
NumEnums: 1,
- NumMessages: 47,
+ NumMessages: 48,
NumExtensions: 0,
NumServices: 1,
},
diff --git a/proto/worker/worker.proto b/proto/worker/worker.proto
index 32a075bb..58d92d17 100644
--- a/proto/worker/worker.proto
+++ b/proto/worker/worker.proto
@@ -57,6 +57,10 @@ message CreateSandboxRequest {
// Supports exact ("api.anthropic.com") and wildcard ("*.openai.com") patterns.
// Empty = all hosts allowed.
repeated string egress_allowlist = 13;
+ // Per-secret host restrictions: env var name → comma-separated allowed hosts.
+ // Secrets are only substituted in requests to matching hosts.
+ // Empty value or missing key = substitute on all allowed hosts.
+ map<string, string> secret_allowed_hosts = 14;
}
message CreateSandboxResponse {