0

I'm trying to parametrize the mounting of a drive in adocker container based on the UNC, USERNAME and PASSWORD used by docker-compose during the container creation/run process.

The password has some funky characters and seems to only partially injected (missing some letters at the end). I tried without using variables and with plan text and the result was the same.

Here is the code:

.env used to populate env variables in docker-compose

USERNAME=...
PASS=...
UNC=...

docker-compose.yml which creates the container and includes the env vars

service_name:
        environment:
          - USERNAME=${USERNAME}
          - PASS=${PASS}
          - UNC=${UNC}

mount.sh file which mounts the filesystem in the container using the passed env variables

mount -t cifs $UNC /dest_dir -o user=$USERNAME,password=$PASS --verbose

I've tried escaping every letter, escaping only the special characters, enclosing in single quotes. Pretty much everything I found here

Any ideas?

user3535074
  • 1,268
  • 8
  • 26
  • 48
  • Are spaces around the `=` char in your two config files optional? I ask because you aren't being consistent. Even if the spaces are allowed and ignored you should be consistent. More important you should almost always enclose var expansion in double-quotes in POSIX shells because word splitting happens after var expansion. So instead of `-o user=$USERNAME,password=$PASS` you should do `-o "user=$USERNAME,password=$PASS"`. – Kurtis Rader Aug 27 '18 at 22:27
  • the extra spaces were were types writing the question - they aren't in the actual code. I had no idea about the splitting after variable expansion - I tried -o "user=$USERNAME,password=$PASS" but it still didn't work.. – user3535074 Aug 28 '18 at 09:57
  • The argument to the `-o` option is a comma-separated list. A comma in the password would mess that up. I don't know the details of how mount parses that argument, but other characters might also be problematic. Perhaps there is a way to escape them inside the argument? Also, the Ubuntu man page for mount(8) doesn't even show password as a potential argument for -o. – Jim Janney Sep 01 '18 at 01:46

0 Answers0