A file the mesh can deliver and cannot read
Everything else in a declaration is visible to whatever carried it. The message is signed so it cannot be forged, and signing does not make it unreadable — a password in `content` is a password the broker sees, which is the transitive trust this design refuses everywhere else. So a node generates a third key at enrolment and reports the public half, exactly as it does for its identity and its overlay key. A file may arrive `sealed` instead of `content`; the host opens it with that key and writes the result. The control plane can then store a credential it cannot use, and the broker relays a blob it cannot read. A third key rather than reusing one of the two. The identity key signs and is Ed25519; the overlay key is WireGuard's and is tied to being on the private network, which a machine may not be. A key used for two purposes is one rotation away from breaking the other. Details that are not incidental: - sealed and content together is refused, so "was this the secret or the placeholder" is answerable by looking - a sealed file defaults to 0600 rather than 0644, because the consequence differs; an explicit mode still wins - a node with no sealing key refuses the file rather than skipping it. A machine that quietly omits the one resource carrying a credential looks configured and cannot connect - what is recorded is a digest of what was written, so drift on a credential is still detected without the node keeping the value, and the report that goes back over the broker carries neither The key is made at enrolment rather than on first use. One made later is one the mesh was never told about, so nothing could ever be sealed to it, and the node would look fine and receive nothing. This is why sealing was borrowed from another mesh's mistakes rather than its design: there, credentials sit encrypted in the control plane's database — which guards the database file and nothing else, since the same value is also in each node's environment file in plain text and inside every connection string composed from it. Its own tooling has to search by value rather than by name to find the copies, and says the ones inside composed URLs are usually the only copies in use.
This commit is contained in:
+36
-9
@@ -98,6 +98,7 @@ func Apply(
|
||||
origin string,
|
||||
run Runner,
|
||||
log func(string),
|
||||
unseal Unseal,
|
||||
) (Report, store.State, error) {
|
||||
if log == nil {
|
||||
log = func(string) {}
|
||||
@@ -129,7 +130,7 @@ func Apply(
|
||||
|
||||
for _, resource := range d.Resources {
|
||||
was, _ := known.Find(resource.Identity())
|
||||
outcome, err := applyOne(ctx, sys, resource, run, changed, was)
|
||||
outcome, err := applyOne(ctx, sys, resource, run, changed, was, unseal)
|
||||
if err != nil {
|
||||
return report, known, &Error{Resource: resource.Identity(), Err: err, Done: report}
|
||||
}
|
||||
@@ -150,13 +151,17 @@ func Apply(
|
||||
return report, known, nil
|
||||
}
|
||||
|
||||
// Unseal opens a value the mesh sealed to this node. Nil when the node has no sealing key, which
|
||||
// makes every sealed file an error rather than a silently skipped one.
|
||||
type Unseal func(sealed string) ([]byte, error)
|
||||
|
||||
func applyOne(ctx context.Context, sys system.System, r declaration.Resource, run Runner,
|
||||
changed map[string]bool, previous store.Applied) (Outcome, error) {
|
||||
changed map[string]bool, previous store.Applied, unseal Unseal) (Outcome, error) {
|
||||
switch res := r.(type) {
|
||||
case *declaration.Directory:
|
||||
return applyDirectory(res)
|
||||
case *declaration.File:
|
||||
return applyFile(res, previous)
|
||||
return applyFile(res, previous, unseal)
|
||||
case *declaration.Service:
|
||||
return applyService(ctx, sys, res, run, changed)
|
||||
case *declaration.Package:
|
||||
@@ -239,10 +244,32 @@ func applyDirectory(r *declaration.Directory) (Outcome, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func applyFile(r *declaration.File, previous store.Applied) (Outcome, error) {
|
||||
func applyFile(r *declaration.File, previous store.Applied, unseal Unseal) (Outcome, error) {
|
||||
out := begin(r)
|
||||
out.wrote = digestOf(r.Content)
|
||||
mode, err := modeOf(r.Mode, 0o644)
|
||||
|
||||
// What actually goes on disk. For a sealed file the mesh never had this, and neither did
|
||||
// whatever carried the declaration here.
|
||||
content := r.Content
|
||||
// A secret written world-readable is a secret. The default differs from an ordinary file's
|
||||
// for that reason alone; an explicit mode still wins, because a module may need its own user
|
||||
// to read it and only the module knows which.
|
||||
fallback := os.FileMode(0o644)
|
||||
if r.Secret() {
|
||||
fallback = 0o600
|
||||
if unseal == nil {
|
||||
// Refused rather than skipped. A machine that quietly does not apply the one resource
|
||||
// carrying a credential is a machine that looks configured and cannot connect.
|
||||
return out, fmt.Errorf(
|
||||
"%s is sealed to this node and this node has no sealing key", r.Path)
|
||||
}
|
||||
opened, err := unseal(r.Sealed)
|
||||
if err != nil {
|
||||
return out, fmt.Errorf("cannot open %s: %w", r.Path, err)
|
||||
}
|
||||
content = string(opened)
|
||||
}
|
||||
out.wrote = digestOf(content)
|
||||
mode, err := modeOf(r.Mode, fallback)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
@@ -260,7 +287,7 @@ func applyFile(r *declaration.File, previous store.Applied) (Outcome, error) {
|
||||
}
|
||||
}
|
||||
|
||||
contentSame := existed && string(existing) == r.Content
|
||||
contentSame := existed && string(existing) == content
|
||||
|
||||
// Whether the machine still holds what this host last put there. When it does not, and the
|
||||
// declaration has not changed either, somebody edited it — and saying so is the whole
|
||||
@@ -272,7 +299,7 @@ func applyFile(r *declaration.File, previous store.Applied) (Outcome, error) {
|
||||
if err := os.MkdirAll(filepath.Dir(r.Path), 0o755); err != nil {
|
||||
return out, err
|
||||
}
|
||||
if err := writeAtomically(r.Path, []byte(r.Content), mode); err != nil {
|
||||
if err := writeAtomically(r.Path, []byte(content), mode); err != nil {
|
||||
return out, err
|
||||
}
|
||||
} else if !modeSame {
|
||||
@@ -286,7 +313,7 @@ func applyFile(r *declaration.File, previous store.Applied) (Outcome, error) {
|
||||
if err != nil {
|
||||
return out, fmt.Errorf("wrote %s and cannot read it back: %w", r.Path, err)
|
||||
}
|
||||
if string(written) != r.Content {
|
||||
if string(written) != content {
|
||||
return out, fmt.Errorf("%s does not contain what was declared after writing it", r.Path)
|
||||
}
|
||||
info, err := os.Stat(r.Path)
|
||||
|
||||
Reference in New Issue
Block a user