Skip to content

Commit

Permalink
feat: added support to Docker secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
augustomelo committed Apr 23, 2024
1 parent 1ee037f commit 3ccbc1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ EXPOSE 139 445

ENV USER "samba"
ENV PASS "secret"
ENV PASS_SECRETFILE=/run/secrets/pass
ENV UID 1000
ENV GID 1000
ENV RW true
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ services:
- 445:445
volumes:
- /home/example:/storage
secrets:
- pass
restart: on-failure

secrets:
pass:
file: ./samba_pass.txt
```
Via Docker CLI:
Expand All @@ -46,6 +52,8 @@ docker run -it --rm -p 445:445 -e "USER=samba" -e "PASS=secret" -v "/home/exampl

You can set `UID` and `GID` environment variables to change the user/group id's, and set `RW: false` to make the share read-only.

You can set a different path for the pass file, by changing the variable `PASS_SECRETFILE`. Have in mind that passsing the secret it will override the `PASS` value.

If you need more advanced features, you can modify the [smb.conf](https://github.com/dockur/samba/blob/master/smb.conf) file in this repo, and bind mount it to the container like this:

```yaml
Expand Down
5 changes: 5 additions & 0 deletions samba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ else
fi
fi

# Check if the secret file exists and if its size is greater than zero
if [ -s "$PASS_SECRETFILE" ]; then
PASS=$(cat "$PASS_SECRETFILE")
fi

# Change Samba password
echo -e "$PASS\n$PASS" | smbpasswd -a -c "$config" -s "$USER" > /dev/null || { echo "Failed to change Samba password for $USER"; exit 1; }

Expand Down

0 comments on commit 3ccbc1f

Please sign in to comment.