-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restrict users to their own messages & auto-persist w/ encrypted storage #3
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
55aea84
Restrict users to their own messages
jzombie ef13877
Auto-save on changes and persist data to `data` directory
jzombie 64e75d3
Merge branch 'main' into feature-acl
jzombie c003389
Merge branch 'main' of github.com:jzombie/docker-mqtt-mosquitto-cloud…
jzombie 60434df
Add commented config line
jzombie b330d9b
Encrypted retain (#7)
jzombie 66c2d54
Remove non-utilized entry
jzombie 6fcb399
Fix typo
jzombie 09d72a3
Add additional check for encryption files on host
jzombie 0962ad3
Add check to ensure encryption files are not present in the project d…
jzombie f523e88
Fix incorrect indentation
jzombie d4f2b5e
Fix incorrect indentation
jzombie 1eeb8a5
Add `GOCRYPT_PASSWORD`
jzombie 2748dbd
Fix invalid type
jzombie dfcb352
Add commented-out ports notes
jzombie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.env | ||
data/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Start with an Alpine base image | ||
FROM alpine:latest | ||
|
||
# Install necessary packages including FUSE, Mosquitto, and gocryptfs | ||
RUN apk update && \ | ||
apk add --no-cache \ | ||
bash \ | ||
fuse \ | ||
gocryptfs \ | ||
mosquitto \ | ||
mosquitto-clients \ | ||
shadow | ||
|
||
# Create necessary directories and set permissions | ||
RUN mkdir -p /encrypted /var/lib/mosquitto && \ | ||
chown -R mosquitto:mosquitto /var/lib/mosquitto /encrypted && \ | ||
chmod -R 700 /var/lib/mosquitto && \ | ||
chmod -R 700 /encrypted | ||
|
||
# Ensure mosquitto user has a valid shell | ||
RUN usermod -s /bin/bash mosquitto | ||
|
||
# Copy the Mosquitto configuration files and entrypoint script | ||
COPY mosquitto.conf /mosquitto/config/mosquitto.conf | ||
COPY aclfile /mosquitto/config/aclfile | ||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
# Ensure entrypoint script is executable | ||
RUN chmod +x /entrypoint.sh | ||
|
||
# Expose Mosquitto ports | ||
EXPOSE 1883 9001 | ||
|
||
# Set entrypoint | ||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Only allow messages to be read and written within topics that match the username | ||
pattern readwrite %u/# | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# Ensure GOCRYPT_PASSWORD is set | ||
if [ -z "$GOCRYPT_PASSWORD" ]; then | ||
echo "GOCRYPT_PASSWORD is not set. Exiting." | ||
exit 1 | ||
fi | ||
|
||
# Create /var/lib/mosquitto directory if not exists | ||
mkdir -p /var/lib/mosquitto | ||
|
||
# Adjust permissions for the mosquitto user | ||
chown mosquitto:mosquitto /var/lib/mosquitto /encrypted | ||
|
||
# Initialize or mount the encrypted filesystem as the mosquitto user | ||
su mosquitto -c " | ||
if [ ! -f /encrypted/gocryptfs.conf ]; then | ||
echo \"Initializing encrypted filesystem\" | ||
if [ \"\$(ls -A /encrypted)\" ]; then | ||
echo \"Error: /encrypted directory is not empty. Cannot initialize.\" | ||
exit 1 | ||
fi | ||
echo \"$GOCRYPT_PASSWORD\" | gocryptfs -init /encrypted | ||
fi | ||
|
||
echo \"Mounting encrypted filesystem\" | ||
echo \"$GOCRYPT_PASSWORD\" | gocryptfs /encrypted /var/lib/mosquitto | ||
|
||
# Debug: Check if gocryptfs is mounted | ||
echo \"Checking if gocryptfs is mounted:\" | ||
mount | grep gocryptfs || echo \"gocryptfs is not mounted\" | ||
" | ||
|
||
# Run Mosquitto as the mosquitto user | ||
exec su mosquitto -c "mosquitto -c /mosquitto/config/mosquitto.conf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
listener 1883 | ||
allow_anonymous true | ||
|
||
listener 9001 | ||
protocol websockets | ||
|
||
# Debug logging | ||
# log_type all | ||
|
||
acl_file /mosquitto/config/aclfile | ||
|
||
# Enable persistent storage | ||
persistence true | ||
|
||
# Set the location for the persistence files | ||
persistence_location /var/lib/mosquitto | ||
|
||
# `mosquitto.db` is the default | ||
# persistence_file mosquitto.db | ||
|
||
# If configured with `autosave_on_changes` represents, this represents the total | ||
# number of changes before an autosave. Otherwise, it uses seconds, and defaults | ||
# to 1800 (30 minutes). | ||
autosave_interval 1 | ||
|
||
autosave_on_changes true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what restricts users to their own messages. It is used in combination with the
acl_file /mosquitto/config/aclfile
entry inmosquitto/mosquitto.conf
.