Is iCloud Keychain safe for storing API keys?
By Maria Otworowska,
What Apple's encryption covers
Apple's iCloud data security overview lists Passwords and Keychain as end-to-end encrypted in both Standard Data Protection and Advanced Data Protection. That's not true of everything in iCloud: under Standard Data Protection, iCloud Drive is encrypted in transit and on the server with keys Apple holds.
Apple's security guide says synced keychain items "can't be decrypted by any other devices or by Apple". So a breach of Apple's servers, or a request to Apple for your data, doesn't expose them.
Other apps can't read your items by default
On top of encryption, the Keychain separates apps from each other. Apple's documentation on keychain access groups says each app's items stay isolated from all other apps by default, and that sharing is limited to apps delivered by a single development team. That applies to items in the data protection keychain, which is where iCloud Keychain items live. The older file-based keychain uses a different access model.
Not every keychain item syncs
This catches a lot of developers. macOS has two keychains, as Apple's TN3137 explains: the older file-based login keychain and the data protection keychain. Only the data protection keychain works with iCloud Keychain, and even there, an app has to mark each item to sync. Apple's security guide notes that by default, items added by third-party apps don't sync.
The security command-line tool works with the file-based keychain, so a key you add with security add-generic-password stays on that Mac. Tools built on the same older API, like envchain, behave the same way. More on the options in where to store API keys on a Mac.
What it doesn't protect against
Encryption at rest and app isolation answer "can someone else get my keys from storage?" They don't answer "what can programs running as me do?"
- The app that owns the keys. Whatever app stored a key can read it, and so can any tool that app gives you, like a command-line helper. That's the point of storing it.
- Programs you run with the key. Once a key is handed to a command as an environment variable, that command and its child processes have it. They can print it, log it or send it somewhere.
- AI coding agents acting as you. An agent that can run the same commands you can can usually get the same keys you can. Instructions and output masking reduce accidents. They aren't a wall.
- Your Apple Account itself. Anyone who can sign in as you on a trusted device gets your keychain. Use a strong password and two-factor authentication.
How fidelius uses it
fidelius, our Mac app, keeps each API key as an item in your iCloud Keychain, marked to sync, in fidelius's own access group. So your keys reach every Mac signed in to your Apple ID, Apple can't read them, and there's no fidelius server that receives them. accio, the command that comes with it, reads a project's keys and hands them to the one command you run.
The short version
- iCloud Keychain is end-to-end encrypted. Apple can't read synced items.
- Apps can't read each other's keychain items by default.
- Keys added with the security command don't sync. Apps have to opt items in.
- The real exposure is the moment a key reaches a process, so give keys only to the commands that need them.