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

[TEP-0089] - Spire Package #5039

Merged
merged 1 commit into from
Sep 19, 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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ run:
skip-dirs:
- vendor
- pkg/client
- pkg/spire/test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is the spire test client copied over from spire - any reason for excluding it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spire test package had a bunch of linting errors but as it was copied over from spire, I was not sure if I made sense to fix it all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a verbatim copy, or are we making modifications?

(if we're making modifications, I'd prefer to keep linting on for our changes if possible)

we should also add instructions for how this was imported for if/when we need to update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the test client needs to be part of the pipeline code base, we will need license headers in each file under pkg/spire/test, fix linting errors, and some kind of documentation on why ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue #5281 to track this.

timeout: 10m
modules-download-mode: vendor
13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/tektoncd/pipeline
go 1.18

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ahmetb/gen-crd-api-reference-docs v0.3.1-0.20220720053627-e327d0730470 // Waiting for https://github.com/ahmetb/gen-crd-api-reference-docs/pull/43/files to merge
github.com/cloudevents/sdk-go/v2 v2.11.0
github.com/containerd/containerd v1.5.13
Expand All @@ -18,11 +19,14 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198
github.com/pkg/errors v0.9.1
github.com/spiffe/go-spiffe/v2 v2.1.1
github.com/spiffe/spire-api-sdk v1.3.1
github.com/tektoncd/plumbing v0.0.0-20220817140952-3da8ce01aeeb
go.opencensus.io v0.23.0
go.uber.org/zap v1.23.0
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
gomodules.xyz/jsonpatch/v2 v2.2.0
gopkg.in/square/go-jose.v2 v2.5.1
k8s.io/api v0.23.9
k8s.io/apimachinery v0.23.9
k8s.io/client-go v0.23.9
Expand All @@ -38,7 +42,6 @@ require github.com/benbjohnson/clock v1.1.0 // indirect
require k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9

require (
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
Expand All @@ -51,6 +54,8 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
)

require github.com/zeebo/errs v1.2.2 // indirect

require (
cloud.google.com/go/compute v1.5.0 // indirect
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
Expand Down Expand Up @@ -136,7 +141,7 @@ require (
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/stretchr/testify v1.8.0
github.com/vbatts/tar-split v0.11.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/automaxprocs v1.4.0 // indirect
Expand All @@ -155,8 +160,8 @@ require (
google.golang.org/api v0.70.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220303160752-862486edd9cc // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/grpc v1.46.0
google.golang.org/protobuf v1.28.0
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
22 changes: 18 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions pkg/reconciler/testing/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
_ "knative.dev/pkg/client/injection/kube/informers/factory/filtered/fake"
)

// SetupFakeContext sets up the the Context and the fake filtered informers for the tests.
// SetupFakeContext sets up the Context and the fake filtered informers for the tests.
func SetupFakeContext(t *testing.T) (context.Context, []controller.Informer) {
ctx, _, informer := setupFakeContextWithLabelKey(t)
cloudEventClientBehaviour := cloudevent.FakeClientBehaviour{
Expand All @@ -31,6 +31,12 @@ func SetupFakeContext(t *testing.T) (context.Context, []controller.Informer) {
return WithLogger(ctx, t), informer
}

// SetupDefaultContext sets up the Context and the default filtered informers for the tests.
func SetupDefaultContext(t *testing.T) (context.Context, []controller.Informer) {
ctx, _, informer := setupDefaultContextWithLabelKey(t)
return WithLogger(ctx, t), informer
}

// WithLogger returns the the Logger
func WithLogger(ctx context.Context, t *testing.T) context.Context {
return logging.WithLogger(ctx, TestLogger(t))
Expand All @@ -42,7 +48,7 @@ func TestLogger(t *testing.T) *zap.SugaredLogger {
return logger.Sugar().Named(t.Name())
}

// setupFakeContextWithLabelKey sets up the the Context and the fake informers for the tests
// setupFakeContextWithLabelKey sets up the Context and the fake informers for the tests
// The provided context includes the FilteredInformerFactory LabelKey.
func setupFakeContextWithLabelKey(t zaptest.TestingT) (context.Context, context.CancelFunc, []controller.Informer) {
ctx, c := context.WithCancel(logtesting.TestContextWithLogger(t))
Expand All @@ -51,3 +57,12 @@ func setupFakeContextWithLabelKey(t zaptest.TestingT) (context.Context, context.
ctx, is := injection.Fake.SetupInformers(ctx, &rest.Config{})
return ctx, c, is
}

// setupDefaultContextWithLabelKey sets up the Context and the default informers for the tests
// The provided context includes the FilteredInformerFactory LabelKey.
func setupDefaultContextWithLabelKey(t zaptest.TestingT) (context.Context, context.CancelFunc, []controller.Informer) {
ctx, c := context.WithCancel(logtesting.TestContextWithLogger(t))
ctx = filteredinformerfactory.WithSelectors(ctx, v1beta1.ManagedByLabelKey)
ctx, is := injection.Default.SetupInformers(ctx, &rest.Config{})
return ctx, c, is
}
68 changes: 68 additions & 0 deletions pkg/spire/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright 2022 The Tekton 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

http://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 config

import (
"fmt"
"sort"
"strings"
)

// SpireConfig holds the images reference for a number of container images used
// across tektoncd pipelines.
type SpireConfig struct {
// The trust domain corresponds to the trust root of a SPIFFE identity provider.
TrustDomain string
// Path to the spire agent socket defined by the CSI driver
SocketPath string
// Spire server address
ServerAddr string
// Prefix to attach to the node name when registering it with the spire server
NodeAliasPrefix string

// MockSpire only to be used for testing the controller, will not exhibit
// all characteristics of spire since it is only being used in the context
// of process memory.
MockSpire bool
}

// Validate returns an error if any image is not set.
func (c SpireConfig) Validate() error {
var unset []string
for _, f := range []struct {
v, name string
}{
{c.TrustDomain, "spire-trust-domain"},
{c.SocketPath, "spire-socket-path"},
{c.ServerAddr, "spire-server-addr"},
{c.NodeAliasPrefix, "spire-node-alias-prefix"},
} {
if f.v == "" {
unset = append(unset, f.name)
}
}
if len(unset) > 0 {
sort.Strings(unset)
return fmt.Errorf("found unset spire configuration flags: %s", unset)
}

if !strings.HasPrefix(c.NodeAliasPrefix, "/") {
return fmt.Errorf("Spire node alias should start with a /")
}

return nil
}
Loading