For anyone who has come looking for a solution to a similar problem, here's how I solved it.
Credit to pszafer here: https://bbs.archlinux.org/viewtopic.php?id=191797
So it turns out that indeed it is due to lightdm that ubuntu was disabling the automatic lock. To get around thata I wrote the following script that calls dm-tool to lock the screen, saved in the home directory:
#!/bin/sh
export XDG_SEAT_PATH="/org/freedesktop/DisplayManager/Seat0"
dm-tool lock
Note that you Seat0
might be different for you. You can check that by running
dm-tool list-seats
Then I put this script saved at /etc/systemd/system/dmlock.service
:
[Unit]
Description=DM Lock before sleep
Before=sleep.target
[Service]
ExecStart=/home/path/to/previous/script
[Install]
WantedBy=sleep.target
Then you need to enable the service using
systemctl enable dmlock.service
You can also test if it is working with
systemctl start dmlock.service