Documentation
¶
Overview ¶
Package backup makes encrypted backups of the controller (§13) and ships them to S3. A bundle holds a consistent SQLite snapshot (VACUUM INTO) and the key material in the data directory (CA, registry token key, …), sealed with the master key. The header carries the master key wrapped by the recovery key, so restoring needs the bundle plus the recovery key only.
Index ¶
- Constants
- Variables
- func ControllerID(dataDir string) (string, error)
- func Create(ctx context.Context, st *store.Store, box *secrets.Box, dataDir string, ...) error
- func CreateWith(ctx context.Context, st *store.Store, box *secrets.Box, dataDir string, ...) error
- func Download(ctx context.Context, cfg Config, name string) ([]byte, string, error)
- func Folders(ctx context.Context, cfg Config) (map[string][]Object, error)
- func InsideCluster(rawURL string, nodeIPs []string) bool
- func NewOpenReader(r io.Reader, key []byte) (io.Reader, error)
- func NewSealWriter(w io.Writer, key []byte) (io.WriteCloser, error)
- func Rekey(bundle []byte, box *secrets.Box) ([]byte, error)
- func Repoint(ctx context.Context, st *store.Store, box *secrets.Box, access Config, ...) error
- func Restore(bundle []byte, recoveryKey, dataDir string, force bool) ([]string, error)
- func StandbyError(standby func() (string, bool)) error
- func WriteClaim(dataDir string) error
- type Config
- type Creds
- type Manager
- func (m *Manager) AddressLink(ctx context.Context) (link, cluster string, expires time.Time, err error)
- func (m *Manager) Check(ctx context.Context, c Config) error
- func (m *Manager) CheckOwner(ctx context.Context) (OwnerState, error)
- func (m *Manager) Config() (Config, bool)
- func (m *Manager) Disable(ctx context.Context) error
- func (m *Manager) EndpointInUse(_ context.Context, id string) string
- func (m *Manager) Kick()
- func (m *Manager) List(ctx context.Context) ([]Object, error)
- func (m *Manager) Load(ctx context.Context) error
- func (m *Manager) PublishAddress(ctx context.Context, where ctladdr.Address, sign func([]byte) ([]byte, error)) error
- func (m *Manager) Reachable(ctx context.Context) error
- func (m *Manager) Recovery() (Storage, bool)
- func (m *Manager) RekeyAll(ctx context.Context) (RekeyResult, error)
- func (m *Manager) Run(ctx context.Context)
- func (m *Manager) RunNow(ctx context.Context) (Object, error)
- func (m *Manager) SetConfig(ctx context.Context, c Config) error
- func (m *Manager) Silenced() (string, bool)
- func (m *Manager) Standby() (string, bool)
- func (m *Manager) Status() Status
- func (m *Manager) WriteBundle(ctx context.Context, w io.Writer) error
- type Meta
- type Object
- type Owner
- type OwnerState
- type RekeyResult
- type Status
- type Storage
Constants ¶
const (
// Ext is the bundle file extension.
Ext = ".synbak"
)
const MetaFile = "meta.json"
MetaFile is the bundle entry that says what made it.
const (
// TopicUpdated carries Status after every backup run.
TopicUpdated = "backup.updated"
)
Variables ¶
var ErrCurrent = errors.New("the backup already opens with the current recovery key")
ErrCurrent means a bundle already carries the current wrapped master key.
var ErrForeignBackups = errors.New("this folder already holds the backups of another SynCloud cluster")
ErrForeignBackups: the folder holds another cluster's backups.
var ErrNotConfigured = errors.New("backups are not configured")
ErrNotConfigured is returned when no S3 destination is set.
var ErrNothingToRestore = errors.New("there is nothing to restore it from")
ErrNothingToRestore means the recovery storage holds nothing to bring an item back from, as opposed to a failure to look or to restore.
var ErrOtherMasterKey = errors.New("the backup was made with another master key")
ErrOtherMasterKey means a bundle was sealed with another master key (another install, or one from before a restore onto a new key).
var ErrRecovering = errors.New("held until the recovery reaches it")
ErrRecovering means the work waits for a recovery to finish.
var ErrStandby = errors.New("this controller is on standby")
ErrStandby means this controller may not write outside the cluster.
var ErrStreamDamaged = errors.New("the snapshot is damaged or the key is wrong")
ErrStreamDamaged means a stream was changed, cut off or opened with the wrong key.
var ErrWrongRecoveryKey = errors.New("the recovery key does not open the backup")
ErrWrongRecoveryKey means the recovery key does not open a backup.
Functions ¶
func ControllerID ¶ added in v1.1.0
ControllerID is the identity of the controller of a data directory ("" when it has none yet).
func Create ¶
func Create(ctx context.Context, st *store.Store, box *secrets.Box, dataDir string, w io.Writer) error
Create writes an encrypted bundle of dataDir to w.
func CreateWith ¶ added in v1.1.0
func CreateWith(ctx context.Context, st *store.Store, box *secrets.Box, dataDir string, hostFiles map[string]string, w io.Writer) error
CreateWith is Create with files from outside the data directory (the host's controller settings), by bundle name; missing ones are left out.
func Folders ¶ added in v1.1.0
Folders lists the controller backups in a bucket by folder, newest first in each: those of cfg.Prefix when it is set, else of every folder. The folders SynCloud keeps other data in are not searched.
func InsideCluster ¶ added in v1.1.0
InsideCluster reports whether an S3 address is on this cluster: on a node, in its private networks or a service's name. Such storage is lost with the cluster.
func NewOpenReader ¶ added in v1.1.0
NewOpenReader decrypts a stream NewSealWriter wrote. Reads fail with ErrStreamDamaged when it was changed, cut off or the key is wrong.
func NewSealWriter ¶ added in v1.1.0
NewSealWriter encrypts what is written to it into w; Close writes the last chunk, without which the stream does not open.
func Rekey ¶ added in v0.2.0
Rekey gives a bundle the box's current wrapped master key, so it opens with the current recovery key (Phase 19b). The body is checked to be sealed with the box's master key and is kept byte for byte. A bundle that already has the current key returns ErrCurrent and needs no upload.
func Repoint ¶ added in v1.1.0
func Repoint(ctx context.Context, st *store.Store, box *secrets.Box, access Config, endpoint func(ctx context.Context, id string, access Config) error) error
Repoint makes the restored settings in st reach the storage with the access a person gave: the connection backups use gets that address and key, and the settings the folder the backup was found in. endpoint changes a registered connection.
func Restore ¶
Restore unpacks bundle into dataDir using the recovery key. dataDir must not hold a database unless force is set. It returns the restored file names.
func StandbyError ¶ added in v1.1.0
StandbyError is ErrStandby with the reason, or nil; standby may be nil.
func WriteClaim ¶ added in v1.1.0
WriteClaim asks the controller of dataDir to take over its recovery storage when it next starts. Only a recovery, or a person on the server, calls it.
Types ¶
type Config ¶
type Config struct {
// EndpointID is a registered S3 connection (ID; name accepted on input).
EndpointID string `json:"endpointId,omitempty"`
// EndpointName is the connection's name (shown, not stored).
EndpointName string `json:"endpointName,omitempty"`
Endpoint string `json:"endpoint"` // e.g. https://s3.eu-central-1.amazonaws.com, http://10.0.0.5:9000
Region string `json:"region"`
PathStyle bool `json:"pathStyle,omitempty"`
Bucket string `json:"bucket"`
Prefix string `json:"prefix"`
AccessKeyID string `json:"accessKeyId"`
SecretAccessKey string `json:"secretAccessKey,omitempty"`
IntervalMinutes int `json:"intervalMinutes"`
Retain int `json:"retain"`
// RetainDays keeps, besides the newest Retain, the newest backup of each
// of the last RetainDays days (default 30; -1 none).
RetainDays int `json:"retainDays"`
}
Config is where and how often backups go. With EndpointID the credentials are a registered S3 connection's, read live at every run, so rotating its key there applies here too; otherwise they are the ones entered with the settings, and the secret is stored sealed.
type Manager ¶
type Manager struct {
// Drill: this controller is a recovery rehearsal and writes nothing.
Drill func() bool
// HoldPrune holds back removing old backups (a recovery is running).
HoldPrune func() bool
// Connection resolves a registered S3 connection (by ID or name); nil
// means only entered credentials can be used.
Connection func(ctx context.Context, ref string) (Creds, error)
// Connections lists the registered S3 connections, so backups set up
// with entered keys can move to the matching one (adopt).
Connections func(ctx context.Context) ([]Creds, error)
// Register adds an S3 connection and returns its ID: hand-entered keys
// become one, so the rest of the data can use the same storage.
Register func(ctx context.Context, c Creds) (string, error)
// HostFiles are files outside the data directory each bundle carries
// (bundle name -> path), such as the controller's settings.
HostFiles map[string]string
// Address is where this controller is reached (shown in the owner
// marker).
Address func() string
// standby is why this controller may not write outside ("" when it may);
// Retired reports whether this controller handed the cluster to a new
// server (Phase 29d); may be nil.
Retired func() bool
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) AddressLink ¶ added in v1.1.0
func (m *Manager) AddressLink(ctx context.Context) (link, cluster string, expires time.Time, err error)
AddressLink is a temporary read-only link to the address file, for agents. It gives no other access to the storage.
func (*Manager) Check ¶ added in v1.1.0
Check validates c and that its bucket takes uploads, without storing it.
func (*Manager) CheckOwner ¶ added in v1.1.0
func (m *Manager) CheckOwner(ctx context.Context) (OwnerState, error)
CheckOwner reads the marker, takes it or refreshes it when this controller may, and updates Standby. With the storage unreachable the last verdict stands, unless the storage refuses the key or this controller has been away too long to rely on it.
func (*Manager) Config ¶
Config returns the configuration without the secret; with a connection, its current address and key ID.
func (*Manager) EndpointInUse ¶ added in v0.5.3
EndpointInUse blocks deleting the S3 connection backups go to.
func (*Manager) Kick ¶ added in v1.1.0
func (m *Manager) Kick()
Kick asks for a backup soon: something a restore must not lose changed (a database created or deleted, a key or the storage changed).
func (*Manager) PublishAddress ¶ added in v1.1.0
func (m *Manager) PublishAddress(ctx context.Context, where ctladdr.Address, sign func([]byte) ([]byte, error)) error
PublishAddress writes where this controller is into the recovery storage, signed by the cluster CA.
func (*Manager) Reachable ¶ added in v1.1.0
Reachable reads the owner marker: whether this server can use the storage.
func (*Manager) Recovery ¶ added in v1.1.0
Recovery returns the recovery storage: set when backups use a registered connection.
func (*Manager) RekeyAll ¶ added in v0.2.0
func (m *Manager) RekeyAll(ctx context.Context) (RekeyResult, error)
RekeyAll re-keys every stored backup in place so it opens with the current recovery key (Phase 19b). Backups are not run meanwhile.
func (*Manager) SetConfig ¶
SetConfig validates c, checks that the bucket is reachable, stores it and triggers a first backup.
func (*Manager) Silenced ¶ added in v1.1.0
Silenced is Standby for notifications: they still go out while ownership merely cannot be confirmed, so that a person hears about it.
type Meta ¶ added in v1.1.0
type Meta struct {
Version string `json:"version"`
Commit string `json:"commit"`
CreatedAt time.Time `json:"createdAt"`
}
Meta is what made a bundle: the release that restores it best.
type Owner ¶ added in v1.1.0
type Owner struct {
ClusterID string `json:"clusterId"`
ControllerID string `json:"controllerId"`
// Epoch counts takeovers: a marker with a lower one than a controller
// claimed with was written late by one already replaced.
Epoch int `json:"epoch"`
Address string `json:"address,omitempty"`
Version string `json:"version,omitempty"`
ClaimedAt time.Time `json:"claimedAt"`
SeenAt time.Time `json:"seenAt"`
}
Owner is the marker.
type OwnerState ¶ added in v1.1.0
type OwnerState string
OwnerState is what the marker says about this controller.
const ( OwnerOwned OwnerState = "owned" OwnerClaimed OwnerState = "claimed" // taken over just now OwnerReplaced OwnerState = "replaced" // another controller took over OwnerForeign OwnerState = "foreign" // another cluster's folder OwnerUnknown OwnerState = "unknown" // the storage could not be read )
type RekeyResult ¶ added in v0.2.0
type RekeyResult struct {
Rekeyed int `json:"rekeyed"`
// Current already opened with the current recovery key.
Current int `json:"current"`
// Skipped were made with another master key and left as they are.
Skipped []string `json:"skipped"`
// Failed could not be read or written (name: error).
Failed []string `json:"failed"`
}
RekeyResult is the outcome of re-keying the stored backups.