GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: resolve credentials for protected HTTP(S) repositories by Ankitsinghsisodya · Pull Request #3637 · knative/func Conversation
|
|
Hi @Ankitsinghsisodya. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Adds HTTP(S) credential resolution for protected template repositories by retrying go-git clones with BasicAuth sourced from ~/.git-credentials and ~/.netrc, addressing cases where go-git doesn’t consult system credential helpers.
Changes:
git.Clone / git.PlainClone on transport.ErrAuthenticationRequired using credentials resolved from ~/.git-credentials, then ~/.netrc.credentialsForURL behavior and isAuthError.Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
pkg/functions/repository.go |
Adds credential lookup + auth-retry logic for in-memory and disk clones; introduces git-credentials and netrc parsing helpers. |
pkg/functions/repository_credentials_test.go |
Adds tests for credential resolution and auth-error detection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| // TestCredentialsForURL_HTTPS verifies that credentials stored in | ||
| // ~/.git-credentials are returned for a matching HTTPS URL. | ||
| func TestCredentialsForURL_HTTPS(t *testing.T) { |
There was an error while loading. Please reload this page.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@ ## main #3637 +/- ## ========================================== + Coverage 56.61% 56.66% +0.05% ========================================== Files 181 181 Lines 20853 20992 +139 ========================================== + Hits 11806 11896 +90 - Misses 7833 7871 +38 - Partials 1214 1225 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Nice addition! One thing: it appears you are matching only host, not port. Port also should match (with possible exception of implicit ports 80 and 443). On the other hand scheme matching seems to be too restrictive. Credentials valid for http://localhost should match https://localhost in my opinion. Examples: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Done sir |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // scanNetRC is a minimal netrc(5) token scanner. It returns the login and | ||
| // password for the first "machine" stanza whose name matches host. Falls back | ||
| // to the "default" stanza when no exact match is found. | ||
| func scanNetRC(content, host string) (login, password string) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
btw would it be worth simply adding a ignore case for line starting w #? AFAIK netrc does not officially support comments but apparently programs like curl do actually mention that its ok to use and they do ignore them. Python has some issues i found python/cpython#104511 but also supports them.
So maybe adding that would make this code a bit more robust. just a thought
cc @matejvasek
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ignore case for line starting w #
you mean skip lines starting with # ?
First time I read that I thought you wanted to turn down case sensitivity 😄
Yes we should skip lines starting with # IMO
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have handled the problem. scanNetRC skips lines starting with # before tokenising... I have also added a test TestScanNetRC_CommentLinesIgnored to cover it...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
When --repository points to a protected HTTP(S) remote, go-git's pure-Go clone had no access to the system credential stack, causing authentication failures even when the user had credentials configured via ~/.git-credentials or ~/.netrc. Adds credentialsForURL which reads credentials from, in order: 1. ~/.git-credentials (git credential store helper format) 2. ~/.netrc The retry follows git's own challenge/response model: an anonymous clone is attempted first; credentialsForURL is only called when the server responds with HTTP 401 (transport.ErrAuthenticationRequired). This avoids sending credentials to servers that do not require them. No subprocesses are spawned and no git binary on PATH is required. Fixes #3415 Signed-off-by: Ankitsinghsisodya <[email protected]>
Introduces new tests to verify credential matching behavior for different URL schemes and port configurations. The tests ensure that: - Credentials stored under `http://` are returned for `https://` requests and vice-versa. - Credentials with explicit non-standard ports do not match URLs on different ports. - Credentials with explicit ports match requests with the same port. - Implicit default ports (80 for http, 443 for https) are treated as equivalent to no port. These changes enhance the robustness of the credential handling logic in the repository.
Introduces new tests for the scanNetRC function to verify its behavior when parsing .netrc files. The tests ensure that: - The first matching machine stanza is returned when multiple stanzas match the same host. - Lines beginning with '#' are correctly ignored as comments during parsing. These additions enhance the reliability of the credential retrieval process from .netrc files.
|
/hold for @matejvasek |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Ankitsinghsisodya, gauron99 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
/unhold |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Unable to clone git repository as template if the repo is protected
There was an error while loading. Please reload this page.