I followed this thread instructions and managed to solve the codesigning issues we had on Sierra. The thing is that after a while we installed Sierra in a new machine and now it doesn't work anymore.
Our application is a node application that forks a process where the signing happens. The strange thing is that if you launch the forked script from Terminal (in a SSH session) it works fine but if you launch the application that forks the process, it doesn't work and the codesigning fails with "code object is not signed at all".
This same application works fine also from SSH on another machine with Sierra that was updated from El Capitan. I really don't know what might be the difference between both machines for this to happen as both have the same versions of Sierra, XCode, codesign, etc but there must be something that's affecting.
Any idea of anything that could be affecting to this strange behaviour? Anything I could try?
Thank you.
Note:
Executing:
security set-key-partition-list -S apple-tool:,apple: -s -k 'password' 'keychain'
from console and then:
codesign -vfs '$IDENTITY' '${PRODUCT}' --keychain 'keychain'
works fine but when launched from inside the node app, it always fails.
For everyone out there in the same situation I've finally after much debugging and looking research that the issue had to do with the fact that we were using PM2 for the node service managemente. By default PM2 Launch Daemon plist is:
But for the process to be able to access the keychains we need to add a SessionCreate key:
Just restart the PM2 service and now it works. For some reason that parameter was already added in old machine.
Thanks to this answer and his author joensson for leading me to the solution.