Skip to content

Commit ef3d769

Browse files
committed
[TEP-0089] Enable SPIRE for signing taskrun results in alpha.
Breaking down PR tektoncd#4759 originally proposed by @pxp928 to address TEP-0089 according @lumjjb suggestions. Plan for breaking down PR is PR 1.1: api PR 1.2: entrypointer (+cmd line + test/entrypointer) Entrypoint takes results and signs the results (termination message). PR 1.3: reconciler + pod + cmd/controller + integration tests Controller will verify the signed result. This commit corresponds to 1.3 above.
1 parent 2d38f5f commit ef3d769

31 files changed

+2538
-77
lines changed

cmd/controller/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ func main() {
6262
flag.StringVar(&opts.Images.ImageDigestExporterImage, "imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.")
6363
flag.StringVar(&opts.Images.WorkingDirInitImage, "workingdirinit-image", "", "The container image containing our working dir init binary.")
6464

65+
flag.StringVar(&opts.SpireConfig.TrustDomain, "spire-trust-domain", "example.org", "Experimental: The SPIRE Trust domain to use.")
66+
flag.StringVar(&opts.SpireConfig.SocketPath, "spire-socket-path", "unix:///spiffe-workload-api/spire-agent.sock", "Experimental: The SPIRE agent socket for SPIFFE workload API.")
67+
flag.StringVar(&opts.SpireConfig.ServerAddr, "spire-server-addr", "spire-server.spire.svc.cluster.local:8081", "Experimental: The SPIRE server address for workload/node registration.")
68+
flag.StringVar(&opts.SpireConfig.NodeAliasPrefix, "spire-node-alias-prefix", "/tekton-node/", "Experimental: The SPIRE node alias prefix to use.")
69+
6570
// This parses flags.
6671
cfg := injection.ParseAndGetRESTConfigOrDie()
6772

6873
if err := opts.Images.Validate(); err != nil {
6974
log.Fatal(err)
7075
}
76+
if err := opts.SpireConfig.Validate(); err != nil {
77+
log.Fatal(err)
78+
}
7179
if cfg.QPS == 0 {
7280
cfg.QPS = 2 * rest.DefaultQPS
7381
}

cmd/imagedigestexporter/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
2021
"encoding/json"
2122
"flag"
2223

24+
"github.com/tektoncd/pipeline/pkg/spire"
25+
"github.com/tektoncd/pipeline/pkg/spire/config"
2326
"github.com/tektoncd/pipeline/pkg/termination"
2427
"knative.dev/pkg/logging"
2528

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

3641
/* The input of this go program will be a JSON string with all the output PipelineResources of type
@@ -76,6 +81,21 @@ func main() {
7681

7782
}
7883

84+
if enableSpire != nil && *enableSpire && socketPath != nil && *socketPath != "" {
85+
ctx := context.Background()
86+
spireConfig := config.SpireConfig{
87+
SocketPath: *socketPath,
88+
}
89+
90+
spireWorkloadAPI := spire.NewEntrypointerAPIClient(&spireConfig)
91+
signed, err := spireWorkloadAPI.Sign(ctx, output)
92+
if err != nil {
93+
logger.Fatal(err)
94+
}
95+
96+
output = append(output, signed...)
97+
}
98+
7999
if err := termination.WriteMessage(*terminationMessagePath, output); err != nil {
80100
logger.Fatalf("Unexpected error writing message %s to %s", *terminationMessagePath, err)
81101
}

config/config-feature-flags.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,7 @@ data:
8585
# will fail the taskrun/pipelinerun. "warn" will only log the err message and "skip"
8686
# will skip the whole verification
8787
resource-verification-mode: "skip"
88+
# Setting this flag to "true" enables spire integration with pipeline.
89+
# This is an experimental feature and thus should still be considered
90+
# an alpha feature.
91+
enable-spire: "false"

docs/spire.md

Lines changed: 285 additions & 0 deletions
Large diffs are not rendered by default.

pkg/apis/pipeline/options.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ limitations under the License.
1616

1717
package pipeline
1818

19+
import (
20+
spireconfig "github.com/tektoncd/pipeline/pkg/spire/config"
21+
)
22+
1923
// Options holds options passed to the Tekton Pipeline controllers
2024
// typically via command-line flags.
2125
type Options struct {
22-
Images Images
26+
Images Images
27+
SpireConfig spireconfig.SpireConfig
2328
}

pkg/pod/pod.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
3131
"github.com/tektoncd/pipeline/pkg/internal/computeresources/tasklevel"
3232
"github.com/tektoncd/pipeline/pkg/names"
33+
"github.com/tektoncd/pipeline/pkg/spire"
3334
corev1 "k8s.io/api/core/v1"
3435
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3536
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -120,6 +121,12 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
120121
featureFlags := config.FromContextOrDefaults(ctx).FeatureFlags
121122
alphaAPIEnabled := featureFlags.EnableAPIFields == config.AlphaAPIFields
122123

124+
// Entrypoint arg to enable or disable spire
125+
var commonExtraEntrypointArgs []string
126+
if config.FromContextOrDefaults(ctx).FeatureFlags.EnableSpire {
127+
commonExtraEntrypointArgs = append(commonExtraEntrypointArgs, "-enable_spire")
128+
}
129+
123130
// Add our implicit volumes first, so they can be overridden by the user if they prefer.
124131
volumes = append(volumes, implicitVolumes...)
125132
volumeMounts = append(volumeMounts, implicitVolumeMounts...)
@@ -190,11 +197,13 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
190197
}
191198

192199
readyImmediately := isPodReadyImmediately(*featureFlags, taskSpec.Sidecars)
200+
// append credEntrypointArgs with entrypoint arg that contains if spire is enabled by configmap
201+
commonExtraEntrypointArgs = append(commonExtraEntrypointArgs, credEntrypointArgs...)
193202

194203
if alphaAPIEnabled {
195-
stepContainers, err = orderContainers(credEntrypointArgs, stepContainers, &taskSpec, taskRun.Spec.Debug, !readyImmediately)
204+
stepContainers, err = orderContainers(commonExtraEntrypointArgs, stepContainers, &taskSpec, taskRun.Spec.Debug, !readyImmediately)
196205
} else {
197-
stepContainers, err = orderContainers(credEntrypointArgs, stepContainers, &taskSpec, nil, !readyImmediately)
206+
stepContainers, err = orderContainers(commonExtraEntrypointArgs, stepContainers, &taskSpec, nil, !readyImmediately)
198207
}
199208
if err != nil {
200209
return nil, err
@@ -275,6 +284,32 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
275284
return nil, err
276285
}
277286

287+
if config.FromContextOrDefaults(ctx).FeatureFlags.EnableSpire {
288+
volumes = append(volumes, corev1.Volume{
289+
Name: spire.WorkloadAPI,
290+
VolumeSource: corev1.VolumeSource{
291+
CSI: &corev1.CSIVolumeSource{
292+
Driver: "csi.spiffe.io",
293+
},
294+
},
295+
})
296+
297+
for i := range stepContainers {
298+
c := &stepContainers[i]
299+
c.VolumeMounts = append(c.VolumeMounts, corev1.VolumeMount{
300+
Name: spire.WorkloadAPI,
301+
MountPath: spire.VolumeMountPath,
302+
})
303+
}
304+
for i := range initContainers {
305+
c := &initContainers[i]
306+
c.VolumeMounts = append(c.VolumeMounts, corev1.VolumeMount{
307+
Name: spire.WorkloadAPI,
308+
MountPath: spire.VolumeMountPath,
309+
})
310+
}
311+
}
312+
278313
mergedPodContainers := stepContainers
279314

280315
// Merge sidecar containers with step containers.

0 commit comments

Comments
 (0)