Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(cloudcp): keep hosted billing lease cache writable

rcourtman4a6da5a2200c
diff --git a/internal/cloudcp/docker/manager.go b/internal/cloudcp/docker/manager.go
index 700571cde6..7676d3a1b5 100644
--- a/internal/cloudcp/docker/manager.go
+++ b/internal/cloudcp/docker/manager.go
@@ -76,8 +76,8 @@ func (m *Manager) CreateAndStart(ctx context.Context, tenantID, tenantDataDir st
if err := m.ensureDaemonReachable(ctx); err != nil {
return "", err
}
- if err := prepareImmutableMountSources(tenantDataDir, tenantRuntimeUID, tenantRuntimeGID); err != nil {
- return "", fmt.Errorf("prepare immutable tenant mounts for %s: %w", tenantID, err)
+ if err := prepareTenantRuntimeMountSources(tenantDataDir, tenantRuntimeUID, tenantRuntimeGID); err != nil {
+ return "", fmt.Errorf("prepare tenant runtime mounts for %s: %w", tenantID, err)
}
labels := TraefikLabels(tenantID, m.cfg.BaseDomain, m.cfg.ContainerPort)
@@ -126,12 +126,19 @@ func (m *Manager) CreateAndStart(ctx context.Context, tenantID, tenantDataDir st
func tenantImmutableOwnershipPaths() []string {
return []string{
- "/etc/pulse/billing.json",
"/etc/pulse/secrets/handoff.key",
"/etc/pulse/.cloud_handoff_key",
}
}
+func tenantRuntimeOwnershipPaths() []string {
+ return []string{
+ "billing.json",
+ filepath.Join("secrets", "handoff.key"),
+ ".cloud_handoff_key",
+ }
+}
+
func tenantEnv(tenantID, baseDomain string) []string {
publicURL := ""
tenantID = strings.TrimSpace(tenantID)
@@ -162,12 +169,6 @@ func tenantMounts(tenantDataDir string) []mount.Mount {
Source: tenantDataDir,
Target: "/etc/pulse",
},
- {
- Type: mount.TypeBind,
- Source: filepath.Join(tenantDataDir, "billing.json"),
- Target: "/etc/pulse/billing.json",
- ReadOnly: true,
- },
{
Type: mount.TypeBind,
Source: filepath.Join(tenantDataDir, "secrets", "handoff.key"),
@@ -183,12 +184,8 @@ func tenantMounts(tenantDataDir string) []mount.Mount {
}
}
-func prepareImmutableMountSources(tenantDataDir string, uid, gid int) error {
- for _, relPath := range []string{
- "billing.json",
- filepath.Join("secrets", "handoff.key"),
- ".cloud_handoff_key",
- } {
+func prepareTenantRuntimeMountSources(tenantDataDir string, uid, gid int) error {
+ for _, relPath := range tenantRuntimeOwnershipPaths() {
path := filepath.Join(tenantDataDir, relPath)
if err := os.Chmod(path, 0o600); err != nil {
return fmt.Errorf("chmod %s: %w", path, err)
diff --git a/internal/cloudcp/docker/manager_test.go b/internal/cloudcp/docker/manager_test.go
index 371730d17a..667c0e3097 100644
--- a/internal/cloudcp/docker/manager_test.go
+++ b/internal/cloudcp/docker/manager_test.go
@@ -14,7 +14,6 @@ func TestTenantImmutableOwnershipPaths(t *testing.T) {
got := tenantImmutableOwnershipPaths()
want := []string{
- "/etc/pulse/billing.json",
"/etc/pulse/secrets/handoff.key",
"/etc/pulse/.cloud_handoff_key",
}
@@ -34,8 +33,8 @@ func TestTenantMountsKeepImmutableFilesReadOnly(t *testing.T) {
tenantDataDir := filepath.Join("/tmp", "tenant-data")
mounts := tenantMounts(tenantDataDir)
- if len(mounts) != 4 {
- t.Fatalf("len(mounts) = %d, want 4", len(mounts))
+ if len(mounts) != 3 {
+ t.Fatalf("len(mounts) = %d, want 3", len(mounts))
}
if mounts[0].Target != "/etc/pulse" {
@@ -58,9 +57,14 @@ func TestTenantMountsKeepImmutableFilesReadOnly(t *testing.T) {
}
}
- checkMount(1, "/etc/pulse/billing.json", filepath.Join(tenantDataDir, "billing.json"))
- checkMount(2, "/etc/pulse/secrets/handoff.key", filepath.Join(tenantDataDir, "secrets", "handoff.key"))
- checkMount(3, "/etc/pulse/.cloud_handoff_key", filepath.Join(tenantDataDir, ".cloud_handoff_key"))
+ for _, mounted := range mounts {
+ if mounted.Target == "/etc/pulse/billing.json" {
+ t.Fatalf("billing.json should be writable through the tenant data mount, got dedicated mount %+v", mounted)
+ }
+ }
+
+ checkMount(1, "/etc/pulse/secrets/handoff.key", filepath.Join(tenantDataDir, "secrets", "handoff.key"))
+ checkMount(2, "/etc/pulse/.cloud_handoff_key", filepath.Join(tenantDataDir, ".cloud_handoff_key"))
}
func TestTenantEnvIncludesImmutableOwnershipContract(t *testing.T) {
@@ -74,8 +78,8 @@ func TestTenantEnvIncludesImmutableOwnershipContract(t *testing.T) {
"PULSE_MULTI_TENANT_ENABLED=true": true,
"PUID=1000": true,
"PGID=1000": true,
- "PULSE_PUBLIC_URL=https://t-example.cloud.pulserelay.pro": true,
- immutableOwnershipPathsEnv + "=/etc/pulse/billing.json:/etc/pulse/secrets/handoff.key:/etc/pulse/.cloud_handoff_key": true,
+ "PULSE_PUBLIC_URL=https://t-example.cloud.pulserelay.pro": true,
+ immutableOwnershipPathsEnv + "=/etc/pulse/secrets/handoff.key:/etc/pulse/.cloud_handoff_key": true,
}
if len(env) != len(want) {
t.Fatalf("len(env) = %d, want %d", len(env), len(want))
@@ -105,7 +109,7 @@ func TestTenantEnvOmitsPublicURLWithoutTenantContext(t *testing.T) {
}
}
-func TestPrepareImmutableMountSourcesAlignsOwnershipAndPermissions(t *testing.T) {
+func TestPrepareTenantRuntimeMountSourcesAlignsOwnershipAndPermissions(t *testing.T) {
t.Parallel()
tenantDataDir := t.TempDir()
@@ -127,8 +131,8 @@ func TestPrepareImmutableMountSourcesAlignsOwnershipAndPermissions(t *testing.T)
uid := os.Getuid()
gid := os.Getgid()
- if err := prepareImmutableMountSources(tenantDataDir, uid, gid); err != nil {
- t.Fatalf("prepareImmutableMountSources: %v", err)
+ if err := prepareTenantRuntimeMountSources(tenantDataDir, uid, gid); err != nil {
+ t.Fatalf("prepareTenantRuntimeMountSources: %v", err)
}
for _, path := range paths {
@@ -189,7 +193,7 @@ func TestCreateAndStartFailsBeforeImmutablePrepWhenDockerUnavailable(t *testing.
if !strings.Contains(err.Error(), "ping docker daemon") {
t.Fatalf("CreateAndStart error = %v, want ping docker daemon failure", err)
}
- if strings.Contains(err.Error(), "prepare immutable tenant mounts") {
+ if strings.Contains(err.Error(), "prepare tenant runtime mounts") {
t.Fatalf("CreateAndStart error = %v, want daemon failure before mount preparation", err)
}
}
diff --git a/scripts/installtests/docker_entrypoint_test.go b/scripts/installtests/docker_entrypoint_test.go
index c0d2ee11ee..ca1450ddf8 100644
--- a/scripts/installtests/docker_entrypoint_test.go
+++ b/scripts/installtests/docker_entrypoint_test.go
@@ -30,11 +30,11 @@ func TestDockerEntrypointSkipsImmutableOwnershipPaths(t *testing.T) {
}
immutablePaths := []string{
- filepath.Join(root, "billing.json"),
filepath.Join(secretsDir, "handoff.key"),
filepath.Join(root, ".cloud_handoff_key"),
}
mutablePaths := []string{
+ filepath.Join(root, "billing.json"),
filepath.Join(root, "system.json"),
filepath.Join(root, ".env"),
}