This is mainly here so that when this happens to me again, I know what to do about it.
Having spent a while not being able to sign software packages I discovered that when you SSH into OSX, your keychain remains locked. So you have to issue the following command to unlock the user keychain:
security unlock-keychain
You’ll be prompted for your password, after which your keychain will be unlocked and accessible to your scripts as expected.