Documentation
¶
Overview ¶
Package linklocal makes the AWS link-local service addresses (169.254.170.2 for ECS task credentials, 169.254.169.254 for EC2 IMDS) reachable from Docker containers without root.
A labelled bridge network owns the address; a tiny busybox relay container holds it and forwards plain HTTP to the emulator. Containers join the network as a secondary endpoint.
Index ¶
- Constants
- Variables
- type API
- type Manager
- func (m *Manager) Active(ctx context.Context) bool
- func (m *Manager) Attach(ctx context.Context, containerID, owner string) error
- func (m *Manager) Close() error
- func (m *Manager) NetworkName() string
- func (m *Manager) OwnerOf(ctx context.Context, ip string) (string, bool)
- func (m *Manager) Release(containerID string)
- func (m *Manager) Remove(ctx context.Context) error
- type Spec
Constants ¶
const ( // DefaultImage is the relay image; it must already exist locally, it is never pulled. DefaultImage = "alpine:3.21" // PeerHeader carries the connecting container's address to the emulator. PeerHeader = "X-Gopherstack-Peer" // IMDSPathPrefix is where the IMDS relay forwards; the EC2 handler resolves the instance from PeerHeader. IMDSPathPrefix = "/_gopherstack/ec2/imds/linklocal" // NetworkPrefix prefixes every link-local network and relay container name. NetworkPrefix = "gopherstack-linklocal-" )
Variables ¶
var ErrImageMissing = errors.New("linklocal: relay image not present locally")
ErrImageMissing is returned when the relay image is not present locally.
var ErrNetworkRemove = errors.New("linklocal: network remove")
ErrNetworkRemove is returned when the link-local network cannot be removed.
var ErrNotRunning = errors.New("linklocal: relay container not running")
ErrNotRunning is returned when the relay container does not stay up.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface {
ImageInspect(
ctx context.Context, image string, opts ...mobyclient.ImageInspectOption,
) (mobyclient.ImageInspectResult, error)
NetworkCreate(
ctx context.Context, name string, opts mobyclient.NetworkCreateOptions,
) (mobyclient.NetworkCreateResult, error)
NetworkList(ctx context.Context, opts mobyclient.NetworkListOptions) (mobyclient.NetworkListResult, error)
NetworkInspect(
ctx context.Context, id string, opts mobyclient.NetworkInspectOptions,
) (mobyclient.NetworkInspectResult, error)
NetworkConnect(
ctx context.Context, id string, opts mobyclient.NetworkConnectOptions,
) (mobyclient.NetworkConnectResult, error)
NetworkRemove(
ctx context.Context, id string, opts mobyclient.NetworkRemoveOptions,
) (mobyclient.NetworkRemoveResult, error)
ContainerCreate(
ctx context.Context, opts mobyclient.ContainerCreateOptions,
) (mobyclient.ContainerCreateResult, error)
ContainerStart(
ctx context.Context, id string, opts mobyclient.ContainerStartOptions,
) (mobyclient.ContainerStartResult, error)
ContainerList(ctx context.Context, opts mobyclient.ContainerListOptions) (mobyclient.ContainerListResult, error)
ContainerInspect(
ctx context.Context, id string, opts mobyclient.ContainerInspectOptions,
) (mobyclient.ContainerInspectResult, error)
ContainerRemove(
ctx context.Context, id string, opts mobyclient.ContainerRemoveOptions,
) (mobyclient.ContainerRemoveResult, error)
}
API is the Docker surface the manager uses.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns one link-local network and relay. It is safe for concurrent use.
func NewFromEnv ¶
NewFromEnv returns a Manager over the Docker daemon named by DOCKER_HOST.
func (*Manager) Active ¶
Active reports whether the relay is up, creating it on first use. A failure is logged once and not retried for a minute.
func (*Manager) Attach ¶
Attach joins containerID (created, started or not) to the link-local network as a secondary endpoint that never carries the default route. owner is recorded for OwnerOf.
func (*Manager) NetworkName ¶
NetworkName is the Docker network holding the relay.
func (*Manager) OwnerOf ¶
OwnerOf resolves the owner of the container holding link-local address ip.
type Spec ¶
type Spec struct {
// Name distinguishes the network and relay container ("ecs", "imds").
Name string
// Image is the relay image (busybox with nc); defaults to DefaultImage.
Image string
// Subnet is the link-local network CIDR.
Subnet netip.Prefix
// ProxyIP is the address the relay holds inside Subnet.
ProxyIP netip.Addr
// UpstreamHost and UpstreamPort are where the relay forwards, as seen from inside the network.
UpstreamHost string
UpstreamPort string
// PathPrefix is prepended to every forwarded request path.
PathPrefix string
// OwnerLabel is the container label naming the owning entity, used to recover owners after a restart.
OwnerLabel string
}
Spec describes one link-local network and its relay.