Advertisement
Guest User

Untitled

a guest
May 27th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. #!/bin/sh
  2. ###############################################################################
  3. #
  4. # A script to secure a standalone Zenoss installation.
  5. #
  6. # This script should be run after installing Zenoss, but before starting the
  7. # zenoss service for the first time.
  8. #
  9. # Example steps:
  10. #
  11. # yum -y --nogpgcheck --enablerepo=epel localinstall zenoss_core-4.2.3-1697.el6.x86_64.rpm
  12. # su - zenoss
  13. # sh secure_zenoss.sh
  14. # exit
  15. # service zenoss start
  16. #
  17. ###############################################################################
  18.  
  19. cat << END_OF_CHANGELOG > /dev/null
  20.  
  21. 2013-01-06 Daniel Robbins <drobbins@zenoss.com>
  22.  
  23. * Make etc/ perm fix always enabled (wouldn't enable properly on some builds)
  24.  
  25. 2013-01-04 Chet Luther <cluther@zenoss.com>
  26.  
  27. * Initial revision
  28. * ZEN-4836: Set 0600 permission on all configuration files
  29. * ZEN-4837: Use a randomized secure password everywhere
  30. * ZEN-????: Zenoss install should help secure MySQL root user
  31. * ZEN-1847: Restrict zeneventserver to only listen on 127.0.0.1
  32.  
  33. END_OF_CHANGELOG
  34.  
  35.  
  36. ### Prerequisites #############################################################
  37.  
  38. if [ -z "$ZENHOME" ]
  39. then
  40. echo "ZENHOME not set. Login as the zenoss user before running this script."
  41. exit 1
  42. fi
  43.  
  44. if ! openssl --version >/dev/null 2>&1
  45. then
  46. echo "This script requires the openssl command line tool to be installed."
  47. exit 2
  48. fi
  49.  
  50. ### ZEN-4837: Set 0600 permission on all configuration files (ZEN-4836) #######
  51.  
  52. echo "Restricting permissions on $ZENHOME/etc/*.conf*"
  53. chmod 0600 $ZENHOME/etc/*.conf*
  54.  
  55. ### ZEN-4837: Use a randomized secure password everywhere #####################
  56.  
  57. # Generate a random secure password. Must replace / to make later sed simpler.
  58. RANDOM_PASSWORD=$(openssl rand -base64 15 | sed 's/\//x/')
  59.  
  60. # Ensure that global.conf exists. Otherwise zenglobalconf fails.
  61. if [ ! -f $ZENHOME/etc/global.conf ]
  62. then
  63. cp $ZENHOME/etc/global.conf.example $ZENHOME/etc/global.conf
  64. fi
  65.  
  66. # Update global.conf passwords only if they haven't already been set.
  67. GLOBAL_CONF_PWD_PROPERTIES="
  68. zodb-password
  69. amqppassword
  70. zep-password
  71. hubpassword
  72. "
  73.  
  74. for PWD_PROP in $GLOBAL_CONF_PWD_PROPERTIES
  75. do
  76. # To set properties that don't exist (i.e. hubpassword)
  77. if ! zenglobalconf -p $PWD_PROP > /dev/null
  78. then
  79. echo "Assigning secure password for global.conf:$PWD_PROP"
  80. zenglobalconf -u $PWD_PROP=$RANDOM_PASSWORD
  81.  
  82. # To set properties that have default value (i.e. everything else)
  83. elif [ "$(zenglobalconf -p $PWD_PROP)" == "zenoss" ]
  84. then
  85. echo "Assigning secure password for global.conf:$PWD_PROP"
  86. zenglobalconf -u $PWD_PROP=$RANDOM_PASSWORD
  87. fi
  88. done
  89.  
  90. # Get the current secure password in case we didn't set it on this run.
  91. RANDOM_PASSWORD=$(zenglobalconf -p hubpassword)
  92.  
  93. # Update hubpasswd only if it hasn't been changed from the default.
  94. if ! grep -q "^admin:${RANDOM_PASSWORD}\$" $ZENHOME/etc/hubpasswd
  95. then
  96. echo "Assigning secure password for hubpassword:admin"
  97. sed -i "s/admin:.*/admin:${RANDOM_PASSWORD}/" $ZENHOME/etc/hubpasswd
  98. fi
  99.  
  100.  
  101. ### ZEN-????: Zenoss install should help secure MySQL root user ###############
  102.  
  103. MYSQL_ADMIN_PASSWORD=$(zenglobalconf -p zodb-admin-password)
  104. if [ -z "$(zenglobalconf -p zodb-admin-password)" ]
  105. then
  106. if mysql -uroot mysql -e "select 1" >/dev/null 2>&1
  107. then
  108. echo "MySQL is configured with a blank root password."
  109.  
  110. if [ -t 1 ]
  111. then
  112. printf "Configure a secure MySQL root password? [Yn]: "
  113. read YESNO
  114.  
  115. if echo "$YESNO" | egrep -iq Y
  116. then
  117. while [ 1 ]
  118. do
  119. printf " Enter new MySQL root password: "
  120. stty -echo ; read MYSQL_ROOT_PASSWORD_1 ; stty echo
  121. echo
  122.  
  123. printf "Confirm new MySQL root password: "
  124. stty -echo ; read MYSQL_ROOT_PASSWORD_2 ; stty echo
  125. echo
  126.  
  127. if [ -z "$MYSQL_ROOT_PASSWORD_1" ]
  128. then
  129. echo "A blank password is not acceptable."
  130. continue
  131. fi
  132.  
  133. if [ "$MYSQL_ROOT_PASSWORD_1" != "$MYSQL_ROOT_PASSWORD_2" ]
  134. then
  135. echo "Passwords don't match. Try again."
  136. continue
  137. fi
  138.  
  139. break
  140. done
  141.  
  142. echo "Changing MySQL root password."
  143. mysqladmin -uroot -h localhost password "$MYSQL_ROOT_PASSWORD_1"
  144.  
  145. for ROOT_PWD_PROP in zodb-admin-password zep-admin-password
  146. do
  147. echo "Assigning MySQL root password for global.conf:$ROOT_PWD_PROP"
  148. zenglobalconf -u $ROOT_PWD_PROP="$MYSQL_ROOT_PASSWORD_1"
  149. done
  150. fi
  151. fi
  152.  
  153. # Using a blank MySQL root password failed.
  154. else
  155. echo "Zenoss needs root MySQL access to create its databases."
  156.  
  157. if [ -t 1 ]
  158. then
  159. printf "Enter the MySQL root user password: "
  160. stty -echo ; read MYSQL_ROOT_PASSWORD ; stty echo
  161. echo
  162.  
  163. for ROOT_PWD_PROP in zodb-admin-password zep-admin-password
  164. do
  165. echo "Assigning MySQL root password for global.conf:$ROOT_PWD_PROP"
  166. zenglobalconf -u $ROOT_PWD_PROP="$MYSQL_ROOT_PASSWORD"
  167. done
  168. fi
  169. fi
  170. fi
  171.  
  172.  
  173. ### ZEN-1847: Restrict zeneventserver to only listen on 127.0.0.1 #############
  174.  
  175. if ! grep -q 'Djetty.host=localhost' ~/.bashrc
  176. then
  177. echo "Forcing zeneventserver to only listen on 127.0.0.1:8084"
  178. echo 'export DEFAULT_ZEP_JVM_ARGS="-Djetty.host=localhost -server"' >> ~/.bashrc
  179. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement