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

Remove knative/pkg deps #2092

Merged
merged 3 commits into from
Jul 25, 2022
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
2 changes: 1 addition & 1 deletion cmd/cosign/cli/fulcio/depcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package fulcio_test
import (
"testing"

"knative.dev/pkg/depcheck"
"github.com/depcheck-test/depcheck-test/depcheck"
)

func TestNoDeps(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/cenkalti/backoff/v3 v3.2.2
github.com/chrismellard/docker-credential-acr-env v0.0.0-20220119192733-fe33c00cee21
github.com/cyberphone/json-canonicalization v0.0.0-20210823021906-dc406ceaf94b
github.com/depcheck-test/depcheck-test v0.0.0-20220607135614-199033aaa936
github.com/go-openapi/runtime v0.24.1
github.com/go-openapi/strfmt v0.21.3
github.com/go-openapi/swag v0.21.1
Expand Down Expand Up @@ -70,6 +71,7 @@ require (
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
golang.org/x/net v0.0.0-20220708220712-1185a9018129
golang.org/x/oauth2 v0.0.0-20220718184931-c8730f7fcb92
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
golang.org/x/time v0.0.0-20220411224347-583f2d630306
Expand All @@ -82,7 +84,6 @@ require (
k8s.io/apimachinery v0.23.5
k8s.io/client-go v0.23.5
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
knative.dev/pkg v0.0.0-20220325200448-1f7514acd0c2
sigs.k8s.io/release-utils v0.6.0
)

Expand Down Expand Up @@ -130,7 +131,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
Expand Down Expand Up @@ -277,7 +277,6 @@ require (
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.11 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,6 @@ github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb/go.mod h1:PkYb9DJNAw
github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blendle/zapdriver v1.3.1 h1:C3dydBOWYRiOk+B8X9IVZ5IOe+7cl+tGOexN4QqHfpE=
github.com/blendle/zapdriver v1.3.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc=
github.com/blizzy78/varnamelen v0.3.0/go.mod h1:hbwRdBvoBqxk34XyQ6HA0UH3G0/1TKuv5AC4eaBT0Ec=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bombsimon/wsl/v3 v3.3.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc=
Expand Down Expand Up @@ -672,6 +670,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/denis-tingajkin/go-header v0.4.2/go.mod h1:eLRHAVXzE5atsKAnNRDB90WHCFFnBUn4RN0nRcs1LJA=
github.com/denisenkom/go-mssqldb v0.11.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0=
github.com/depcheck-test/depcheck-test v0.0.0-20220607135614-199033aaa936 h1:foGzavPWwtoyBvjWyKJYDYsyzy+23iBV7NKTwdk+LRY=
github.com/depcheck-test/depcheck-test v0.0.0-20220607135614-199033aaa936/go.mod h1:ttKPnOepYt4LLzD+loXQ1rT6EmpyIYHro7TAJuIIlHo=
github.com/devigned/tab v0.1.1/go.mod h1:XG9mPq0dFghrYvoBF3xdRrJzSTX1b7IQrvaL9mzjeJY=
github.com/dgraph-io/badger/v3 v3.2103.2 h1:dpyM5eCJAtQCBcMCZcT4UBZchuTJgCywerHHgmxfxM8=
github.com/dgraph-io/badger/v3 v3.2103.2/go.mod h1:RHo4/GmYcKKh5Lxu63wLEMHJ70Pac2JqZRYGhlyAo2M=
Expand Down Expand Up @@ -3303,8 +3303,6 @@ k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
knative.dev/pkg v0.0.0-20220325200448-1f7514acd0c2 h1:dJ1YKQ1IvCfxtYqS1dHm18VT153ntHi5uJsFVv7oxfc=
knative.dev/pkg v0.0.0-20220325200448-1f7514acd0c2/go.mod h1:5xt0nzCwxvQ2N4w71smY7pYm5nVrQ8qnRsMinSLVpio=
mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48=
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
Expand Down
18 changes: 8 additions & 10 deletions pkg/cosign/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/google/go-containerregistry/pkg/name"
"github.com/sigstore/cosign/pkg/cosign/bundle"
ociremote "github.com/sigstore/cosign/pkg/oci/remote"
"knative.dev/pkg/pool"
"golang.org/x/sync/errgroup"
)

type SignedPayload struct {
Expand Down Expand Up @@ -78,11 +78,12 @@ func FetchSignaturesForReference(ctx context.Context, ref name.Reference, opts .
return nil, fmt.Errorf("no signatures associated with %v: %w", ref, err)
}

g := pool.New(runtime.NumCPU())
signatures := make([]SignedPayload, len(l))
var g errgroup.Group
g.SetLimit(runtime.NumCPU())
for i, sig := range l {
i, sig := i, sig
g.Go(func() (err error) {
g.Go(func() error {
signatures[i].Payload, err = sig.Payload()
if err != nil {
return err
Expand Down Expand Up @@ -128,17 +129,14 @@ func FetchAttestationsForReference(ctx context.Context, ref name.Reference, opts
return nil, fmt.Errorf("no attestations associated with %v: %w", ref, err)
}

g := pool.New(runtime.NumCPU())
attestations := make([]AttestationPayload, len(l))
var g errgroup.Group
g.SetLimit(runtime.NumCPU())
for i, att := range l {
i, att := i, att
g.Go(func() (err error) {
g.Go(func() error {
attestPayload, _ := att.Payload()
err = json.Unmarshal(attestPayload, &attestations[i])
if err != nil {
return err
}
return err
return json.Unmarshal(attestPayload, &attestations[i])
})
}
if err := g.Wait(); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/cosign/rego/rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"

"github.com/open-policy-agent/opa/rego"
"knative.dev/pkg/logging"
)

// The query below should meet the following requirements:
Expand Down Expand Up @@ -112,7 +111,6 @@ func ValidateJSONWithModuleInput(jsonBody []byte, moduleInput string) error {
for _, result := range rs {
isCompliant, ok := result.Bindings[CosignEvaluationRule].(bool)
if ok && isCompliant {
logging.FromContext(ctx).Info("Validated policy is compliant")
return nil
}
}
Expand Down
12 changes: 5 additions & 7 deletions pkg/policy/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ package policy
import (
"context"
"fmt"
"log"

"cuelang.org/go/cue/cuecontext"
"github.com/sigstore/cosign/pkg/cosign/rego"

"knative.dev/pkg/logging"
)

// EvaluatePolicyAgainstJson is used to run a policy engine against JSON bytes.
Expand All @@ -33,7 +32,6 @@ import (
// policyBody - String representing either cue or rego language
// jsonBytes - Bytes to evaluate against the policyBody in the given language
func EvaluatePolicyAgainstJSON(ctx context.Context, name, policyType string, policyBody string, jsonBytes []byte) error {
logging.FromContext(ctx).Debugf("Evaluating JSON: %s against policy: %s", string(jsonBytes), policyBody)
switch policyType {
case "cue":
cueValidationErr := evaluateCue(ctx, jsonBytes, policyBody)
Expand All @@ -53,8 +51,8 @@ func EvaluatePolicyAgainstJSON(ctx context.Context, name, policyType string, pol

// evaluateCue evaluates a cue policy `evaluator` against `attestation`
func evaluateCue(ctx context.Context, attestation []byte, evaluator string) error {
logging.FromContext(ctx).Infof("Evaluating attestation: %s", string(attestation))
logging.FromContext(ctx).Infof("Evaluator: %s", evaluator)
log.Printf("Evaluating attestation: %s", string(attestation))
log.Printf("Evaluator: %s", evaluator)

cueCtx := cuecontext.New()
cueEvaluator := cueCtx.CompileString(evaluator)
Expand All @@ -74,8 +72,8 @@ func evaluateCue(ctx context.Context, attestation []byte, evaluator string) erro

// evaluateRego evaluates a rego policy `evaluator` against `attestation`
func evaluateRego(ctx context.Context, attestation []byte, evaluator string) error {
logging.FromContext(ctx).Infof("Evaluating attestation: %s", string(attestation))
logging.FromContext(ctx).Infof("Evaluating evaluator: %s", evaluator)
log.Printf("Evaluating attestation: %s", string(attestation))
log.Printf("Evaluating evaluator: %s", evaluator)

return rego.ValidateJSONWithModuleInput(attestation, evaluator)
}