· Datacenter

I locked myself out of my own cluster

I stopped a cluster service on a hypervisor host during a rename and my SSH key stopped working, because the key file was a link into the filesystem that service provides. What to check before you stop anything your own login depends on.

On April 21 I locked myself out of one of my own hypervisor hosts. I was renaming the node, I stopped a service earlier in the procedure than I should have, and the host stopped accepting my SSH key. The way back in was to carry a keyboard to the machine. The mistake was entirely mine. I stopped a service without asking what else depended on it, and one of the things that depended on it was my own login.

The host is the third machine in my lab, the older one. It runs the same open-source hypervisor as my main host. That hypervisor keeps its cluster configuration in a small database and presents the database to the rest of the system as a filesystem, mounted at a fixed path. A dedicated service provides the mount. While the service runs, the files are there. When it stops, the mount goes away and the directory under it is empty.

Renaming a node means changing that configuration, and the procedure involves stopping the service partway through. I stopped it at the wrong point.

What I did not have in my head was where root's SSH keys live on a host like this. In the default setup, the authorized keys file in root's home directory is a symbolic link, and the link points into the cluster filesystem.

You can see the rest coming. Each time someone logs in, the SSH server reads the file named by its AuthorizedKeysFile setting, which defaults to .ssh/authorized_keys in the user's home directory. On my host that path was a link. When the mount went away the link stayed, pointing at a file that no longer existed. The Linux manual has a name for this: "A symbolic link that refers to a pathname that does not exist is said to be a dangling link." The SSH server was running normally. It looked for my key, found no file to compare against, and refused me.

I had no other remote way in. I wrote in April that machines in this class have no management controller, so when one stops responding, somebody has to walk over to it. I wrote that sentence one week after doing the walking. In May I wrote a whole post about building a way back in before you lock anything down, and I will admit now that it came from recent experience.

At the console, with a keyboard plugged in, I could put it right. Getting there was the cost, and at a remote site it would have been a drive.

How stopping one service removed my SSH login
  1. I stop the cluster serviceDuring a node rename, earlier in the procedure than I should have.
  2. The mount goes awayThe service provides the mount. Without it the directory is empty.
  3. The key file link danglesRoot's authorized keys file is a symbolic link into that filesystem.
  4. The SSH server refuses my keyIt runs normally and finds no file to compare my key against.
  5. I walk to the machineThe host has no management controller, so the fix needs a keyboard.

Before stopping that service I now replace the link with an ordinary copy of the key file.

Here is what I do now before stopping that service on either hypervisor host.

  1. Copy the real key file out of the cluster filesystem to an ordinary file beside the link.
  2. Remove the link and move the copy into its place.
  3. Set the file so that only its owner can read and write it. The SSH server's StrictModes option, on by default, checks "file modes and ownership of the user's files and home directory before accepting login," and a key file with loose permissions is refused.
  4. Do the maintenance.
  5. When the service is running again, delete the ordinary file and put the link back, so the host returns to its normal arrangement.

The first three steps take less time than reading them does. They turn a dependency on a running service into a plain file on the local disk for the length of the maintenance.

There is a second prerequisite that belongs to the rename specifically. The cluster filesystem has a local mode for working on a single node, and it refuses to start unless the host's name resolves to a real network address. A loopback address does not count. During a rename, name resolution is the very thing you are changing. Put the host's address in the hosts file before you begin, and confirm the name resolves to it.

The key file is the link that hurts, but it may not be the only one. Before stopping any service that provides a mount, list every symbolic link that points into it:

find /root /etc -type l -lname '/path/to/the/mount/*'

Every line of output is a file that disappears when the mount does. Read the list and decide, for each one, whether you need it during the maintenance.

The same failure exists well outside this hypervisor. Anywhere a login depends on something that a service provides, stopping that service can remove the login. Home directories on a network share put every user's key file on the far side of a mount. Accounts that come from a directory service stop resolving when the directory client cannot reach it. Each of those is a reasonable design, and each one is fine until the day the thing you are working on is the thing your login needs.

So before you stop a service on a machine you can only reach over the network, trace your own login first. Find which file the SSH server reads for your account. Check whether it is a link, and where the link finally resolves, with readlink -f. Then check which filesystem the resolved path lives on, and whether that filesystem is a local disk or something a service provides. If any step in that chain passes through the thing you are about to stop, fix that before you touch the service.

The other protection is a scheduled undo. I made this point in the May post: where a platform has no timed rollback, schedule the revert yourself before the change and cancel it afterward. Here that would be a job set to start the service again ten minutes later. Had I done that in April, the mount should have come back without me, and my key with it.

One caveat. A scheduled restart only helps if the service is able to start, and in the middle of a rename it may not be. That is why the local copy of the key comes first and the scheduled undo second. The copy does not depend on anything coming back.

In a datacenter the walk is replaced by the server's management controller, which gives you a console from a separate network. That is the real answer, and it is the one a mini PC does not have. It also has its own version of this question. If the controller's login goes through the same directory service you are about to restart, you have moved the problem up one level and kept it.

Whose problem this was is simple. The hypervisor did what it is built to do. I stopped a service on a machine with no second way in, without checking what my login depended on. I now run the symlink search before any maintenance on those hosts, and I read the output before I type anything else.

Views are my own.