Upgrade VMware ESX from the command line

VMware has some of the worst documentation in the entire industry, so I’m saving here these notes for fellow admins that need to deal with this.

First, you have to identify your current profile

# ssh YOUR_ESX_SERVER
~ # esxcli software profile get
(Updated) HP-ESXi-5.1.0-standard-iso
   Name: HP-ESXi-5.1.0-standard-iso
   Vendor: YOUR_VENDOR
   Creation Time: 2017-11-07T15:24:51
   Modification Time: 2017-11-07T15:25:06
   Stateless Ready: False

With that info you can go on the VMware website (or your vendor website) and download the new release. In my case this is an HP server, so I downloaded VMware-ESXi-5.5.0-Update3-3116895-HP-550.9.4.26-Nov2015-depot.zip from the download page.

Then I loaded the depot file to the ESX server:

# scp VMware-ESXi-*-depot.zip YOUR_ESX_SERVER:/vmfs/volumes/YOUR_VOLUME_NAME/

At this point I shut down all VMs on the server and put it in maintenance mode, then logged back in in console, found out the new profile name and ran the upgrade:

# ssh YOUR_ESX_SERVER
# ~ esxcli software sources profile list -d /vmfs/volumes/YOUR_VOLUME_NAME/VMware-ESXi-5.5.0-Update3-3116895-HP-550.9.4.26-Nov2015-depot.zip
Name                              Vendor           Acceptance Level
--------------------------------  ---------------  ----------------
HP-ESXi-5.5.0-Update3-550.9.4.26  Hewlett-Packard  PartnerSupported

~ # esxcli software profile update -d /vmfs/volumes/YOUR_VOLUME_NAME/VMware-ESXi-5.5.0-Update3-3116895-HP-550.9.4.26-Nov2015-depot.zip -p HP-ESXi-5.5.0-Update3-550.9.4.26
Update Result
  Message: The update completed successfully, but the system needs to be rebooted for the changes to be effective.
  Reboot Required: true

I rebooted the system, as required, and then logged back in to check the updates:

~ # esxcli software profile get
(Updated) HP-ESXi-5.1.0-standard-iso
   Name: (Updated) HP-ESXi-5.1.0-standard-iso
   Vendor: YOUR_VENDOR
   Creation Time: 2017-11-07T15:24:51
   Modification Time: 2017-11-07T15:25:06
   Stateless Ready: False
   Description: 

      2017-11-07T15:24:51.436759+00:00: The following VIBs are
      installed:
        net-bnx2x     2.712.50.v55.6-1OEM.550.0.0.1331820
        ata-pata-amd  0.3.10-3vmw.550.0.0.1331820
        sata-sata-sil24       1.1-1vmw.550.0.0.1331820
[...]

Hopefully nobody out there will have to deal with this, but if you do, I hope I got you covered.

Reference:

Advertisements

How to solve OpenVPN errors after upgrading OpenSSL

I went on upgrading OpenVPN and OpenSSL on an old production system, but after restarting the service, the clients would not connect. There were two different problems a “CRL expired” error and after fixing that a “CRL signature failed” error.

CRL expired

The OpenVPN server logs were reporting:

Mon Nov  6 10:04:22 2017 TCP connection established with [AF_INET]192.168.100.1:19347
Mon Nov  6 10:04:23 2017 192.168.100.1:19347 TLS: Initial packet from [AF_INET]192.168.100.1:19347, sid=150b3618 b004e9a4
Mon Nov  6 10:04:23 2017 192.168.100.1:19347 VERIFY ERROR: depth=0, error=CRL has expired: C=IT, ST=PR, L=Parma, O=domain, OU=domain.eu, CN=user, name=user, emailAddress=info@stardata.it
Mon Nov  6 10:04:23 2017 192.168.100.1:19347 OpenSSL: error:140890B2:SSL routines:SSL3_GET_CLIENT_CERTIFICATE:no certificate returned
Mon Nov  6 10:04:23 2017 192.168.100.1:19347 TLS_ERROR: BIO read tls_read_plaintext error
Mon Nov  6 10:04:23 2017 192.168.100.1:19347 TLS Error: TLS object -> incoming plaintext read error
Mon Nov  6 10:04:23 2017 192.168.100.1:19347 TLS Error: TLS handshake failed
Mon Nov  6 10:04:23 2017 192.168.100.1:19347 Fatal TLS error (check_tls_errors_co), restarting
Mon Nov  6 10:04:23 2017 192.168.100.1:19347 SIGUSR1[soft,tls-error] received, client-instance restarting

This is a common problem on older systems, the culprit is in the OpenSSL configuration used to generate the CRL, that is limited to just 30 days by default.

So, I had to regenerate my CRL after increasing the default_crl_days parameter in the ssl config to 180 (for our use case is more than enough), using:

$ openssl  ca  -gencrl  -keyfile keys/ca.key  \
               -cert keys/ca.crt  -out keys/crl.pem \
               -config easy-rsa/openssl-1.0.0.cnf

CRL signature failed

Due to the vulnerabilities found in MD5, this hashing routine has been disabled by default on modern SSL. Our certificates, though, were still using it, so the new error message (after fixing the CRL), became:

