Skip to content

Commit

Permalink
Merge branch 'main' into gitlab-e2e-testfixes
Browse files Browse the repository at this point in the history
Signed-off-by: raghavkaul <[email protected]>
  • Loading branch information
raghavkaul authored May 19, 2023
2 parents 0783bad + 03dc18d commit edb5ba7
Show file tree
Hide file tree
Showing 21 changed files with 427 additions and 99 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -208,7 +208,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -304,7 +304,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -352,7 +352,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -261,7 +261,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -309,7 +309,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -357,7 +357,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -405,7 +405,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -453,7 +453,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -501,7 +501,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -549,7 +549,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -597,7 +597,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -645,7 +645,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -693,7 +693,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -740,7 +740,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -812,7 +812,7 @@ jobs:
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -859,7 +859,7 @@ jobs:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2
uses: arduino/setup-protoc@4b3578161eece2eb20a9dfd84bb8ed105e684dba # v1.2.0
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publishimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
make install
make scorecard-ko
- name: Install Cosign
uses: sigstore/cosign-installer@03d0fecf172873164a163bbc64bed0f3bf114ed7
uses: sigstore/cosign-installer@dd6b2e2b610a11fd73dd187a43d57cc1394e35f9
- name: Sign image
run: |
cosign sign --yes ghcr.io/${{github.repository_owner}}/scorecard/v4:${{ github.sha }}
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ RESULTS
|---------|------------------------|--------------------------------|--------------------------------|---------------------------------------------------------------------------|
```

##### Using GitHub Enterprise Server (GHES) based Repository

To use a GitHub Enterprise host `github.corp.com`, use the `GH_HOST` environment variable.

```shell
# Set the GitHub Enterprise host without https prefix or slash with relevant authentication token
export GH_HOST=github.corp.com
export GITHUB_AUTH_TOKEN=token

