Skip to content

Commit 4b32ebc

Browse files
committed
refactor: simplify trustd/apid rootfs setup
These services run from an empty rootfs, and instead of bind-mounting `/sbin/init` (multi-service binary) into it outside of container startup flow, simply use a container mount to bind the binary into the initially empty rootfs. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent dc98e35 commit 4b32ebc

3 files changed

Lines changed: 2 additions & 11 deletions

File tree

internal/app/machined/pkg/system/services/apid.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func (o *APID) Runner(r runtime.Runtime) (runner.Runner, error) {
180180
// Set the mounts.
181181
mounts := []specs.Mount{
182182
{Type: "bind", Destination: "/etc/ssl", Source: "/etc/ssl", Options: []string{"bind", "ro"}},
183+
{Type: "bind", Destination: "/apid", Source: "/sbin/init", Options: []string{"bind", "ro"}},
183184
{Type: "bind", Destination: filepath.Dir(constants.MachineSocketPath), Source: filepath.Dir(constants.MachineSocketPath), Options: []string{"rbind", "ro"}},
184185
{Type: "bind", Destination: filepath.Dir(constants.APIRuntimeSocketPath), Source: filepath.Dir(constants.APIRuntimeSocketPath), Options: []string{"rbind", "rw"}},
185186
}

internal/app/machined/pkg/system/services/trustd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func (t *Trustd) Runner(r runtime.Runtime) (runner.Runner, error) {
168168
// Set the mounts.
169169
mounts := []specs.Mount{
170170
{Type: "bind", Destination: filepath.Dir(constants.TrustdRuntimeSocketPath), Source: filepath.Dir(constants.TrustdRuntimeSocketPath), Options: []string{"rbind", "ro"}},
171+
{Type: "bind", Destination: "/trustd", Source: "/sbin/init", Options: []string{"bind", "ro"}},
171172
}
172173

173174
mounts = bindMountContainerMarker(mounts)

internal/app/machined/pkg/system/services/utils.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
specs "github.com/opencontainers/runtime-spec/specs-go"
1313

1414
"github.com/siderolabs/talos/internal/pkg/containermode"
15-
mount "github.com/siderolabs/talos/internal/pkg/mount/v3"
1615
"github.com/siderolabs/talos/pkg/machinery/constants"
1716
)
1817

@@ -24,16 +23,6 @@ func prepareRootfs(id string) error {
2423
return fmt.Errorf("failed to create rootfs %q: %w", rootfsPath, err)
2524
}
2625

27-
executablePath := filepath.Join(rootfsPath, id)
28-
29-
if err := os.WriteFile(executablePath, nil, 0o555); err != nil { // r-xr-xr-x, non-root programs should be able to execute & read
30-
return fmt.Errorf("failed to create empty executable %q: %w", executablePath, err)
31-
}
32-
33-
if err := mount.BindReadonly("/sbin/init", executablePath); err != nil {
34-
return fmt.Errorf("failed to create bind mount for %q: %w", executablePath, err)
35-
}
36-
3726
return nil
3827
}
3928

0 commit comments

Comments
 (0)