The Mac Server Setup framework uses macOS Keychain Services for secure credential storage and transfer. The system replaces plaintext credential files with encrypted keychain storage, transferring credentials from development machine to target server through external keychain files.
- Development Machine (prep-airdrop.sh) - Retrieves credentials from 1Password and creates external keychain file
- Target Server (first-boot.sh) - Imports credentials from external keychain to admin keychain only
- Application Setup (app-setup/*.sh) - Retrieves credentials from admin keychain and embeds them into service scripts with restrictive file permissions for secure runtime access
operator-{SERVER_NAME_LOWER}: Operator account passwordplex-nas-{SERVER_NAME_LOWER}: NAS credentials for media access (format:username:password)
timemachine-{SERVER_NAME_LOWER}: Time Machine backup credentials (format:username:password)wifi-{SERVER_NAME_LOWER}: WiFi password for network setup
Creates temporary keychain with random password, stores credentials from 1Password, verifies storage, locks keychain, and copies to output directory with manifest file.
Service identifiers:
KEYCHAIN_OPERATOR_SERVICE="operator-${SERVER_NAME_LOWER}"KEYCHAIN_PLEX_NAS_SERVICE="plex-nas-${SERVER_NAME_LOWER}"KEYCHAIN_TIMEMACHINE_SERVICE="timemachine-${SERVER_NAME_LOWER}"KEYCHAIN_WIFI_SERVICE="wifi-${SERVER_NAME_LOWER}"
Single-phase admin import process:
- Admin Import - Transfers credentials from external keychain to admin's keychain
Note: Operator keychain population has been removed as it's no longer needed. The operator account is created before first login, meaning no login keychain exists yet. NFS mount scripts use host-based authentication (no embedded credentials), and other service scripts embed credentials as needed during application setup.
Uses get_keychain_credential() function to retrieve credentials securely during setup, then embeds them directly into service scripts with restrictive file permissions (mode 700) for runtime access.
Services use embedded credentials that were securely inserted during application setup. This eliminates the need for interactive keychain unlocks in LaunchAgent contexts while maintaining security through restrictive file permissions.
- NAS Credentials:
username:passwordformat, parsed with bash parameter expansion - Simple Credentials: Plain password strings for account creation and network auth
- Encrypted keychain storage eliminates plaintext credential files
- Immediate credential verification prevents corrupt transfers
- Memory cleanup after credential use
- Proper file permissions (600) on keychain files and manifests
- Password masking in logs
- External keychain cleanup after import
Mounts the NAS media share via NFS. Unlike the previous SMB approach, NFS uses host-based authentication — no credentials are embedded in the script. The script is still deployed with restrictive permissions (mode 700) since it runs sudo for the mount command.
- keychain_manifest.conf: Contains service identifiers and keychain metadata
- External keychain file:
mac-server-setup-dbtransferred with setup package
- Graceful handling of missing optional credentials
- Verification of credential storage and retrieval
- Comprehensive error collection and reporting
- Encrypted storage throughout transfer process
- No plaintext credential files in setup packages
- Proper access controls and memory management
- Automatic credential storage in admin keychain during setup
- Simple single-function credential retrieval interface for setup scripts
- Embedded credentials in service scripts eliminate runtime keychain dependencies
- Error resilience with graceful degradation
- Consistent credential handling across all scripts
- Integration with Keychain Access.app for debugging
Common diagnostic approaches for setup-time credential issues:
- Verify keychain file existence and permissions
- Test credential retrieval manually with
securitycommands - Check keychain unlock status and access permissions
- Use Keychain Access.app for GUI credential inspection
For runtime credential problems with service scripts:
-
Script permissions: Verify service scripts have mode 700 permissions
ls -la ~/.local/bin/mount-nas-media.sh # Should show: -rwx------
-
Credential validation: Check for unconfigured placeholders in scripts
grep "__.*__" ~/.local/bin/mount-nas-media.sh # Should return no results if properly configured
-
Service script logs: Check service-specific log files
tail -f ~/.local/state/${server-name}-mount.log
The system provides comprehensive logging and error collection to identify credential-related issues during setup.