final fix for smb mounting
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 30 Aug 2024 12:28:02 +0000 (14:28 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 30 Aug 2024 12:28:02 +0000 (14:28 +0200)
Dockerfile
music_assistant/server/providers/filesystem_smb/__init__.py

index b2c49dc33819f86d9121766affa144ae0839f22b..7dce44d2202df8cfde0f47c11d7de7dc72b3cb04 100644 (file)
@@ -14,7 +14,7 @@ RUN set -x \
         wget \
         tzdata \
         sox \
-        samba \
+        cifs-utils \
     # install ffmpeg from community repo
     && apk add --no-cache ffmpeg --repository=https://dl-cdn.alpinelinux.org/alpine/v3.20/community \
     # install snapcast from community repo
index 9a7a4c98ad585f195d32fd3734bf0d1b1407e23f..1168f2f1415b1862bd97a52c8e7251865d791b29 100644 (file)
@@ -6,8 +6,6 @@ import os
 import platform
 from typing import TYPE_CHECKING
 
-import aiofiles
-
 from music_assistant.common.helpers.util import get_ip_from_host
 from music_assistant.common.models.config_entries import ConfigEntry, ConfigValueType
 from music_assistant.common.models.enums import ConfigEntryType
@@ -164,14 +162,6 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
         password = self.config.get_value(CONF_PASSWORD)
         share = str(self.config.get_value(CONF_SHARE))
 
-        # somehow alpine doesn't accept the PASSWD env var and passing it in the options string
-        # means we cant support any special characters, so alternative is to use a credentials file
-        creds_file = f"/tmp/{self.instance_id}_smb_creds"  # noqa: S108
-        async with aiofiles.open(creds_file, "w") as _file:
-            await _file.write(f"username={username}\n")
-            if password:
-                await _file.write(f"password={password}\n")
-
         # handle optional subfolder
         subfolder = str(self.config.get_value(CONF_SUBFOLDER))
         if subfolder:
@@ -196,8 +186,17 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
             options = ["rw"]
             if mount_options := str(self.config.get_value(CONF_MOUNT_OPTIONS)):
                 options += mount_options.split(",")
-            options.append(f"credentials={creds_file}")
             options_str = ",".join(options)
+
+            # pass the username+password using (scoped) env variables
+            # to prevent leaking in the process list and special chars supported
+            env_vars = {
+                **os.environ,
+                "USER": username,
+            }
+            if password:
+                env_vars["PASSWD"] = str(password)
+
             mount_cmd = [
                 "mount",
                 "-t",
@@ -215,10 +214,9 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
         self.logger.log(
             VERBOSE_LOG_LEVEL,
             "Using mount command: %s",
-            " ".join([m.replace(str(password), "########") if password else m for m in mount_cmd]),
+            " ".join(mount_cmd),
         )
-        returncode, output = await check_output(*mount_cmd)
-        self.mass.create_task(os.remove, creds_file)
+        returncode, output = await check_output(*mount_cmd, env=env_vars)
         if returncode != 0:
             msg = f"SMB mount failed with error: {output.decode()}"
             raise LoginFailed(msg)