Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Better support for local & CI workflow for conan remote login #17365

Closed
1 task done
schwaerz opened this issue Nov 22, 2024 · 25 comments · May be fixed by #17374
Closed
1 task done

[feature] Better support for local & CI workflow for conan remote login #17365

schwaerz opened this issue Nov 22, 2024 · 25 comments · May be fixed by #17374
Assignees
Milestone

Comments

@schwaerz
Copy link
Contributor

What is your suggestion?

Following up on #5443:

It looks like what was implemented back then is no longer available or did not make it into the final Conan 2.x release.

What would be very useful to us (to reduce the required scripting in every repository):

Have one conan remote ... command to

  1. Log on in CI using CONAN_LOGIN_USERNAME and CONAN_PASSWORD
  2. Log on to the remote when executed locally, where...
    • It shall ask interactively for username and password for a remote if not authenticated
    • It shall not ask for username and passort if already authenticated to the remote - and the authentication token is still valid

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded
Copy link
Member

Hi @schwaerz

Thanks for your suggestion.

I have been reviewing this, but so far it seems that this is how the conan remote auth works:

I have added an extra check in #17374, to validate that when the user is authenticated and the token is valid, it will not request credentials to the user again.

@schwaerz
Copy link
Contributor Author

@memsharded Thanks for the update. I will need to try with conan auth once more. Maybe I did something wrong.

@memsharded
Copy link
Member

Great, looking forward your feedback.
As you can see, the test framework that we have should be pretty straightforward, it can help a lot to automate testing, avoiding lots of manual tests, if you want to leverage it.

@schwaerz
Copy link
Contributor Author

Unfortunately it does not seem to work for me. I executed the following using conan 2.9.3 on my local machine. Conan did not ask for username and / or password:

schwaerz@localhost:~/repositories/c-lib$ ./pdm.sh run conan remote auth conan-css-iphub-local
conan-css-iphub-local:
    user: schwaerz
schwaerz@localhost:~/repositories/c-lib$ ./pdm.sh run conan remote logout conan-css-iphub-local
Changed user of remote 'conan-css-iphub-local' from 'schwaerz' (authenticated) to 'None' (anonymous)
schwaerz@localhost:~/repositories/c-lib$ ./pdm.sh run conan remote auth conan-css-iphub-local
conan-css-iphub-local:
    user: None

@schwaerz
Copy link
Contributor Author

I just tried enabling some debug logging. However it looks like the -v option to conan remote / conan remote auth does not work.

@memsharded
Copy link
Member

I am a bit surprised about that. I have tried to add a new test to the PR (90437b9), you can check it, but also tried locally against a real ArtifactoryCE server:

$ conan remote auth art
Remote 'art' needs authentication, obtaining credentials
Remote 'art' username: admin
Please enter a password for user 'admin' on remote 'art':
art:
    user: admin


$ conan remote logout art
Changed user of remote 'art' from 'admin' (authenticated) to 'None' (anonymous)

$ conan remote auth art
Remote 'art' needs authentication, obtaining credentials
Remote 'art' username: admin
Please enter a password for user 'admin' on remote 'art':
art:
    user: admin

@schwaerz
Copy link
Contributor Author

Could this be possibly related to some specific settings on the Artifactory remote?

@memsharded
Copy link
Member

It seems there is something different in your setup, I don't see the Remote 'art' needs authentication, obtaining credentials message, even the first remote auth, I don't understand why.

@schwaerz
Copy link
Contributor Author

I will try some debugging.

@memsharded
Copy link
Member

Could this be possibly related to some specific settings on the Artifactory remote?

It might be. Maybe if the repo allows anonymous reads, then it doesn't really need auth, so the conan remote auth will continue without issues. For this kind of configuration, users must explicitly conan remote login to force authentication.

@schwaerz
Copy link
Contributor Author

schwaerz commented Nov 25, 2024

The repo does not allow anonymous access. However the check_credentials REST api call seems to return 200 anyways:

