Browse code

Merge "Configure an authorized user for the QPID broker"

Jenkins authored on 2014/10/28 12:25:05
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+sasl2-bin # NOPRIME
... ...
@@ -1,3 +1,4 @@
1 1
 qpid-proton-c-devel # NOPRIME
2 2
 python-qpid-proton # NOPRIME
3
+cyrus-sasl-lib # NOPRIME
3 4
 
... ...
@@ -132,39 +132,14 @@ function install_rpc_backend {
132 132
         # Install rabbitmq-server
133 133
         install_package rabbitmq-server
134 134
     elif is_service_enabled qpid; then
135
-        local qpid_conf_file=/etc/qpid/qpidd.conf
136 135
         if is_fedora; then
137 136
             install_package qpid-cpp-server
138
-            if [[ $DISTRO =~ (rhel6) ]]; then
139
-                qpid_conf_file=/etc/qpidd.conf
140
-                # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to
141
-                # be no or you get GSS authentication errors as it
142
-                # attempts to default to this.
143
-                sudo sed -i.bak 's/^auth=yes$/auth=no/' $qpid_conf_file
144
-            fi
145 137
         elif is_ubuntu; then
146 138
             install_package qpidd
147
-            sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
148
-            sudo chmod o+r /etc/qpid/qpidd.sasldb
149 139
         else
150 140
             exit_distro_not_supported "qpid installation"
151 141
         fi
152
-        # If AMQP 1.0 is specified, ensure that the version of the
153
-        # broker can support AMQP 1.0 and configure the queue and
154
-        # topic address patterns used by oslo.messaging.
155
-        if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then
156
-            QPIDD=$(type -p qpidd)
157
-            if ! $QPIDD --help | grep -q "queue-patterns"; then
158
-                exit_distro_not_supported "qpidd with AMQP 1.0 support"
159
-            fi
160
-            if ! grep -q "queue-patterns=exclusive" $qpid_conf_file; then
161
-                cat <<EOF | sudo tee --append $qpid_conf_file
162
-queue-patterns=exclusive
163
-queue-patterns=unicast
164
-topic-patterns=broadcast
165
-EOF
166
-            fi
167
-        fi
142
+        _configure_qpid
168 143
     elif is_service_enabled zeromq; then
169 144
         # NOTE(ewindisch): Redis is not strictly necessary
170 145
         # but there is a matchmaker driver that works
... ...
@@ -240,10 +215,9 @@ function iniset_rpc_backend {
240 240
             iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
241 241
         fi
242 242
         iniset $file $section qpid_hostname ${QPID_HOST:-$SERVICE_HOST}
243
-        if is_ubuntu; then
244
-            QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
243
+        if [ -n "$QPID_USERNAME" ]; then
244
+            iniset $file $section qpid_username $QPID_USERNAME
245 245
             iniset $file $section qpid_password $QPID_PASSWORD
246
-            iniset $file $section qpid_username admin
247 246
         fi
248 247
     elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
249 248
         iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
... ...
@@ -263,6 +237,83 @@ function qpid_is_supported {
263 263
     ( ! is_suse )
264 264
 }
265 265
 
266
+# Set up the various configuration files used by the qpidd broker
267
+function _configure_qpid {
268
+
269
+    # the location of the configuration files have changed since qpidd 0.14
270
+    local qpid_conf_file
271
+    if [ -e /etc/qpid/qpidd.conf ]; then
272
+        qpid_conf_file=/etc/qpid/qpidd.conf
273
+    elif [ -e /etc/qpidd.conf ]; then
274
+        qpid_conf_file=/etc/qpidd.conf
275
+    else
276
+        exit_distro_not_supported "qpidd.conf file not found!"
277
+    fi
278
+
279
+    # force the ACL file to a known location
280
+    local qpid_acl_file=/etc/qpid/qpidd.acl
281
+    if [ ! -e $qpid_acl_file ]; then
282
+        sudo mkdir -p -m 755 `dirname $qpid_acl_file`
283
+        sudo touch $qpid_acl_file
284
+        sudo chmod o+r $qpid_acl_file
285
+    fi
286
+    sudo sed -i.bak '/^acl-file=/d' $qpid_conf_file
287
+    echo "acl-file=$qpid_acl_file" | sudo tee --append $qpid_conf_file
288
+
289
+    sudo sed -i '/^auth=/d' $qpid_conf_file
290
+    if [ -z "$QPID_USERNAME" ]; then
291
+        # no QPID user configured, so disable authentication
292
+        # and access control
293
+        echo "auth=no" | sudo tee --append $qpid_conf_file
294
+        cat <<EOF | sudo tee $qpid_acl_file
295
+acl allow all all
296
+EOF
297
+    else
298
+        # Configure qpidd to use PLAIN authentication, and add
299
+        # QPID_USERNAME to the ACL:
300
+        echo "auth=yes" | sudo tee --append $qpid_conf_file
301
+        if [ -z "$QPID_PASSWORD" ]; then
302
+            read_password QPID_PASSWORD "ENTER A PASSWORD FOR QPID USER $QPID_USERNAME"
303
+        fi
304
+        # Create ACL to allow $QPID_USERNAME full access
305
+        cat <<EOF | sudo tee $qpid_acl_file
306
+group admin ${QPID_USERNAME}@QPID
307
+acl allow admin all
308
+acl deny all all
309
+EOF
310
+        # Add user to SASL database
311
+        if is_ubuntu; then
312
+            install_package sasl2-bin
313
+        elif is_fedora; then
314
+            install_package cyrus-sasl-lib
315
+        fi
316
+        local sasl_conf_file=/etc/sasl2/qpidd.conf
317
+        sudo sed -i.bak '/PLAIN/!s/mech_list: /mech_list: PLAIN /' $sasl_conf_file
318
+        local sasl_db=`sudo grep sasldb_path $sasl_conf_file | cut -f 2 -d ":" | tr -d [:blank:]`
319
+        if [ ! -e $sasl_db ]; then
320
+            sudo mkdir -p -m 755 `dirname $sasl_db`
321
+        fi
322
+        echo $QPID_PASSWORD | sudo saslpasswd2 -c -p -f $sasl_db -u QPID $QPID_USERNAME
323
+        sudo chmod o+r $sasl_db
324
+    fi
325
+
326
+    # If AMQP 1.0 is specified, ensure that the version of the
327
+    # broker can support AMQP 1.0 and configure the queue and
328
+    # topic address patterns used by oslo.messaging.
329
+    if [ "$RPC_MESSAGING_PROTOCOL" == "AMQP1" ]; then
330
+        QPIDD=$(type -p qpidd)
331
+        if ! $QPIDD --help | grep -q "queue-patterns"; then
332
+            exit_distro_not_supported "qpidd with AMQP 1.0 support"
333
+        fi
334
+        if ! grep -q "queue-patterns=exclusive" $qpid_conf_file; then
335
+            cat <<EOF | sudo tee --append $qpid_conf_file
336
+queue-patterns=exclusive
337
+queue-patterns=unicast
338
+topic-patterns=broadcast
339
+EOF
340
+        fi
341
+    fi
342
+}
266 343
 
267 344
 # Restore xtrace
268 345
 $XTRACE