Fixing Jenkins error: Missing certificates and keys in keychain

Updated: February 3, 2024 By: Guest Contributor Post a comment

The Problem

When working with Jenkins in complex CI/CD pipelines, it’s common to encounter various errors. One frustrating issue is the “Missing certificates and keys in keychain” error. This occurs typically when Jenkins tries to access resources or perform tasks that require authentication with certificates that are supposed to be in the keychain but for some reason, are not detected or accessible. Understanding the causes and navigating through potential solutions is crucial for maintaining a seamless automation process.

Understanding the Causes

This error is generally caused by misconfigurations or changes in the environment. Potential causes include:

  • Corrupted Jenkins credential store.
  • Missing keychain access for the Jenkins user.
  • Updating or migrating Jenkins without properly transferring certificates.
  • Insufficient permissions to access keychain.

Solution 1: Verify Jenkins Credential Store

The first solution involves checking if the Jenkins credential store holds the necessary certificates and keys. Sometimes, credentials can become corrupted or fail to migrate properly.

  1. Navigate to Jenkins Dashboard.
  2. Go to Credentials -> System -> Global credentials.
  3. Verify or add the necessary certificates and keys.

Notes: This solution is straightforward but does require appropriate access rights to the Jenkins system. Also, it’s a good starting point before diving into more complex troubleshooting.

Solution 2: Reset Keychain Access

If Jenkins lacks the correct permissions for keychain access, resetting these permissions might resolve the issue.

  1. On the machine running Jenkins, open Terminal.
  2. Reset the keychain access permissions using the following command:
    sudo security unlock-keychain /Library/Keychains/System.keychain
  3. Enter the machine’s administrator password when prompted.

Output: ‘keychain unlocked’

Notes: This method directly manipulates system settings and requires administrative access. It’s effective but carries the risk of affecting other system components or services depending on keychain access.

Solution 3: Manual Keychain Configuration

Manually configuring or re-adding the certificates and keys directly into the keychain can address cases where they are missing or not properly recognized.

  1. Open Keychain Access on the Mac hosting Jenkins.
  2. Select the login keychain and find the target certificate.
  3. If the certificate isn’t there, manually add it by dragging the certificate file into the Keychain Access window or using the import option.
  4. Ensure Jenkins user has the necessary permissions to access this keychain.

Notes: This solution provides a direct method to ensure the certificates are in place. However, it requires manual intervention and might not be suitable for all environments, especially those heavily automated or without GUI access.

Conclusion

Fixing the “Missing certificates and keys in keychain” error in Jenkins can be approached from multiple angles depending on the underlying cause. Starting with verifying Jenkins credentials, adjusting keychain permissions, to manual keychain management, each solution offers a path towards resolution but comes with its considerations regarding access rights, system security, and operational overhead. Whichever method you choose, ensure you’re familiar with the possible impact on your Jenkins instance and the broader system.