c-lib-3.11schwaerz@localhost:~/repositories/c-lib$ curl -I https://artifactory.url/artifactory/api/conan/conan-css-iphub-local/v2/users/check_credentials
HTTP/1.1 200 
Date: Mon, 25 Nov 2024 11:07:05 GMT
Connection: keep-alive
X-JFrog-Version: Artifactory/7.63.14 76314900
X-Artifactory-Id: ceaa3e3d815fee0bb7a5f60661ef5f20e09dd998
X-Artifactory-Node-Id: artifactory-ha-artifactory-ha-primary-2
X-Conan-Server-Version: 0.20.0
X-Conan-Server-Capabilities: complex_search,checksum_deploy,revisions,matrix_params
Strict-Transport-Security: always

@schwaerz
Copy link
Contributor Author

I did not find the documentation for this REST call. Probably you have a link so I could check with our Artifactory guys what's going on?

@schwaerz
Copy link
Contributor Author

schwaerz commented Nov 25, 2024

What I found:
If I run curl like this - I will get the 401 as expected:

curl -I -H "Authorization: Bearer foo" https://artifactory.url/artifactory/api/conan/conan-css-iphub-local/v2/users/check_credentials

If I then use a valid token, I will get a 200:

curl -I -H "Authorization: Bearer {my-valid-token}" https://artifactory.url/artifactory/api/conan/conan-css-iphub-local/v2/users/check_credentials

@schwaerz
Copy link
Contributor Author

So maybe this can be fixed in conan after all?

@schwaerz
Copy link
Contributor Author

conan remote auth will work if I revoke the token in Artfactory. But it doesn't if I do a conan remote logout or if I never called conan remote login before.

@schwaerz
Copy link
Contributor Author

following could be a workaround:

If we set token to something other than None here: https://github.com/conan-io/conan/blob/develop2/conans/client/rest/auth_manager.py#L30, the authentication will be done as expected.

However I am not sure how to test this properly - or whether you would accept a PR doing that? Maybe this would have other implications I currently cannot see?

@schwaerz
Copy link
Contributor Author

@memsharded As it took not much time to come up with a quick fix, I gave it a shot.

@memsharded
Copy link
Member

I did not find the documentation for this REST call. Probably you have a link so I could check with our Artifactory guys what's going on?

I am afraid we don't have any documentation of the http rest api, just the code (both client and server side)

conan remote auth will work if I revoke the token in Artfactory. But it doesn't if I do a conan remote logout or if I never called conan remote login before.

But if it is not a server side different configuration, why the unitttest linked in the PR will work, and the conan remote logout will work as expected?

@schwaerz
Copy link
Contributor Author

schwaerz commented Nov 26, 2024

But if it is not a server side different configuration, why the unitttest linked in the PR will work, and the conan remote logout will work as expected?

I cannot tell. But what I can see is that the check_crededentials endpoint will always return 200 on our instance if no authentication header is provided. However if you provide an invalid token instead, it returns 401 as expected.

@schwaerz
Copy link
Contributor Author

@memsharded Another question wrt to this: Do you believe it makes sense to create a ticket wrt the the 200 response of check_credentials?
As this API call is not documented I wonder whether it is officially supported in Artifactory?

@memsharded
Copy link
Member

Just in case, in my local Artifactory conan repo:

$ curl -I https://localhost:8081/artifactory/api/conan/conan/v2/users/check_credentials
curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid

@schwaerz
Copy link
Contributor Author

Let me try to get some local server running.

@schwaerz
Copy link
Contributor Author

schwaerz commented Nov 27, 2024

Works like a charm with Artifactory CE version 7.63.12

curl -I http://localhost:8082/artifactory/api/conan/conan-local/v2/users/check_credentials
2/users/check_credentials
HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=ISO-8859-1
Date: Wed, 27 Nov 2024 10:14:13 GMT
Www-Authenticate: Basic realm="Artifactory Realm"

@schwaerz
Copy link
Contributor Author

I think I found the setting causing this behavior. If anonymous access is enabled on instance level, check_credentials returns 200 for the locally hosted Artifactory CE (same version like our official server), too.

grafik

schwaerz added a commit to schwaerz/conan that referenced this issue Nov 27, 2024
memsharded pushed a commit that referenced this issue Nov 28, 2024
* Fix `conan remote auth` for anonymous-access enabled Artifactory instances (#17365)

* `--force` option to `conan remote auth`
@memsharded memsharded added this to the 2.10.0 milestone Nov 28, 2024
@memsharded
Copy link
Member

Implemented in #17377 for next Conan 2.10, with conan remote auth --force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants