Skip to content

SessionVault, a Chrome extension we built and maintain for a client, is on the Chrome Web Store.We built SessionVault, now on the Chrome Web Store.Read how we built it

ThynkDone
← All posts

Linux Basics

Three things on our own server that looked fine and weren't

A certificate tool broken by an unrelated pip install, a mail server handing out a self-signed certificate, and a contact form that thanked people and told nobody.

Mason Akers5 min read

We run our own mail server, our own live chat and this website on one Ubuntu box. It's partly so we have somewhere to try things before we do them for clients, and partly because we like knowing exactly where everything lives.

In October I sat down to do a bit of housekeeping and found three things that had been broken for weeks or months. None of them threw an error anyone would see. The site loaded, mail went out, the chat bubble worked. Everything looked fine.

Here's what was actually going on.

1. Certbot had been dead since September

I only noticed because a certificate on one of our subdomains had expired. That should never happen. Certbot renews certificates a month before they run out, so an expired one means renewal has been failing for at least four weeks.

Running it by hand gave this:

$ sudo certbot renew
AttributeError: module 'OpenSSL.crypto' has no attribute 'X509Extension'

Certbot hadn't changed. It was the Ubuntu package, version 2.9, installed with apt and never touched. What had changed was a Python library it depends on.

Back on 8 September I'd installed mitmproxy with pip to debug something, system-wide, without a virtualenv. Pip pulled in pyOpenSSL 26.2 and cryptography 48 to satisfy mitmproxy, and put them in /usr/local/lib/python3.12/dist-packages. Python checks that folder before the one apt uses, so from that morning on, every time certbot started it loaded the new pyOpenSSL. And pyOpenSSL 26.2 had removed X509Extension, which certbot 2.9 still uses.

So one unrelated pip install quietly broke certificate renewal for the whole server, and the renewal timer kept failing every twelve hours in a log nobody was reading.

The obvious fix would be to downgrade pyOpenSSL. But mitmproxy needs the new one, and the next pip install would just break things again. The real problem is that certbot and my experiments were sharing one Python. So I moved certbot out:

$ sudo apt remove certbot python3-certbot-apache
$ sudo snap install --classic certbot
$ sudo ln -sf /snap/bin/certbot /usr/bin/certbot
$ sudo certbot renew --dry-run

The snap carries its own Python and its own libraries, so nothing I install with pip can reach it. The dry run passed, every certificate renewed, and it has renewed on its own since.

What I took from it: anything that keeps the server alive (certbot, backups, monitoring) shouldn't share a Python with things you install on a whim. And "it's on a timer" isn't the same as "it works". The status table on our homepage now shows how many days each certificate has left, checked from outside the server, so a renewal that stops working shows up weeks before anything expires.

2. The mail server was handing out a self-signed certificate

This one I found while fixing the first.

Our mail runs on mailcow. The webmail at mail.thynkdone.com had a proper Let's Encrypt certificate, so in a browser everything looked right. But mail apps don't talk to port 443. They use 993 for IMAP and 465 or 587 for sending, and those are served by Dovecot and Postfix inside mailcow's containers, not by Apache.

I checked what they were actually presenting:

$ openssl s_client -connect mail.thynkdone.com:993 </dev/null 2>/dev/null | openssl x509 -noout -issuer
issuer=C = DE, L = Willich, O = mailcow, CN = mail.thynkdone.com

That's mailcow's own self-signed certificate, the one it generates on first start. We'd told mailcow not to fetch certificates itself because Apache sits in front of it, and nothing was copying the real certificate into the place Postfix and Dovecot read it from. Webmail looked secure. The mail ports weren't.

Most people would never notice. Our live chat did. Chatwoot pulls emails from the support inbox over IMAP, and it checks certificates properly. Its log had the same line every minute:

certificate verify failed (self-signed certificate)

Every minute, since the inbox was set up in May. Which meant that in five months Chatwoot had not imported a single email sent to our support address. Replies from Chatwoot still went out, but only because certificate checking had been switched off for sending, as a workaround someone (me) had forgotten about.

The fix was a small deploy hook for certbot. When the mail certificate renews, the hook copies it into mailcow's certificate folder, checks the key matches, and reloads Postfix, Dovecot and mailcow's nginx the same way mailcow does it itself. Then it connects to ports 465 and 993 and compares fingerprints, so a copy that didn't take shows up straight away instead of five months later.

After that I turned certificate checking back on everywhere it had been switched off, sent a test email to the support address, and watched it arrive in Chatwoot. First one ever.

3. The contact form said "Message sent" and told nobody

The last one was the most embarrassing, and the simplest.

Our contact form sends a message to the backend, the backend says thanks, the visitor sees "Message sent". Behind that, the backend was meant to forward each message to a Telegram chat.

The Telegram settings were empty. The code saw that, logged a warning, and returned success anyway. So the form thanked the visitor and the message went nowhere.

I found it the boring way: I sent a test message and waited for it to show up, and it didn't. Nothing else would have told me. The visitor sees a thank-you, the server log has a warning nobody reads, and from the outside it looks exactly like a quiet week.

The fix has two parts. The form now emails every message to our support inbox, from a send-only address, with the visitor's address as the reply-to. It lands in Chatwoot like any other email, and replying there goes straight back to them. And if no notification goes out at all, the form now shows an error with our email address instead of a cheerful "Message sent". A form that fails loudly is better than one that lies.

What the three have in common

None of these were hard to fix. Each took an afternoon at most. What made them dangerous was that from the outside nothing looked wrong. The site loaded, mail sent, the form said thanks.

Two habits came out of it that we now apply to client systems too:

  • Test the whole path, not the part you can see. Send the email and check it arrives. Submit the form and check someone gets told. Renew the certificate by hand once in a while.
  • Watch things from outside the box. A timer that fails in a log file is invisible. A status check that turns red isn't.

All three are fixed now, and the checks that would have caught them are running on our homepage.

Need a hand with this?

We build and run this kind of thing for clients every day. Tell us what you are working on.