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

[question] how to inject SCM credentials when building packages from sources #6452

Closed
GordonJess opened this issue Jan 31, 2020 · 8 comments
Closed
Assignees

Comments

@GordonJess
Copy link

GordonJess commented Jan 31, 2020

I've already read a related issues on this topic (5595) but wasn't able to find a solution to my problem.

When I try to rebuild a package from source, conan tries to checkout the url which was automatically stored in the scm::url attribute. But since the url is stored without the credentials since 4207 (which I do agree with), the cloning of sources fails during authentication. I also want to avoid storing credentials in scm::username or scm::password fields.

I did read a suggestion to use the proxies section in conan.conf to embed user/password in urls, but I from what I can tell the user:pass here is only for authenticating against the proxy itself, not the request url. Or maybe I'm missing something...?

Git credential caches are also not a good option for me since they still require the password to be manually input every so often, which would be a real pain for the CI slaves.

Ideally I'd like to provide the credentials to conan on the command line. or for conan to take the values from environmental variables (like the solution for artifactory credentials). Of course this might be an issue when one command rebuilds several packages coming from different sources which need different creds. Maybe storing default creds per url in conan.conf can have default credentials per url.

How are other users typically handling this? Any suggestions would be much appreciated!

@czoido czoido self-assigned this Jan 31, 2020
@czoido
Copy link
Contributor

czoido commented Jan 31, 2020

Hi @GordonJess,

We are going to release some new things for scm in 1.22 that maybe could help you:

You will be able to define a scm_to_conandata in the conan.conf so that if you are using auto your scm dictionary is evaluated in the conandata.yml (but not the username and password). That way you can get the username and password from the environment and that information won't be stored anywhere.

@GordonJess
Copy link
Author

Brilliant! Looking forward to it!

@jgsogo
Copy link
Contributor

jgsogo commented Feb 10, 2020

#6334 was merged and released as an opt-in in v1.22. I think it should close this issue too, right?

@jonathangoorin
Copy link

@czoido Hi I'm new to conan - and I can't quite figure how to use your solution.
I Also have private repository that I need to clone in source method and for that I have to pass the github credentials from jenkins

If you can point me up to location for the RTFM, that'd be also great :)

@czoido
Copy link
Contributor

czoido commented Apr 8, 2020

Hi @jonathangoorin,
This is the section in the documentation: https://docs.conan.io/en/latest/creating_packages/package_repo.html#capturing-the-remote-and-commit-scm
We also have an example in the release post: https://blog.conan.io/2020/02/11/New-conan-release-1-22.html
Hope this helps, feel free to ask if you have any doubts on how to use it.

@Parcley
Copy link

Parcley commented Oct 20, 2021

I don't really understand how this solves the question:
In this case, we can only store credentials in conandata.yml for packages, which we are creating on our own.

But image if I have two packages:

  • package rootPackage, which has a dependency on dependency
  • package dependency, which has its source code in a git repo (which requires credentials)

If I want to install all dependencies for rootPackage, dependency is being built (e.g. when using --build=missing and the correct binary is not available). When trying to build dependency, its sources need to be downloaded and now we cannot download the sources (typical error messages will be: fatal: could not read Username for '<repo>': No such device or address).

Now this could be solved by storing git credentials for dependency's git repository in my computer's git configuration files. But this is not always a good idea for automated CI machines, which do not want to permanently store credentials.

A solution, which might work, is to add new environment variables (e.g. CONAN_SCM_USERNAME and CONAN_SCM_PASSWORD), which will auttomatically be used for the Scm class, if no explicit credentials are provided in the conanfile.

the logic of reading from an environment variable should probably be near this code:

self._password = password

@ptomasz1
Copy link

ptomasz1 commented Apr 6, 2023

I agree with @Parcley - proposed solution solved completely different issue.

Are you going to address the right problem?

@memsharded
Copy link
Member

Conan 2.0 provides a source_credentials.json file to define credentials for tools.file.download(), please check: https://docs.conan.io/2/reference/config_files/source_credentials.html

Otherwise, this issue is quite outdated, the scm component has been removed in Conan 2.0 (and already legacy in Conan 1.X, with alternative approaches). For git credentials, the recommendation is to use orthogonal authentication methods, like ssh-keys, GIT_ASKPASS or something similar, and if env-vars are to be be used, for sure recipes can os.getenv() and load those env-vars to provide auth for their git-clone operations.

As this is outdated issue referring to removed scm, I am going to close it as outdated. If you think there is still a gap for Conan 2.0 @ptomasz1, it would be great to have a new ticket, referring to the new approaches (raw conandata.yml + source() method, without scm component). Thanks!

@memsharded memsharded closed this as not planned Won't fix, can't repro, duplicate, stale Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants