π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
feat: support new env variables to handle custom certificates and security - Support MINIO_CA_PATH - Support MINIO_INSECURE_TLS
Smaug6739268adf4e9dea
diff --git a/backend/app/minio.go b/backend/app/minio.goindex 5fc15344..87408485 100644--- a/backend/app/minio.go+++ b/backend/app/minio.go@@ -4,7 +4,10 @@ import ("alexandrie/pkg/logger""alexandrie/utils""context"+ "crypto/tls"+ "crypto/x509""fmt"+ "net/http""net/url""os""strings"@@ -27,7 +30,50 @@ func MinioConnection() (*minio.Client, *minio.Client, error) {return nil, nil, fmt.Errorf("MINIO NOT CONFIGURED")}- // HTTPS detection+ // ---------------------------------------------------------------------+ // TLS configuration+ // ---------------------------------------------------------------------++ rootCAs, err := x509.SystemCertPool()+ if err != nil {+ rootCAs = x509.NewCertPool()+ }++ if caPath := os.Getenv("MINIO_CA_PATH"); caPath != "" {+ caCert, err := os.ReadFile(caPath)+ if err != nil {+ logger.Error("s3", "Failed to read CA certificate: "+err.Error())+ } else if !rootCAs.AppendCertsFromPEM(caCert) {+ logger.Error("s3", "Provided CA certificate could not be parsed")+ } else {+ logger.Success("s3", "Custom S3 CA certificate loaded")+ }+ }++ insecureTLS := os.Getenv("MINIO_INSECURE_TLS") == "true"++ internalTLSConfig := &tls.Config{+ RootCAs: rootCAs,+ InsecureSkipVerify: insecureTLS,+ }++ publicTLSConfig := &tls.Config{+ RootCAs: rootCAs,+ InsecureSkipVerify: insecureTLS,+ }++ internalTransport := &http.Transport{+ TLSClientConfig: internalTLSConfig,+ }++ publicTransport := &http.Transport{+ TLSClientConfig: publicTLSConfig,+ }++ // ---------------------------------------------------------------------+ // Internal MinIO client+ // ---------------------------------------------------------------------+isSecure := trueif os.Getenv("MINIO_SECURE") != "" && os.Getenv("MINIO_SECURE") != "true" {isSecure = false@@ -35,27 +81,33 @@ func MinioConnection() (*minio.Client, *minio.Client, error) {isSecure = false}- // Initialize minio client object.- minioClient, errInit := minio.New(internalEndpoint, &minio.Options{- Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),- Secure: isSecure,+ minioClient, err := minio.New(internalEndpoint, &minio.Options{+ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),+ Secure: isSecure,+ Transport: internalTransport,})- if errInit != nil {- logger.Error("s3", fmt.Sprintf("Failed to initialize MinIO client: %v", errInit))+ if err != nil {+ logger.Error("s3", fmt.Sprintf("Failed to initialize MinIO client: %v", err))os.Exit(1)}- // Signer client for public URLs+ // ---------------------------------------------------------------------+ // Signer client (public URLs / CDN)+ // ---------------------------------------------------------------------+publicURL, err := url.Parse(publicEndpoint)if err != nil {logger.Error("s3", "CONFIG: MINIO_PUBLIC_URL is not a valid URL")os.Exit(1)}+isPublicSecure := publicURL.Scheme == "https"+signerClient, err := minio.New(publicURL.Host, &minio.Options{Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),Secure: isPublicSecure,BucketLookup: minio.BucketLookupPath,+ Transport: publicTransport,})if err != nil {logger.Error("s3", fmt.Sprintf("Failed to create signer client: %v", err))@@ -63,15 +115,17 @@ func MinioConnection() (*minio.Client, *minio.Client, error) {os.Exit(1)}- // Setup main public bucket for user files (avatars, uploads, etc.)+ // ---------------------------------------------------------------------+ // Buckets setup+ // ---------------------------------------------------------------------+bucketName := os.Getenv("MINIO_BUCKET")setupPublicBucket(ctx, minioClient, bucketName)- // Setup private bucket for backups (only accessible via presigned URLs)backupBucket := utils.GetBackupBucketName()setupPrivateBackupBucket(ctx, minioClient, backupBucket)- return minioClient, signerClient, errInit+ return minioClient, signerClient, nil}// setupPublicBucket creates and configures the main public bucket