@vscode/macos-keychain
v0.0.1
Published
Native macOS Keychain access with keychain-access-groups support for VS Code
Readme
@vscode/macos-keychain
Native Node.js addon for macOS Keychain access with keychain-access-groups support, enabling secret sharing between apps signed by the same team.
Overview
This module wraps the macOS Security framework (SecItemAdd, SecItemCopyMatching, SecItemUpdate, SecItemDelete) and supports the kSecAttrAccessGroup attribute for sharing keychain items across multiple applications via Keychain Access Groups.
Uses kSecUseDataProtectionKeychain = true, which is required for access group support on macOS.
Requirements
- macOS only
- Node.js with N-API support
- For shared access groups: both apps must be signed by the same team and include the
keychain-access-groupsentitlement
Installation
npm install @vscode/macos-keychainAPI
// Store a secret (creates or updates)
keychainSet(service: string, account: string, value: string): void;
// Retrieve a secret
keychainGet(service: string, account: string): string | undefined;
// Delete a secret (returns true if deleted, false if not found)
keychainDelete(service: string, account: string): boolean;
// List all account names for a service
keychainList(service: string): string[];The keychain access group is auto-detected from the process's keychain-access-groups entitlement at load time. If no entitlement is present, the access group is omitted and items go to the default keychain.
Usage
const { keychainSet, keychainGet, keychainDelete, keychainList } = require('@vscode/macos-keychain');
const SERVICE = 'com.microsoft.vscode.shared-secrets';
// Store a secret
keychainSet(SERVICE, 'github.auth', 'my-token');
// Read it back
const token = keychainGet(SERVICE, 'github.auth');
// List all accounts
const accounts = keychainList(SERVICE);
// Delete
keychainDelete(SERVICE, 'github.auth');Entitlements
For cross-app secret sharing, both apps need the same access group in their entitlements:
<key>keychain-access-groups</key>
<array>
<string>$(TeamIdentifierPrefix)com.microsoft.vscode.shared-secrets</string>
</array>Testing
npm install
npm testThe test suite runs without code signing or entitlements — since no keychain-access-groups entitlement is present, the addon skips kSecAttrAccessGroup and kSecUseDataProtectionKeychain, so items go to the default keychain.
When running inside a signed app with the keychain-access-groups entitlement, the access group is auto-detected and kSecUseDataProtectionKeychain = true is set. The app must be signed with the matching entitlement, otherwise all operations will fail with -34018 (errSecMissingEntitlement).
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit Contributor License Agreements.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.
