mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-11-06 19:01:10 +00:00
de28c6781e
The lambdatestlink agent now loads its identity, seals fw_cfg and dials the host exactly as the normal agent does, then carries the test stream over that mutual-TLS connection instead of a device path. Nothing tenant-facing starts until the host's first valid frame: a refusal after the handshake, an early close or a shutdown never starts the bootstrap. Each VM serves one invocation and then stops. The normal agent is unchanged and still accepts no invocations. The tagged tests join the race tier for the two packages that carry the build tag.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/mulgadc/spinifex/spinifex/agents/lambda/hostlink"
|
|
)
|
|
|
|
// Exit statuses: the guest refused to start, the control connection failed,
|
|
// or the host closed it.
|
|
const (
|
|
exitRefused = 2
|
|
exitLink = 1
|
|
exitClosed = 0
|
|
)
|
|
|
|
type startup struct {
|
|
fwCfgDir string
|
|
fwCfgRoot string
|
|
unload func() error
|
|
}
|
|
|
|
func defaultStartup() startup {
|
|
return startup{fwCfgDir: hostlink.FwCfgDir, fwCfgRoot: hostlink.FwCfgRoot, unload: hostlink.UnloadFwCfg}
|
|
}
|
|
|
|
// connect loads the identity, seals fw_cfg whether or not the load succeeded,
|
|
// then dials the host. Under TLS 1.3 a host refusal is seen only on first read.
|
|
func (s startup) connect(ctx context.Context) (*tls.Conn, int, error) {
|
|
id, loadErr := hostlink.LoadIdentity(s.fwCfgDir)
|
|
if err := hostlink.SealFwCfg(s.fwCfgRoot, s.unload); err != nil {
|
|
return nil, exitRefused, errors.Join(loadErr, err)
|
|
}
|
|
if loadErr != nil {
|
|
return nil, exitRefused, loadErr
|
|
}
|
|
conn, err := hostlink.Dial(ctx, id)
|
|
if err != nil {
|
|
if ctx.Err() != nil {
|
|
err = fmt.Errorf("%w: %w", err, context.Cause(ctx))
|
|
}
|
|
return nil, exitLink, err
|
|
}
|
|
return conn, 0, nil
|
|
}
|