-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There are several parts to this change: 1. Implement a new `ephemeralca` that just generates an in-memory certificate, 1. Rename `pkg/ca/pkcs11ca` to `pkg/ca/x509ca` since it had nothing `PKCS11` specific (shared with `ephemeralca` logic), 1. Add support for Kubernetes OIDC via Service Account Projected Volumes, 1. Have the KinD e2e test use `ephemeralca` and `cosign sign` an image. I can split some of these pieces apart, but wanted to get this all working end-to-end, since a key goal was enabling e2e testing on KinD. This follows a lot of the ideas from: https://github.com/mattmoor/kind-oidc Related: #212 Fixes: #194 Signed-off-by: Matt Moore <mattomata@gmail.com>
- Loading branch information
Showing
17 changed files
with
461 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 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. | ||
|
||
url: https://kubernetes.default.svc | ||
contact: mattmoor@chainguard.dev | ||
description: "service account projected volumes" | ||
type: "kubernetes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 api | ||
|
||
import ( | ||
"context" | ||
"crypto/x509" | ||
"encoding/pem" | ||
|
||
"github.com/sigstore/fulcio/pkg/ca/ephemeralca" | ||
"github.com/sigstore/fulcio/pkg/ca/x509ca" | ||
"github.com/sigstore/fulcio/pkg/challenges" | ||
) | ||
|
||
func EphemeralCASigningCertHandler(ctx context.Context, subj *challenges.ChallengeResult, publicKey []byte) (string, []string, error) { | ||
rootCA, privKey := ephemeralca.CA() | ||
|
||
pkixPubKey, err := x509.ParsePKIXPublicKey(publicKey) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
|
||
clientCert, _, err := x509ca.CreateClientCertificate(rootCA, subj, pkixPubKey, privKey) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
|
||
// Format in PEM | ||
rootPEM := pem.EncodeToMemory(&pem.Block{ | ||
Type: "CERTIFICATE", | ||
Bytes: rootCA.Raw, | ||
}) | ||
|
||
return clientCert, []string{string(rootPEM)}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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 ephemeralca | ||
|
||
import ( | ||
"context" | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"crypto/rand" | ||
"crypto/x509" | ||
"crypto/x509/pkix" | ||
"math" | ||
"math/big" | ||
"time" | ||
) | ||
|
||
var ( | ||
ca *x509.Certificate | ||
privKey interface{} | ||
) | ||
|
||
func Initialize(context.Context) error { | ||
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
if err != nil { | ||
return err | ||
} | ||
privKey = priv | ||
|
||
// TODO: We could make it so this could be passed in by the user | ||
serialNumber, err := rand.Int(rand.Reader, new(big.Int).SetInt64(math.MaxInt64)) | ||
if err != nil { | ||
return err | ||
} | ||
rootCA := &x509.Certificate{ | ||
SerialNumber: serialNumber, | ||
Subject: pkix.Name{ | ||
Organization: []string{"sigstore"}, | ||
Country: []string{"USA"}, | ||
Province: []string{"WA"}, | ||
Locality: []string{"Kirkland"}, | ||
StreetAddress: []string{"767 6th St S"}, | ||
PostalCode: []string{"98033"}, | ||
}, | ||
NotBefore: time.Now(), | ||
NotAfter: time.Now().AddDate(10, 0, 0), | ||
IsCA: true, | ||
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, | ||
BasicConstraintsValid: true, MaxPathLen: 1, | ||
} | ||
|
||
caBytes, err := x509.CreateCertificate(rand.Reader, rootCA, rootCA, priv.Public(), priv) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ca, err = x509.ParseCertificate(caBytes) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func CA() (*x509.Certificate, interface{}) { | ||
return ca, privKey | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.