scorecard --repo=github.corp.com/org/repo
# OR without github host url
scorecard --repo=org/repo
```

##### Using a Package manager

For projects in the `--npm`, `--pypi`, or `--rubygems` ecosystems, you have the
Expand Down Expand Up @@ -539,13 +553,7 @@ Community Meeting Calendar | Biweekly Thursdays, 1:00pm-2:00pm PST <br>[Calen
Meeting Notes | [Notes](https://docs.google.com/document/d/1dB2U7_qZpNW96vtuoG7ShmgKXzIg6R5XT5Tc-0yz6kE/edit#heading=h.4k8ml0qkh7tl)
Slack Channel | [#security_scorecards](https://slack.openssf.org/#security_scorecards)

&nbsp; | Facilitators | Company | Profile
---------------------------------------------------------------- | ----------------- | ------- | -------
<img width="30px" src="https://github.com/azeemshaikh38.png"> | Azeem Shaikh | Google | [azeemshaikh38](https://github.com/azeemshaikh38)
<img width="30px" src="https://github.com/laurentsimon.png"> | Laurent Simon | Google | [laurentsimon](https://github.com/laurentsimon)
<img width="30px" src="https://github.com/naveensrinivasan.png"> | Naveen Srinivasan | Endor Labs | [naveensrinivasan](https://github.com/naveensrinivasan)
<img width="30px" src="https://github.com/chrismcgehee.png"> | Chris McGehee | Datto | [chrismcgehee](https://github.com/chrismcgehee)
<img width="30px" src="https://github.com/justaugustus.png"> | Stephen Augustus | Cisco | [justaugustus](https://github.com/justaugustus)
__Maintainers__ are listed in the [CODEOWNERS file](.github/CODEOWNERS).

### Report a Security Issue

Expand Down
20 changes: 20 additions & 0 deletions checker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestGetClients(t *testing.T) { //nolint:gocognit
shouldCIIBeNil bool
wantErr bool
experimental bool
isGhHost bool
}{
{
name: "localURI is not empty",
Expand Down Expand Up @@ -94,6 +95,21 @@ func TestGetClients(t *testing.T) { //nolint:gocognit
wantErr: false,
experimental: true,
},
{
name: "repoURI is corp github host",
args: args{
ctx: context.Background(),
repoURI: "https://github.corp.com/ossf/scorecard",
localURI: "",
},
shouldOSSFuzzBeNil: false,
shouldRepoClientBeNil: false,
shouldVulnClientBeNil: false,
shouldRepoBeNil: false,
shouldCIIBeNil: false,
wantErr: false,
isGhHost: true,
},
}

for _, tt := range tests {
Expand All @@ -102,6 +118,10 @@ func TestGetClients(t *testing.T) { //nolint:gocognit
if tt.experimental {
t.Setenv("SCORECARD_EXPERIMENTAL", "true")
}
if tt.isGhHost {
t.Setenv("GH_HOST", "github.corp.com")
t.Setenv("GH_TOKEN", "PAT")
}
got, repoClient, ossFuzzClient, ciiClient, vulnsClient, err := GetClients(tt.args.ctx, tt.args.repoURI, tt.args.localURI, tt.args.logger) //nolint:lll
if (err != nil) != tt.wantErr {
t.Fatalf("GetClients() error = %v, wantErr %v", err, tt.wantErr)
Expand Down
32 changes: 29 additions & 3 deletions clients/githubrepo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"errors"
"fmt"
"net/http"
"os"
"strings"
"time"

"github.com/google/go-github/v38/github"
Expand Down Expand Up @@ -59,6 +61,8 @@ type Client struct {
commitDepth int
}

const defaultGhHost = "github.com"

// InitRepo sets up the GitHub repo in local storage for improving performance and GitHub token usage efficiency.
func (client *Client) InitRepo(inputRepo clients.Repo, commitSHA string, commitDepth int) error {
ghRepo, ok := inputRepo.(*repoURL)
Expand Down Expand Up @@ -126,7 +130,11 @@ func (client *Client) InitRepo(inputRepo clients.Repo, commitSHA string, commitD

// URI implements RepoClient.URI.
func (client *Client) URI() string {
return fmt.Sprintf("github.com/%s/%s", client.repourl.owner, client.repourl.repo)
host, isHost := os.LookupEnv("GH_HOST")
if !isHost {
host = defaultGhHost
}
return fmt.Sprintf("%s/%s/%s", host, client.repourl.owner, client.repourl.repo)
}

// LocalPath implements RepoClient.LocalPath.
Expand Down Expand Up @@ -259,8 +267,26 @@ func CreateGithubRepoClientWithTransport(ctx context.Context, rt http.RoundTripp
httpClient := &http.Client{
Transport: rt,
}
client := github.NewClient(httpClient)
graphClient := githubv4.NewClient(httpClient)

var client *github.Client
var graphClient *githubv4.Client
githubHost, isGhHost := os.LookupEnv("GH_HOST")

if isGhHost && githubHost != defaultGhHost {
githubRestURL := fmt.Sprintf("https://%s/api/v3", strings.TrimSpace(githubHost))
githubGraphqlURL := fmt.Sprintf("https://%s/api/graphql", strings.TrimSpace(githubHost))

var err error
client, err = github.NewEnterpriseClient(githubRestURL, githubRestURL, httpClient)
if err != nil {
panic(fmt.Errorf("error during CreateGithubRepoClientWithTransport:EnterpriseClient: %w", err))
}

graphClient = githubv4.NewEnterpriseClient(githubGraphqlURL, httpClient)
} else {
client = github.NewClient(httpClient)
graphClient = githubv4.NewClient(httpClient)
}

return &Client{
ctx: ctx,
Expand Down
9 changes: 8 additions & 1 deletion clients/githubrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package githubrepo
import (
"fmt"
"net/url"
"os"
"strings"

"github.com/ossf/scorecard/v4/clients"
Expand All @@ -42,7 +43,11 @@ func (r *repoURL) parse(input string) error {
// This will takes care for repo/owner format.
// By default it will use github.com
case l == two:
t = "github.com/" + c[0] + "/" + c[1]
githubHost, isGhHost := os.LookupEnv("GH_HOST")
if !isGhHost {
githubHost = "github.com"
}
t = githubHost + "/" + c[0] + "/" + c[1]
case l >= three:
t = input
}
Expand Down Expand Up @@ -83,8 +88,10 @@ func (r *repoURL) String() string {

// IsValid implements Repo.IsValid.
func (r *repoURL) IsValid() error {
githubHost := os.Getenv("GH_HOST")
switch r.host {
case "github.com":
case githubHost:
default:
return sce.WithMessage(sce.ErrorUnsupportedHost, r.host)
}
Expand Down
Loading

0 comments on commit edb5ba7

Please sign in to comment.