Skip to content

Commit

Permalink
Add TrustedKeys CRD for holding TUF or bring your own keys.
Browse files Browse the repository at this point in the history
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
  • Loading branch information
vaikas committed Nov 14, 2022
1 parent ba6cdef commit 8c8d85e
Show file tree
Hide file tree
Showing 38 changed files with 3,152 additions and 15 deletions.
116 changes: 116 additions & 0 deletions cmd/trustedkeys/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// Copyright 2021 The Sigstore 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 main

import (
"context"
"flag"
"log"

"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/signals"
"knative.dev/pkg/webhook"
"knative.dev/pkg/webhook/certificates"
"knative.dev/pkg/webhook/resourcesemantics"
"knative.dev/pkg/webhook/resourcesemantics/defaulting"
"knative.dev/pkg/webhook/resourcesemantics/validation"
"sigs.k8s.io/release-utils/version"

"github.com/sigstore/policy-controller/pkg/apis/policy/v1alpha1"
"github.com/sigstore/policy-controller/pkg/reconciler/trustedkeys"

// Register the provider-specific plugins
_ "github.com/sigstore/sigstore/pkg/signature/kms/aws"
_ "github.com/sigstore/sigstore/pkg/signature/kms/azure"
_ "github.com/sigstore/sigstore/pkg/signature/kms/gcp"
_ "github.com/sigstore/sigstore/pkg/signature/kms/hashivault"
)

var (
// mutatingWebhookName holds the name of the mutating webhook configuration
// resource dispatching admission requests to policy-webhook.
// It is also the name of the webhook which is injected by the controller
// with the resource types, namespace selectors, CABindle and service path.
// If this changes, you must also change:
// ./config/501-policy-webhook-configurations.yaml
// https://github.com/sigstore/helm-charts/blob/main/charts/policy-controller/templates/policy-webhook/policy_webhook_configurations.yaml
mutatingWebhookName = flag.String("mutating-webhook-name", "defaulting.tufroot.sigstore.dev", "The name of the mutating webhook configuration as well as the webhook name that is automatically configured, if exists, with different rules and client settings setting how the admission requests to be dispatched to policy-webhook.")
// validatingWebhookName holds the name of the validating webhook configuration
// resource dispatching admission requests to policy-webhook.
// It is also the name of the webhook which is injected by the controller
// with the resource types, namespace selectors, CABindle and service path.
// If this changes, you must also change:
// ./config/501-policy-webhook-configurations.yaml
// https://github.com/sigstore/helm-charts/blob/main/charts/policy-controller/templates/policy-webhook/policy_webhook_configurations.yaml
validatingWebhookName = flag.String("validating-webhook-name", "validating.tufroot.sigstore.dev", "The name of the validating webhook configuration as well as the webhook name that is automatically configured, if exists, with different rules and client settings setting how the admission requests to be dispatched to policy-webhook.")
)

var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
// v1alpha1
v1alpha1.SchemeGroupVersion.WithKind("TrustedKeys"): &v1alpha1.TrustedKeys{},
}

func main() {
opts := webhook.Options{
ServiceName: "policy-webhook",
Port: 8443,
SecretName: "policy-webhook-certs",
}
ctx := webhook.WithOptions(signals.NewContext(), opts)

// Allow folks to configure the port the webhook serves on.
flag.IntVar(&opts.Port, "secure-port", opts.Port, "The port on which to serve HTTPS.")

v := version.GetVersionInfo()
vJSON, _ := v.JSONString()
log.Printf("%v", vJSON)
// This calls flag.Parse()
sharedmain.MainWithContext(ctx, "trustedkeys",
certificates.NewController,
trustedkeys.NewController,
NewTUFRootValidatingAdmissionController,
NewTUFRootMutatingAdmissionController,
)
}

func NewTUFRootValidatingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return validation.NewAdmissionController(
ctx,
*validatingWebhookName,
"/validating",
types,
func(ctx context.Context) context.Context {
return ctx
},
true,
)
}

func NewTUFRootMutatingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
return defaulting.NewAdmissionController(
ctx,
*mutatingWebhookName,
"/defaulting",
types,
func(ctx context.Context) context.Context {
return ctx
},
true,
)
}
28 changes: 28 additions & 0 deletions config/config-tuf-roots.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2022 The Sigstore 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.

apiVersion: v1
kind: ConfigMap
metadata:
name: config-tuf-roots
namespace: cosign-system

