Skip to content

Commit

Permalink
[TEP-0089] - Phase 1 Signed TaskRun Results
Browse files Browse the repository at this point in the history
Signed-off-by: pxp928 <[email protected]>
  • Loading branch information
pxp928 committed Apr 28, 2022
1 parent 68f2a66 commit 9d3aead
Show file tree
Hide file tree
Showing 175 changed files with 28,100 additions and 67 deletions.
8 changes: 8 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,20 @@ func main() {
flag.StringVar(&opts.Images.ImageDigestExporterImage, "imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.")
flag.StringVar(&opts.Images.WorkingDirInitImage, "workingdirinit-image", "", "The container image containing our working dir init binary.")

flag.StringVar(&opts.SpireConfig.TrustDomain, "spire-trust-domain", "example.org", "Experimental: The SPIRE Trust domain to use.")
flag.StringVar(&opts.SpireConfig.SocketPath, "spire-socket-path", "/spiffe-workload-api/spire-agent.sock", "Experimental: The SPIRE agent socket for SPIFFE workload API.")
flag.StringVar(&opts.SpireConfig.ServerAddr, "spire-server-addr", "spire-server.spire.svc.cluster.local:8081", "Experimental: The SPIRE server address for workload/node registration.")
flag.StringVar(&opts.SpireConfig.NodeAliasPrefix, "spire-node-alias-prefix", "/tekton-node/", "Experimental: The SPIRE node alias prefix to use.")

// This parses flags.
cfg := injection.ParseAndGetRESTConfigOrDie()

if err := opts.Images.Validate(); err != nil {
log.Fatal(err)
}
if err := opts.SpireConfig.Validate(); err != nil {
log.Fatal(err)
}
if cfg.QPS == 0 {
cfg.QPS = 2 * rest.DefaultQPS
}
Expand Down
12 changes: 12 additions & 0 deletions cmd/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"github.com/tektoncd/pipeline/pkg/credentials/dockercreds"
"github.com/tektoncd/pipeline/pkg/credentials/gitcreds"
"github.com/tektoncd/pipeline/pkg/entrypoint"
"github.com/tektoncd/pipeline/pkg/spire"
"github.com/tektoncd/pipeline/pkg/spire/config"
"github.com/tektoncd/pipeline/pkg/termination"
)

Expand All @@ -49,6 +51,8 @@ var (
onError = flag.String("on_error", "", "Set to \"continue\" to ignore an error and continue when a container terminates with a non-zero exit code."+
" Set to \"stopAndFail\" to declare a failure with a step error and stop executing the rest of the steps.")
stepMetadataDir = flag.String("step_metadata_dir", "", "If specified, create directory to store the step metadata e.g. /tekton/steps/<step-name>/")
enableSpire = flag.Bool("enable_spire", false, "If specified by configmap, this enables spire signing and verification")
socketPath = flag.String("spire-socket-path", "/spiffe-workload-api/spire-agent.sock", "Experimental: The SPIRE agent socket for SPIFFE workload API.")
)

const (
Expand Down Expand Up @@ -122,6 +126,13 @@ func main() {
}
}

var spireWorkloadAPI spire.EntrypointerAPIClient
if enableSpire != nil && *enableSpire && socketPath != nil && *socketPath != "" {
spireWorkloadAPI = spire.NewSpireEntrypointerAPIClient(config.SpireConfig{
SocketPath: *socketPath,
})
}

e := entrypoint.Entrypointer{
Command: append(cmd, flag.Args()...),
WaitFiles: strings.Split(*waitFiles, ","),
Expand All @@ -136,6 +147,7 @@ func main() {
BreakpointOnFailure: *breakpointOnFailure,
OnError: *onError,
StepMetadataDir: *stepMetadataDir,
SpireWorkloadAPI: spireWorkloadAPI,
}

// Copy any creds injected by the controller into the $HOME directory of the current
Expand Down
20 changes: 20 additions & 0 deletions cmd/imagedigestexporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ limitations under the License.
package main

import (
"context"
"encoding/json"
"flag"

"github.com/tektoncd/pipeline/pkg/spire"
"github.com/tektoncd/pipeline/pkg/spire/config"
"github.com/tektoncd/pipeline/pkg/termination"
"knative.dev/pkg/logging"

Expand All @@ -31,6 +34,8 @@ import (
var (
images = flag.String("images", "", "List of images resources built by task in json format")
terminationMessagePath = flag.String("terminationMessagePath", "/tekton/termination", "Location of file containing termination message")
enableSpire = flag.Bool("enable_spire", false, "If specified by configmap, this enables spire signing and verification")
socketPath = flag.String("spire-socket-path", "/spiffe-workload-api/spire-agent.sock", "Experimental: The SPIRE agent socket for SPIFFE workload API.")
)

/* The input of this go program will be a JSON string with all the output PipelineResources of type
Expand Down Expand Up @@ -82,6 +87,21 @@ func main() {

}

if enableSpire != nil && *enableSpire && socketPath != nil && *socketPath != "" {
ctx := context.Background()
spireConfig := config.SpireConfig{
SocketPath: *socketPath,
}

spireWorkloadAPI := spire.NewSpireEntrypointerAPIClient(spireConfig)
signed, err := spireWorkloadAPI.Sign(ctx, output)
if err != nil {
logger.Fatal(err)
}

output = append(output, signed...)
}

if err := termination.WriteMessage(*terminationMessagePath, output); err != nil {
logger.Fatalf("Unexpected error writing message %s to %s", *terminationMessagePath, err)
}
Expand Down
4 changes: 4 additions & 0 deletions config/config-feature-flags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ data:
# Setting this flag to "true" enables CloudEvents for Runs, as long as a
# CloudEvents sink is configured in the config-defaults config map
send-cloudevents-for-runs: "false"
# Setting this flag to "true" enables spire integration with pipeline.
# This is an experimental feature and thus should still be considered
# an alpha feature.
enable-spire: "false"
Loading

0 comments on commit 9d3aead

Please sign in to comment.