Mon Nov  6 10:14:40 2017 TCP connection established with [AF_INET]192.168.100.1:18463
Mon Nov  6 10:14:41 2017 192.168.100.1:18463 TLS: Initial packet from [AF_INET]192.168.100.1:18463, sid=13fdd1fe 5d82d4d6
Mon Nov  6 10:14:42 2017 192.168.100.1:18463 VERIFY ERROR: depth=0, error=CRL signature failure: C=IT, ST=PR, L=Parma, O=domain, OU=domain.eu, CN=user, name=user, emailAddress=info@stardata.it
Mon Nov  6 10:14:42 2017 192.168.100.1:18463 OpenSSL: error:140890B2:SSL routines:SSL3_GET_CLIENT_CERTIFICATE:no certificate returned
Mon Nov  6 10:14:42 2017 192.168.100.1:18463 TLS_ERROR: BIO read tls_read_plaintext error
Mon Nov  6 10:14:42 2017 192.168.100.1:18463 TLS Error: TLS object -> incoming plaintext read error
Mon Nov  6 10:14:42 2017 192.168.100.1:18463 TLS Error: TLS handshake failed
Mon Nov  6 10:14:42 2017 192.168.100.1:18463 Fatal TLS error (check_tls_errors_co), restarting
Mon Nov  6 10:14:42 2017 192.168.100.1:18463 SIGUSR1[soft,tls-error] received, client-instance restarting

This one was trickier to solve. It turns out that you can re-enable MD5 as a workaround using two environment variables: NSS_HASH_ALG_SUPPORT=+MD5 and OPENSSL_ENABLE_MD5_VERIFY=1. In my case, I just added them to openvpn init script because the system is going to be decommissioned soon.

References

Develop a Jekyll website… without Jekyll

Containers are great for developers: when I’m messing around with code I try to keep everything neatly containerized, so I can just pull my repository on some other machine, run a few scripts and be ready to keep on developing without having to install stuff on the main Operating System.

Jekyll is a nice Static Website Generator, used prominently on GitHub. An already-made Jekyll container exists, but I couldn’t find out how (or even if) you could use it to create a Jekyll website from scratch. So I fired up a generic Ruby container and installed jekyll in it to create the base layout, then I ran the already-made jekyll container to build the website.

$ cat > Gemfile <<EOF
source 'https://rubygems.org'
gem "jekyll"
EOF

