Skip to content

Commit

Permalink
modularize the fulcio and rekor URLs
Browse files Browse the repository at this point in the history
Signed-off-by: Ramon Petgrave <[email protected]>
  • Loading branch information
ramonpetgrave64 committed Aug 12, 2024
1 parent fa01e80 commit 0c7d87b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion internal/builders/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func runBuild(dry bool, configFile, evalEnvs string) error {
}

func runProvenanceGeneration(subject, digest, commands, envs, workingDir, rekor string) error {
s := sigstore.NewDefaultBundleSigner()
s := sigstore.NewBundleSigner(sigstore.DefaultFulcioAddr, rekor)

attBytes, err := pkg.GenerateProvenance(subject, digest,
commands, envs, workingDir, s, nil)
if err != nil {
Expand Down
32 changes: 25 additions & 7 deletions signing/sigstore/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (
)

// BundleSigner is used to produce Sigstore Bundles from provenance statements.
type BundleSigner struct{}
type BundleSigner struct {
fulcioAddr string
rekorAddr string
}

type sigstoreBundleAtt struct {
cert []byte
Expand All @@ -45,7 +48,14 @@ func (s *sigstoreBundleAtt) Bytes() []byte {

// NewDefaultBundleSigner creates a new BundleSigner instance.
func NewDefaultBundleSigner() *BundleSigner {
return &BundleSigner{}
return NewBundleSigner(DefaultFulcioAddr, DefaultRekorAddr)
}

func NewBundleSigner(fulcioAddr string, rekorAddr string) *BundleSigner {

Check failure on line 54 in signing/sigstore/bundle.go

View workflow job for this annotation

GitHub Actions / golangci-lint

paramTypeCombine: func(fulcioAddr string, rekorAddr string) *BundleSigner could be replaced with func(fulcioAddr, rekorAddr string) *BundleSigner (gocritic)
return &BundleSigner{
fulcioAddr: fulcioAddr,
rekorAddr: rekorAddr,
}
}

// Sign signs the given provenance statement and returns the signed Sigstore Bundle.
Expand Down Expand Up @@ -78,7 +88,11 @@ func (s *BundleSigner) Sign(ctx context.Context, statement *intoto.Statement) (s
rawToken := TokenStruct.RawToken

// signing opts.
bundleOpts, err := getDefaultBundleOptsWithIdentityToken(&rawToken)
bundleOpts, err := getBundleOpts(
&s.fulcioAddr,
&s.rekorAddr,
&rawToken,
)
if err != nil {
return nil, err
}
Expand All @@ -104,20 +118,24 @@ func (s *BundleSigner) Sign(ctx context.Context, statement *intoto.Statement) (s
return bundleAtt, nil
}

// getDefaultBundleOptsWithIdentityToken provides the default opts for sigstoreSign.Bundle().
func getDefaultBundleOptsWithIdentityToken(identityToken *string) (*sigstoreSign.BundleOptions, error) {
// getBundleOpts provides the opts for sigstoreSign.Bundle().
func getBundleOpts(
fulcioAddr *string,
rekorAddr *string,
identityToken *string,
) (*sigstoreSign.BundleOptions, error) {
bundleOpts := &sigstoreSign.BundleOptions{}

fulcioOpts := &sigstoreSign.FulcioOptions{
BaseURL: "https://fulcio.sigstore.dev",
BaseURL: *fulcioAddr,
}
bundleOpts.CertificateProvider = sigstoreSign.NewFulcio(fulcioOpts)
bundleOpts.CertificateProviderOptions = &sigstoreSign.CertificateProviderOptions{
IDToken: *identityToken,
}

rekorOpts := &sigstoreSign.RekorOptions{
BaseURL: "https://rekor.sigstore.dev",
BaseURL: *rekorAddr,
}
bundleOpts.TransparencyLogs = append(bundleOpts.TransparencyLogs, sigstoreSign.NewRekor(rekorOpts))
return bundleOpts, nil
Expand Down
4 changes: 2 additions & 2 deletions signing/sigstore/fulcio.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

const (
defaultFulcioAddr = options.DefaultFulcioURL
DefaultFulcioAddr = options.DefaultFulcioURL

Check failure on line 35 in signing/sigstore/fulcio.go

View workflow job for this annotation

GitHub Actions / golangci-lint

exported: exported const DefaultFulcioAddr should have comment (or a comment on this block) or be unexported (revive)
defaultOIDCIssuer = options.DefaultOIDCIssuerURL
defaultOIDCClientID = "sigstore"
)
Expand Down Expand Up @@ -63,7 +63,7 @@ func (a *attestation) Cert() []byte {
// NewDefaultFulcio creates a new Fulcio instance using the public Fulcio
// server and public sigstore OIDC issuer.
func NewDefaultFulcio() *Fulcio {
return NewFulcio(defaultFulcioAddr, defaultOIDCIssuer, defaultOIDCClientID)
return NewFulcio(DefaultFulcioAddr, defaultOIDCIssuer, defaultOIDCClientID)
}

// NewFulcio creates a new Fulcio instance.
Expand Down

0 comments on commit 0c7d87b

Please sign in to comment.