WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
// Inbound traffic-token registry.
|
||||
//
|
||||
// Cube and E2B sandboxes only accept requests carrying their per-sandbox
|
||||
// traffic token. Cube's SDK attaches that header
|
||||
// itself once Sandbox.TrafficAccessToken is set, but go-e2b stores the token
|
||||
// and never sends it — so for E2B the header has to be added by the one
|
||||
// component WeKnora owns on that path: the data-plane RoundTripper.
|
||||
//
|
||||
// This registry is the lookup that makes it possible. It is process-local and
|
||||
// lost on restart, which is fine: the first reconnect after a restart carries
|
||||
// the token up from the session binding and re-registers it.
|
||||
|
||||
package sandbox
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// InboundTokenHeader is the header both providers accept. Cube additionally
|
||||
// accepts "cube-traffic-access-token"; sending the E2B spelling covers both.
|
||||
const InboundTokenHeader = "e2b-traffic-access-token"
|
||||
|
||||
// InboundTokenRegistry maps a sandbox ID to its inbound credential.
|
||||
type InboundTokenRegistry struct {
|
||||
tokens sync.Map // sandboxID -> string
|
||||
}
|
||||
|
||||
// NewInboundTokenRegistry returns an empty registry.
|
||||
func NewInboundTokenRegistry() *InboundTokenRegistry {
|
||||
return &InboundTokenRegistry{}
|
||||
}
|
||||
|
||||
// Put records the token for sandboxID. An empty token is not stored
|
||||
// (Docker, or a handle that omitted the credential).
|
||||
func (r *InboundTokenRegistry) Put(sandboxID, token string) {
|
||||
if r == nil || sandboxID == "" || token == "" {
|
||||
return
|
||||
}
|
||||
r.tokens.Store(strings.ToLower(sandboxID), token)
|
||||
}
|
||||
|
||||
// Get returns the token for sandboxID, or "" when none is known.
|
||||
func (r *InboundTokenRegistry) Get(sandboxID string) string {
|
||||
if r == nil || sandboxID == "" {
|
||||
return ""
|
||||
}
|
||||
if value, ok := r.tokens.Load(strings.ToLower(sandboxID)); ok {
|
||||
return value.(string)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Delete forgets sandboxID. Called when the sandbox is destroyed.
|
||||
func (r *InboundTokenRegistry) Delete(sandboxID string) {
|
||||
if r == nil || sandboxID == "" {
|
||||
return
|
||||
}
|
||||
r.tokens.Delete(strings.ToLower(sandboxID))
|
||||
}
|
||||
|
||||
// sandboxIDFromDataPlaneHost extracts the sandbox ID from an envd authority of
|
||||
// the form "<port>-<sandboxID>.<domain>", or "" when host is not one.
|
||||
//
|
||||
// Matching on this shape rather than on the configured sandbox domain is
|
||||
// deliberate: an E2B Cloud deployment may leave sandbox_domain empty and let
|
||||
// the SDK resolve its own default, and a domain-based check would then never
|
||||
// fire. The registry lookup is the real authority — only Cube/E2B sandboxes
|
||||
// whose token WeKnora recorded are in it.
|
||||
func sandboxIDFromDataPlaneHost(host string) string {
|
||||
host = strings.ToLower(strings.TrimSpace(host))
|
||||
if host == "" {
|
||||
return ""
|
||||
}
|
||||
if idx := strings.LastIndex(host, ":"); idx != -1 && !strings.Contains(host[idx:], "]") {
|
||||
host = host[:idx]
|
||||
}
|
||||
label, _, found := strings.Cut(host, ".")
|
||||
if !found {
|
||||
return ""
|
||||
}
|
||||
port, sandboxID, found := strings.Cut(label, "-")
|
||||
if !found || sandboxID == "" {
|
||||
return ""
|
||||
}
|
||||
if _, err := strconv.Atoi(port); err != nil {
|
||||
return ""
|
||||
}
|
||||
return sandboxID
|
||||
}
|
||||
Reference in New Issue
Block a user