feat(connectors): a secret setting is resolved through its engine before the extension starts (#2026)
This commit is contained in:
1 file changed
+45
@@ -348,10 +348,15 @@ func (m *Module) launch(ctx context.Context, a store.Accepted) error {
|
||||
return m.fail(ctx, a.Name, fmt.Errorf("settings: %w", err))
|
||||
}
|
||||
}
|
||||
settings, secretSettings, err := m.splitSecretSettings(ctx, a, settings)
|
||||
if err != nil {
|
||||
return m.fail(ctx, a.Name, err)
|
||||
}
|
||||
secrets, err := m.secrets(ctx, a)
|
||||
if err != nil {
|
||||
return m.fail(ctx, a.Name, err)
|
||||
}
|
||||
maps.Copy(secrets, secretSettings)
|
||||
spec := Spec{
|
||||
Name: a.Name, Path: a.Path, SHA256: a.SHA256,
|
||||
Env: a.Env, Egress: a.Egress, Settings: settings, Secrets: secrets,
|
||||
@@ -392,6 +397,46 @@ func (m *Module) launch(ctx context.Context, a store.Accepted) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// refSuffix marks a setting that names a secret rather than holding one. The
|
||||
// host resolves it through the named engine, so the extension never reads the
|
||||
// reference.
|
||||
const refSuffix = "_ref"
|
||||
|
||||
// splitSecretSettings separates a package's secret settings from the rest,
|
||||
// resolves each reference, and returns the plain settings and the secrets the
|
||||
// extension is configured with. A secret engine's own settings must hold
|
||||
// their values: an engine never waits on another engine.
|
||||
func (m *Module) splitSecretSettings(ctx context.Context, a store.Accepted, settings map[string]string) (map[string]string, map[string]string, error) {
|
||||
plain := make(map[string]string, len(settings))
|
||||
secrets := map[string]string{}
|
||||
for key, value := range settings {
|
||||
name, isRef := strings.CutSuffix(key, refSuffix)
|
||||
if !isRef {
|
||||
plain[key] = value
|
||||
continue
|
||||
}
|
||||
if a.Contract == store.ContractSecretEngine {
|
||||
return nil, nil, fmt.Errorf("setting %q: a secret engine's own settings must hold their values", key)
|
||||
}
|
||||
engineName, ref, ok := strings.Cut(value, ":")
|
||||
if !ok || engineName == "" || ref == "" {
|
||||
return nil, nil, fmt.Errorf("setting %q wants engine:key", key)
|
||||
}
|
||||
m.mu.RLock()
|
||||
engine, running := m.engines[engineName]
|
||||
m.mu.RUnlock()
|
||||
if !running {
|
||||
return nil, nil, fmt.Errorf("setting %q: secret engine %q isn't running", key, engineName)
|
||||
}
|
||||
secret, err := engine.Resolve(ctx, ref)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("setting %q: %w", key, err)
|
||||
}
|
||||
secrets[name] = secret
|
||||
}
|
||||
return plain, secrets, nil
|
||||
}
|
||||
|
||||
// release stops whatever ran under name, so one accepted package is what a
|
||||
// name runs.
|
||||
func (m *Module) release(name string) {
|
||||
|
||||
Reference in new issue
Block a user