Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: trust Arcane's CA roots inside the Rustic container (#4554)
Mczubia4415048ad4a
diff --git a/backend/pkg/libarcane/rustic/run.go b/backend/pkg/libarcane/rustic/run.goindex 1491dfa2f..33c6d3939 100644--- a/backend/pkg/libarcane/rustic/run.go+++ b/backend/pkg/libarcane/rustic/run.go@@ -17,6 +17,7 @@ import ("github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/timeouts""github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/volumehelper"+ "github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/vuln")// Run executes one Rustic command in an ephemeral container built from@@ -68,6 +69,11 @@ func Run(ctx context.Context, dockerClient *client.Client, password string, commtime.Sleep(5 * time.Second)}}()+ if bundle := trustBundle(); len(bundle) > 0 {+ if copyErr := vuln.CopyFilesToContainer(ctx, dockerClient, created.ID, "/", map[string][]byte{trustBundlePath: bundle}); copyErr != nil {+ return "", fmt.Errorf("failed to copy CA certificates into Rustic container: %w", copyErr)+ }+ }if _, containerStartErr := dockerClient.ContainerStart(ctx, created.ID, client.ContainerStartOptions{}); containerStartErr != nil {return "", fmt.Errorf("failed to start Rustic container: %w", containerStartErr)}diff --git a/backend/pkg/libarcane/rustic/trust.go b/backend/pkg/libarcane/rustic/trust.gonew file mode 100644index 000000000..22f65595a--- /dev/null+++ b/backend/pkg/libarcane/rustic/trust.go@@ -0,0 +1,74 @@+package rustic++import (+ "bytes"+ "encoding/pem"+ "os"+ "path/filepath"+)++// trustBundlePath is a path the Rustic binary probes for system roots.+const trustBundlePath = "etc/ssl/certs/ca-certificates.crt"++// Same lookup order as Go's crypto/x509 on Linux.+var (+ defaultCertFiles = []string{+ "/etc/ssl/certs/ca-certificates.crt",+ "/etc/pki/tls/certs/ca-bundle.crt",+ "/etc/ssl/ca-bundle.pem",+ "/etc/pki/tls/cacert.pem",+ "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem",+ "/etc/ssl/cert.pem",+ }+ defaultCertDirs = []string{"/etc/ssl/certs", "/etc/pki/tls/certs"}+)++// trustBundle returns the PEM roots Arcane itself trusts, honoring+// SSL_CERT_FILE and SSL_CERT_DIR, so the Rustic image (which ships no CA+// store) can reach endpoints signed by a private CA.+func trustBundle() []byte {+ files := defaultCertFiles+ if file := os.Getenv("SSL_CERT_FILE"); file != "" {+ files = []string{file}+ }+ dirs := defaultCertDirs+ if dir := os.Getenv("SSL_CERT_DIR"); dir != "" {+ dirs = filepath.SplitList(dir)+ }++ var bundle bytes.Buffer+ seen := map[string]bool{}+ appendCerts := func(data []byte) {+ for {+ var block *pem.Block+ block, data = pem.Decode(data)+ if block == nil {+ return+ }+ if block.Type != "CERTIFICATE" || seen[string(block.Bytes)] {+ continue+ }+ seen[string(block.Bytes)] = true+ _ = pem.Encode(&bundle, block)+ }+ }++ for _, file := range files {+ if data, err := os.ReadFile(file); err == nil {+ appendCerts(data)+ break+ }+ }+ for _, dir := range dirs {+ entries, err := os.ReadDir(dir)+ if err != nil {+ continue+ }+ for _, entry := range entries {+ if data, readErr := os.ReadFile(filepath.Join(dir, entry.Name())); readErr == nil {+ appendCerts(data)+ }+ }+ }+ return bundle.Bytes()+}