Documentation
¶
Index ¶
- Variables
- type Address
- type Arper
- type Config
- type DHCPServer
- type Database
- func (d Database) AllocateIPAM(a *Address) (err error)
- func (d Database) DeleteKVs(kvs *KVs) (err error)
- func (d Database) DeleteNetwork(n *Network) (err error)
- func (d Database) DeleteVM(vm *VM) (err error)
- func (d Database) GetConfig(vmID string) (config *Config, err error)
- func (d Database) GetHostnameByMAC(mac string) (config *Config, err error)
- func (d Database) GetIPAddress(a *Address) (err error)
- func (d Database) GetIPAddressAllocation(a *Address) (err error)
- func (d Database) GetKVs(vmID string) (kvs KVs, err error)
- func (d Database) GetNetwork(n *Network) (err error)
- func (d Database) GetVM(vm *VM) error
- func (d Database) GetVMFromMacAddress(vm *VM) error
- func (d Database) GetVMs() (vms []*VM, err error)
- func (d Database) InsertConfig(cfg *Config) (err error)
- func (d Database) InsertNetwork(n *Network) (err error)
- func (d Database) InsertVM(vm *VM) (err error)
- func (d Database) MarkVMAsDeleted(vm *VM) (err error)
- func (d Database) UpdateAllocation(a *Address) (err error)
- func (d Database) UpdateKVs(kvs *KVs) (err error)
- type HTTPServer
- type Hypervisor
- func (h *Hypervisor) CreateAndStart(dom libvirtxml.Domain) (err error)
- func (h *Hypervisor) Delete(id string) (err error)
- func (h *Hypervisor) IsRunning(id string) bool
- func (h *Hypervisor) Restart(id string) (err error)
- func (h *Hypervisor) StartExisting(id string) (err error)
- func (h *Hypervisor) Stop(id string) (err error)
- type IPAM
- type KV
- type KVs
- type Network
- type Server
- func (s *Server) All(_ *emptypb.Empty, ss grpc.ServerStreamingServer[server.VM]) (err error)
- func (s *Server) Create(ctx context.Context, req *server.VM) (out *server.VM, err error)
- func (s *Server) CreateNetwork(ctx context.Context, req *server.NetworkRequest) (resp *server.NetworkResponse, err error)
- func (s *Server) Delete(ctx context.Context, vm *server.VM) (*server.VM, error)
- func (s *Server) DeleteKVs(ctx context.Context, in *server.KVs) (*server.KVs, error)
- func (s *Server) DeleteNetwork(ctx context.Context, req *server.NetworkRequest) (_ *emptypb.Empty, err error)
- func (s *Server) Get(ctx context.Context, req *server.VM) (out *server.VM, err error)
- func (s *Server) GetKVs(ctx context.Context, in *server.VM) (*server.KVs, error)
- func (s *Server) Purge(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error)
- func (s *Server) Restart(ctx context.Context, vm *server.VM) (*server.VM, error)
- func (s *Server) Start(ctx context.Context, vm *server.VM) (*server.VM, error)
- func (s *Server) Stop(ctx context.Context, vm *server.VM) (*server.VM, error)
- func (s *Server) UpsertKVs(ctx context.Context, in *server.KVs) (*server.KVs, error)
- type Tailscale
- type VM
- type VMType
Constants ¶
This section is empty.
Variables ¶
var ( BaseImages = map[string]string{ "base": filepath.Join(threesImagesDir, "base.qcow2"), "arch": filepath.Join(threesImagesDir, "arch.qcow2"), } )
var Migrations embed.FS
Functions ¶
This section is empty.
Types ¶
type Arper ¶
type Arper struct {
// contains filtered or unexported fields
}
An Arper provides access to the host ARP table.
We use this to gate access to the Config endpoint; that endpoint contains passwords and tailscale keys and stuff.
By matching on source address for calls to the config endpoint, we can ensure the correct data is returned to the correct threes domain.
_However_ we also want to stop malicious threes domains from changing their IP address to be able to exfiltrate data.
Thus we want to lookup the MAC address of the IP Address making the call, and make sure it matches the MAC+IP pair as known by our IPAM.
func NewArper ¶
NewArper accepts a network interface, and a pointer to the IPAM, and returns a new Arper instance
type Config ¶
type Config struct {
VM string `json:"-" db:"vm"`
Hostname string `json:"hostname" db:"hostname"`
Token string `json:"token" db:"ts_token"`
Script string `json:"script" db:"script"`
PublicKey string `json:"public_key" db:"public_key"`
}
Config holds various bits of data for the config http endpoint to return.
type DHCPServer ¶
type DHCPServer struct {
// contains filtered or unexported fields
}
DHCPServer allows us to provide threes domains with a management IP address via the IPAM.
These management addresses are important, because that's how machines get access to the internet, and also in case tailscale crashes, or breaks, or goes down, and we need to SSH in to get access to fix stuff.
Providing threes domains IP addresses via DHCP allows us to avoid weird configurations or whatever
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func ConnectToDatabase ¶
func (Database) AllocateIPAM ¶
func (Database) DeleteNetwork ¶
func (Database) GetHostnameByMAC ¶
func (Database) GetIPAddress ¶
func (Database) GetIPAddressAllocation ¶
func (Database) GetNetwork ¶
func (Database) GetVMFromMacAddress ¶
func (Database) InsertConfig ¶
func (Database) InsertNetwork ¶
func (Database) MarkVMAsDeleted ¶
func (Database) UpdateAllocation ¶
type HTTPServer ¶
func NewHTTPServer ¶
func NewHTTPServer(a *Arper, db *Database) *HTTPServer
func (*HTTPServer) GetConfig ¶
func (s *HTTPServer) GetConfig(c *gin.Context)
func (*HTTPServer) GetHostname ¶
func (s *HTTPServer) GetHostname(c *gin.Context)
func (*HTTPServer) GetKV ¶
func (s *HTTPServer) GetKV(c *gin.Context)
func (*HTTPServer) GetPublicKey ¶
func (s *HTTPServer) GetPublicKey(c *gin.Context)
func (*HTTPServer) GetScript ¶
func (s *HTTPServer) GetScript(c *gin.Context)
func (*HTTPServer) GetToken ¶
func (s *HTTPServer) GetToken(c *gin.Context)
type Hypervisor ¶
type Hypervisor struct {
// contains filtered or unexported fields
}
func NewHypervisor ¶
func NewHypervisor() (h *Hypervisor, err error)
func (*Hypervisor) CreateAndStart ¶
func (h *Hypervisor) CreateAndStart(dom libvirtxml.Domain) (err error)
func (*Hypervisor) Delete ¶
func (h *Hypervisor) Delete(id string) (err error)
func (*Hypervisor) IsRunning ¶
func (h *Hypervisor) IsRunning(id string) bool
func (*Hypervisor) Restart ¶
func (h *Hypervisor) Restart(id string) (err error)
func (*Hypervisor) StartExisting ¶
func (h *Hypervisor) StartExisting(id string) (err error)
func (*Hypervisor) Stop ¶
func (h *Hypervisor) Stop(id string) (err error)
type IPAM ¶
type IPAM struct {
// contains filtered or unexported fields
}
func (*IPAM) GetAllocation ¶
type KVs ¶
type KVs []KV
func (*KVs) FromProtobuf ¶
func (KVs) RedactedMap ¶
func (*KVs) ToProtobuf ¶
type Network ¶
type Network struct {
Name string `db:"name"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
DeletedAt time.Time `db:"deleted_at"`
}
func (*Network) NewFromProtobuf ¶
func (n *Network) NewFromProtobuf(in *server.NetworkRequest)
func (*Network) Reponse ¶
func (n *Network) Reponse() *server.NetworkResponse
type Server ¶
type Server struct {
server.UnimplementedThreesServer
// contains filtered or unexported fields
}
Server implements the gRPC interface to threes, and is where the magic lives
func (*Server) CreateNetwork ¶
func (s *Server) CreateNetwork(ctx context.Context, req *server.NetworkRequest) (resp *server.NetworkResponse, err error)
CreateNetwork implements the Server.CreateNetwork gRPC call
func (*Server) DeleteNetwork ¶
func (*Server) Purge ¶
Purge should be run periodically; it will permanently delete any VMs marked as 'deleted', which frees up the hostname and disk space to be used again
type Tailscale ¶
type Tailscale struct {
// contains filtered or unexported fields
}
func NewTailscale ¶
func (*Tailscale) CreateAuthToken ¶
func (*Tailscale) CreateNetwork ¶
func (*Tailscale) DeleteNetwork ¶
type VM ¶
type VM struct {
ID string `db:"id"`
Name string `db:"name" validate:"alphanum,min=3"`
Description string `db:"description" validate:"printascii,max=256"`
Network string `db:"network" validate:"alphanum"`
Image string `db:"image" validate:"isValidImage"`
IPAddress string `db:"management_ip_address"`
MACAddress string `db:"mac_address"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
DeletedAt time.Time `db:"deleted_at"`
Type *VMType `db:"type"`
// contains filtered or unexported fields
}
func (*VM) CopyImageToDomainDisk ¶
func (*VM) DiskLocation ¶
func (*VM) Domain ¶
func (vm *VM) Domain() libvirtxml.Domain