Skip to content

Commit

Permalink
feat: added support to Docker secrets (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
augustomelo authored Apr 23, 2024
1 parent 1ee037f commit f5720b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ docker run -it --rm -p 445:445 -e "USER=samba" -e "PASS=secret" -v "/home/exampl

You can set the `USER` and `PASS` environment variables to modify the credentials for the share from their defaults (user `samba` with password `secret`).

If you would like to avoid putting the credentials in your compose file in plain text, you can also supply the password via a secret:

```yaml
services:
samba:
..<snip>..
secrets:
- pass

secrets:
pass:
file: ./samba_pass.txt
```
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.

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:
Expand Down
6 changes: 6 additions & 0 deletions samba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -Eeuo pipefail
# Set variables for group and share directory
group="smb"
share="/storage"
secret="/run/secrets/pass"

# Create shared directory
mkdir -p "$share" || { echo "Failed to create directory $share"; exit 1; }
Expand Down Expand Up @@ -70,6 +71,11 @@ else
fi
fi

# Check if the secret file exists and if its size is greater than zero
if [ -s "$secret" ]; then
PASS=$(cat "$secret")
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 f5720b3

Please sign in to comment.