acquia / cli

Command-line interface for Acquia Cloud Platform products
https://docs.acquia.com/acquia-cli/
GNU General Public License v2.0
42 stars 47 forks source link

CLI-1296: `auth:login` on 2.23.1 > Invalid key in Cloud datastore #1708

Closed alchatti closed 5 months ago

alchatti commented 5 months ago

Describe the bug When using the latest version of acli which is 2.23.1 the command auth:login [-k|--key KEY] [-s|--secret SECRET] no longer works and generates the following error.

In AuthLoginCommand.php line 31:

  Invalid key in Cloud datastore; run acli auth:logout && acli auth:login to fix

auth:login [-k|--key KEY] [-s|--secret SECRET]

On reverting to 2.23.0 the authentication works as expected.

To Reproduce Steps to reproduce the behavior:

  1. Update to 2.23.1 acli self:update
  2. Login using auth:login [-k|--key KEY] [-s|--secret SECRET]
  3. Login fails with
    [Acquia\Cli\Exception\AcquiaCliException]
    Invalid key in Cloud datastore; run acli auth:logout && acli auth:login to fix
  4. acli auth:logout && acli auth:login doesn't fix the issue.

Expected behavior Login to succeed and be able to execute cli commands

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context The Pipeline CI/CD job also fails when using the latest version and works when reverting to 2.23.0

anavarre commented 5 months ago

Looks like it was introduced with #1702

danepowell commented 5 months ago

I cannot reproduce this issue. I tried running acli auth:login -k <key> -s <secret> with no cloud_api.conf, and then again immediately afterwards with the same key.

Is it possible that the error message is legitimate and your datastore (cloud_api.conf) is corrupt?

If you can't determine this on your own, you can post the contents of ~/.acquia/cloud_api.conf or $XDG_CONFIG_HOME/acquia/cloud_api.conf, being sure to redact secrets, but leave enough of the key so that I can see where it's used in the file. Or you can submit this information via a support ticket.

alchatti commented 5 months ago

@danepowell give me couple of days to check, as I am having the issue on both my local development machine and the Azure pipeline image which resets with every job.

It could be a PHP version issue or one of the dependencies. Will share the logs as soon as I am able.

jhu9000 commented 5 months ago

Experiencing same on github runner ubuntu 22.04.4 LTS.

alchatti commented 5 months ago

@danepowell For the CI/CD pipeline, I start with the command acli -n telemetry:disable then the file ~/.acquia/cloud_api.conf will only contain the following

{
    "send_telemetry": false
}

The following statement will be true src/Command/Auth/AuthLoginCommand.php@31

if (is_array($keys) && !array_key_exists($activeKey, $keys)) {
 throw new AcquiaCliException('Invalid key in Cloud datastore; run acli auth:logout && acli auth:login to fix');
}
is_array($keys):true
!array_key_exists($activeKey, $keys):true
$keys = $this->datastoreCloud->get('keys');

Is returning array(0) although there is no keys inside the file at this stage. I think it is a side effect when setting the datastore src/DataStore/Datastore.php#L32

The issue is triggered during CI/CD pipeline by set some settings for the CLI before auth function such as switching on/off the telemetry.

I have raised a pull request without conflicting with the intended solution for #1702

danepowell commented 5 months ago

Thanks for finding the root cause here. The reason for the regression was that our tests mocked the datastore in a way that didn't exactly reflect the real behavior (keys were null instead of an empty array if unset), and we didn't have a test for the explicit case of an existing datastore with no keys.

I've fixed all of our tests to prevent that happening again.