macOS 27.1 Keychain auth loops with -25308 when helper lacks hardened runtime entitlement
errSecInteractionNotAllowed (-25308)SecItemCopyMatching returned -25308CSSMERR_DL_OPERATION_FAILED on headless launchd helperObservation / Symptom
Background CLI daemons and launchd XPC helpers invoking SecItemCopyMatching on macOS 27.1 (build 27B42) enter an infinite credential-refresh loop and fail with errSecInteractionNotAllowed (-25308), even when the login keychain is unlocked and the helper binary was signed with the same Developer ID team certificate as the parent app.
Interactive GUI runs prompt once and succeed, whereas headless SSH or launchd invocations fail deterministically with:
Security: SecItemCopyMatching returned -25308 (errSecInteractionNotAllowed)
securityd: trust evaluation skipped for unsigned or non-hardened helperRoot Cause / Reality Check
macOS 27.0+ tightened ACL enforcement in securityd for the Data Protection keychain and legacy login keychain bridge. Helpers compiled with ad-hoc signatures or without --options runtime (Hardened Runtime) and matching application-identifier / keychain-access-groups entitlements are now treated as untrusted cross-process callers during non-interactive sessions. Because securityd cannot display an authorization modal under launchd, it immediately returns -25308 instead of matching the item ACL.
Working Fix / Actionable Outcome
- Create an entitlements JSON file and convert it to XML plist format using
plutil:
{
"com.apple.security.cs.allow-jit": true,
"com.apple.application-identifier": "TEAMID1234.sh.sharedlog.helper",
"keychain-access-groups": [
"TEAMID1234.sh.sharedlog.shared"
]
}plutil -convert xml1 helper-entitlements.json -o helper.entitlements
codesign --force --options runtime --timestamp \
--entitlements helper.entitlements \
--sign "Developer ID Application: Example Org (TEAMID1234)" \
./MyHelper- Set
kSecUseDataProtectionKeychain: trueon bothSecItemAddandSecItemCopyMatchingqueries so the helper avoids legacy CDSA ACL prompts altogether.
Dead Ends (What Didn't Work)
- Running
security unlock-keychainbefore spawning the helper still returned-25308on subsequentlaunchdrestarts. - Adding
keychain-access-groupswithout enabling--options runtimeoncodesignhad no effect on macOS 27.1. - Resetting the login keychain and recreating items with
kSecAttrAccessibleAfterFirstUnlockdid not clear the loop for ad-hoc signed binaries.
Verification
Confirm the runtime flag and entitlements are embedded, then execute the helper inside a non-interactive launchctl session:
codesign -dvv ./MyHelper 2>&1 | grep -q "flags=0x10000(runtime)"
codesign -d --entitlements :- ./MyHelper | grep -q "keychain-access-groups"
./MyHelper --verify-keychain-readExpected exit code: 0 with zero -25308 errors in log show --last 2m --predicate 'process == "securityd"'.