Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GitHub attestation endpoint #2195

Merged
merged 4 commits into from
Jan 25, 2024
Merged
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
45 changes: 43 additions & 2 deletions cmd/dev/app/container/cmd_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ package container

import (
"context"
"encoding/json"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/stacklok/minder/internal/db"
"github.com/stacklok/minder/internal/providers"
"github.com/stacklok/minder/internal/verifier"
"github.com/stacklok/minder/internal/verifier/sigstore/container"
provifv1 "github.com/stacklok/minder/pkg/providers/v1"
)

// CmdVerify returns the verify container command
// CmdVerify is the root command for the container verify subcommands
func CmdVerify() *cobra.Command {
var verifyCmd = &cobra.Command{
Use: "verify",
Expand All @@ -39,6 +44,8 @@ func CmdVerify() *cobra.Command {
verifyCmd.Flags().StringP("owner", "o", "", "owner of the artifact")
verifyCmd.Flags().StringP("name", "n", "", "name of the artifact")
verifyCmd.Flags().StringP("digest", "s", "", "digest of the artifact")
verifyCmd.Flags().StringP("token", "t", "", "token to authenticate to the provider."+
"Can also be set via the AUTH_TOKEN environment variable.")

if err := verifyCmd.MarkFlagRequired("owner"); err != nil {
fmt.Fprintf(os.Stderr, "Error marking flag as required: %s\n", err)
Expand All @@ -55,6 +62,11 @@ func CmdVerify() *cobra.Command {
os.Exit(1)
}

if err := viper.BindPFlag("auth.token", verifyCmd.Flags().Lookup("token")); err != nil {
fmt.Fprintf(os.Stderr, "Error binding flag: %s\n", err)
os.Exit(1)
}

viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

return verifyCmd
Expand All @@ -67,7 +79,14 @@ func runCmdVerify(cmd *cobra.Command, _ []string) error {

token := viper.GetString("auth.token")

artifactVerifier, err := verifier.NewVerifier(verifier.VerifierSigstore, token)
ghcli, err := buildGitHubClient(context.Background(), token)
if err != nil {
return fmt.Errorf("cannot build github client: %w", err)
}

artifactVerifier, err := verifier.NewVerifier(
verifier.VerifierSigstore,
container.WithAccessToken(token), container.WithGitHubClient(ghcli))
if err != nil {
return fmt.Errorf("error getting sigstore verifier: %w", err)
}
Expand All @@ -85,3 +104,25 @@ func runCmdVerify(cmd *cobra.Command, _ []string) error {

return nil
}

func buildGitHubClient(ctx context.Context, token string) (provifv1.GitHub, error) {
pbuild := providers.NewProviderBuilder(
&db.Provider{
Name: "test",
Version: "v1",
Implements: []db.ProviderType{
"rest",
"git",
"github",
},
Definition: json.RawMessage(`{
"rest": {},
"github": {}
}`),
},
db.ProviderAccessToken{},
token,
)

return pbuild.GetGitHub(ctx)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
Expand Down
5 changes: 4 additions & 1 deletion internal/controlplane/handlers_githubwebhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/stacklok/minder/internal/reconcilers"
"github.com/stacklok/minder/internal/util"
"github.com/stacklok/minder/internal/verifier"
"github.com/stacklok/minder/internal/verifier/sigstore/container"
pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1"
provifv1 "github.com/stacklok/minder/pkg/providers/v1"
)
Expand Down Expand Up @@ -745,7 +746,9 @@ func storeSignatureAndWorkflowInVersion(
version *pb.ArtifactVersion,
) error {
// get the verifier for sigstore
artifactVerifier, err := verifier.NewVerifier(verifier.VerifierSigstore, client.GetToken())
artifactVerifier, err := verifier.NewVerifier(
verifier.VerifierSigstore,
container.WithAccessToken(client.GetToken()), container.WithGitHubClient(client))
if err != nil {
return fmt.Errorf("error getting sigstore verifier: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/reconcilers/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/stacklok/minder/internal/providers/github"
"github.com/stacklok/minder/internal/util"
"github.com/stacklok/minder/internal/verifier"
"github.com/stacklok/minder/internal/verifier/sigstore/container"
pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1"
)

Expand Down Expand Up @@ -153,7 +154,9 @@ func (e *Reconciler) handleArtifactsReconcilerEvent(ctx context.Context, evt *Re
}

// create artifact verifier
artifactVerifier, err := verifier.NewVerifier(verifier.VerifierSigstore, cli.GetToken())
artifactVerifier, err := verifier.NewVerifier(
verifier.VerifierSigstore,
container.WithAccessToken(cli.GetToken()), container.WithGitHubClient(cli))
if err != nil {
return fmt.Errorf("error getting sigstore verifier: %w", err)
}
Expand Down
Loading
Loading