Laravel

Addressing Laravel Homestead MySQL Password Expiration

January 7, 2017 · 3 min read

On November 7th 2016, I was hit with a peculiar issue I've never seen before working in a provisioned Homestead box. The exception:

PDOException in Connector.php line 55:
SQLSTATE[HY000] [1862] Your password has expired. To log in you must change it using a client that supports expired passwords.

Firing up a different vagrant machine, I was greeted with the same problem. This seemed to affect all of the vagrant boxes using version laravel/homestead (virtualbox, 0.3.3).

On the machine, the MySQL version displayed by mysql --version is

mysql  Ver 14.14 Distrib 5.7.9, for Linux (x86_64) using  EditLine wrapper

MySQL 5.7's password expiration policy seemed to point to the culprit.

From MySQL 5.7.4 to 5.7.10, the default default_password_lifetime value is 360 (passwords must be changed approximately once per year). For those versions, be aware that, if you make no changes to the default_password_lifetime variable or to individual user accounts, all user passwords will expire after 360 days, and all user accounts will start running in restricted mode when this happens.

Looking at the list of users with relevant columns shown that the password for the user homestead was set on 2015-11-13 03:50:18.

mysql> select host, user, authentication_string, password_expired, password_last_changed, password_lifetime from mysql.user;
+-----------+-----------+-------------------------------------------+------------------+-----------------------+-------------------+
| host      | user      | authentication_string                     | password_expired | password_last_changed | password_lifetime |
+-----------+-----------+-------------------------------------------+------------------+-----------------------+-------------------+
| localhost | root      | *14E65567ABDB5135D0CFD9A70B3032C179A49EE7 | N                | 2016-11-08 22:28:11   |              NULL |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                | 2015-11-13 03:50:10   |              NULL |
| 0.0.0.0   | root      | *14E65567ABDB5135D0CFD9A70B3032C179A49EE7 | N                | 2015-11-13 03:50:15   |              NULL |
| 0.0.0.0   | homestead | *14E65567ABDB5135D0CFD9A70B3032C179A49EE7 | N                | 2015-11-13 03:50:18   |              NULL |
| %         | homestead | *14E65567ABDB5135D0CFD9A70B3032C179A49EE7 | N                | 2015-11-13 03:50:18   |              NULL |
+-----------+-----------+-------------------------------------------+------------------+-----------------------+-------------------+
5 rows in set (0.00 sec)

Date manipulation in PHP showed that 360 days from 2015-11-13 03:50:18 is 2016-11-07 03:50:18, about the time this started occurring.

It was later that I discovered this pull request didn't make it into branch revert-56-master used to build the 0.3.3 box. It succinctly described the problem at hand.

I saw 4 possible choices for a permanent solution:

  1. Set default_password_lifetime=0 explicitly in /etc/mysql/my.cnf.
  2. Upgrade MySQL to 5.7.11 or higher as the default was changed from 360 to 0.
  3. Create the homestead user with the keywords PASSWORD EXPIRE NEVER to disable password expiration for that user.
  4. All of the above.

Solution

In looking to correct upstream, the pull request was denied with very good reason. It was a ton of work to seemingly get the 5.6 branch up to master and I have absolutely no guarantee that something wasn't broken in the process.

Not being content with abandoning that work, I pushed a vagrant virtualbox image that should continue the 5.6 branch forward for the foreseeable future. There is one major caveat, it requires a patch to Homestead v2 to accommodate the changes introduced.

Steps required to use the image:

  1. Add the new vagrant image: vagrant box add w0rd-driven/homestead.
  2. Add the line box: "w0rd-driven/homestead" in Homestead.yaml to specify a different vagrant box than the default of laravel/homestead.
  3. Add the line "laravel/homestead": "2.0.x-dev" to the require-dev section of composer.json.
  4. Add or update the repositories section of composer.json:
"repositories": [
    {
        "type": "git",
        "url": "https://github.com/w0rd-driven/homestead.git"
    }
],
  1. Run composer update to change to the new composer package.
  2. Rebuild your box using vagrant destroy -f then vagrant up.
  3. Test everything.

I've enabled issues on both forks of settler and homestead. Unfortunately, I don't have VMWare Fusion to build the vmware provider image. If anyone has the capabilities, I would gladly grant the access to push the image.