From 35aa7f4246d5775d5f923efa706ec296c927378e Mon Sep 17 00:00:00 2001 From: Augusto Caringi Date: Feb 05 2018 15:59:26 +0000 Subject: Merge branch 'master' into f27 --- diff --git a/Dockerfile b/Dockerfile index d69467c..8d2bb63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM registry.fedoraproject.org/fedora:rawhide +FROM registry.fedoraproject.org/fedora:27 # Cassandra image for Fedora. # @@ -6,9 +6,20 @@ FROM registry.fedoraproject.org/fedora:rawhide # * /var/lib/cassandra/data - Datastore for Cassandra # Environment: -LABEL MAINTAINER "Tomas Repik" +LABEL MAINTAINER "Augusto Caringi" -ENV NAME=cassandra VERSION=0 RELEASE=30 ARCH=x86_64 SUMMARY='Cassandra is an OpenSource database for high-scale application' DESCRIPTION='Cassandra is a partitioned row store. Rows are organized into tables with a required primary key. Partitioning means that Cassandra can distribute your data across multiple machines in an application-transparent matter. Cassandra will automatically re-partition as machines are added/removed from the cluster. Row store means that like relational databases, Cassandra organizes data by rows and columns. The Cassandra Query Language (CQL) is a close relative of SQL.' +ENV NAME=cassandra \ + VERSION=0 \ + RELEASE=31 \ + ARCH=x86_64 \ + SUMMARY="Cassandra is an OpenSource database for high-scale application" \ + DESCRIPTION="Cassandra is a partitioned row store. Rows are organized \ +into tables with a required primary key. Partitioning means that Cassandra can \ +distribute your data across multiple machines in an application-transparent \ +matter. Cassandra will automatically re-partition as machines are \ +added/removed from the cluster. Row store means that like relational \ +databases, Cassandra organizes data by rows and columns. The Cassandra Query \ +Language (CQL) is a close relative of SQL." LABEL summary="$SUMMARY" \ description="$DESCRIPTION" \ @@ -20,14 +31,15 @@ LABEL summary="$SUMMARY" \ usage="docker run cassandra" \ help="help.1" -LABEL io.k8s.description="$SUMMARY" \ - io.k8s.display-name="Cassandra 3.9" \ +LABEL io.k8s.description="$SUMMARY" \ + io.k8s.display-name="Cassandra 3.11" \ io.openshift.expose-services="7199:cassandra" \ io.openshift.tags="database,cassandra,cassandra39" -ENV CASSANDRA_VERSION=3.9 \ +ENV CASSANDRA_VERSION=3.11 \ # Set paths to avoid hard-coding them in scripts. HOME=/var/lib/cassandra \ + CASSANDRA_CONF_DIR=/etc/cassandra/ \ CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/cassandra # 7000: intra-node communication @@ -36,7 +48,7 @@ ENV CASSANDRA_VERSION=3.9 \ # 9042: CQL EXPOSE 7000 7001 7199 9042 -RUN INSTALL_PKGS="cassandra-server cassandra" && \ +RUN INSTALL_PKGS="cassandra-server cassandra jemalloc" && \ dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ dnf clean all diff --git a/root/usr/bin/run-cassandra b/root/usr/bin/run-cassandra index 6e1ea49..6579e02 100755 --- a/root/usr/bin/run-cassandra +++ b/root/usr/bin/run-cassandra @@ -2,18 +2,30 @@ set -o pipefail +echo "Initializing..." + source ${CONTAINER_SCRIPTS_PATH}/common.sh save_env_config_vars -if [ "$CASSANDRA_ADMIN_PASSWORD" ]; then - create_admin_user - turn_authorization_on -# so far this is not working because cassandra-env.sh file is not modifiable (sits in scripts directory) -# turn_on_jmx_authentication -# the admin password is not mandatory yet, just uncomment in case of change -#else -# usage "CASSANDRA_ADMIN_PASSWORD has to be set" +if is_authorization_on; then + echo "Authorization already enabled for this container, not setting new admin password..." +elif test "$(ls -A "$HOME/cassandra" 2> /dev/null)"; then + # If the container is using a not empty provided volume *and* authorization if turned off, + # don't try to set a new CASSANDRA_ADMIN_PASSWORD, just enable authorization + echo "Using a populated data directory, CASSANDRA_ADMIN_PASSWORD already set" + turn_authorization_on + set_password_authenticator +else + if [ "$CASSANDRA_ADMIN_PASSWORD" ]; then + create_admin_user + turn_authorization_on + # so far this is not working because cassandra-env.sh file is not modifiable (sits in scripts directory) + # turn_on_jmx_authentication + # makes the admin password mandatory + else + usage "CASSANDRA_ADMIN_PASSWORD has to be set" + fi fi exec cassandra -f diff --git a/root/usr/share/container-scripts/cassandra/README.md b/root/usr/share/container-scripts/cassandra/README.md index 439e947..89dd74a 100644 --- a/root/usr/share/container-scripts/cassandra/README.md +++ b/root/usr/share/container-scripts/cassandra/README.md @@ -66,26 +66,26 @@ matches the user UID or name which is running inside the container.** Usage ----- -For this, we will assume that you are using the `fedora/cassandra-39` image. +For this, we will assume that you are using the `fedora/cassandra-311` image. If you want to set only the mandatory environment variables and store the database in the `/home/user/database` directory on the host filesystem, execute the following command: ``` -$ docker run -d -v /home/user/database:/var/lib/cassandra/data fedora/cassandra-39 +$ docker run -d -v /home/user/database:/var/lib/cassandra/data fedora/cassandra-311 ``` Ports ----- By default, Cassandra uses 7000 for cluster communication (7001 if SSL is enabled), 9042 for native protocol clients, and 7199 for JMX. The internode communication and native protocol ports are configurable in the Cassandra Configuration File (cassandra.yaml). The JMX port is configurable in cassandra-env.sh (through JVM options). All ports are TCP. - + Documentation ------------- See http://cassandra.apache.org/doc/latest/ - + Requirements ------------ @@ -118,4 +118,4 @@ docker logs See also -------- -The Dockerfile is using a cassandra rpm package from Fedora. More information is found at: https://admin.fedoraproject.org/pkgdb/package/rpms/cassandra/ +The Dockerfile is using a cassandra rpm package from Fedora. More information is found at: https://admin.fedoraproject.org/pkgdb/package/rpms/cassandra/ diff --git a/root/usr/share/container-scripts/cassandra/common.sh b/root/usr/share/container-scripts/cassandra/common.sh index c82f063..7372948 100644 --- a/root/usr/share/container-scripts/cassandra/common.sh +++ b/root/usr/share/container-scripts/cassandra/common.sh @@ -26,7 +26,7 @@ within the container or visit https://github.com/sclorg/cassandra-container/." exit 1 } -# update cassandra config file (cassandra.yaml) based on the environment varibales +# update cassandra config file (cassandra.yaml) based on the environment variables # set by the user function save_env_config_vars() { # check whether the user mounted in his own config file @@ -44,7 +44,13 @@ function save_env_config_vars() { fi # alter the seeds in the config file - sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" + sed -ri 's/(- seeds:).*/\1 "'"$HOSTNAME,$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" + + # alter the rpc_address to allow external CQL client connections + sed -ri 's/(rpc_address:).*/\1 '"$HOSTNAME"'/' "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" + + # alter the listen_address to allow internode communication + sed -ri 's/(listen_address:).*/\1 '"$HOSTNAME"'/' "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" for yaml in \ cluster_name \ @@ -91,7 +97,7 @@ function create_admin_user() { # change the config sed -ri 's/(^authenticator:).*/\1 PasswordAuthenticator/' "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" # echo config changed - + # start cassandra with authentication cassandra >/dev/null & # echo starting server @@ -104,12 +110,14 @@ function create_admin_user() { done # echo admin super user created - # login as admin and drop the default super user + # login as admin and drop the default super user cqlsh $HOSTNAME -u admin -p "$CASSANDRA_ADMIN_PASSWORD" <<< "DROP ROLE cassandra;" >/dev/null # echo cassandra super user dropped # shut the cassandra down - nodetool stopdaemon 2>/dev/null + #nodetool stopdaemon #2>/dev/null + pkill -f 'java.*cassandra' + sleep 3 # echo server stopped # optionaly create a cqlshrc file with the login information @@ -138,6 +146,20 @@ function turn_authorization_on() { # echo config changed } +# set authenticator to PasswordAuthenticator +function set_password_authenticator { + sed -ri 's/(^authenticator:).*/\1 PasswordAuthenticator/' "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" +} + +# check if authorization is on +function is_authorization_on() { + result=`grep authorizer: $CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE|cut -d' ' -f2` + if [ "$result" == "CassandraAuthorizer" ]; then + return 0 + fi + return 1 +} + # turn on the JMX authentication using Cassandra's internal authentication and authorization function turn_on_jmx_authentication() { # disable JMX local