feat(archied): OpenShell tasks get model keys through gateway providers (#1864)
This commit is contained in:
8 files changed
+429
-15
No files matched your search
@@ -502,13 +502,16 @@ func (b *boot) setupContainers(ctx context.Context) func() {
|
||||
if b.cfg.Containers.Runtime != config.RuntimeOpenShell {
|
||||
return closeDocker
|
||||
}
|
||||
rt, closeOpenShell, err := startOpenShell(ctx, b.cfgHolder, b.secrets, b.log)
|
||||
rt, client, closeOpenShell, err := startOpenShell(ctx, b.cfgHolder, b.secrets, b.log)
|
||||
if err != nil {
|
||||
b.log.ErrorContext(ctx, "autonomous workflows unavailable: openshell runtime", "err", err)
|
||||
b.taskRuntime = nil
|
||||
return closeDocker
|
||||
}
|
||||
b.taskRuntime = daemon.OpenShellRuntime(rt)
|
||||
settings := b.cfg.Containers.OpenShell
|
||||
bindings := runCredentialResolver{runs: b.stateStoreGrants.Client, models: b.taskModels, config: b.cfgHolder, secrets: b.secrets, credentials: b.credentialWatch}
|
||||
b.modelEgress = newOpenShellModelEgress(client, settings.Workspace, b.cfg.Instance, b.secrets, bindings, b.log)
|
||||
return func() { closeOpenShell(); closeDocker() }
|
||||
}
|
||||
|
||||
@@ -746,7 +749,9 @@ func (b *boot) setupBackends(ctx context.Context) error {
|
||||
b.addCleanup(closeContainers)
|
||||
err := b.connectNATS(ctx)
|
||||
if err == nil {
|
||||
b.setupModelEgress(ctx)
|
||||
if b.modelEgress == nil {
|
||||
b.setupModelEgress(ctx)
|
||||
}
|
||||
b.startEgressRelay(ctx)
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -28,7 +28,7 @@ type modelEgress struct {
|
||||
secrets *secret.Registry
|
||||
}
|
||||
|
||||
func (m modelEgress) Open(token, org string, providers map[string]config.Provider) (daemon.ModelSession, error) {
|
||||
func (m modelEgress) Open(_ context.Context, token, org string, providers map[string]config.Provider) (daemon.ModelSession, error) {
|
||||
// Each keyed provider's credential variable: the operator's, or the name
|
||||
// derived for a provider that carries only a secret reference.
|
||||
keyed := make(map[string]string, len(providers))
|
||||
@@ -84,10 +84,15 @@ func (m modelEgress) providerKey(name string, p config.Provider, org string, bou
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
if m.secrets == nil {
|
||||
return resolveKeyRef(m.secrets, name, p)
|
||||
}
|
||||
|
||||
// resolveKeyRef resolves p's api_key_ref to its key.
|
||||
func resolveKeyRef(secrets *secret.Registry, name string, p config.Provider) (string, error) {
|
||||
if secrets == nil {
|
||||
return "", fmt.Errorf("provider %q: no secret engine is available to resolve its api_key_ref", name)
|
||||
}
|
||||
value, err := m.secrets.Resolve(p.APIKey)
|
||||
value, err := secrets.Resolve(p.APIKey)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("provider %q: resolve api_key_ref: %w", name, err)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestModelEgressResolvesProviderSecretRefs(t *testing.T) {
|
||||
proxy: proxy, secrets: secret.NewRegistry(),
|
||||
config: config.NewHolder(config.Config{Containers: config.ContainerConfig{Credentials: tc.bindings}}),
|
||||
}
|
||||
session, err := m.Open("run-credential", "org-test", map[string]config.Provider{"used": tc.provider})
|
||||
session, err := m.Open(t.Context(), "run-credential", "org-test", map[string]config.Provider{"used": tc.provider})
|
||||
if tc.wantErr != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
|
||||
t.Fatalf("err = %v, want one naming %q", err, tc.wantErr)
|
||||
@@ -108,7 +108,7 @@ func TestModelEgressSubstitutesTheProviderKey(t *testing.T) {
|
||||
"alpha": {Class: "openai", BaseURL: "http://api.alpha.example", APIKey: config.SecretRef{Engine: "env", Key: "PROVIDER_KEY"}},
|
||||
},
|
||||
}.ModelProviders()
|
||||
session, err := m.Open("run-credential", "org-test", providers)
|
||||
session, err := m.Open(t.Context(), "run-credential", "org-test", providers)
|
||||
if err != nil {
|
||||
t.Fatalf("open model egress: %v", err)
|
||||
}
|
||||
|
||||
@@ -17,23 +17,23 @@ import (
|
||||
// removes the sandboxes a previous daemon left. A gateway that is down only
|
||||
// degrades: the runtime is returned, and each task parks on its failed
|
||||
// acquire until the gateway answers.
|
||||
func startOpenShell(ctx context.Context, cfgHolder *config.Holder, secrets *secret.Registry, log *slog.Logger) (*openshell.Runtime, func(), error) {
|
||||
func startOpenShell(ctx context.Context, cfgHolder *config.Holder, secrets *secret.Registry, log *slog.Logger) (*openshell.Runtime, *v1.Client, func(), error) {
|
||||
cfg := cfgHolder.Get()
|
||||
settings := cfg.Containers.OpenShell
|
||||
auth := v1.NoAuth()
|
||||
if settings.Token != (config.SecretRef{}) {
|
||||
if secrets == nil {
|
||||
return nil, nil, fmt.Errorf("openshell gateway token: no secret engine is available")
|
||||
return nil, nil, nil, fmt.Errorf("openshell gateway token: no secret engine is available")
|
||||
}
|
||||
token, err := secrets.Resolve(settings.Token)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("openshell gateway token: %w", err)
|
||||
return nil, nil, nil, fmt.Errorf("openshell gateway token: %w", err)
|
||||
}
|
||||
auth = v1.StaticToken(token)
|
||||
}
|
||||
client, err := v1.NewClient(v1.Config{Address: settings.Address, Auth: auth})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("openshell gateway %s: %w", settings.Address, err)
|
||||
return nil, nil, nil, fmt.Errorf("openshell gateway %s: %w", settings.Address, err)
|
||||
}
|
||||
rt := openshell.New(client, openshell.Options{
|
||||
Workspace: settings.Workspace,
|
||||
@@ -55,5 +55,5 @@ func startOpenShell(ctx context.Context, cfgHolder *config.Holder, secrets *secr
|
||||
}
|
||||
}
|
||||
log.InfoContext(ctx, "task sandboxes run on openshell", "gateway", settings.Address, "workspace", settings.Workspace)
|
||||
return rt, closeClient, nil
|
||||
return rt, client, closeClient, nil
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package archied
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"maps"
|
||||
"net"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
v1 "github.com/ai-openshell/sdk-go/openshell/v1"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/daemon"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
const (
|
||||
// providerDeleteAttempts and providerDeleteWait bound how long Close waits
|
||||
// for the gateway to detach a provider from a sandbox it is still deleting.
|
||||
providerDeleteAttempts = 5
|
||||
providerDeleteWait = 2 * time.Second
|
||||
providerCloseTimeout = time.Minute
|
||||
)
|
||||
|
||||
var nonNameChars = regexp.MustCompile(`[^a-z0-9]+`)
|
||||
|
||||
// gatewayProviders is the part of the OpenShell client model egress needs.
|
||||
type gatewayProviders interface {
|
||||
Providers() v1.ProviderInterface
|
||||
}
|
||||
|
||||
// keyResolver resolves the org's bound credential for a service on behalf of
|
||||
// the run a credential names.
|
||||
type keyResolver interface {
|
||||
Resolve(ctx context.Context, credential, service string) (string, error)
|
||||
}
|
||||
|
||||
// openShellModelEgress opens task sandboxes' model sessions on the OpenShell
|
||||
// gateway. Each keyed provider's real key is registered as a gateway provider
|
||||
// owned by the task; the gateway puts a placeholder in the sandbox and
|
||||
// substitutes the key on requests to the provider's host, so the key never
|
||||
// enters the sandbox.
|
||||
type openShellModelEgress struct {
|
||||
client gatewayProviders
|
||||
workspace string
|
||||
instance string
|
||||
secrets *secret.Registry
|
||||
bindings keyResolver
|
||||
log *slog.Logger
|
||||
|
||||
mu sync.Mutex
|
||||
owned map[string][]string // run credential -> gateway provider names
|
||||
}
|
||||
|
||||
func newOpenShellModelEgress(client gatewayProviders, workspace, instance string, secrets *secret.Registry, bindings keyResolver, log *slog.Logger) *openShellModelEgress {
|
||||
if workspace == "" {
|
||||
workspace = "default"
|
||||
}
|
||||
return &openShellModelEgress{client: client, workspace: workspace, instance: instance, secrets: secrets, bindings: bindings, log: log, owned: map[string][]string{}}
|
||||
}
|
||||
|
||||
func (m *openShellModelEgress) Open(ctx context.Context, token, org string, providers map[string]config.Provider) (daemon.ModelSession, error) {
|
||||
var session daemon.ModelSession
|
||||
for _, name := range slices.Sorted(maps.Keys(providers)) {
|
||||
p := providers[name]
|
||||
keyEnv := p.KeyEnv(name)
|
||||
if keyEnv == "" {
|
||||
continue
|
||||
}
|
||||
mp, err := m.openProvider(ctx, token, org, name, keyEnv, p)
|
||||
if err != nil {
|
||||
m.Close(ctx, token)
|
||||
return daemon.ModelSession{}, err
|
||||
}
|
||||
session.Providers = append(session.Providers, mp)
|
||||
}
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (m *openShellModelEgress) openProvider(ctx context.Context, token, org, name, keyEnv string, p config.Provider) (daemon.ModelProvider, error) {
|
||||
host, port, err := providerEndpoint(p)
|
||||
if err != nil {
|
||||
return daemon.ModelProvider{}, fmt.Errorf("provider %q: %w", name, err)
|
||||
}
|
||||
key, err := m.key(ctx, token, org, name, p)
|
||||
if err != nil {
|
||||
return daemon.ModelProvider{}, err
|
||||
}
|
||||
profile, err := m.ensureProfile(ctx, keyEnv, p.Class)
|
||||
if err != nil {
|
||||
return daemon.ModelProvider{}, fmt.Errorf("provider %q: %w", name, err)
|
||||
}
|
||||
gateway, err := m.providerName()
|
||||
if err != nil {
|
||||
return daemon.ModelProvider{}, err
|
||||
}
|
||||
// Recorded before the create so a call that fails after the gateway
|
||||
// accepted it is still deleted.
|
||||
m.own(token, gateway)
|
||||
if _, err := m.client.Providers().Create(ctx, m.workspace, &v1.Provider{
|
||||
Name: gateway,
|
||||
Type: profile,
|
||||
Spec: v1.ProviderSpec{Credentials: map[string]string{keyEnv: key}},
|
||||
}); err != nil {
|
||||
return daemon.ModelProvider{}, fmt.Errorf("provider %q: create gateway provider: %w", name, err)
|
||||
}
|
||||
return daemon.ModelProvider{Gateway: gateway, Host: host, Port: port}, nil
|
||||
}
|
||||
|
||||
// key is the real key for provider name: its api_key_ref, or the org's
|
||||
// credential binding for a provider that only declares an env var.
|
||||
func (m *openShellModelEgress) key(ctx context.Context, token, org, name string, p config.Provider) (string, error) {
|
||||
if p.APIKey != (config.SecretRef{}) {
|
||||
return resolveKeyRef(m.secrets, name, p)
|
||||
}
|
||||
key, err := m.bindings.Resolve(ctx, token, name)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("provider %q has no usable credential binding named %q in org %s: %w", name, name, org, err)
|
||||
}
|
||||
if key = strings.TrimSpace(key); key == "" {
|
||||
return "", fmt.Errorf("provider %q: credential binding resolved empty", name)
|
||||
}
|
||||
return key, nil
|
||||
}
|
||||
|
||||
// keyHeaders are the request headers providers that do not take a bearer
|
||||
// token read their key from, by class. The gateway only substitutes a
|
||||
// credential where its profile says it is placed.
|
||||
var keyHeaders = map[string]string{
|
||||
"anthropic": "x-api-key",
|
||||
"gemini": "x-goog-api-key",
|
||||
"gemini-interactions": "x-goog-api-key",
|
||||
}
|
||||
|
||||
// ensureProfile makes sure a profile declaring keyEnv as its one credential,
|
||||
// placed where class's providers read it, exists, and returns its id.
|
||||
// Profiles are shared and stay.
|
||||
func (m *openShellModelEgress) ensureProfile(ctx context.Context, keyEnv, class string) (string, error) {
|
||||
credential := v1.ProfileCredential{Name: "api_key", EnvVars: []string{keyEnv}, Required: true, Secret: true}
|
||||
id := "archie-" + strings.ReplaceAll(strings.ToLower(keyEnv), "_", "-")
|
||||
if header, ok := keyHeaders[class]; ok {
|
||||
credential.AuthStyle, credential.HeaderName = "header", header
|
||||
id += "-" + header
|
||||
}
|
||||
profiles := m.client.Providers().Profiles()
|
||||
if _, err := profiles.Get(ctx, "", id); err == nil {
|
||||
return id, nil
|
||||
} else if !v1.IsNotFound(err) {
|
||||
return "", fmt.Errorf("look up gateway profile %s: %w", id, err)
|
||||
}
|
||||
res, err := profiles.Import(ctx, "", []v1.ProfileImportItem{{
|
||||
Source: "archie",
|
||||
Profile: v1.ProviderProfile{
|
||||
ID: id,
|
||||
DisplayName: keyEnv,
|
||||
Category: v1.ProfileCategoryInference,
|
||||
InferenceCapable: true,
|
||||
Credentials: []v1.ProfileCredential{credential},
|
||||
},
|
||||
}})
|
||||
if err == nil && res.Imported {
|
||||
return id, nil
|
||||
}
|
||||
// Another task may have imported it first.
|
||||
if _, getErr := profiles.Get(ctx, "", id); getErr == nil {
|
||||
return id, nil
|
||||
}
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("import gateway profile %s: %w", id, err)
|
||||
}
|
||||
return "", fmt.Errorf("import gateway profile %s: rejected: %+v", id, res.Diagnostics)
|
||||
}
|
||||
|
||||
// providerName is a unique gateway provider name. It carries neither the run
|
||||
// credential nor the key.
|
||||
func (m *openShellModelEgress) providerName() (string, error) {
|
||||
var b [6]byte
|
||||
if _, err := rand.Read(b[:]); err != nil {
|
||||
return "", fmt.Errorf("name gateway provider: %w", err)
|
||||
}
|
||||
instance := strings.Trim(nonNameChars.ReplaceAllString(strings.ToLower(m.instance), "-"), "-")
|
||||
if instance == "" {
|
||||
instance = "archie"
|
||||
}
|
||||
return "archie-" + instance + "-" + hex.EncodeToString(b[:]), nil
|
||||
}
|
||||
|
||||
func (m *openShellModelEgress) own(token, gateway string) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.owned[token] = append(m.owned[token], gateway)
|
||||
}
|
||||
|
||||
// Close deletes every gateway provider Open created for token. It outlives
|
||||
// ctx's cancellation: a cancelled task must still lose its keys.
|
||||
func (m *openShellModelEgress) Close(ctx context.Context, token string) {
|
||||
m.mu.Lock()
|
||||
names := m.owned[token]
|
||||
delete(m.owned, token)
|
||||
m.mu.Unlock()
|
||||
if len(names) == 0 {
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), providerCloseTimeout)
|
||||
defer cancel()
|
||||
for _, name := range names {
|
||||
if err := m.deleteProvider(ctx, name); err != nil {
|
||||
m.log.ErrorContext(ctx, "openshell: gateway provider not deleted", "provider", name, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deleteProvider retries while the gateway still has the provider attached to
|
||||
// a sandbox it is deleting.
|
||||
func (m *openShellModelEgress) deleteProvider(ctx context.Context, name string) error {
|
||||
var err error
|
||||
for attempt := range providerDeleteAttempts {
|
||||
if attempt > 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-time.After(providerDeleteWait):
|
||||
}
|
||||
}
|
||||
_, err = m.client.Providers().Delete(ctx, m.workspace, name, v1.DeleteOptions{AllowMissing: true})
|
||||
if err == nil || !v1.IsConflict(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// providerEndpoint is the host and port p's key may be sent to.
|
||||
func providerEndpoint(p config.Provider) (string, int, error) {
|
||||
host, err := egress.ProviderHost(p.Class, p.BaseURL)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
if h, port, err := net.SplitHostPort(host); err == nil {
|
||||
n, convErr := strconv.Atoi(port)
|
||||
if convErr != nil {
|
||||
return "", 0, fmt.Errorf("provider host %q has a bad port: %w", host, convErr)
|
||||
}
|
||||
return h, n, nil
|
||||
}
|
||||
return host, 443, nil
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package archied
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"maps"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/ai-openshell/sdk-go/openshell/v1"
|
||||
"github.com/ai-openshell/sdk-go/openshell/v1/fake"
|
||||
"github.com/ai-openshell/sdk-go/openshell/v1/types"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// stubProfiles stands in for the profile API the SDK fake leaves unimplemented.
|
||||
type stubProfiles struct {
|
||||
v1.ProfileInterface
|
||||
known map[string]bool
|
||||
items *[]v1.ProviderProfile
|
||||
}
|
||||
|
||||
func (s stubProfiles) Get(_ context.Context, _, id string) (*v1.ProviderProfile, error) {
|
||||
if s.known[id] {
|
||||
return &v1.ProviderProfile{ID: id}, nil
|
||||
}
|
||||
return nil, &types.StatusError{Code: types.ErrorNotFound, Message: "no such profile"}
|
||||
}
|
||||
|
||||
func (s stubProfiles) Import(_ context.Context, _ string, items []v1.ProfileImportItem) (*v1.ImportResult, error) {
|
||||
for _, it := range items {
|
||||
s.known[it.Profile.ID] = true
|
||||
*s.items = append(*s.items, it.Profile)
|
||||
}
|
||||
return &v1.ImportResult{Imported: true}, nil
|
||||
}
|
||||
|
||||
type stubProviders struct {
|
||||
v1.ProviderInterface
|
||||
profiles stubProfiles
|
||||
}
|
||||
|
||||
func (s stubProviders) Profiles() v1.ProfileInterface { return s.profiles }
|
||||
|
||||
type fakeGateway struct{ providers stubProviders }
|
||||
|
||||
func (g fakeGateway) Providers() v1.ProviderInterface { return g.providers }
|
||||
|
||||
type fixedBindings string
|
||||
|
||||
func (f fixedBindings) Resolve(context.Context, string, string) (string, error) {
|
||||
return string(f), nil
|
||||
}
|
||||
|
||||
// The OpenShell model session registers each keyed provider's real key on the
|
||||
// gateway, hands the sandbox no key, and removes the provider when the task
|
||||
// ends. Guards a key leaking into the session or outliving its task.
|
||||
func TestOpenShellModelEgressHoldsKeysOnTheGateway(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
providers map[string]config.Provider
|
||||
wantKeys map[string]string // key env -> real key held on the gateway
|
||||
wantHosts []string
|
||||
wantHeader string // header the profile places the key in; empty means a bearer token
|
||||
}{
|
||||
{
|
||||
name: "secret reference",
|
||||
providers: map[string]config.Provider{
|
||||
"alpha": {Class: "openai", BaseURL: "https://api.alpha.example", APIKey: config.SecretRef{Engine: "env", Key: "ALPHA_SECRET"}},
|
||||
},
|
||||
wantKeys: map[string]string{config.ProviderKeyEnvName("alpha"): "alpha-fake-key"},
|
||||
wantHosts: []string{"api.alpha.example"},
|
||||
},
|
||||
{
|
||||
name: "org binding, and a provider with no key is skipped",
|
||||
providers: map[string]config.Provider{
|
||||
"beta": {Class: "openai", BaseURL: "https://api.beta.example", APIKeyEnv: "BETA_KEY"},
|
||||
"local": {Class: "openai", BaseURL: "https://local.example"},
|
||||
},
|
||||
wantKeys: map[string]string{"BETA_KEY": "bound-fake-key"},
|
||||
wantHosts: []string{"api.beta.example"},
|
||||
},
|
||||
{
|
||||
name: "anthropic keys travel in x-api-key",
|
||||
providers: map[string]config.Provider{"claude": {Class: "anthropic", APIKeyEnv: "CLAUDE_KEY"}},
|
||||
wantKeys: map[string]string{"CLAUDE_KEY": "bound-fake-key"},
|
||||
wantHosts: []string{"api.anthropic.com"},
|
||||
wantHeader: "x-api-key",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Setenv("ALPHA_SECRET", "alpha-fake-key")
|
||||
var imported []v1.ProviderProfile
|
||||
fc := fake.NewClient()
|
||||
t.Cleanup(func() { _ = fc.Close() })
|
||||
gw := fakeGateway{stubProviders{ProviderInterface: fc.Providers(), profiles: stubProfiles{known: map[string]bool{}, items: &imported}}}
|
||||
m := newOpenShellModelEgress(gw, "ws", "Test Inst", secret.NewRegistry(), fixedBindings("bound-fake-key"), slog.New(slog.DiscardHandler))
|
||||
|
||||
session, err := m.Open(t.Context(), "run-credential", "org-test", tc.providers)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(session.Env) != 0 || len(session.Mounts) != 0 {
|
||||
t.Fatalf("session carries env %v mounts %v, want none: the gateway sets placeholders", session.Env, session.Mounts)
|
||||
}
|
||||
if len(session.Providers) != len(tc.wantHosts) {
|
||||
t.Fatalf("session providers = %+v, want hosts %v", session.Providers, tc.wantHosts)
|
||||
}
|
||||
held := map[string]string{}
|
||||
for i, mp := range session.Providers {
|
||||
if mp.Host != tc.wantHosts[i] || mp.Port != 443 {
|
||||
t.Errorf("provider %d = %s:%d, want %s:443", i, mp.Host, mp.Port, tc.wantHosts[i])
|
||||
}
|
||||
if strings.Contains(mp.Gateway, "run-credential") || strings.Contains(mp.Gateway, "fake-key") {
|
||||
t.Errorf("gateway name %q leaks the credential or key", mp.Gateway)
|
||||
}
|
||||
got, err := fc.Providers().Get(t.Context(), "ws", mp.Gateway)
|
||||
if err != nil {
|
||||
t.Fatalf("gateway provider %q: %v", mp.Gateway, err)
|
||||
}
|
||||
maps.Copy(held, got.Spec.Credentials)
|
||||
}
|
||||
for env, key := range tc.wantKeys {
|
||||
if held[env] != key {
|
||||
t.Errorf("gateway holds %q = %q, want the real key", env, held[env])
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range imported {
|
||||
if got := p.Credentials[0].HeaderName; got != tc.wantHeader {
|
||||
t.Errorf("profile %s places the key in header %q, want %q", p.ID, got, tc.wantHeader)
|
||||
}
|
||||
}
|
||||
|
||||
m.Close(t.Context(), "run-credential")
|
||||
left, err := fc.Providers().ListAll(t.Context(), "ws")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(left) != 0 {
|
||||
t.Fatalf("%d gateway providers remain after Close, want none", len(left))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// a sentinel under each provider's key variable and reaches the providers
|
||||
// through the egress proxy, which swaps in the org's bound key.
|
||||
type ModelEgress interface {
|
||||
Open(token, org string, providers map[string]config.Provider) (ModelSession, error)
|
||||
Open(ctx context.Context, token, org string, providers map[string]config.Provider) (ModelSession, error)
|
||||
Close(ctx context.Context, token string)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func (d *Daemon) openModelEgress(ctx context.Context, task *workflow.Task, crede
|
||||
if credential == "" {
|
||||
return ModelSession{}, nil, fmt.Errorf("model egress needs a run credential, and no State Store issues one")
|
||||
}
|
||||
session, err := d.ModelEgress.Open(credential, task.OrgOrDefault(), cfg.Providers)
|
||||
session, err := d.ModelEgress.Open(ctx, credential, task.OrgOrDefault(), cfg.Providers)
|
||||
if err != nil {
|
||||
return ModelSession{}, nil, blockedPark{taskstate.BlockerModelCredential, err}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ type recordingModelEgress struct {
|
||||
providers map[string]config.Provider
|
||||
}
|
||||
|
||||
func (r *recordingModelEgress) Open(_, _ string, providers map[string]config.Provider) (ModelSession, error) {
|
||||
func (r *recordingModelEgress) Open(_ context.Context, _, _ string, providers map[string]config.Provider) (ModelSession, error) {
|
||||
r.providers = providers
|
||||
return ModelSession{}, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user