Files
Reims-Go/internal/plugin/secret.go
T
Nwflower 33e28520b7 fix(mcp): read clone secrets and SSH user from the source VM
A temporary clone made by session_create keeps no vm settings of its own, so
vm_unlock on a clone always failed with "secret setting is empty" even though
the source VM had a saved login password and AI access enabled. The SSH user
was empty for the same reason: the clone has no settings and no copied
.reims-go-ssh-user file, while access is granted through the owns-clone path.

Record the source VM key in the temporary VM ownership marker and fall back to
it when a clone has no value of its own. The fallback reads the single stored
secret instead of copying it, so the password never multiplies across clones,
nothing is left behind when a clone is disposed, and revoking AI access on the
source removes the fallback immediately. Surface a clear localized error when
no VM has a saved password.

model: deepseek/deepseek-v4.1-flash
agent: lead (DeepSeek Harness)
2026-12-04 06:02:10 -07:00

44 lines
1.2 KiB
Go

package plugin
import (
"encoding/base64"
"errors"
"strings"
)
const protectedSecretPrefix = "dpapi:v1:"
var ErrSecretNotProtected = errors.New("stored secret is not protected")
// ErrSecretEmpty marks a secret setting that was never saved for the requested
// scope. Callers that may fall back to another VM (a temporary clone reading
// its source) match it with errors.Is instead of comparing text.
var ErrSecretEmpty = errors.New("secret setting is empty")
func protectSettingSecret(value string) (string, error) {
if value == "" || strings.HasPrefix(value, protectedSecretPrefix) {
return value, nil
}
protected, err := protectSecretBytes([]byte(value))
if err != nil {
return "", err
}
return protectedSecretPrefix + base64.StdEncoding.EncodeToString(protected), nil
}
func unprotectSettingSecret(value string) (string, error) {
if !strings.HasPrefix(value, protectedSecretPrefix) {
return "", ErrSecretNotProtected
}
encoded := strings.TrimPrefix(value, protectedSecretPrefix)
protected, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
return "", err
}
plain, err := unprotectSecretBytes(protected)
if err != nil {
return "", err
}
return string(plain), nil
}