Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
   Merge AuthSource changes.
  • Loading branch information
coldfire84 committed Jan 16, 2020
1 parent 44f274e commit 1b27996
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
25 changes: 20 additions & 5 deletions backends/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Mongo struct {
Password string
SaltEncoding string
DBName string
AuthSource string
UsersCollection string
AclsCollection string
Conn *mongo.Client
Expand Down Expand Up @@ -51,6 +52,7 @@ func NewMongo(authOpts map[string]string, logLevel log.Level) (Mongo, error) {
Username: "",
Password: "",
DBName: "mosquitto",
AuthSource: "",
UsersCollection: "users",
AclsCollection: "acls",
}
Expand Down Expand Up @@ -81,6 +83,10 @@ func NewMongo(authOpts map[string]string, logLevel log.Level) (Mongo, error) {
m.DBName = mongoDBName
}

if mongoAuthSource, ok := authOpts["mongo_authsource"]; ok {
m.AuthSource = mongoAuthSource
}

if usersCollection, ok := authOpts["mongo_users"]; ok {
m.UsersCollection = usersCollection
}
Expand All @@ -99,11 +105,20 @@ func NewMongo(authOpts map[string]string, logLevel log.Level) (Mongo, error) {
opts.ApplyURI(addr)

if m.Username != "" && m.Password != "" {
opts.Auth = &options.Credential{
AuthSource: m.DBName,
Username: m.Username,
Password: m.Password,
PasswordSet: true,
if m.AuthSource != "" {
opts.Auth = &options.Credential{
AuthSource: m.AuthSource,
Username: m.Username,
Password: m.Password,
PasswordSet: true,
}
} else {
opts.Auth = &options.Credential{
AuthSource: m.DBName,
Username: m.Username,
Password: m.Password,
PasswordSet: true,
}
}
}

Expand Down
27 changes: 13 additions & 14 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ FROM debian:stable-slim as builder

#Set mosquitto and plugin versions.
#Change them for your needs.
ENV MOSQUITTO_VERSION=1.6.3
ENV PLUGIN_VERSION=0.5.0
ENV GO_VERSION=1.12.6
ENV MOSQUITTO_VERSION=1.6.8
ENV GO_VERSION=1.13.6

WORKDIR /app

Expand All @@ -24,15 +23,14 @@ RUN cd mosquitto-${MOSQUITTO_VERSION} && make WITH_WEBSOCKETS=yes && make instal
RUN wget https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
RUN export PATH=$PATH:/usr/local/go/bin && go version && rm go${GO_VERSION}.linux-amd64.tar.gz

#Get the plugin.
RUN wget https://github.com/iegomez/mosquitto-go-auth/archive/${PLUGIN_VERSION}.tar.gz \
&& ls -l \
&& tar xvf *.tar.gz --strip-components=1 \
&& rm -Rf go*.tar.gz \
&& ls -l

#Build the plugin.
RUN export PATH=$PATH:/usr/local/go/bin && export CGO_CFLAGS="-I/usr/local/include -fPIC" && export CGO_LDFLAGS="-shared" && make
#Get / build the plugin.
RUN mkdir mosquitto-go-auth && \
cd mosquitto-go-auth && \
git clone https://github.com/iegomez/mosquitto-go-auth.git . && \
export PATH=$PATH:/usr/local/go/bin && \
export CGO_CFLAGS="-I/usr/local/include -fPIC" && \
export CGO_LDFLAGS="-shared" && \
make

#Start from a new image.
FROM debian:stable-slim
Expand All @@ -49,7 +47,8 @@ RUN groupadd mosquitto \

#Copy confs, plugin so and mosquitto binary.
COPY --from=builder /app/mosquitto/ /mosquitto/
COPY --from=builder /app/go-auth.so /mosquitto/go-auth.so
COPY --from=builder /app/mosquitto-go-auth/pw /mosquitto/pw
COPY --from=builder /app/mosquitto-go-auth/go-auth.so /mosquitto/go-auth.so
COPY --from=builder /usr/local/sbin/mosquitto /usr/sbin/mosquitto

#Uncomment to copy your custom confs (change accordingly) directly when building the image.
Expand All @@ -63,4 +62,4 @@ COPY --from=builder /usr/local/sbin/mosquitto /usr/sbin/mosquitto
#Expose tcp and websocket ports as defined at mosquitto.conf (change accordingly).
EXPOSE 1883 1884

ENTRYPOINT ["sh", "-c", "/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf" ]
ENTRYPOINT ["sh", "-c", "/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf" ]

0 comments on commit 1b27996

Please sign in to comment.