Client assertion issue for AKS

Intermittent Errors in GitHub Actions Pipeline

I am running a GitHub Actions pipeline for a project which connects to AKS to push the image to container registry. The pipeline intermittently fails with the following errors:

Error: failed to get token: expected an empty error but received: AzureCLICredential: ERROR: AADSTS700024: Client assertion is not within its valid time range. Current time: 2023-06-28T12:03:19.0477284Z, assertion valid from 2023-06-28T11:52:57.0000000Z, expiry time of assertion 2023-06-28T11:57:57.0000000Z. Review the documentation at .
Trace ID: b697e7c6-2728-4a9d-ad98-324fdf903400
Correlation ID: 6d3dc859-2966-4221-a683-feb4e5d9d214
Timestamp: 2023-06-28 12:03:19Z
Interactive authentication is needed. Please run:
az login
Error: Kubernetes cluster unreachable: Get "": getting credentials: exec: executable kubelogin failed with exit code 1

After consecutive retries, the pipeline executes successfully without issues. The screenshot of the GitHub Actions pipeline log is below.

GitHub pipeline log

The intermittent errors in the GitHub Actions pipeline are caused by authentication issues with Azure and Kubernetes. To resolve these errors, follow these steps:

  1. Check the validity of the client assertion time range. Ensure that the system time on the machine running the pipeline is accurate. If the time is incorrect, update it to the correct time.

  2. Review the documentation mentioned in the error message: Azure Active Directory Certificate Credentials. This documentation provides information on how to troubleshoot client assertion errors.

  3. Run the az login command as mentioned in the error message. This command performs interactive authentication and allows you to log in to Azure. Make sure you have the necessary permissions to access the Azure resources required by the pipeline.

  4. Verify the Kubernetes cluster’s accessibility. Ensure that the cluster is reachable and the necessary credentials are correctly configured. The error message indicates that the executable kubelogin failed with exit code 1. Make sure kubelogin is installed and properly configured.

  5. If the above steps do not resolve the issue, consider increasing the number of retries in the GitHub Actions pipeline configuration. This can help mitigate intermittent authentication or connectivity issues.

By following these steps, you should be able to resolve the intermittent errors in your GitHub Actions pipeline.