linklocal

package
v1.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
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

View Source
var ErrImageMissing = errors.New("linklocal: relay image not present locally")

ErrImageMissing is returned when the relay image is not present locally.

View Source
var ErrNetworkRemove = errors.New("linklocal: network remove")

ErrNetworkRemove is returned when the link-local network cannot be removed.

View Source
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 Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns one link-local network and relay. It is safe for concurrent use.

func New

func New(api API, spec Spec) *Manager

New returns a Manager over api. Nothing touches Docker until Active or Attach.

func NewFromEnv

func NewFromEnv(spec Spec) (*Manager, error)

NewFromEnv returns a Manager over the Docker daemon named by DOCKER_HOST.

func (*Manager) Active

func (m *Manager) Active(ctx context.Context) bool

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

func (m *Manager) Attach(ctx context.Context, containerID, owner string) error

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) Close

func (m *Manager) Close() error

Close releases the Docker client; it leaves the relay and network running.

func (*Manager) NetworkName

func (m *Manager) NetworkName() string

NetworkName is the Docker network holding the relay.

func (*Manager) OwnerOf

func (m *Manager) OwnerOf(ctx context.Context, ip string) (string, bool)

OwnerOf resolves the owner of the container holding link-local address ip.

func (*Manager) Release

func (m *Manager) Release(containerID string)

Release forgets containerID's owner and any cached address.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context) error

Remove deletes the relay container and network. It fails if other containers are still attached.

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.

func ECSSpec

func ECSSpec(image, host, port string) Spec

ECSSpec is the 169.254.170.2 task-credentials relay.

func IMDSSpec

func IMDSSpec(image, host, port, ownerLabel string) Spec

IMDSSpec is the 169.254.169.254 instance-metadata relay.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL