Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/handlers/git_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ func getCredentialsForRequest(r *http.Request, credentials *gitCredentialsMap, e
return nil
}

if isPublicGitHubDownload(host, r.URL.Path) {
return nil
}

// Get credentials for the host that not unscoped to specific repositories.
hostCreds := credentials.get(host)
credsForRequest := hostCreds.getCredentialsForRepo(allReposScopeIdentifier)
Expand All @@ -343,6 +347,12 @@ func getCredentialsForRequest(r *http.Request, credentials *gitCredentialsMap, e
return credsForRequest
}

// GitHub release download URLs are public
// and do not require authentication
func isPublicGitHubDownload(host string, path string) bool {
return host == "github.com" && strings.Contains(path, "/releases/download/")
}

// HandleResponse handles retrying failed auth responses with alternate credentials
// when there are multiple tokens configured for the git server.
//
Expand Down
23 changes: 23 additions & 0 deletions internal/handlers/git_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,29 @@ func TestGitServerHandler(t *testing.T) {
"valid github request")
}

func TestGitServerPublicReleaseDownload(t *testing.T) {
installationCred := testGitSourceCred("github.com", "x-access-token", "v1.token")
gheCred := testGitSourceCred("ghe.some-corp.com", "x-access-token", "corp")

credentials := config.Credentials{
installationCred,
gheCred,
}
handler := NewGitServerHandler(credentials, nil)

req := httptest.NewRequest("HEAD", "https://github.com/gradle/gradle-distributions/releases/download/v9.3.0/gradle-9.3.0-bin.zip", nil)
req, _ = handler.HandleRequest(req, nil)
assertUnauthenticated(t, req, "Public github.com release downloads should not be authenticated")

req = httptest.NewRequest("HEAD", "https://ghe.some-corp.com/gradle/gradle-distributions/releases/download/v9.3.0/gradle-9.3.0-bin.zip", nil)
req, _ = handler.HandleRequest(req, nil)
assertHasBasicAuth(t, req,
gheCred.GetString("username"),
gheCred.GetString("password"),
"valid github request")

}

func TestGitServerHandler_AuthenticatedAccessToGitHubRepos(t *testing.T) {
installationToken1 := "v1.token1"
privateRepo1Cred := testGitSourceCred("github.com", "x-access-token", installationToken1, withAccessibleRepos([]string{"github/private-repo-1"}))
Expand Down
Loading