Skip to content
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

[AMQ-9296] Add support of credentials to the docker image #1050

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assembly/src/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ ENV PATH $PATH:$ACTIVEMQ_HOME/bin
# activemq_dist can point to a directory or a tarball on the local system
ARG activemq_dist=NOT_SET

COPY entrypoint.sh /usr/local/bin/entrypoint.sh

# Install build dependencies and activemq
ADD $activemq_dist $ACTIVEMQ_INSTALL_PATH
RUN set -x && \
cp -r $ACTIVEMQ_INSTALL_PATH/apache-activemq-* $ACTIVEMQ_HOME && \
rm -r $ACTIVEMQ_INSTALL_PATH/apache-activemq-*

EXPOSE 8161 61616 5672 61613 1883 61614
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["activemq", "console"]
7 changes: 7 additions & 0 deletions assembly/src/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,10 @@ docker kill activemq
* ActiveMQ WS connector on `61614`

Edit the `docker-compose.yml` file to edit port settings.

### Environment variables

| Name | Description |
|-------------------|-------------------------------------------------------------------------------|
| ACTIVEMQ_USER | User name to access the broker. If not set no user and password are required. |
| ACTIVEMQ_PASSWORD | Password to access the broker. Only used if `ACTIVEMQ_USER` has been set. |
55 changes: 55 additions & 0 deletions assembly/src/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

# Generate the configuration files according to the environment variables related
# to the security that have been set
configure_security() {
if [ -f "${ACTIVEMQ_HOME}/conf/activemq-security.xml" ]; then
echo "Security settings already configured"
else
echo "Configuring security settings"
read -r -d '' REPLACE << END
<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="$\{activemq.username}" password="$\{activemq.password}"/>
</users>
</simpleAuthenticationPlugin>
</plugins>
</broker>
END
REPLACE=${REPLACE//\//\\\/}
REPLACE=${REPLACE//$\\/$}
REPLACE=$(echo $REPLACE | tr '\n' ' ')
sed "s/<\/broker>/$REPLACE/" ${ACTIVEMQ_HOME}/conf/activemq.xml > ${ACTIVEMQ_HOME}/conf/activemq-security.xml
sed -i "s/credentials.properties/credentials-security.properties/" ${ACTIVEMQ_HOME}/conf/activemq-security.xml

cat > ${ACTIVEMQ_HOME}/conf/credentials-security.properties <<- END
activemq.username=${ACTIVEMQ_USER}
activemq.password=${ACTIVEMQ_PASSWORD}
END
fi
}
if [[ $# -eq 2 ]] && [[ "$1" -eq activemq ]] && [[ "$2" -eq console ]] && [[ -n "${ACTIVEMQ_USER}" ]]; then
configure_security
activemq console xbean:activemq-security.xml
else
exec "$@"
fi