$ docker run --rm --volume=$PWD:/usr/src/app -w /usr/src/app -it ruby:latest /bin/bash
[container#1]# bundle install
[...]
Fetching jekyll 3.6.0
Installing jekyll 3.6.0
Bundle complete! 1 Gemfile dependency, 20 gems now installed.
Bundled gems are installed into /usr/local/bundle.
[container#1]# jekyll new test01
[...]
Bundler: Using jekyll 3.6.0
Bundler: Bundle complete! 1 Gemfile dependency, 20 gems now installed.
Bundler: Bundled gems are installed into /usr/local/bundle.
New jekyll site installed in /usr/src/app/test01.
[container#1]# exit
$ ls -l test01
-rw-r--r-- 1 root root  398 ott 14 16:40 404.html
-rw-r--r-- 1 root root  539 ott 14 16:40 about.md
-rw-r--r-- 1 root root 1,7K ott 14 16:40 _config.yml
-rw-r--r-- 1 root root  937 ott 14 16:40 Gemfile
-rw-r--r-- 1 root root  213 ott 14 16:40 index.md
drwxr-xr-x 2 root root 4,0K ott 14 16:40 _posts

Once I had the basic site structure ready, I ran the Jekyll container to build it:

$ cd test01
$ docker run --rm  --volume=$PWD:/srv/jekyll  -it  jekyll/jekyll:latest  jekyll build
Resolving dependencies...
The Gemfile's dependencies are satisfied
Configuration file: /srv/jekyll/_config.yml
            Source: /srv/jekyll
       Destination: /srv/jekyll/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
                    done in 0.292 seconds.
 Auto-regeneration: disabled. Use --watch to enable.
$ ls -lh _site/
-rw-r--r-- 1 velenux velenux 5,5K ott 14 16:44 404.html
drwxr-xr-x 2 velenux velenux 4,0K ott 14 16:44 about
drwxr-xr-x 2 velenux velenux 4,0K ott 14 16:44 assets
-rw-r--r-- 1 velenux velenux 3,7K ott 14 16:44 feed.xml
-rw-r--r-- 1 velenux velenux 5,5K ott 14 16:44 index.html
drwxr-xr-x 3 velenux velenux 4,0K ott 14 16:44 jekyll

So… that’s it, you can now develop your Jekyll website without having Jekyll
installed on your system.

Centralize your logs on the cheap on obsolete systems

This is a tale about what you should never do, but you are often forced to do in this time and age.

I’ll explain the technical solution and then tell the story for some context.

On a recent-ish system, install multitail:

# yum -y --enablerepo=epel install multitail

multitail allows to follow multiple tail or even the output of multiple commands in one single window (or multiple windows handled by ncurses), but it also allows to save the output of those commands to another file. In my case the command line looked like:

multitail --mergeall -D -a all.log \
  -l 'ssh web01 "tail -qF /var/log/apache2/*.log /var/log/apache2/*/*.log"' \
  -l 'ssh web02 "tail -qF /var/log/apache2/*.log /var/log/apache2/*/*.log"'

This would create a file all.log containing the output from tail -qF of Apache logs from web01 and web02.

So, what’s the backstory? Why would I do something like this? Centralized logs are nothing new, right? We have Solutions[tm] for that.

Backstory

Imagine you have a time constraint of “one hour”.

Then imagine you have systems so obsolete that the signing key (valid for 10 years) for their repositories expired.

If I had more time I would try to see if rsyslog was recent enough to have the text-input file module and I would’ve tried to have rsyslog push the logs to a more recent system with logstash/ELK on.

Bonus code

I made a little script to generate the multitail commandline, here, have fun:

#!/bin/bash
HOST_LIST="web01 web02"
LOG_LIST="/var/log/apache2/*.log /var/log/apache2/*/*.log"

CMD_MULTITAIL="multitail --mergeall -D -a all.log"

for target in $HOST_LIST ; do
  CMD_MULTITAIL="$CMD_MULTITAIL -l 'ssh $target \"tail -qF $LOG_LIST\"'"
done

echo $CMD_MULTITAIL

I seriously hope nobody (else) will ever need this, but if you do, I got you covered.

How to use MS SQL Server from PHP 5.x on Linux

Short answer: don’t. It’s a world of pain.

If you really must, keep reading.

Install the required packages

I’ll assume you already have a working webserver and PHP installation, along with the EPEL and Remi repositories.

yum --enablerepo=epel --enablerepo=remi install php-mssql freetds

Make sure the mssql library is loaded

cat /etc/php.d/mssql.ini
; Enable mssql extension module
extension=mssql.so

Configure mssql

In /etc/php.ini make sure these two lines are set like this:

mssql.textlimit = 20971520
mssql.textsize = 20971520

Configure freetds

Edit /etc/freetds.conf to change the text size value and to create a new entry:

[global]
  [...]
  text size = 20971520
[...]
[mssqltest]
  host = 192.168.0.100
  instance = instance_name
  port = 1433
  client charset = UTF-8
  tds version = 8.0
  text size = 20971520

You can omit the instance parameter if you are going to use the default.

Restart Apache and PHP

service httpd configtest && service httpd restart

Test the configuration

Create a simple php script, mssql_test.php:

<?php

$host_db = "mssqltest";  // reference to the name you used in /etc/freetds.conf
$user_db = "your_user";
$pass_db = "your_pass";
$name_db = "your_db_name";

$conn_db = mssql_connect($host_db, $user_db, $pass_db)
  or die("Connection failed to $host_db: " . mssql_get_last_message() . "\n\n");

$dbh     = mssql_select_db($name_db, $conn_db)
  or die("Cannot open DB $name_db: " . mssql_get_last_message() . "\n\n");

echo 'Connected.';

$query_results = mssql_query('SELECT * from YourTable')
  or die ("Cannot run your query: " . mssql_get_last_message() . "\n\n");

$row = mssql_fetch_array($query_results)
  or die ("Cannot fetch row: " . mssql_get_last_message() . "\n\n");

echo "$row\n\n";

mssql_close($link);
?>

References

Ansible: how to skip a specific host or group in a playbook

If you search the Ansible documentation, you’ll probably end up using a when in your playbooks to skip a host.

I found out that it makes more sense to me to skip hosts from the hosts declaration, by prepending them with a !:

---
- name: check on which hosts this would run
  remote_user: root
  hosts: all !bastion
  tasks:
  - name: say hello
    debug:
      msg: "hello {{ ansible_hostname }}"

My hosts file looks like:

[common]
bh[01:02]
ws[01:20]
db[01:03]

[bastion]
bh[01:02]

[ws]
ws[01:20]

[db]
db[01:03]

Running the playbook with the usual commandline:

ansible-playbook -i hosts playbook.yaml

produces the expected result: the debug module is only run on webservers (ws) and databases (db), not on the bastion hosts (bastion).

I hope this will help some other sysadmin out there :)

Firefox Beta PPA on Linux Mint 18.2

I wanted to test out a more recent version of Firefox on Linux Mint 18.2, so I went over to grab the Ubuntu PPA.

I ran the installation commands (as root):

add-apt-repository ppa:mozillateam/firefox-next
apt-get update
apt-get install firefox

But apt wouldn’t update the package, because the default package priorities (check /etc/apt/preferences.d/*.pref) won’t allow the use of Ubuntu packages over Mint packages.

Fair enough, I created a new file /etc/apt/preferences.d/firefox.pref containing:

Package: firefox
Pin: origin ppa.launchpad.net
Pin-Priority: 900

Package: firefox
Pin: release o=Ubuntu
Pin-Priority: 900

And updated to the beta (currently 55.0b12).

Enjoy the 10 fixed bugs and the exciting 127 new bugs to discover!