data:
_example: |
################################
# #
# EXAMPLE CONFIGURATION #
# #
################################
my-custom-tuf-root: "H4sIAAAAAAAA/+x6V3MbudL2XvNXqHSrb61GBlx1LoY5iFEUJeqrU65GYg7ikKLEU/vf36KCLYdj77u2tX5r+VxoigMI3Wh0eAbAKiwX6Wi9WN3/9tMAAKCEeHzKxydQ/vh8xG+EMyKZYlSR34AwKeVvR+LnqfQBm3SNq98AbnE0wfS/90vXGONXxnmeyPPz/wg+rP8pebNaLNZvxuli/mNl7O0hOf9v688pqE/WX+y7Hb2KEf/h6/+fzNFxOhrMgz9+e/SfzNHR8bv1/TIcvz063nvD8f/bv0qXwb27Dat0tJjvW8gbeGz48I48/A53y9EqpPs+FCj7HfjvQLuEvWX6LVG/g3oLT/85Cffpk8SjY2CGKKmJ14aFaDUxzljGCDMgoxUuekOY8Jx5jWgVcUiks/u+ynFw5Hmgh2Gf1Q+eCkHMg7j9HNwwzL7UMAn3I/9uiOnwHU4Hi9VoPZztVfv/D81Hx+kQqZBPvR9+CkKPH379+8MQtzh9r8XR8XJjpyO3F2aio94qK70iVFMwVlqBxFpjGAQdDY1EctTOeaaN55FETtEzoo1mWttHQX/s//7xIO2YWYUgiHPWEcOVZA4V8daQYCFKYJp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BowSGhDB3hIUqqHAhCUUrhpHeeUYIYlJFBE0ql1CSKGE2whAYGUlnNBMTDwcw/HS/r//NVmR/NAL55/i8/q/+Sk0P9fw18rf6/vzr1KhcAPrp+8oWqIin7ExcAovVahhC99EJZwwKgIRhs4CEAU8Lr4DnwaAwzgUmQhmpOmQOC3DglDGhOmJEKHKWGSR6jJBAeGGnkikGgwCVFRxCFNpo6aZnV2nvpjbU/7ALAd99J+6jOUMEYRkWAcmZ1VIFwQ4kBSTglmgcSjeTec1TCg3HUBMUJE4FFwUNAQjByL2gkQggjo2csmBgp5Tx4qRwgjUJ5E4wHDS4oETnhUlkRqQ8B7KHOHHDAAQf8avifAAAA//8nr2ImAEQAAA=="
1 change: 1 addition & 0 deletions config/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ resources:
- config-logging.yaml
- config-leader-election.yaml
- config-image-policies.yaml
- config-tuf-roots.yaml
- config-policy-controller.yaml
4 changes: 3 additions & 1 deletion pkg/apis/config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type cfgKey struct{}
// Config holds the collection of configurations that we attach to contexts.
// +k8s:deepcopy-gen=false
type Config struct {
ImagePolicyConfig *ImagePolicyConfig
ImagePolicyConfig *ImagePolicyConfig
SigstoreKeysConfig *SigstoreKeysMap
}

// FromContext extracts a Config from the provided context.
Expand Down Expand Up @@ -70,6 +71,7 @@ func NewStore(logger configmap.Logger, onAfterStore ...func(name string, value i
logger,
configmap.Constructors{
ImagePoliciesConfigName: NewImagePoliciesConfigFromConfigMap,
SigstoreKeysConfigName: NewSigstoreKeysFromConfigMap,
},
onAfterStore...,
),
Expand Down
30 changes: 30 additions & 0 deletions pkg/apis/config/testdata/config-tuf-roots.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2022 The Sigstore 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.

apiVersion: v1
kind: ConfigMap
metadata:
name: config-tuf-roots
namespace: cosign-system
labels:
policy.sigstore.dev/release: devel

data:
_example: |
################################
# #
# EXAMPLE CONFIGURATION #
# #
################################
my-custom-tuf-root: "H4sIAAAAAAAA/+x6V3MbudL2XvNXqHSrb61GBlx1LoY5iFEUJeqrU65GYg7ikKLEU/vf36KCLYdj77u2tX5r+VxoigMI3Wh0eAbAKiwX6Wi9WN3/9tMAAKCEeHzKxydQ/vh8xG+EMyKZYlSR34AwKeVvR+LnqfQBm3SNq98AbnE0wfS/90vXGONXxnmeyPPz/wg+rP8pebNaLNZvxuli/mNl7O0hOf9v688pqE/WX+y7Hb2KEf/h6/+fzNFxOhrMgz9+e/SfzNHR8bv1/TIcvz063nvD8f/bv0qXwb27Dat0tJjvW8gbeGz48I48/A53y9EqpPs+FCj7HfjvQLuEvWX6LVG/g3oLT/85Cffpk8SjY2CGKKmJ14aFaDUxzljGCDMgoxUuekOY8Jx5jWgVcUiks/u+ynFw5Hmgh2Gf1Q+eCkHMg7j9HNwwzL7UMAn3I/9uiOnwHU4Hi9VoPZztVfv/D81Hx+kQqZBPvR9+CkKPH379+8MQtzh9r8XR8XJjpyO3F2aio94qK70iVFMwVlqBxFpjGAQdDY1EctTOeaaN55FETtEzoo1mWttHQX/s//7xIO2YWYUgiHPWEcOVZA4V8daQYCFKYJpZB94pNEJaSaQKxjC0KqJgAFT8wsYilFFBPPU0GB80QwXRGs6s0t4FIMqBIkZSbyHyQDWTlIKjQJi3QknyubE0YHDSMI7BWow8Gq8g2BBtiMxw8ExZLSJ1DIViHqxVSjHFDSgvlHC/sLGMUjF4ETwIDiCF90opxRVYpsEhcEs5dSJEqzxGY6RRTDhrwBKphWCfGyvGgFagQxIsem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RxCFNpo6aZnV2nvpjbU/7ALAd99J+6jOUMEYRkWAcmZ1VIFwQ4kBSTglmgcSjeTec1TCg3HUBMUJE4FFwUNAQjByL2gkQggjo2csmBgp5Tx4qRwgjUJ5E4wHDS4oETnhUlkRqQ8B7KHOHHDAAQf8avifAAAA//8nr2ImAEQAAA=="
122 changes: 122 additions & 0 deletions pkg/apis/config/tuf_roots.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// Copyright 2022 The Sigstore 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 (
"encoding/json"
"fmt"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"
)

