Skip to content

Commit

Permalink
spire package with tests
Browse files Browse the repository at this point in the history
Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 committed Jul 11, 2022
1 parent 4c021dc commit f58c601
Show file tree
Hide file tree
Showing 221 changed files with 30,447 additions and 728 deletions.
14 changes: 11 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ 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.0
github.com/spiffe/spire-api-sdk v1.3.1
github.com/tektoncd/plumbing v0.0.0-20220329085922-d765a5cba75f
go.opencensus.io v0.23.0
go.uber.org/zap v1.19.1
Expand All @@ -31,6 +33,12 @@ require (
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/zeebo/errs v1.2.2 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // 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 @@ -115,7 +123,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.7.0 // indirect
github.com/stretchr/testify v1.7.1 // indirect
github.com/tektoncd/resolution v0.0.0-20220331203013-e4203c70c5eb
github.com/vbatts/tar-split v0.11.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
Expand All @@ -135,8 +143,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 // indirect
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: 19 additions & 3 deletions go.sum

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

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 image flags: %s", unset)
}

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

return nil
}
Loading

0 comments on commit f58c601

Please sign in to comment.