“mender-agent.pem is on the R/W storage so that it can be generated if missing or corrupted.”
It should never be in a position where it could be corrupted, and there should be a sane, stable way to generate it with a standalone script. This way, one could generate it on first run, save it to somewhere that is mounted read/write at the time, and then will pretty much forever only ever be read-only. Having the same device pop up again to a Mender server because it had to generate a new private key is unexpected and throws red flags.
While mender -bootstrap
will do this generation, it also attempts to contact the remote server. So, even though the private key was generated, mender -bootstrap
on a non-pre-authorized device will return an error that is indistinguishable from the key failing to be generated. I’ve found that openssl
can be used to verify that a private key is sane, this seems to work well enough.
“Of course I would recommend that you make the R/W filesystem ext4, or some other journalled filesystem, so that corruption is not really possible unless there is a hardware problem.”
In the world of users who pull the plug whenever they feel like it, ext4 is not a bulletproof vest. It can help, but its still very possible to end up in a situation with inconsistencies. Compounded with the fact that more devices are moving to solid state drives that end up doing their own internal FTL and wear leveling. Leaving at-risk data on a partition that is mounted read/write is a silly design choice.
For what its worth, I’ve got a setup working where mender-agent.pem
, mender.conf
(using the /etc location as hard configured .conf, with /data location being able to be field updated for site specific configurations), and server.crt
are all mounted on a small read-only partition that is also hardware locked to be read-only unless some special knock sequence is used.
On first boot, configurations are pulled in from an external device, unformatted partitions are formatted, the above files are copied to the read-only partition with mender-agent.pem
being generated and copied in if it doesn’t already exist. From that point on, every boot, symlinks are touched on the RW /data partition to point to their RO counterparts before mender
is started. This ensures that, even if there was some damage, all files can sanely be accessed. mender
is left to deal with sorting out is state database if it has any inconsistencies.
Another bizarre quirk I found is that mender
wants to remove mender-agent.pem
rather than just writing to it. This means a pre-existing symlink will be clobbered with the real file. So, the key needs to be generated, relocated, and then a symlink created.
I hope this helps anyone else in the same boat as I.