-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: npm default runner support (#495)
* update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> * update Signed-off-by: laurentsimon <laurentsimon@google.com> --------- Signed-off-by: laurentsimon <laurentsimon@google.com>
- Loading branch information
1 parent
12910ea
commit 82a1259
Showing
36 changed files
with
2,938 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
#!/bin/bash | ||
|
||
repo="slsa-framework/example-package" | ||
api_version="X-GitHub-Api-Version: 2022-11-28" | ||
# Verify provenance authenticity with slsa-verifier at HEAD | ||
|
||
download_artifact(){ | ||
local run_id="$1" | ||
local artifact_name="$2" | ||
# Get the artifact ID for 'artifact1' | ||
artifact_id=$(gh api -H "Accept: application/vnd.github+json" -H "$api_version" "/repos/$repo/actions/runs/$run_id/artifacts" | jq ".artifacts[] | select(.name == \"$artifact_name\") | .id") | ||
echo "artifact_id:$artifact_id" | ||
|
||
gh api -H "Accept: application/vnd.github+json" -H "$api_version" "/repos/$repo/actions/artifacts/$artifact_id/zip" > "$artifact_name.zip" | ||
unzip "$artifact_name".zip | ||
} | ||
|
||
# Get workflow ID. | ||
workflow_id=$(gh api -H "Accept: application/vnd.github+json" -H "$api_version" "/repos/$repo/actions/workflows?per_page=100" | jq '.workflows[] | select(.path == ".github/workflows/e2e.generic.schedule.main.multi-uses.slsa3.yml") | .id') | ||
echo "workflow_id:$workflow_id" | ||
|
||
# Get the run ID for the most recent run. | ||
run_id=$(gh api -H "Accept: application/vnd.github+json" -H "$api_version" "/repos/$repo/actions/workflows/$workflow_id/runs?per_page=1" | jq '.workflow_runs[0].id') | ||
echo "run_id:$run_id" | ||
|
||
download_artifact "$run_id" "artifacts1" | ||
download_artifact "$run_id" "attestation1.intoto.jsonl" | ||
|
||
cd __EXAMPLE_PACKAGE__ | ||
# shellcheck source=/dev/null | ||
source "./.github/workflows/scripts/e2e-verify.common.sh" | ||
|
||
# Set THIS_FILE to correspond with the artifact properties | ||
export THIS_FILE=e2e.go.workflow_dispatch.main.config-noldflags.slsa3.yml | ||
export THIS_FILE=e2e.generic.schedule.main.multi-uses.slsa3.yml | ||
export BRANCH=main | ||
|
||
# Set BINARY and PROVENANCE | ||
cd - | ||
export BINARY=__THIS_REPO__/cli/slsa-verifier/testdata/gha_go/v1.2.2/binary-linux-amd64-workflow_dispatch | ||
export PROVENANCE=__THIS_REPO__/cli/slsa-verifier/testdata/gha_go/v1.2.2/binary-linux-amd64-workflow_dispatch.intoto.jsonl | ||
export BINARY=artifact1 | ||
export PROVENANCE=attestation1.intoto.jsonl | ||
|
||
GITHUB_REPOSITORY=slsa-framework/example-package verify_provenance_authenticity "./__THIS_REPO__/slsa-verifier" "HEAD" | ||
GITHUB_REPOSITORY="$repo" verify_provenance_authenticity "./__THIS_REPO__/slsa-verifier" "HEAD" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2023 SLSA Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package verify | ||
|
||
import ( | ||
"encoding/hex" | ||
"hash" | ||
"io" | ||
"os" | ||
) | ||
|
||
func computeFileHash(filePath string, h hash.Hash) (string, error) { | ||
f, err := os.Open(filePath) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer f.Close() | ||
|
||
if _, err := io.Copy(h, f); err != nil { | ||
return "", err | ||
} | ||
return hex.EncodeToString(h.Sum(nil)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2022 SLSA Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package verify | ||
|
||
import ( | ||
"context" | ||
"crypto/sha512" | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/slsa-framework/slsa-verifier/v2/options" | ||
"github.com/slsa-framework/slsa-verifier/v2/verifiers" | ||
"github.com/slsa-framework/slsa-verifier/v2/verifiers/utils" | ||
) | ||
|
||
type VerifyNpmPackageCommand struct { | ||
AttestationsPath string | ||
BuilderID *string | ||
SourceURI string | ||
SourceBranch *string | ||
SourceTag *string | ||
SourceVersionTag *string | ||
PackageName *string | ||
PackageVersion *string | ||
BuildWorkflowInputs map[string]string | ||
PrintProvenance bool | ||
} | ||
|
||
func (c *VerifyNpmPackageCommand) Exec(ctx context.Context, tarballs []string) (*utils.TrustedBuilderID, error) { | ||
var builderID *utils.TrustedBuilderID | ||
if !options.ExperimentalEnabled() { | ||
err := errors.New("feature support is only provided in SLSA_VERIFIER_EXPERIMENTAL mode") | ||
fmt.Fprintf(os.Stderr, "Verifying npm package: FAILED: %v\n\n", err) | ||
return nil, err | ||
} | ||
for _, tarball := range tarballs { | ||
tarballHash, err := computeFileHash(tarball, sha512.New()) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Verifying npm package %s: FAILED: %v\n\n", tarball, err) | ||
return nil, err | ||
} | ||
|
||
if c.AttestationsPath == "" { | ||
fmt.Fprintf(os.Stderr, "Verifying npm package %s: FAILED: %v\n\n", tarball, err) | ||
return nil, err | ||
} | ||
provenanceOpts := &options.ProvenanceOpts{ | ||
ExpectedSourceURI: c.SourceURI, | ||
ExpectedBranch: c.SourceBranch, | ||
ExpectedDigest: tarballHash, | ||
ExpectedVersionedTag: c.SourceVersionTag, | ||
ExpectedTag: c.SourceTag, | ||
ExpectedWorkflowInputs: c.BuildWorkflowInputs, | ||
ExpectedPackageName: c.PackageName, | ||
ExpectedPackageVersion: c.PackageVersion, | ||
} | ||
|
||
builderOpts := &options.BuilderOpts{ | ||
ExpectedID: c.BuilderID, | ||
} | ||
|
||
attestations, err := os.ReadFile(c.AttestationsPath) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Verifying npm package %s: FAILED: %v\n\n", tarball, err) | ||
return nil, err | ||
} | ||
|
||
verifiedProvenance, outBuilderID, err := verifiers.VerifyNpmPackage(ctx, attestations, tarballHash, provenanceOpts, builderOpts) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Verifying npm package %s: FAILED: %v\n\n", tarball, err) | ||
return nil, err | ||
} | ||
|
||
if c.PrintProvenance { | ||
fmt.Fprintf(os.Stdout, "%s\n", string(verifiedProvenance)) | ||
} | ||
|
||
builderID = outBuilderID | ||
fmt.Fprintf(os.Stderr, "Verifying npm package %s: PASSED\n\n", tarball) | ||
} | ||
|
||
return builderID, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.