Documentation
¶
Overview ¶
Package workerunit enrolls and installs a bloc's worker on its bastion. It holds the enrollment's root steps and its unprivileged service: the preparing and signing of the enrollment request with the bastion's SSH host key, the service that sends it and fetches and verifies the worker once a person approves it, and the install job that installs the worker and hands it its key. It also renders what bastion init runs over SSH to set the enrollment up: the worker's systemd unit, its directory, its bastion record, its loopback SSH key, and the placing of the enrollment address. Both take the worker's names and paths from here.
Index ¶
- Constants
- Variables
- func Changed(out string) bool
- func Dir(bloc string) (string, error)
- func DirectoryCommand(bloc string, probe Probe) (string, error)
- func DropInPath(bloc string) (string, error)
- func EnrollCommand(bloc string, address bool) (string, error)
- func EnrollmentUploadPath(bloc string) (string, error)
- func ExitStatus(err error) int
- func HostKeyFingerprint(authorizedKey string) (string, error)
- func InstallCommand(bloc string, unit Unit) (string, error)
- func LoopbackCommand(bloc string) (string, error)
- func OCFPStateCommand() (string, error)
- func PrintShown(w io.Writer, s Shown) error
- func ProbeCommand(bloc string) (string, error)
- func ReadUserSetting(path string) (string, error)
- func RecordCommand(bloc string, record Record) (string, error)
- func RestartCommand(bloc string) (string, error)
- func ShowCommand() string
- func StatOwner(_ string, fi fs.FileInfo) (int, int, bool)
- func StatusSentence(st *ServiceStatus) string
- func UnitName(bloc string) (string, error)
- func UnitText(name string) (string, bool)
- func WriteRecord(dataHome, bloc, raw string) error
- type Awaited
- type Bus
- type Candidate
- type Configured
- type Expect
- type HTTPHosting
- type Host
- func (h Host) Await(ctx context.Context, route, token string, ca []byte) (Awaited, error)
- func (h Host) Configure(ctx context.Context, raw string) (Configured, error)
- func (h Host) ConfigureFromAwait(ctx context.Context) (Configured, error)
- func (h Host) Install(ctx context.Context, roots sigchain.Trust, arch string) (Installed, error)
- func (h Host) InstallUnits(ctx context.Context) error
- func (h Host) Prepare(ctx context.Context) (Prepared, error)
- func (h Host) ReadInputs() (Inputs, error)
- func (h Host) Setup(ctx context.Context, start bool) (Prepared, error)
- func (h Host) StartService(ctx context.Context) error
- type HostSystem
- func (HostSystem) AddServiceUser(ctx context.Context, name string) error
- func (HostSystem) DeleteUser(ctx context.Context, name string) error
- func (HostSystem) LookupUser(name string) (int, int, bool, error)
- func (HostSystem) SignWithHostKey(ctx context.Context, keyPath, namespace string, msg []byte) ([]byte, error)
- func (HostSystem) Systemctl(ctx context.Context, args ...string) error
- type Hosting
- type Inputs
- type InstallStatus
- type Installed
- type Layout
- type Link
- type Located
- type NATSBus
- type OCFPState
- type OwnerFunc
- type Prepared
- type Probe
- type Record
- type Release
- type Rules
- type Service
- type ServiceStatus
- type Shown
- type Sources
- type System
- type Unit
- type UnitParams
Constants ¶
const ( CodeHostingNotReady = "SETUP_HOSTING_NOT_READY" CodeHostingClosed = "SETUP_HOSTING_CLOSED" )
The codes the hosting route answers with while it has no address to give, or will never give one.
const ( SourceUserSettings = "the user settings file" SourceRecords = "this workstation's records" SourcePeer = "the bastion of bloc" )
The sources of an enrollment address, in the order the CLI asks them. The environment and the bloc's own config come first, and the caller reads both through the config package. The user settings file, the workstation's records, and the other bastions follow.
const ( // EtcDir holds the root-owned inputs of the enrollment. EtcDir = "/etc/bloc-worker" // EnrollmentPath is the enrollment address, root-owned at mode 0644. EnrollmentPath = EtcDir + "/enrollment" // BlocPath is the name of the bloc the bastion serves, which the // bootstrap writes as root beside the enrollment address. BlocPath = EtcDir + "/bloc" // PendingDir is root-only. Prepare keeps the worker key's seed, the // install key's seed, and the signed request there, and the install // job keeps its progress there. The job deletes it when it finishes. PendingDir = EtcDir + "/pending" // InstallStatusPath is the install job's last outcome, which the // service reads and reports. InstallStatusPath = EtcDir + "/install-status.json" // AwaitRootDir is root-only. Await keeps the hosting route's URL and // the deployment's CA there, which configure trusts over the // service's copies. AwaitRootDir = EtcDir + "/await" // StateDir is the enrollment service's state directory. StateDir = "/var/lib/bloc-enroll" // StagingDir is where the service places a verified download. StagingDir = StateDir + "/staging" // AwaitDir is where await hands the service the hosting route, and // where the service leaves the address it got. AwaitDir = StateDir + "/await" // HostPublicKeyPath is the bastion's Ed25519 host public key, which // the attestation names. HostPublicKeyPath = "/etc/ssh/ssh_host_ed25519_key.pub" // HostPrivateKeyPath is the host key's private half, which only // prepare signs with, through ssh-keygen. HostPrivateKeyPath = "/etc/ssh/ssh_host_ed25519_key" // ServiceUser is the system user the enrollment service runs as. It // has no shell and no sudo rights. ServiceUser = "bloc-enroll" )
The paths of the enrollment on a bastion. Root owns everything under EtcDir and TrustDir. The enrollment service owns StateDir, its only writable path, so the root steps treat everything in it as hostile.
const ( SigningRootsTest = "test" SigningRootsShipped = "shipped" )
The signing roots that ocfp's version output names: the public test root of a lab build, or the shipped roots of every other build.
const ( PhaseWaiting = "waiting" // waiting for the hosting route to give an address PhaseAsking = "asking" // sending the signed request PhasePending = "pending" // a person has not approved the request yet PhaseRejected = "rejected" // a person rejected the request PhaseRemoved = "removed" // a person removed the worker, so the service stopped PhaseApproved = "approved" // approved, reading the release PhaseStaged = "staged" // a verified download waits for the install job PhaseRefused = "refused" // the last answer or check refused, and the service retries PhaseStopped = "stopped" // the service stopped for good PhaseInstalling = "installing" // the install job is running )
The phases the enrollment service reports in its status file.
const ( // TemplateName is the templated unit; each bloc runs as one instance. TemplateName = "bloc-worker@.service" // UnitPath is where the template is installed. UnitPath = unitDir + TemplateName // BinaryPath is where the worker binary is installed, owned by root // with mode 0755. BinaryPath = "/usr/local/bin/bloc-worker" // DataRoot holds each bloc's worker directory. It is on the bastion's // persistent data disk, so the worker's key and credential survive an // operating system replacement. DataRoot = "/data/bloc-worker" // ChangeMarker starts every line the install scripts print when they // change something on the bastion, so the phase knows to restart the // worker. ChangeMarker = "worker-change:" )
The worker's unit comes in two files, as the inception vault's does. The template, bloc-worker@.service, is the same for every bloc and names no user. Each bloc's instance gets a drop-in, bloc-worker@<bloc>.service.d/operator.conf, that names the operator it runs as and the worker's directory, and an instance without that drop-in never starts.
const ( EnrollUnit = "bloc-enroll.service" InstallPathUnit = "bloc-enroll-install.path" InstallServiceUnit = "bloc-enroll-install.service" ConfigurePathUnit = "bloc-enroll-configure.path" ConfigureServiceUnit = "bloc-enroll-configure.service" )
The enrollment's units. Their names are generic, and nothing in them names the managing system.
const ( ExitNotConfigured = 2 ExitStopped = 3 )
The service's exit statuses that systemd must not restart it after: 2 when the bastion has no enrollment address, and 3 when a person removed the worker or the hosting route closed.
const RecordFile = "enrollment"
RecordFile is the name of the copy of a bloc's enrollment address that the CLI keeps in that bloc's data directory. Only the CLI writes it, so the CLI trusts it as a source.
const ( // RemoteOCFP is the ocfp binary the worker runs on its bastion, and // the one that runs the enrollment's root steps. RemoteOCFP = "/usr/local/bin/ocfp" )
The scripts below run on the bastion through the operator's login shell, each as one bash -c '...' command, so none of them may hold a single quote. Only the steps that must be root run under sudo: the creation of the worker's directory, the placing of the enrollment's root-owned inputs, and prepare itself. No script ever carries the enrollment address, which travels only as an uploaded file.
Variables ¶
var ( // ErrNoAnswer reports an ask or a release read that got no answer // in time, or no responder, so the service asks again after its // backoff. ErrNoAnswer = errors.New("the bus gave no answer in time") // ErrCredentialRefused reports that the bus refused the install // credential, so the service asks for a fresh one at once. ErrCredentialRefused = errors.New("the bus refused the install credential") )
The errors a Bus returns that the enrollment service tells apart.
var ( // ErrNoEnrollmentAddress reports that no source names an enrollment // address. A full bootstrap installs the enrollment service and leaves // it stopped, and the narrow worker mode refuses. ErrNoEnrollmentAddress = errors.New("no enrollment address is set for this bloc") // ErrEnrollmentAmbiguous reports sources that name more than one // enrollment address. Which org a bloc enrolls in is a person's // decision, so the CLI never guesses. ErrEnrollmentAmbiguous = errors.New("this workstation knows more than one enrollment address") )
var ( // ErrProbe reports a bastion probe that did not report a value the // install needs. ErrProbe = errors.New("the bastion probe did not report what the worker install needs") // ErrNoHostKey reports a bastion with no usable ed25519 host key, which // the attestation must be signed with. ErrNoHostKey = errors.New("the bastion has no ed25519 host key at " + HostPublicKeyPath) // ErrNoShown reports enrollment output that holds no result. ErrNoShown = errors.New("the bastion's ocfp printed no enrollment result") )
var ( // ErrInvalidBloc reports a bloc name that cannot name a worker unit // instance or directory as written. ErrInvalidBloc = errors.New("the bloc name cannot name a bloc-worker unit instance") // ErrInvalidUnitParams reports a user or home that would break the unit // file or run the worker as the wrong user. ErrInvalidUnitParams = errors.New("invalid bloc-worker unit parameters") )
var ErrCAPinMismatch = errors.New("the enrollment address's CA pin names no certificate of the deployment's CA")
ErrCAPinMismatch refuses an awaited address whose CA pin names no certificate of the deployment's CA that await kept as root.
var ErrMissing = fs.ErrNotExist
ErrMissing reports a file that isn't there. It is not a break of the rules, so it is never logged as one.
var ErrNotConfigured = errors.New("this bastion has no enrollment address yet")
ErrNotConfigured reports a bastion with no enrollment address, whose enrollment service stays stopped until configure gives it one.
var (
ErrRemoved = errors.New("a person removed this worker, so the enrollment stopped")
)
The service's ends. Run returns ErrRemoved when a person removed the worker, and nil when the enrollment finished or the service handed an awaited address on to configure.
var ErrWorkerInstalled = errors.New("the bloc worker is installed, so the enrollment is finished")
ErrWorkerInstalled reports a bastion whose bloc worker is installed, so its enrollment is finished. Prepare and configure change nothing there, because a new request would ask to enroll the bastion twice.
Functions ¶
func DirectoryCommand ¶
DirectoryCommand returns the command that creates DataRoot owned by root and bloc's worker directory, with its ssh and spool directories, owned by the operator with mode 0700.
func DropInPath ¶
DropInPath returns where bloc's instance keeps its operator.conf drop-in.
func EnrollCommand ¶
EnrollCommand returns the command that places bloc's name and, with address, the uploaded enrollment address in the root-owned enrollment directory, and then runs prepare as root, which starts the service once the bastion has an address. With no address it leaves any address the bastion already holds as it is.
func EnrollmentUploadPath ¶
EnrollmentUploadPath returns where the enrollment address is uploaded in bloc's worker directory before the enrollment script places it.
func ExitStatus ¶
ExitStatus returns the exit status the service ends with for err. A status of ExitNotConfigured or ExitStopped keeps systemd from restarting it.
func HostKeyFingerprint ¶
HostKeyFingerprint returns the SHA256 fingerprint of an ed25519 public key in authorized_keys form, as ssh-keygen -l prints it.
func InstallCommand ¶
InstallCommand returns the shell command that installs unit's template at UnitPath and its drop-in at DropInPath(bloc), reloads systemd, and enables bloc's instance without starting it. The script holds no single quote, so it is safe inside bash -c '...'.
func LoopbackCommand ¶
LoopbackCommand returns the command that makes the worker's loopback key, authorizes it for the operator from 127.0.0.1 and ::1 only, and writes the known_hosts file that pins this bastion's host keys.
func OCFPStateCommand ¶
OCFPStateCommand returns the command that reads the signing roots and the digest of the bastion's ocfp, with a script that changes nothing.
func PrintShown ¶
PrintShown writes what a person at the bastion needs to approve it: the fingerprint, the confirmation code, the approval link, and the first answer. None of them is a secret.
func ProbeCommand ¶
ProbeCommand returns the command that reports, one key=value line each, the operator's user, group, and home, whether the bastion's ocfp has 'worker enroll', and the ed25519 host public key.
func ReadUserSetting ¶
ReadUserSetting returns the enrollment address that the user settings file at path sets under bastion.worker.enrollment, or the empty string when the file or the key is missing. A file that doesn't parse is an error, because a setting that can't be read must not read as no setting.
func RecordCommand ¶
RecordCommand returns the command that writes record as bloc's bastion.json with mode 0600, and reports a change only when it differs.
func RestartCommand ¶
RestartCommand returns the command that restarts bloc's worker when it is running, so a changed unit or record takes effect, and does nothing when it is not.
func ShowCommand ¶
func ShowCommand() string
ShowCommand returns the command that prints the enrollment as JSON. It needs no root, because nothing it reads is a secret.
func StatusSentence ¶
func StatusSentence(st *ServiceStatus) string
StatusSentence says in one sentence where the request stands.
func WriteRecord ¶
WriteRecord keeps raw as bloc's record under dataHome, replacing any earlier one. raw must be a valid enrollment address.
Types ¶
type Awaited ¶
type Awaited struct {
// Configured reports that the bastion already had an address or a
// worker, so await changed nothing.
Configured bool `json:"configured"`
}
Awaited is what await did.
type Bus ¶
type Bus interface {
Ask(ctx context.Context, l Link, body []byte, request string) (enroll.Answer, error)
OpenRelease(ctx context.Context, l Link, worker, credential string) (Release, error)
}
Bus is the enrollment service's way to the managing system. Ask sends the signed request through the admission account and returns the answer DecodeAnswer accepted for it. OpenRelease connects with an install credential for the release read of worker.
type Candidate ¶
Candidate is one enrollment address a source holds. Bloc names the bloc whose record or bastion held it, and Raw is the address as it was read.
func ReadRecords ¶
ReadRecords returns the enrollment addresses this workstation recorded, one per bloc directory under dataHome that holds a record. A record that can't be read is passed over, since Locate also passes over one that doesn't parse.
type Configured ¶
type Configured struct {
Prepared Prepared `json:"prepared"`
// Changed reports that configure wrote a new enrollment address.
Changed bool `json:"changed"`
}
Configured is what configure did.
type Expect ¶
Expect is what a root step requires of a file it finds. UID is the owner the file must have. Mode, when set, is the exact permission the file must carry, and when it is zero the file must only not be writable by its group or by others. Limit bounds the read.
type HTTPHosting ¶
type HTTPHosting struct {
// Transport replaces the TLS transport in a test.
Transport http.RoundTripper
}
HTTPHosting is the Hosting of a bastion. It trusts the system's roots and the deployment's CA, and it never follows a redirect, so the token goes only to the route the kit named.
type Host ¶
type Host struct {
Layout Layout
Rules Rules
Sys System
RootUID int
RootGID int
Now func() time.Time
Log io.Writer
// NewKey generates a user nkey. It is nkeys.CreateUser on a bastion.
NewKey func() (nkeys.KeyPair, error)
}
Host is what every root step works through: the bastion's layout, the file rules, the system's tools, and the clock. RootUID is the uid that owns the root-owned files, which is 0 on a bastion and the test's own uid in a test.
func (Host) Await ¶
Await is the root step the hosting bloc's deploy runs. It keeps the hosting route's URL and the deployment's CA in the root-only await directory, hands the service the URL, the CA, and the token in its own await directory, each at mode 0600, and starts the service in its waiting mode with the configure path unit watching for its answer. A bastion that already has an address or a worker is left as it is, so every later deploy's hook changes nothing.
func (Host) Configure ¶
Configure is the root step that gives the bastion its enrollment address. It holds the address to its form, writes it to the root-owned enrollment file at mode 0644, prepares the signed request, installs the units, and restarts the service, which then asks with the new request.
func (Host) ConfigureFromAwait ¶
func (h Host) ConfigureFromAwait(ctx context.Context) (Configured, error)
ConfigureFromAwait adopts the address the service got from the hosting route. It reads the service's await files under the file rules, and it checks the address's CA pin against the deployment's CA that await kept in the root-only await directory, never against the service's copy. It then configures the bastion as Configure does, deletes both await directories, removes the configure units, and restarts the service in its normal mode.
func (Host) Install ¶
Install is the root job that runs when the service stages a verified download. It trusts nothing the service wrote. It reads the staged manifest set and binary under the file rules into its own memory, verifies the set through the whole chain against the root keys and the bastion's trust directory, and checks the binary's size and digest. It checks the service's ca.pem against the address's pin and the worker's directory. Only after every check passes does it install the binary, raise the floors, hand the worker its key and the signed request, and start the worker. It then removes the enrollment units, the service user, and the service's and the pending directories.
func (Host) InstallUnits ¶
InstallUnits writes the units into systemd's directory, each at mode 0644 owned by root, and reloads systemd when one changed. It enables and starts the install path unit, so a verified download installs as soon as the service stages it.
func (Host) Prepare ¶
Prepare is the first stage's root step. It reads its inputs only from root-owned files, generates the worker key and the install key, builds the attestation, and signs it once with the host key. It keeps the worker key's seed, both seeds, and the signed request in the root-only pending directory, and places in the service's state directory a copy of the signed request at mode 0644 and the install key's seed at mode 0600 owned by the service user. It takes no bytes from the service.
When the pending directory already holds a signed request for the same installation, org, bloc, and host key, prepare keeps it, so the request id the service sends never changes on a rerun. It puts back a copy in the state directory that is missing or stale, and it refuses, leaving the file in place, any file there that breaks the file rules. On a bastion whose worker is installed it changes nothing and returns ErrWorkerInstalled.
func (Host) ReadInputs ¶
ReadInputs reads the enrollment address, the bloc name, and the host public key, each from its root-owned file under the file rules.
func (Host) Setup ¶
Setup is prepare's whole root step. It prepares the signed request, installs or refreshes the units, and enables the install path unit. With start it also enables and restarts the service. On a bastion with no enrollment address it installs the units, leaves the service stopped, and returns ErrNotConfigured, so a later address only has to start it. On a bastion whose worker is installed it changes nothing and returns ErrWorkerInstalled.
type HostSystem ¶
type HostSystem struct{}
HostSystem is the bastion's System, which runs the system's own tools.
func (HostSystem) AddServiceUser ¶
func (HostSystem) AddServiceUser(ctx context.Context, name string) error
AddServiceUser runs useradd for a system user with its own group, no home directory, and no login shell.
func (HostSystem) DeleteUser ¶
func (HostSystem) DeleteUser(ctx context.Context, name string) error
DeleteUser runs userdel, and takes its "no such user" exit as done.
func (HostSystem) LookupUser ¶
LookupUser reads name from the system's user database.
func (HostSystem) SignWithHostKey ¶
func (HostSystem) SignWithHostKey(ctx context.Context, keyPath, namespace string, msg []byte) ([]byte, error)
SignWithHostKey runs ssh-keygen -Y sign with msg on its standard input, which writes the signature to its standard output.
type Hosting ¶
type Hosting interface {
Get(ctx context.Context, route, token string, ca []byte) (int, []byte, error)
}
Hosting asks the hosting route for the enrollment address. It returns the status and the body, read within maxHostingBody, or an error when no answer came.
type InstallStatus ¶
type InstallStatus struct {
Attempt string `json:"attempt"`
Code string `json:"code,omitempty"`
Done bool `json:"done"`
At time.Time `json:"at"`
}
InstallStatus is the install job's last outcome. Attempt is the staged attempt it handled, which the service wrote in the ready file.
type Installed ¶
type Installed struct {
Version string `json:"version"`
// Already reports that the install had finished before, so the job
// changed nothing.
Already bool `json:"already,omitempty"`
}
Installed is what the install job did.
type Layout ¶
type Layout struct {
Root string
}
Layout maps the bastion's absolute paths beneath Root, which is empty on a bastion and a temporary directory in a test.
type Link ¶
type Link struct {
Address enroll.Address
Bloc string
Seed []byte
CA []byte
SaveCA func(pem []byte) error
}
Link is what the service connects to the bus with: the address, the bloc, the install key's seed, which signs the connection's nonce, and the saved ca.pem when the address carries a CA pin. SaveCA keeps the root a pinned handshake verified, when no root was saved yet.
type Located ¶
type Located struct {
Address enroll.Address
Raw string
Source string
Peer string
Record bool
Skipped []Candidate
}
Located is the address Locate settled on. Source names where it came from, and Peer the bloc whose bastion supplied it, when one did. Record is set when the caller must keep the address as this bloc's record, because it came from another bastion. Skipped lists the candidates that were passed over because they don't hold to the address's form.
func Locate ¶
Locate finds the enrollment address as the bootstrap does. The first of the environment, the bloc's config, and the user settings file that sets an address settles it, and an address there that doesn't parse is an error. Otherwise the workstation's records and the other bastions decide. One distinct record settles it once no bastion disagrees, and with no record, one distinct address across the bastions settles it, which the caller then records. Any disagreement, or more than one address, is ErrEnrollmentAmbiguous. With nothing found it returns ErrNoEnrollmentAddress. Addresses are compared as whole strings.
type NATSBus ¶
NATSBus is the Bus of a bastion. Each ask is one short connection to the admission account, and each release read one connection under the install credential, so no connection outlives the credential it was opened with.
type OCFPState ¶
OCFPState is what the bastion's ocfp reports about itself: the signing roots it trusts, as its version output names them, and the sha256 digest of the binary. Either is empty when the bastion has no ocfp, and SigningRoots is empty when its ocfp predates the field.
func ParseOCFPState ¶
ParseOCFPState reads what OCFPStateCommand printed, or the same lines in the probe's output. A login banner may come first, so each key's last line wins.
type OwnerFunc ¶
OwnerFunc returns the owner of the file at path from what fstat gave for it. A bastion uses StatOwner, which reads only fi. A test injects its own, so it can stand in a file owned by another user without being root.
type Prepared ¶
type Prepared struct {
Bloc string `json:"bloc"`
RequestID string `json:"request"`
Fingerprint string `json:"fingerprint"`
Confirmation string `json:"confirmation"`
Link string `json:"link"`
// Signed reports that prepare made a new signed request, which it
// does only when an input changed.
Signed bool `json:"signed,omitempty"`
}
Prepared is what prepare reports to the person at the bootstrap. The fingerprint, the confirmation code, and the approval link all derive from the host's public key, so none of them is a secret.
type Probe ¶
type Probe struct {
// User and Group are the operator the worker runs as.
User string
Group string
// Home is the operator's home directory.
Home string
// HostKey is the ed25519 host public key, in authorized_keys form.
HostKey string
// EnrollCLI reports that the bastion's ocfp has 'worker enroll'.
EnrollCLI bool
// OCFP is the signing roots and the digest of the bastion's ocfp.
OCFP OCFPState
}
Probe is what the bastion reports before the enrollment is set up.
func ParseProbe ¶
ParseProbe reads what ProbeCommand printed. A login banner may come first, so each key's last line wins.
type Record ¶
type Record struct {
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
KeyPath string `json:"key_path"`
KnownHosts string `json:"known_hosts"`
RemoteOCFP string `json:"remote_ocfp"`
OwnerDir string `json:"owner_dir"`
SpoolRoot string `json:"spool_root"`
}
Record is the bastion record the worker reads to reach its own bastion. Its fields are exactly the ones the worker's record loader accepts, and it refuses any other.
type Release ¶
type Release interface {
Manifest(ctx context.Context) (enroll.ManifestAnswer, error)
Chunk(ctx context.Context, r enroll.ChunkRequest) (enroll.ChunkAnswer, error)
Status(ctx context.Context, r enroll.StatusRequest) (enroll.StatusAnswer, error)
Close()
}
Release is one connection under an install credential. It sends one request at a time and returns the decoded answer.
type Rules ¶
Rules applies the file rules to the root steps. Every path under a directory that the enrollment service or the worker's user can write is opened without following a link at any component, only a regular file is accepted, each read is bounded, and a found file is never renamed, chowned, or chmodded. A file that breaks a rule is left in place, and the step refuses with a log line that names the path.
func (Rules) Place ¶
func (r Rules) Place(dir, name string, data []byte, uid, gid int, mode fs.FileMode, want Expect) (bool, error)
Place makes dir/name hold data, owned by uid and gid at mode. A file already there that holds to the rules and to want is kept when it holds exactly data, and replaced by a fresh file when it doesn't. A file that breaks a rule is left in place, and Place refuses. It reports whether it wrote a file.
type Service ¶
type Service struct {
Layout Layout
Bus Bus
Hosting Hosting
Roots sigchain.Trust
Arch string
Now func() time.Time
Sleep func(ctx context.Context, d time.Duration) error
Log io.Writer
// Rand draws the backoff's jitter; nil uses the process's source.
Rand func() float64
// Read reads a file without following a link. It is
// enroll.ReadNoFollow on a bastion.
Read func(dir, name string, limit int64) ([]byte, error)
// contains filtered or unexported fields
}
Service is the enrollment service, which runs as the unprivileged user bloc-enroll. It reads only files any user may read and its own state directory. It never reads the worker key's seed, the pending directory, or the host private key, and every read goes through Read so a test can show that.
func NewService ¶
NewService returns the Service of a bastion, which trusts the root keys and revocation statement embedded in this binary. It refuses with TEST_ROOTS_IN_RELEASE, before it reads anything, when the binary trusts the public test root and carries a release version.
func (*Service) AwaitHosting ¶
AwaitHosting is the service's waiting mode on the bloc that hosts its managing system. It polls the hosting route that await handed it, on the fetch backoff, until the route gives an address. It then writes the address and the ready marker that trigger configure, and ends. It logs codes only, never the token, the route, or the address.
type ServiceStatus ¶
type ServiceStatus struct {
Phase string `json:"phase"`
State string `json:"state,omitempty"`
Verdict string `json:"verdict,omitempty"`
Code string `json:"code,omitempty"`
Request string `json:"request,omitempty"`
WorkerID string `json:"workerId,omitempty"`
Version string `json:"version,omitempty"`
Answers int `json:"answers"`
At time.Time `json:"at"`
}
ServiceStatus is what the enrollment service last saw, which show reads and prints. It holds no key, token, or credential.
type Shown ¶
type Shown struct {
Prepared `json:"prepared"`
Status *ServiceStatus `json:"status,omitempty"`
Installed string `json:"installed,omitempty"`
// NoAddress reports a bastion with no enrollment address, whose
// service is installed and stays stopped until it gets one.
NoAddress bool `json:"noAddress,omitempty"`
}
Shown is what show reports: the request as prepare made it, the service's last status, and whether an enrolled worker is installed.
func ParseShown ¶
ParseShown reads the result that prepare or show printed as JSON on the last such line of out, after any login banner or change lines.
type Sources ¶
type Sources struct {
Setting string
SettingSource string
UserSettings string
Records []Candidate
Peers func(ctx context.Context) []Candidate
}
Sources are what Locate asks, in order. Setting is what the environment or the bloc's config set, and SettingSource names which of the two. Peers reads the enrollment files on the bastions of the workstation's other blocs, and it is called only when the records leave the answer open or need a check.
type System ¶
type System interface {
// LookupUser returns name's uid and gid, and found false when there
// is no such user.
LookupUser(name string) (uid, gid int, found bool, err error)
// AddServiceUser creates name as a system user with no shell, no
// home, and no password.
AddServiceUser(ctx context.Context, name string) error
// DeleteUser deletes name. A user that is already gone is not an
// error.
DeleteUser(ctx context.Context, name string) error
// Systemctl runs systemctl with args.
Systemctl(ctx context.Context, args ...string) error
// SignWithHostKey signs msg with the private key at keyPath under
// namespace and returns the armored SSHSIG, as ssh-keygen -Y sign
// writes it.
SignWithHostKey(ctx context.Context, keyPath, namespace string, msg []byte) ([]byte, error)
}
System runs what a root step can't do through files: the service user's lifecycle, systemctl, and the one signing with the host key. A bastion uses HostSystem, and a test injects a fake, so no test runs a real command.
type Unit ¶
type Unit struct {
// Template is the text of bloc-worker@.service.
Template string
// DropIn is the text of the bloc instance's operator.conf drop-in.
DropIn string
}
Unit is the rendered unit, as the two files bastion init installs.
type UnitParams ¶
type UnitParams struct {
// User is the operator user the worker runs as, the same user the
// inception vault's unit runs as.
User string
// Home is that user's home directory.
Home string
}
UnitParams are the bastion-specific values the drop-in is rendered with.