Guest User

vcenter-cert-install-csript

a guest
Mar 11th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 23.42 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #VCSA SSO and vSphere Web Client Configuration Script
  4.  
  5. ##
  6. #   THIS PART ADDED BY BENNY SHTARK
  7. #
  8. #   IMPORTANT!
  9. #   Create "A" record for IP of the server for the HOSTNAME first!
  10. #
  11. #   COPY THIS ENTIRE FOLDER WITH 4 CERTIFICATE FILES TO SOMEWHERE ON VCENTER.
  12. #   THEN RUN FOLLOWING
  13. #  
  14. #   chmod +x chcert.sh
  15. #   ./chcert.sh <server>.example.com 'vmware@localhost' '1server.crt,2inter.crt,3root.crt' 4private.key <server>.example.com
  16. #
  17. #    of course, change replace <server> with the server actual HOSTNAME
  18. #
  19. #
  20.  
  21.  
  22. #CHANGELOG - Version - 2012.10.08-01
  23. # - Fixed logbrowser issue, per http://derek858.blogspot.com/2012/10/vmware-vcenter-51-installation-part-14.html
  24. #CHANGELOG - Version - 2012.10.04-02
  25. # - Fixed a typo in a variable name (again, whoops)
  26. #CHANGELOG - Version - 2012.10.04-01
  27. # - Minor updates to comments and command line output
  28. # - Added toggle variable to disable undesired embedded services or leave them enabled
  29. # - Added code to disable ssh as root
  30. # - Added code to change the root password
  31. # - Added code to set the SSO master password and the admin password (required to successfully add the AD domain as an identity source)
  32. #CHANGELOG - Version - 2012.10.02-02
  33. # - Fixed a typo in a variable name
  34. #CHANGELOG - Version - 2012.10.02-01
  35. # - Added comments in script header
  36. # - Added code to remove dos line feeds from certificate files (typically due to incorrect transfer mode)
  37. # - Added test that exits if the certificate change fails
  38. # - Added test to make sure the private key file exists and was created with rsagen
  39. # - Added test that exits if the the VCSA fails to join Active Directory
  40. # - Added code before each exit to purge the bash history if any passwords are specified at the command line
  41. # - Added code to add the AD domain to SSO as an identity source (sometimes SSO does this on it's own, sometimes it doesn't...)
  42. # CHANGELOG - Version - 2012.10.01-01
  43. # - Initial Release
  44.  
  45. #FEATURES - this script will
  46. # 1. Accept the EULA
  47. # 2. Configure the fully-qualified hostname
  48. # 3. Join Active Directory (if desired)
  49. # 4. Enable the embedded vCenter SSO service
  50. # 5. Replace the self-signed SSL certs with those provided by a CA
  51. # 6. Re-configure the vSphere Web Client and SSO service to function behind a load-balancer
  52. # 7. Disable undesired embedded services (chkconfig <service> off): vcenter, inventory (for use with an external vCenter Server)
  53. # 8. Set the SSO master password and the admin password
  54. # 9. Add the AD domain as an SSO identity source
  55. #10. Set the root password
  56.  
  57. # TODO
  58. # - Configure AD domain as a default identity source
  59. # - Configure SSO service with AD admin group
  60. # - Configure Syslog target
  61. # - Init script to fix hostname and search domain issues
  62. # - Disable additional unnecessary/undesired services - logbrowser? netdumper? syslog-collector?
  63.  
  64. #PREREQUISITES and ASSUMPTIONS
  65. # - Generate a trusted CA certificate for the VCSA. Be sure to include digitalSignature, keyEncipherment, dataEncipherment, serverAuth, and subjectAltName
  66. # - This script requires certificate files for the server, intermediate CAs, and the root CA.
  67. # - Certificate files must be in Base 64-encoded X.509 format. Be sure to use text transfer mode.
  68. # - Configure the load balancer, if one will be used (it must be done before running the script)
  69. # - This script is intended to be run against a VCSA that was just deployed from the OVF.
  70. # - It is assumed that appliance usernames, passwords, services, and ports remain at their defaults.
  71.  
  72. #EXPECTED USAGE
  73. # - Copy this script and the certificate files to the VCSA
  74. # - Login as root
  75. # - chmod +x <scriptname>
  76. # - ./<scriptname> VCSA_HOSTFQDN LOCALOS_ADMIN_PASS CERT_CHAIN CERT_KEY VCENTER_SSO_ALIASFQDN 'AD_PASS' AD_USER AD_DOMAIN 'SSO_MASTER_PASS' 'SSO_ADMIN_PASS'
  77. #
  78. #Required Parameters:
  79. # - VCSA_HOSTFQDN: Fully qualified hostname of the VCSA. i.e. 'hostname.domain.local'
  80. # - LOCALOS_ADMIN_PASS: Password to set for the local root account. Use single quotes around the password. e.g. '\''1mR00t@localos'\'''
  81. # - CERT_CHAIN: Comma-delimited, ordered list of certificate filenames. Files must be in current directory. Provide certificates for: the VCSA, intermediate CA(s), and the root CA. i.e. 'server.crt,intermediate.crt,root.crt'
  82. # - CERT_KEY: Filename containing the private key for the VCSA certificate. i.e. 'rui.key'
  83. # - VCENTER_SSO_ALIASFQDN: Fully-qualified name of the load-balanced alias for the vCenter Single-Sign On service. If no load balancer, just repeat the hostname.fqdn. i.e. 'vcsso.domain.local'
  84. #Optional Parameters:
  85. # - AD_PASS: Password of an Active Directory account that has permissions to join computers to the domain. Be sure to use single quotes around the password. i.e. 'Im@passw0rd.'
  86. # - AD_USER: Username of an Active Directory account that has permissions to join computers to the domain. i.e. 'john.doe'
  87. # - AD_DOMAIN: Domain name in dotted format. i.e. 'domain.local'
  88. # - SSO_MASTER_PASS: Password to set for the SSO master. It is used to recover passwords. DO NOT LOSE THIS PASSWORD. e.g. '1mp0rt@nt'
  89. # - SSO_ADMIN_PASS: Password to set for the SSO admin user. e.g. e.g. '1manSS0@dmin'
  90.  
  91. #CREDITS
  92. # Scripts compiled and modified by:
  93. # Loren Gordon
  94. # lorenATfleet-it.com
  95. #
  96. # Original scripts by:
  97. # William Lam
  98. # www.virtuallyghetto.com
  99. #
  100. # Logbrowser fix by:
  101. # Derek Seaman and Terafirma
  102. # http://derek858.blogspot.com/2012/10/vmware-vcenter-51-installation-part-14.html
  103.  
  104. # User Configurations
  105. VCSA_HOSTFQDN=${1:-UNSET}
  106. LOCALOS_ADMIN_PASS=${2:-UNSET}
  107. CERT_CHAIN=${3:-UNSET} # Format: Comma separated, ordered list of the server, intermediate, and root CA certs in Base 64 encoded X.509 format. i.e. server.crt,intermediate.crt,root.crt
  108. CERT_KEY=${4:-UNSET}
  109. VCENTER_SSO_ALIASFQDN=${5:-UNSET}
  110. AD_PASS=${6:-UNSET}
  111. AD_USER=${7:-UNSET}
  112. AD_DOMAIN=${8:-UNSET} # Format: Dotted domain name. i.e. google.com, dodiis.net, etc
  113. SSO_MASTER_PASS=${9:-UNSET}
  114. SSO_ADMIN_PASS=${10:-UNSET}
  115. LOCALOS_ADMIN_USER=root
  116. VCENTER_SSO_PORT=7444 # 7444 is the default SSO port
  117. LDAP_PROTO=ldaps    # ldaps or ldap
  118. LDAP_PORT=3269      # 389 or 3268 for ldap, 636 or 3269 for ldaps
  119. DISABLE_ROOT_SSH=0  # 1 to disable ssh for root; 0 to leave it enabled
  120. DISABLE_UNDESIRED_SERVICES=0 # 1 to disable undesired services; 0 to leave them enabled
  121.  
  122. ## DO NOT EDIT BEYOND HERE ##
  123.  
  124. VCSA_SHORTNAME=$(echo ${VCSA_HOSTFQDN} | cut -d. -f1)
  125. SSO_SRV=${VCENTER_SSO_ALIASFQDN}:${VCENTER_SSO_PORT}
  126. VI_REGTOOL=/usr/lib/vmware-sso/bin/vi_regtool
  127. CERT_PATH=/root/${VCSA_HOSTFQDN}-certs
  128. SSO_CERT=${CERT_PATH}/${VCENTER_SSO_ALIASFQDN}.crt
  129. VCSA_CERT=${CERT_PATH}/rui.crt
  130. VCSA_CERTKEY=${CERT_PATH}/rui.key
  131. JOIN_AD=0
  132.  
  133. countdown()
  134. {
  135. #This function will pause while counting down from an input number to 0, displaying the decrementing count
  136.   countdown=${1:-15}
  137.   w=${#countdown}
  138.   while [ ${countdown} -gt 0 ]
  139.   do
  140.     sleep 1 &
  141.     printf " %${w}d\r" "$countdown"
  142.     countdown=$(( $countdown - 1 ))
  143.     wait
  144.   done
  145.   printf "\a"
  146. } 2>/dev/null
  147.  
  148. if [ ! "${AD_PASS}" = "UNSET" ]; then JOIN_AD=1; fi
  149.  
  150. echo "Validating parameter count..."
  151. CHECK_PARAMS=0
  152. if [ $# -lt 5 ]; then CHECK_PARAMS=1; fi
  153. if [ $# -gt 5 ] && [ ! $# -eq 10 ]; then CHECK_PARAMS=1; fi
  154. if [ ${CHECK_PARAMS} -eq 1 ]; then
  155.     echo 'ERROR: Incorrect parameter count.'
  156.     echo 'This script requires a minimum of 5 parameters:'
  157.     echo '    $1 is the hostname.f.q.d.n for the vCenter Server Appliance that is being configured. e.g. vcsa.domain.local'
  158.     echo '    $2 is the password to set for the local root account. Use single quotes around the password. e.g. '\''1mR00t@localos'\'''
  159.     echo '    $3 is a comma-delimited, ordered list of certificate filenames that form a complete certificate chain.'
  160.     echo '         The certificates must be in Base 64-encoded X.509 format.'
  161.     echo '         The order must be the server certificate, then the intermediate CA certificate(s), then the root CA certificate.'
  162.     echo '         There can be as many intermediate CA certs as needed to complete the chain.'
  163.     echo '         i.e. '\''server.crt,intermediate1.crt,intermediate2,root.crt'\'''
  164.     echo '    $4 is the filename of the private key for the server certificate. Key must be RSA format.'
  165.     echo '    $5 is the load-balanced alias.f.q.d.n for the vCenter Single-Sign On service. If not behind a load balancer, just repeat the hostname.fqdn'
  166.     echo 'This script accepts another 5 optional parameters. These parameters are only required to join the system to Active Directory:'
  167.     echo '    $6 is the password of the active directory user specified in the next parameter. Use single quotes around the password. e.g. '\''1man3X@mple'\'''
  168.     echo '    $7 is the active directory username that will add the server to Active Directory. e.g. imausername'
  169.     echo '    $8 is the Active Directory domain name in dotted format. e.g. google.com, dodiis.net, etc'
  170.     echo '    $9 is the master password the script will set for the SSO service. It is used to recover passwords. DO NOT LOSE THIS PASSWORD. e.g. '\''1mp0rt@nt'\'''
  171.     echo '    $10 is the password the script will set for the SSO admin user. e.g. e.g. '\''1manSS0@dmin'\'''
  172.     echo 'Exiting...'
  173.     echo "Purging .bash_history file to remove any passwords..."
  174.     cat /dev/null > ~/.bash_history
  175.     exit 1
  176. fi
  177.  
  178. echo "Input parameters:"
  179. echo "   VCSA_HOSTFQDN=${VCSA_HOSTFQDN}"
  180. echo "   LOCALOS_ADMIN_PASS=${LOCALOS_ADMIN_PASS}"
  181. echo "   CERT_CHAIN=${CERT_CHAIN}"
  182. echo "   CERT_KEY=${CERT_KEY}"
  183. echo "   VCENTER_SSO_ALIASFQDN=${VCENTER_SSO_ALIASFQDN}"
  184. echo "   AD_PASS=${AD_PASS}"
  185. echo "   AD_USER=${AD_USER}"
  186. echo "   AD_DOMAIN=${AD_DOMAIN}"
  187. echo "   SSO_MASTER_PASS=${SSO_MASTER_PASS}"
  188. echo "   SSO_ADMIN_PASS=${SSO_ADMIN_PASS}"
  189. echo "   VCENTER_SSO_PORT=${VCENTER_SSO_PORT}"
  190. echo "   LDAP_PROTO=${LDAP_PROTO}"
  191. echo "   LDAP_PORT=${LDAP_PORT}"
  192. echo "Make sure the certificate files listed are in the current directory and all parameter values are correct."
  193. echo "The CERT_CHAIN parameter must be in this order: servercert,intermediateCAcert,rootCAcert."
  194. echo
  195. read -e -p "Is everything ready to proceed [YES|NO]? (NO): " CHECK_VALUES
  196. CHECK_VALUES=${CHECK_VALUES:-NO}
  197.  
  198. if [ ! "${CHECK_VALUES}" = "YES" ]; then
  199.     echo "Exiting due to user response of NO or unrecognized input. Only a YES response will proceed. Please re-run the script when ready."
  200.     echo "Purging .bash_history file to remove any passwords..."
  201.     cat /dev/null > ~/.bash_history
  202.     exit 1
  203. fi
  204.  
  205. echo "Testing parameter values..."
  206. CERT_CHAIN=$(echo ${CERT_CHAIN} | sed 's/,/ /g')
  207. echo "Checking for certificate files: ${CERT_CHAIN}"
  208. for file in ${CERT_CHAIN}
  209. do
  210.     if [ ! -e "${file}" ]; then
  211.         echo "Certificate file not found: ${file}"
  212.         echo "Check input values and make sure file is in the current directory. It is safe to re-run the script at this exit point."
  213.         echo "Purging .bash_history file to remove any passwords..."
  214.         cat /dev/null > ~/.bash_history
  215.         exit 1
  216.     fi
  217. done
  218. echo "Checking for certificate key: ${CERT_KEY}"
  219. if [ ! -e "${CERT_KEY}" ]; then
  220.     echo "Certificate key file not found: ${CERT_KEY}"
  221.     echo "Check input values and make sure file is in the current directory. It is safe to re-run the script at this exit point."
  222.     echo "Purging .bash_history file to remove any passwords..."
  223.     cat /dev/null > ~/.bash_history
  224.     exit 1
  225. fi 
  226. echo "Checking that certificate key was created with rsagen: ${CERT_KEY}"
  227. TEST_KEY=`grep RSA ${CERT_KEY}`
  228. if [ -z "${TEST_KEY}" ]; then
  229.     echo "Certificate key is not RSA format: ${CERT_KEY}"
  230.     echo "Regenerate the key file as an RSA key; then generate a new certificate; then re-run the script."
  231.     echo "Purging .bash_history file to remove any passwords..."
  232.     cat /dev/null > ~/.bash_history
  233.     exit 1
  234. fi 
  235. echo "Parameter tests complete. Continuing..."
  236.  
  237. echo
  238. echo "Accepting EULA ..."
  239. /usr/sbin/vpxd_servicecfg eula accept
  240.  
  241. # NOTE: Upon reboot, one of the VMware init scripts does something strange to the hostname, so it shows up as 'hostname' rather
  242. # than 'hostname.fqdn' in the lighttp UI (port 5480) and upon ssh login.
  243. # Also, the VMware init scripts will re-write /etc/resolv.conf and wipe the DNS search domain.
  244. # No fixes as of yet, but impact appears to be purely cosmetic.
  245. # Perhaps a S99 init script will work around the problem...
  246. echo "Configuring VCSA hostname (${VCSA_HOSTFQDN})..."
  247. echo ${VCSA_HOSTFQDN} > /etc/HOSTNAME
  248. /bin/hostname --file /etc/HOSTNAME
  249. sed -i "s/localhost.localdom localhost/${VCSA_HOSTFQDN} ${VCSA_SHORTNAME}/g" /etc/hosts
  250. IP_ADDR=`ifconfig eth0 | awk '/inet addr:/{print $2}' | awk -F":" '{print $2}'`
  251.  
  252. SEARCH_DOM=`hostname -d`
  253. TESTSEARCH=`grep ${SEARCH_DOM} /etc/resolv.conf`
  254. echo "Configuring DNS search suffix (${SEARCH_DOM})..."
  255. if [ -z "${TESTSEARCH}" ]; then
  256.     echo search ${SEARCH_DOM} >> /etc/resolv.conf
  257. else
  258.     echo "DNS search domain already configured. Skipping..."
  259. fi
  260.  
  261. if [ ${JOIN_AD} -eq 1 ]; then
  262.     echo "Configuring Active Directory ..."
  263.     STATUS_JOINAD=`/usr/sbin/vpxd_servicecfg ad write "${AD_USER}" "${AD_PASS}" "${AD_DOMAIN}"`
  264.     STATUS_JOINAD=`echo ${STATUS_JOINAD} | cut -d= -f2`
  265.     if [ ! ${STATUS_JOINAD} -eq 0 ]; then
  266.         echo "Failed to join Active Directory."
  267.         echo "Command entered: /usr/sbin/vpxd_servicecfg ad write "${AD_USER}" "${AD_PASS}" "${AD_DOMAIN}""
  268.         echo "Exit string: VC_CFG_RESULT=${STATUS_JOINAD}"
  269.         echo "Exit code definition: $(grep ${STATUS_JOINAD} /usr/sbin/vpxd_servicecfg)"
  270.         echo
  271.         echo "Double check the username, password, and domain name; then re-run the script."
  272.         echo "If the script continues failing at this point, re-deploy the VCSA from OVF and try again."
  273.         echo "Purging .bash_history file to remove any passwords..."
  274.         cat /dev/null > ~/.bash_history
  275.         exit 1
  276.     fi
  277.     echo "VCSA joined to AD successfully. Return code is: VC_CFG_RESULT=${STATUS_JOINAD}"
  278.     /opt/likewise/bin/lw-set-default-domain ${AD_DOMAIN}
  279. fi
  280.  
  281. echo
  282. echo "Enabling SSO and vSphere Web Client. This will take several minutes..."
  283. /usr/sbin/vpxd_servicecfg sso write embedded
  284.  
  285. echo "Enabling embedded vCenter service. This is required to start the vCenter server and change the SSL certs successfully..."
  286. /usr/sbin/vpxd_servicecfg db write embedded
  287.  
  288. echo "Starting vCenter service. This service must be started once to change the SSL certs successfully..."
  289. service vmware-vpxd start
  290.  
  291. echo "Stopping services to update certificates..."
  292. echo "Running 'service vmware-vpxd stop'"
  293. service vmware-vpxd stop
  294. echo "Running 'service vmware-sso stop'"
  295. service vmware-sso stop
  296.  
  297. echo
  298. ### Create .crt chain
  299. mkdir ${CERT_PATH}
  300. cat /dev/null > ${VCSA_CERT} #Make sure the cert chain starts with an empty file
  301. echo "Creating the server certificate chain with certificate files: ${CERT_CHAIN}"
  302. for file in ${CERT_CHAIN}
  303. do
  304.     #Remove line feeds from incorrect transfer mode and append the cert to the chain file
  305.     awk '{sub (/\r$/,"");print}' ${file} >> ${VCSA_CERT}
  306. done
  307.  
  308. cp ${CERT_KEY} ${VCSA_CERTKEY} #Copy the key file to the expected location
  309.  
  310. echo "Saving self-signed root CA SSO certificate to /etc/ssl/certs/SSO-STS-Root.pem..."
  311. cp /etc/ssl/certs/Embedded-SSO-Server-Root-CA.pem /etc/ssl/certs/SSO-STS-Root.pem
  312.  
  313. echo "Updating the SSL certficates. This will take a minute or so..."
  314. STATUS_CERTCHANGE=`/usr/sbin/vpxd_servicecfg certificate change ${VCSA_CERT} ${VCSA_CERTKEY}`
  315. STATUS_CERTCHANGE=`echo ${STATUS_CERTCHANGE} | cut -d= -f2`
  316. if [ ! ${STATUS_CERTCHANGE} -eq 0 ]; then
  317.     echo "Certificate change was unsuccessful."
  318.     echo "Command entered: /usr/sbin/vpxd_servicecfg certificate change ${VCSA_CERT} ${VCSA_CERTKEY}"
  319.     echo "Exit string: VC_CFG_RESULT=${STATUS_CERTCHANGE}"
  320.     echo "Exit code definition: $(grep ${STATUS_CERTCHANGE} /usr/sbin/vpxd_servicecfg)"
  321.     echo
  322.     echo "Double check the certificates and the certificate order; then re-run the script."
  323.     echo "Certificate order must be: server.crt,intermediateCA2.crt, intermediateCA1.crt, rootCA.crt"
  324.     echo "If the script continues failing at this point, re-deploy the VCSA from OVF and try again."
  325.     echo "Purging .bash_history file to remove any passwords..."
  326.     cat /dev/null > ~/.bash_history
  327.     exit 1
  328. fi
  329. echo "Certificate change successful. Return code is: VC_CFG_RESULT=${STATUS_CERTCHANGE}"
  330.  
  331. echo
  332. echo "Starting services to complete certificate change..."
  333. service vmware-vpxd start
  334. service vmware-sso start
  335. service vami-lighttp restart
  336. service vsphere-client restart
  337.  
  338. echo "Sleeping 40 seconds to let the vSphere Web Client initialize..."
  339. countdown 40
  340.  
  341. echo
  342. echo "Setting root password..."
  343. echo "${LOCALOS_ADMIN_PASS}" | passwd --stdin ${LOCALOS_ADMIN_USER}
  344.  
  345. ${VI_REGTOOL} listServices https://${VCSA_HOSTFQDN}:${VCENTER_SSO_PORT}/lookupservice/sdk > /tmp/localservices
  346.  
  347. echo
  348. echo "Re-configuring SSO to use load-balanced alias..."
  349. #Build the properties files, per VMware KB2033588
  350. cat > /tmp/sts.properties << ENDSTS
  351. [service]
  352. friendlyName=Security Token Service at ${VCENTER_SSO_ALIASFQDN}
  353. version=1.0
  354. type=urn:sso:sts
  355. description=The Security Token Service of the Single Sign On server
  356.  
  357. [endpoint0]
  358. uri=https://${SSO_SRV}/ims/STSService
  359. ssl=${SSO_CERT}
  360. protocol=wsTrust
  361. ENDSTS
  362. cat > /tmp/gc.properties << ENDGC
  363. [service]
  364. friendlyName=SSO Group Check Service at ${VCENTER_SSO_ALIASFQDN}
  365. version=1.0
  366. type=urn:sso:groupcheck
  367. description=The Group Check interface of the Single Sign On server
  368.  
  369. [endpoint0]
  370. uri=https://${SSO_SRV}/sso-adminserver/sdk
  371. ssl=${SSO_CERT}
  372. protocol=vmomi
  373. ENDGC
  374. cat > /tmp/admin.properties << ENDADMIN
  375. [service]
  376. friendlyName=SSO Administration Service at ${VCENTER_SSO_ALIASFQDN}
  377. version=1.0
  378. type=urn:sso:admin
  379. description=The Administration Service of the Single Sign On server
  380.  
  381. [endpoint0]
  382. uri=https://${SSO_SRV}/sso-adminserver/sdk
  383. ssl=${SSO_CERT}
  384. protocol=vmomi
  385. ENDADMIN
  386.  
  387. #Write files containing the SSO Service IDs
  388. grep -B2 type=urn:sso:sts /tmp/localservices | grep serviceId | cut -d= -f2 > /tmp/sts.id
  389. grep -B2 type=urn:sso:groupcheck /tmp/localservices | grep serviceId | cut -d= -f2 > /tmp/gc.id
  390. grep -B2 type=urn:sso:admin /tmp/localservices | grep serviceId | cut -d= -f2 > /tmp/admin.id
  391.  
  392. #Get SSL certificate for ${SSO_SRV}
  393. echo "Retrieving ${SSO_SRV} SSL Certificate"
  394. echo "" | openssl s_client -connect ${SSO_SRV} 2> /dev/null 1> /tmp/cert
  395.  
  396. echo "Storing ${SSO_SRV} SSL Certificate in ${SSO_CERT}"
  397. openssl x509 -in /tmp/cert > ${SSO_CERT}
  398.  
  399. echo "Adding Lookup Service URL to /etc/vmware/ls_url.txt & /etc/vmware-sso/ls_url.txt"
  400. cp /etc/vmware/ls_url.txt /etc/vmware/ls_url.txt.bak
  401. cp /etc/vmware-sso/ls_url.txt /etc/vmware-sso/ls_url.txt.bak
  402. echo "https://${SSO_SRV}/lookupservice/sdk" > /etc/vmware/ls_url.txt
  403. echo "https://${SSO_SRV}/lookupservice/sdk" > /etc/vmware-sso/ls_url.txt
  404.  
  405. #Update the SSO services
  406. echo "Updating SSO services...(this won't work behind a load balancer if the SSL certs didn't update successfully)"
  407. ${VI_REGTOOL} updateService -d https://${VCSA_HOSTFQDN}:${VCENTER_SSO_PORT}/lookupservice/sdk -u ${LOCALOS_ADMIN_USER} -p ${LOCALOS_ADMIN_PASS} -si /tmp/sts.id -ip /tmp/sts.properties
  408. ${VI_REGTOOL} updateService -d https://${VCSA_HOSTFQDN}:${VCENTER_SSO_PORT}/lookupservice/sdk -u ${LOCALOS_ADMIN_USER} -p ${LOCALOS_ADMIN_PASS} -si /tmp/gc.id -ip /tmp/gc.properties
  409. ${VI_REGTOOL} updateService -d https://${VCSA_HOSTFQDN}:${VCENTER_SSO_PORT}/lookupservice/sdk -u ${LOCALOS_ADMIN_USER} -p ${LOCALOS_ADMIN_PASS} -si /tmp/admin.id -ip /tmp/admin.properties
  410.  
  411. #Fix the logbrowser service
  412. #Internally, it seems the logbrowser service needs to trust the self-signed certificate for some yet-unknown reason
  413. echo
  414. echo "Repointing the logbrowser service to the saved self-signed certificate..."
  415. sed -i.bak 's/.*sso-certs=.*/sso-certs=\/etc\/ssl\/certs\/SSO-STS-Root.pem/' /usr/lib/vmware-logbrowser/conf/logbrowser.properties
  416. service vmware-logbrowser restart
  417.  
  418. #####
  419. #Next section stops, disables, and unregisters the undesired local services and solution users
  420. #If the local vpxd service is stopped but not unregistered, there will be an error when logging into the web client
  421. #####
  422. if [ ${DISABLE_UNDESIRED_SERVICES} -eq 1 ]; then
  423.     echo
  424.     echo "Disabling undesired services..."
  425.     echo "Running 'service vmware-vpxd stop'"
  426.     service vmware-vpxd stop
  427.  
  428.     echo "Disabling the vCenter service with 'chkconfig vmware-vpxd off'"
  429.     chkconfig vmware-vpxd off
  430.  
  431.     echo "Removing local vpxd solution user..."
  432.     VPXD_USER=$(grep ownerId=vpxd /tmp/localservices | cut -d= -f2 | cut -d@ -f1)
  433.     ${VI_REGTOOL} unregisterSolution -d https://${SSO_SRV}/lookupservice/sdk -u ${LOCALOS_ADMIN_USER} -p ${LOCALOS_ADMIN_PASS} -su ${VPXD_USER}
  434.  
  435.     echo "Removing local vpxd service registration..."
  436.     grep -B1 serviceName="vpxd" /tmp/localservices | grep serviceId | cut -d= -f2 > /tmp/vpxd.id
  437.     ${VI_REGTOOL} unregisterService -d https://${SSO_SRV}/lookupservice/sdk -u ${LOCALOS_ADMIN_USER} -p ${LOCALOS_ADMIN_PASS} -si /tmp/vpxd.id
  438.     rm /tmp/vpxd.id
  439.  
  440.     echo "Running 'service vmware-inventoryservice stop'"
  441.     service vmware-inventoryservice stop
  442.  
  443.     echo "Disabling the Inventory service with 'chkconfig vmware-inventoryservice off'"
  444.     chkconfig vmware-inventoryservice off
  445. fi
  446. ####
  447.  
  448. #
  449. # Add AD domain as an SSO identity source
  450. # Command may fail if there are certificate or SSL problems with the DC
  451. #
  452. if [ ${JOIN_AD} -eq 1 ]; then
  453.     echo
  454.     echo "Resetting the SSO master password..."
  455.     source /etc/vmware-sso/keys/recovery.cfg
  456.     /usr/lib/vmware-sso/utils/ssowrench manage-secrets -a change -u "${SSO_RECOVERY_USERNAME}" -p "${SSO_RECOVERY_PASSWORD}" -N "${SSO_MASTER_PASS}"
  457.  
  458.     echo "Resetting the SSO admin password..."
  459.     /usr/lib/vmware-sso/utils/ssowrench reset-admin-password -u admin -p "${SSO_ADMIN_PASS}" -m "${SSO_MASTER_PASS}"
  460.    
  461.     echo "Attempting to identify two domain controllers..."
  462.     DC1=`dig any _gc._tcp.${AD_DOMAIN} | grep -A2 ";; ADDITIONAL" | grep IN | awk -F". " 'NR==1{print $1}'`
  463.     DC2=`dig any _gc._tcp.${AD_DOMAIN} | grep -A2 ";; ADDITIONAL" | grep IN | awk -F". " 'NR==2{print $1}'`
  464.     AD_ALIAS=`/opt/likewise/bin/lw-get-status |awk '/Netbios name:/{print $3}'`
  465.     if [ ! -z "${DC1}" ] && [ ! -z "${DC2}" ]; then
  466.         echo "Found ${DC1} and ${DC2}."
  467.         echo "Attempting to add ${AD_DOMAIN} as an SSO identity source..."
  468.         echo "Running command: /usr/lib/vmware-sso/utils/ssowrench manage-identity-sources -a create -u admin -p ${SSO_ADMIN_PASS} -S -X -r ${LDAP_PROTO}://${DC1}:${LDAP_PORT} -f ${LDAP_PROTO}://${DC2}:${LDAP_PORT} -L ${AD_USER}@${AD_DOMAIN} -P ${AD_PASS} -d ${AD_DOMAIN} -l ${AD_ALIAS} --use-gssapi"
  469.         /usr/lib/vmware-sso/utils/ssowrench manage-identity-sources -a create -u admin -p "${SSO_ADMIN_PASS}" -S -X -r ${LDAP_PROTO}://${DC1}:${LDAP_PORT} -f ${LDAP_PROTO}://${DC2}:${LDAP_PORT} -L ${AD_USER}@${AD_DOMAIN} -P "${AD_PASS}" -d ${AD_DOMAIN} -l ${AD_ALIAS} --use-gssapi
  470.         echo
  471.         echo "Sometimes there's a problem with the VCSA when adding the domain as an identity source. "
  472.         echo "If there is an error message, try adding the identity source manually via the vSphere Web Client."
  473.         echo "If that fails, try resetting the computer account in active directory and re-deploying the VCSA."
  474.     else
  475.         echo "Couldn't identify domain controllers. Manually add the domain as an SSO identity source."
  476.     fi
  477. fi
  478.  
  479. if [ "${DISABLE_ROOT_SSH}" -eq 1 ]; then
  480.     echo
  481.     echo "Disabling ssh as root..."
  482.     sed -i.bak 's/.*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
  483.     service sshd restart
  484. fi
  485.  
  486. #Purge passwords from bash history
  487. #Technically, this shouldn't do anything since the history file is written on exit and this *should* be a newly deployed VCSA... :)"
  488. echo
  489. echo "Purging .bash_history file to remove passwords..."
  490. cat /dev/null > ~/.bash_history
  491.  
  492. echo
  493. echo "VCSA configuration completed. Run 'history -c' to remove "
  494. echo "passwords from the command line history of the current "
  495. echo "shell session or they will be written to the history file. "
  496. echo "Then run 'reboot' to restart the VCSA."
Add Comment
Please, Sign In to add comment