bitbake: fetch2/git: fix initial http authed clone
cover bitbake: fetch2/git: fix initial http authed clone
This patch fixes initial clones of git repositories authenticated via basic http authentication. This became apparent when code was reused to clone submodules too.
The method is the recommended way of cloning source code by CI runners. This patch fixes the currently broken behvior.
Beware, that already cloned repositories are not affected.
Based on master (d94ccd506d04aff182ab48f501f6f366d5dd14f5).
Leif Middelschulte (1):
bitbake: fetch2/git: set password in https clones too
lib/bb/fetch2/git.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
2.21.0
PATCH 1/1 bitbake: fetch2/git: set password in https clones too
Fetching submodules via https, using the basic HTTP auth scheme, failed.
Example for a broken URL:SRC_URI = "gitsm://example.com/some_repo.git;protocol=https;user=john:secret"
Now, if some_repo.git had a relative submodule, the initial clone would fail:
Quoted 2 lines
fatal: could not read Username for 'https://example.com':
No such device or address
This happended, because the password was correctly read into another ud-field (pswd), but not added back, when the URL was rebuilt.
--- lib/bb/fetch2/git.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/bb/fetch2/git.py +3 -1
@@ -570,7 +570,9 @@ class Git(FetchMethod): """ Return the repository URL """ - if ud.user: + if ud.user and ud.pswd: + username = "%s:%s@" % (ud.user, ud.pswd) + elif ud.user: username = ud.user + '@' else: username = ""
Signature · 1 line
2.21.0
Quoted 6 lines · Leif Middelschulte
This patch fixes initial clones of git repositories authenticated via basic http authentication. This became apparent when code was reused to clone submodules too.
The method is the recommended way of cloning source code by CI runners. This patch fixes the currently broken behvior.
Hi,
Recommended by whom specifically? Encoding passwords in URIs was deprecated RFC 3986 for security reasons. Some tools may not be aware of security sensitive information contained in URIs.
RFC 3986:
Quoted 3 lines
Applications should not render as clear text any data after the first colon (":") character found within a userinfo subcomponent ...
Having passwords and security sensitive info in the bitbake metadata also seems a bit weird to me, but bb.fetch2.decodeurl() does support extracting it. I thought the git fetcher didn't support auth details (other than user) via the URI by design, but this is just my assumption.
The gitcredentials manpage recommends using the global configuration with [credential.<uri-pattern>] blocks to specify this instead.
https://git-scm.com/docs/gitcredentials
Signature · 1 line
olofjn
Quoted 3 lines · Olof Johansson
The gitcredentials manpage recommends using the global configuration with [credential.<uri-pattern>] blocks to specify this instead.
... Sorry, this was an incomplete description based on a cursory reading, but it does seem to outline several available solutions to your problem, including storing unencrypted on disk to integrating with system password managers...
Quoted 1 line
(SSH transport with key based authentication is also nice to deal with, if possible. The authenticated git hosts I know of provide SSH transport, but I suppose not all.)
Signature · 1 line
olofjn
Hello Olof,
thank you for your reply.
I appologize for the late reply, I was out of office.
Am Dienstag, den 04.06.2019, 19:38 +0200 schrieb Olof Johansson:
Quoted 11 lines · Leif Middelschulte
Quoted 6 lines
This patch fixes initial clones of git repositories authenticated via basic http authentication. This became apparent when code was reused to clone submodules too.
The method is the recommended way of cloning source code by CI runners. This patch fixes the currently broken behvior.
Hi,
Recommended by whom specifically?
By "recommended", I was referring to cloning source code via HTTPs within CIs, by using dynamically created/valid tokens:
https://docs.gitlab.com/ee/ci/triggers/README.html#ci-job-token
I was not referring to the URI scheme specifically.
Quoted 4 lines
Encoding passwords in URIs was
deprecated RFC 3986 for security reasons. Some tools may not be aware of security sensitive information contained in URIs.
Quoted 8 lines
RFC 3986:
Quoted 3 lines
Applications should not render as clear text any data after the first colon (":") character found within a userinfo subcomponent ...
Having passwords and security sensitive info in the bitbake metadata also seems a bit weird to me, but
bb.fetch2.decodeurl()does support extracting it.
I'm whitelisting an environment variable (CI_JOB_TOKEN) before I source a bitbake environment. So the credentials are not hard-coded, but use the following format within SRC_URIs:
user=gitlab-ci-runner:${CI_JOB_TOKEN};protocol=https
It used to be supported (rocko). Apparently unintended. It was just this behavioral break (in warrior) that lead me creating this patch.
Quoted 3 lines
I thought the git fetcher didn't
support auth details (other than user) via the URI by design, but this is just my assumption.
AFAICS git indeed supports specifying complete credentials as via the URI.
Quoted 7 lines
The gitcredentials manpage recommends using the global configuration with [credential.<uri-pattern>] blocks to specify this instead.
Thank you for the hint. I'll use git's native integration then[0].
For the record:
git config --global credential.https://gitlab.example.com.username gitlab-ci-token
git config --global credential.https://gitlab.example.com.helper '!f() { echo "password=echo $CI_JOB_TOKEN"; }; f'
[0] https://git-scm.com/docs/api-credentials#_credential_helpers
So feel free to just drop this patch.
Again thanks for the feedback.
Signature · 24 lines
Best Regards, KLS Martin GmbH + Co. KG, A KLS Martin Group company Leif Middelschulte Software Development Engineer KLS Martin GmbH + Co. KG Am Flughafen 18 79108 Freiburg im Breisgau / Germany Telefon +49 (761) 557 997-543 Fax +49 (761) 557 997-520 [email protected]; www.klsmartin.com Registergericht: Freiburg im Breisgau; Handelsregister: HRA 4044 Geschäftsführer: Michael Martin, Karl Leibinger, Christian Leibinger Persönlich haftende Gesellschafterin: KLS Martin Verwaltungsgesellschaft mbH Registergericht: Stuttgart; Handelsregister: HRB 451316 USt.-Id-Nr. DE 237467280 Diese E-Mail enthält vertrauliche und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.