jfrog / jfrog-cli

JFrog CLI is a client that provides a simple interface that automates access to the JFrog products.
https://www.jfrog.com/confluence/display/CLI/JFrog+CLI
Apache License 2.0
538 stars 236 forks source link

jf atc permanently breaks cli auth generated via jf login #2490

Open StephenWithPH opened 8 months ago

StephenWithPH commented 8 months ago

Describe the bug

Having authenticated the cli using jf login, then invoked jf atc, future invocations of jf atc or jf rt ping fail with:

09:42:30 [🚨Error] Refresh access token failed: server response: 404 Not Found
{
  "errors": [
    {
      "code": "NOT_FOUND",
      "message": "Token matching the provided refresh token was not found."
    }
  ]
}

Current behavior

Initial State

Authenticate jfrog cli via Web UI

Create access token for use in scripting with jfrog cli

    JFROG_CLI_LOG_LEVEL=DEBUG jf atc

    09:19:15 [Debug] JFrog CLI version: 2.52.10
    09:19:15 [Debug] OS/Arch: darwin/arm64
    09:19:15 [Debug] Usage Report: Sending info...
    09:19:15 [Debug] Refreshing token...
    09:19:15 [Debug] Creating lock in: <redacted>
    09:19:30 [Debug] Sending HTTP POST request to: https://<JFrog Platform URL>/access/api/v1/tokens
    09:19:30 [Debug] Releasing lock: <redacted>
    09:19:30 [Debug] Sending HTTP POST request to: https://<JFrog Platform URL>/access/api/v1/tokens
    09:19:30 [Debug] Refreshing token...
    09:19:30 [Debug] Creating lock in: <redacted>
    09:19:30 [Debug] Fetched new token from config.
    09:19:30 [Debug] Releasing lock: <redacted>
    09:19:30 [Debug] Sending HTTP GET request to: https://<JFrog Platform URL>/artifactory/api/system/version
    09:19:31 [Debug] Artifactory response: 200
    09:19:31 [Debug] JFrog Artifactory version is: 7.81.2
    09:19:31 [Debug] Refreshing token...
    09:19:31 [Debug] Creating lock in: <redacted>
    09:19:46 [Debug] Sending HTTP POST request to: https://<JFrog Platform URL>/access/api/v1/tokens
    09:19:46 [Debug] Releasing lock: <redacted>
    09:19:46 [Debug] Couldnt send usage info. Error: Refresh access token failed: server response: 404 Not Found
    {
        "errors": [
            {
                "code": "NOT_FOUND",
                "message": "Token matching the provided refresh token was not found."
            }
        ]
    }
    {
        "scope": "applied-permissions/user",
        "access_token": <redacted>,
        "expires_in": 28800,
        "token_type": "Bearer",
        "token_id": "8715eabd-680b-4d4f-b626-eb31aeef1601"
    }

Attempt to create another access token for use in scripting with jfrog cli

JFROG_CLI_LOG_LEVEL=DEBUG jf atc

09:36:06 [Debug] JFrog CLI version: 2.52.10
09:36:06 [Debug] OS/Arch: darwin/arm64
09:36:06 [Debug] Usage Report: Sending info...
09:36:06 [Debug] Refreshing token...
09:36:06 [Debug] Creating lock in: <redacted>
09:36:21 [Debug] Sending HTTP POST request to: https://<JFrog Platform URL>/access/api/v1/tokens
09:36:21 [Debug] Releasing lock: <redacted>
09:36:21 [Debug] Refreshing token...
09:36:21 [Debug] Creating lock in: <redacted>
09:36:36 [Debug] Sending HTTP POST request to: https://<JFrog Platform URL>/access/api/v1/tokens
09:36:36 [Debug] Releasing lock: <redacted>
09:36:36 [Debug] Couldnt get Artifactory version. Error: Refresh access token failed: server response: 404 Not Found
{
    "errors": [
        {
            "code": "NOT_FOUND",
            "message": "Token matching the provided refresh token was not found."
        }
    ]
}
09:36:36 [🚨Error] Refresh access token failed: server response: 404 Not Found
{
    "errors": [
        {
            "code": "NOT_FOUND",
            "message": "Token matching the provided refresh token was not found."
        }
    ]
}

Reproduction steps

See above.

Expected behavior

Having authenticated the cli using jf login, can repeatedly invoke jf atc as needed, receiving no errors and a valid token that can be used, e.g:

curl -H "Authorization: Bearer $(jf atc --expiry 60 | jq --raw-output '. | .access_token')" https://<JFrog Platform URL>/access/api/v1/tokens

JFrog CLI version

jf version 2.52.10

Operating system type and version

darwin/arm64 14.4 (23E214)

JFrog Artifactory version

SaaS

JFrog Xray version

SaaS

RobiNino commented 7 months ago

Hi @StephenWithPH , Thank you for reporting this issue. I created https://github.com/jfrog/jfrog-cli-core/pull/1177 to fix the issue with refreshing the tokens.

As for the error going to stdout, I verified that errors thrown from the usage report are always reported to the debug log that defaults to stderr. Can you make sure that you don't have logs printed to stdout?

Thanks

StephenWithPH commented 7 months ago

As for the error going to stdout, I verified that errors thrown from the usage report are always reported to the debug log that defaults to stderr. Can you make sure that you don't have logs printed to stdout?

I likely failed to unset some redirection while I was debugging / repro'ing to open the issue. I apologize.