const (
// SigstoreKeysConfigName is the name of ConfigMap created by the
// reconciler and consumed by the admission webhook for validating.
SigstoreKeysConfigName = "config-sigstore-keys"
)

// serializedTUF represents a serialized TUF Root that has root.json as well as
// the serialized Repository for it.
type serializedTUF struct {
// This is the initial root.json file.
RootJSON []byte `json:"rootJSON"`
// This is the serialized TUF repository
Repository []byte `json:"repository"`
}

// SigstoreKeys contains all the necessary Keys and Certificates for validating
// against a specific instance of Sigstore.
type SigstoreKeys struct {
// FulcioRoots has Fulcio Root Certificates.
// TODO(vaikas); Should there really be multiples here?
FulcioRoots [][]byte `json:"fulcioRoots"`
// FulcioIntermediates has Fulcio Intermediate Certificates
// TODO(vaikas); Should there really be multiples here?
FulcioIntermediates [][]byte `json:"fulcioIntermediates"`
RekorKeys [][]byte `json:"rekorKeys"`
CTLogKeys [][]byte `json:"ctLogKeys"`
TSAKeys []byte `json:"tsaKeys"`
}

type SigstoreKeysMap struct {
SigstoreKeys map[string]SigstoreKeys
}

// NewSigstoreKeysFromMap creates a map of SigstoreKeys to use for validation.
func NewSigstoreKeysFromMap(data map[string]string) (map[string]SigstoreKeys, error) {
ret := make(map[string]SigstoreKeys, len(data))
// Spin through the ConfigMap. Each entry will have a serialized form of
// necessary validation keys in the form of SigstoreKeys.
for k, v := range data {
// This is the example that we use to document / test the ConfigMap.
if k == "_example" {
continue
}
if v == "" {
return nil, fmt.Errorf("configmap has an entry %q but no value", k)
}
sigstoreKeys := &SigstoreKeys{}

if err := parseSigstoreKeys(v, sigstoreKeys); err != nil {
return nil, fmt.Errorf("failed to parse the entry %q : %q : %w", k, v, err)
}
ret[k] = *sigstoreKeys
}
return ret, nil
}

// NewImagePoliciesConfigFromConfigMap creates a Features from the supplied ConfigMap
func NewSigstoreKeysFromConfigMap(config *corev1.ConfigMap) (map[string]SigstoreKeys, error) {
return NewSigstoreKeysFromMap(config.Data)
}

func parseSigstoreKeys(entry string, out interface{}) error {
j, err := yaml.YAMLToJSON([]byte(entry))
if err != nil {
return fmt.Errorf("config's value could not be converted to JSON: %w : %s", err, entry)
}
return json.Unmarshal(j, &out)
}

// CreateTUFClientFromSerialized takes a serialized TUF Repository which has
// been tarred, gzipped and base64 encoded.
// unmarshals it and returns an initialized TUF Client.
/*
func CreateTUFClientFromSerialized(in []byte, targets string) (*client.Client, error) {
serialized := &serializedTUF{}
if err := json.Unmarshal(in, serialized); err != nil {
return nil, fmt.Errorf("unmarshaling %w", err)
}
decoded := make([]byte, 0, len(in))
_, err := base64.RawStdEncoding.Decode(decoded, in)
if err != nil {
return nil, fmt.Errorf("base64 decoding: %w", err)
}
remoteFS, err := tuf.UncompressMemFS(bytes.NewReader(decoded))
if err != nil {
return nil, fmt.Errorf("uncompressing: %w", err)
}
remote, err := client.NewFileRemoteStore(remoteFS, targets)
local := client.MemoryLocalStore()
client := client.NewClient(local, remote)
// Does this need to be inited here or something?
return client, nil
}
*/
Loading

0 comments on commit 8c8d85e

Please sign in to comment.