mirror of
https://github.com/fluxerapp/fluxer.git
synced 2026-11-20 01:01:18 -08:00
fix(rexctl): relabel instance bind mounts for selinux (#4235)
This commit is contained in:
1 parent
234e838dd1
commit
463f87f40c
7 files changed
+48
-18
No files matched your search
@@ -262,15 +262,16 @@ type volumeRef struct {
|
||||
short string
|
||||
full string
|
||||
bind string
|
||||
label string
|
||||
}
|
||||
|
||||
func (v volumeRef) mount(target string, readOnly bool) engine.Mount {
|
||||
return engine.Mount{Volume: v.full, Bind: v.bind, Target: target, ReadOnly: readOnly}
|
||||
return engine.Mount{Volume: v.full, Bind: v.bind, Target: target, ReadOnly: readOnly, SELinux: v.label}
|
||||
}
|
||||
|
||||
func dataVolume(model *types.Project, project string, have []engine.Volume, short string) (volumeRef, bool) {
|
||||
if bind := boundData(model, short); bind != "" {
|
||||
return volumeRef{short: short, bind: bind}, true
|
||||
if bind, label := boundData(model, short); bind != "" {
|
||||
return volumeRef{short: short, bind: bind, label: label}, true
|
||||
}
|
||||
if full, ok := findVolume(have, project, short); ok {
|
||||
return volumeRef{short: short, full: full}, true
|
||||
@@ -278,17 +279,21 @@ func dataVolume(model *types.Project, project string, have []engine.Volume, shor
|
||||
return volumeRef{}, false
|
||||
}
|
||||
|
||||
func boundData(model *types.Project, short string) string {
|
||||
func boundData(model *types.Project, short string) (string, string) {
|
||||
dm, ok := stack.DataMounts[short]
|
||||
if !ok || model == nil {
|
||||
return ""
|
||||
return "", ""
|
||||
}
|
||||
for _, v := range model.Services[dm.Service].Volumes {
|
||||
if v.Type == types.VolumeTypeBind && v.Target == dm.Target && v.Source != "" {
|
||||
return v.Source
|
||||
label := ""
|
||||
if v.Bind != nil {
|
||||
label = v.Bind.SELinux
|
||||
}
|
||||
return v.Source, label
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return "", ""
|
||||
}
|
||||
|
||||
func volumesToCopy(ctx context.Context, inst *instance.Instance, values map[string]string, p *engine.Project, model *types.Project, m *Manifest, scope string, mark bool) ([]volumeRef, error) {
|
||||
|
||||
@@ -122,6 +122,7 @@ type Mount struct {
|
||||
Bind string
|
||||
Target string
|
||||
ReadOnly bool
|
||||
SELinux string
|
||||
}
|
||||
|
||||
type EventStatus string
|
||||
|
||||
@@ -5,6 +5,7 @@ package engine
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/cli"
|
||||
"github.com/compose-spec/compose-go/v2/types"
|
||||
@@ -29,3 +30,21 @@ func BindSources(ctx context.Context, s Spec) ([]string, error) {
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func bindSELinux(v types.ServiceVolumeConfig) string {
|
||||
if v.Bind == nil {
|
||||
return ""
|
||||
}
|
||||
return v.Bind.SELinux
|
||||
}
|
||||
|
||||
func bindSpec(m Mount) string {
|
||||
opts := []string{"rw"}
|
||||
if m.ReadOnly {
|
||||
opts[0] = "ro"
|
||||
}
|
||||
if m.SELinux != "" {
|
||||
opts = append(opts, m.SELinux)
|
||||
}
|
||||
return m.Bind + ":" + m.Target + ":" + strings.Join(opts, ",")
|
||||
}
|
||||
@@ -217,7 +217,12 @@ func (p *Project) Helper(ctx context.Context, o HelperOptions) error {
|
||||
return &Error{Op: "helper", Class: ClassInvalidConfig, Err: errors.New("no image for the helper container")}
|
||||
}
|
||||
mounts := make([]mount.Mount, 0, len(o.Mounts))
|
||||
var binds []string
|
||||
for _, m := range o.Mounts {
|
||||
if m.Bind != "" && m.SELinux != "" {
|
||||
binds = append(binds, bindSpec(m))
|
||||
continue
|
||||
}
|
||||
if m.Bind != "" {
|
||||
mounts = append(mounts, mount.Mount{Type: mount.TypeBind, Source: m.Bind, Target: m.Target, ReadOnly: m.ReadOnly})
|
||||
continue
|
||||
@@ -226,7 +231,7 @@ func (p *Project) Helper(ctx context.Context, o HelperOptions) error {
|
||||
}
|
||||
for attempt := 1; ; attempt++ {
|
||||
out := &deliveredWriter{}
|
||||
err := p.runHelper(ctx, c, image, mounts, o, out)
|
||||
err := p.runHelper(ctx, c, image, mounts, binds, o, out)
|
||||
if attempt == 1 && out.n.Load() == 0 && o.Stdin == nil && errors.Is(err, ErrHelperStalled) {
|
||||
detailf("engine: helper stalled before it sent any output, starting it again")
|
||||
continue
|
||||
@@ -262,7 +267,7 @@ func (d *deliveredWriter) close() {
|
||||
d.mu.Unlock()
|
||||
}
|
||||
|
||||
func (p *Project) runHelper(ctx context.Context, c client.APIClient, image string, mounts []mount.Mount, o HelperOptions, out *deliveredWriter) error {
|
||||
func (p *Project) runHelper(ctx context.Context, c client.APIClient, image string, mounts []mount.Mount, binds []string, o HelperOptions, out *deliveredWriter) error {
|
||||
if err := p.removeHelpers(ctx, c); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -284,7 +289,7 @@ func (p *Project) runHelper(ctx context.Context, c client.APIClient, image strin
|
||||
api.OneoffLabel: "True",
|
||||
},
|
||||
},
|
||||
HostConfig: &container.HostConfig{Mounts: mounts, GroupAdd: o.GroupAdd, NetworkMode: container.NetworkMode(cmp.Or(o.Network, "none")), LogConfig: container.LogConfig{Type: "none"}},
|
||||
HostConfig: &container.HostConfig{Mounts: mounts, Binds: binds, GroupAdd: o.GroupAdd, NetworkMode: container.NetworkMode(cmp.Or(o.Network, "none")), LogConfig: container.LogConfig{Type: "none"}},
|
||||
Name: p.Name + "-rexctl-helper-" + randomID(),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -213,7 +213,7 @@ func (p *Project) HelperFor(service string) HelperOptions {
|
||||
}
|
||||
for _, v := range svc.Volumes {
|
||||
if v.Type == types.VolumeTypeBind && v.Source != "" {
|
||||
o.Mounts = append(o.Mounts, Mount{Bind: v.Source, Target: v.Target, ReadOnly: v.ReadOnly})
|
||||
o.Mounts = append(o.Mounts, Mount{Bind: v.Source, Target: v.Target, ReadOnly: v.ReadOnly, SELinux: bindSELinux(v)})
|
||||
}
|
||||
}
|
||||
return o
|
||||
|
||||
@@ -288,9 +288,9 @@ services:
|
||||
FLUXER_EDGE_TLS_DIRECTIVE: ${FLUXER_EDGE_TLS:+tls ${FLUXER_EDGE_TLS:-}}
|
||||
FLUXER_ADMIN_BASE_PATH: ${FLUXER_ADMIN_BASE_PATH:-/admin}
|
||||
volumes:
|
||||
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
||||
- ./certs:/certs:ro
|
||||
- ./caddy.d:/etc/caddy/conf.d:ro
|
||||
- ./Caddyfile:/etc/caddy/Caddyfile:ro,z
|
||||
- ./certs:/certs:ro,z
|
||||
- ./caddy.d:/etc/caddy/conf.d:ro,z
|
||||
- edge-data:/data
|
||||
- edge-config:/config
|
||||
healthcheck:
|
||||
@@ -548,7 +548,7 @@ services:
|
||||
FLUXER_API_EMBEDDED_WORKER: "${FLUXER_API_EMBEDDED_WORKER:-false}"
|
||||
FLUXER_MEDIA_PROXY_ATTACHMENT_URL_SECRETS_BASE64: ${FLUXER_MEDIA_PROXY_ATTACHMENT_URL_SECRETS_BASE64:-}
|
||||
volumes:
|
||||
- ./ca:/etc/fluxer/ca:ro
|
||||
- ./ca:/etc/fluxer/ca:ro,z
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "bash -c 'exec 3<>/dev/tcp/127.0.0.1/8080 && printf \"GET /_health HTTP/1.0\\r\\nHost: 127.0.0.1\\r\\n\\r\\n\" >&3 && head -n 1 <&3 | grep -q \" 200 \"'"]
|
||||
<<: *fluxer-app-healthcheck
|
||||
@@ -584,7 +584,7 @@ services:
|
||||
FLUXER_WORKER_POSTGRES_SYNCHRONOUS_COMMIT: "${FLUXER_WORKER_POSTGRES_SYNCHRONOUS_COMMIT:-}"
|
||||
FLUXER_MEDIA_PROXY_ATTACHMENT_URL_SECRETS_BASE64: ${FLUXER_MEDIA_PROXY_ATTACHMENT_URL_SECRETS_BASE64:-}
|
||||
volumes:
|
||||
- ./ca:/etc/fluxer/ca:ro
|
||||
- ./ca:/etc/fluxer/ca:ro,z
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "find /tmp/fluxer-worker-heartbeat -newermt '-30 seconds' | grep -q ."]
|
||||
<<: *fluxer-app-healthcheck
|
||||
|
||||
@@ -15,8 +15,8 @@ services:
|
||||
FLUXER_VOICE_EDGE_GLOBAL_OPTIONS: ${FLUXER_VOICE_EDGE_EMAIL:+email ${FLUXER_VOICE_EDGE_EMAIL:-}}
|
||||
FLUXER_VOICE_EDGE_SNI_OPTION: ${FLUXER_VOICE_EDGE_IP:+default_sni ${FLUXER_VOICE_EDGE_IP:-}}
|
||||
volumes:
|
||||
- ./Caddyfile.voice:/etc/caddy/Caddyfile:ro
|
||||
- ./sites.d:/etc/caddy/sites.d:ro
|
||||
- ./Caddyfile.voice:/etc/caddy/Caddyfile:ro,z
|
||||
- ./sites.d:/etc/caddy/sites.d:ro,z
|
||||
- edge-data:/data
|
||||
- edge-config:/config
|
||||
networks:
|
||||
|
||||
Reference in new issue
Block a user