Skip to content

Commit 77fdfc9

Browse files
committed
Merge branch 'master' into max/cert-mgr-crud
2 parents 9fdef64 + 6476eb4 commit 77fdfc9

File tree

19 files changed

+919
-507
lines changed

19 files changed

+919
-507
lines changed

.github/workflows/labeler.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
- uses: actions/labeler@v3
1212
with:
1313
repo-token: "${{ secrets.GITHUB_TOKEN }}"
14-
configuration-path: .github/needs-triage-labeler.yml
14+
configuration-path: .github/labeler.yml

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PREFIX?=
1515
SRC=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
1616
GOOS_OVERRIDE ?=
1717
OUTPUT_ROOT=output/
18+
RELEASE=./.releases
1819

1920
all: lint test build
2021

api/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func LogCertificate(w http.ResponseWriter, cert *x509.Certificate) {
418418
if len(val.CredentialID) > 0 {
419419
m["provisioner"] = fmt.Sprintf("%s (%s)", val.Name, val.CredentialID)
420420
} else {
421-
m["provisioner"] = string(val.Name)
421+
m["provisioner"] = val.Name
422422
}
423423
break
424424
}

authority/authority.go

+7
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ func (a *Authority) init() error {
395395
}
396396
}
397397

398+
// Check if a KMS with decryption capability is required and available
399+
if a.requiresDecrypter() {
400+
if _, ok := a.keyManager.(kmsapi.Decrypter); !ok {
401+
return errors.New("keymanager doesn't provide crypto.Decrypter")
402+
}
403+
}
404+
398405
// TODO: decide if this is a good approach for providing the SCEP functionality
399406
// It currently mirrors the logic for the x509CAService
400407
if a.requiresSCEPService() && a.scepService == nil {

authority/provisioner/scep.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ type SCEP struct {
2727
secretChallengePassword string
2828
}
2929

30-
// GetID returns the provisioner unique identifier. The name and credential id
31-
// should uniquely identify any JWK provisioner.
30+
// GetID returns the provisioner unique identifier.
3231
func (s *SCEP) GetID() string {
3332
if s.ID != "" {
3433
return s.ID
3534
}
3635
return s.GetIDForToken()
3736
}
3837

39-
// GetIDForToken returns the provisioner unique identifier.
40-
func (s SCEP) GetIDForToken() string {
38+
// GetIDForToken returns an identifier that will be used to load the provisioner
39+
// from a token.
40+
func (s *SCEP) GetIDForToken() string {
4141
return "scep/" + s.Name
4242
}
4343

ca/ca.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ func (ca *CA) Init(config *config.Config) (*CA, error) {
229229
return nil, err
230230
}
231231
handler = m.Middleware(handler)
232+
insecureHandler = m.Middleware(insecureHandler)
232233
}
233234

234235
// Add logger if configured
@@ -238,6 +239,7 @@ func (ca *CA) Init(config *config.Config) (*CA, error) {
238239
return nil, err
239240
}
240241
handler = logger.Middleware(handler)
242+
insecureHandler = logger.Middleware(insecureHandler)
241243
}
242244

243245
ca.srv = server.New(config.Address, handler, tlsConfig)
@@ -288,7 +290,17 @@ func (ca *CA) Stop() error {
288290
if err := ca.auth.Shutdown(); err != nil {
289291
log.Printf("error stopping ca.Authority: %+v\n", err)
290292
}
291-
return ca.srv.Shutdown()
293+
var insecureShutdownErr error
294+
if ca.insecureSrv != nil {
295+
insecureShutdownErr = ca.insecureSrv.Shutdown()
296+
}
297+
298+
secureErr := ca.srv.Shutdown()
299+
300+
if insecureShutdownErr != nil {
301+
return insecureShutdownErr
302+
}
303+
return secureErr
292304
}
293305

294306
// Reload reloads the configuration of the CA and calls to the server Reload
@@ -322,6 +334,13 @@ func (ca *CA) Reload() error {
322334
return errors.Wrap(err, "error reloading ca")
323335
}
324336

337+
if ca.insecureSrv != nil {
338+
if err = ca.insecureSrv.Reload(newCA.insecureSrv); err != nil {
339+
logContinue("Reload failed because insecure server could not be replaced.")
340+
return errors.Wrap(err, "error reloading insecure server")
341+
}
342+
}
343+
325344
if err = ca.srv.Reload(newCA.srv); err != nil {
326345
logContinue("Reload failed because server could not be replaced.")
327346
return errors.Wrap(err, "error reloading server")

cas/apiv1/options.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ type Options struct {
4545
// KeyManager is the KMS used to generate keys in SoftCAS.
4646
KeyManager kms.KeyManager `json:"-"`
4747

48-
// Project and Location are parameters used in CloudCAS to create a new
49-
// certificate authority.
50-
Project string `json:"-"`
51-
Location string `json:"-"`
48+
// Project, Location, CaPool and GCSBucket are parameters used in CloudCAS
49+
// to create a new certificate authority. If a CaPool does not exist it will
50+
// be created. GCSBucket is optional, if not provided GCloud will create a
51+
// managed bucket.
52+
Project string `json:"-"`
53+
Location string `json:"-"`
54+
CaPool string `json:"-"`
55+
CaPoolTier string `json:"-"`
56+
GCSBucket string `json:"-"`
5257
}
5358

5459
// CertificateIssuer contains the properties used to use the StepCAS certificate

cas/cloudcas/certificate.go

+18-27
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212

1313
"github.com/pkg/errors"
1414
kmsapi "github.com/smallstep/certificates/kms/apiv1"
15-
pb "google.golang.org/genproto/googleapis/cloud/security/privateca/v1beta1"
16-
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
15+
pb "google.golang.org/genproto/googleapis/cloud/security/privateca/v1"
1716
)
1817

1918
var (
@@ -67,11 +66,10 @@ func createCertificateConfig(tpl *x509.Certificate) (*pb.Certificate_Config, err
6766
config := &pb.CertificateConfig{
6867
SubjectConfig: &pb.CertificateConfig_SubjectConfig{
6968
Subject: createSubject(tpl),
70-
CommonName: tpl.Subject.CommonName,
7169
SubjectAltName: createSubjectAlternativeNames(tpl),
7270
},
73-
ReusableConfig: createReusableConfig(tpl),
74-
PublicKey: pk,
71+
X509Config: createX509Parameters(tpl),
72+
PublicKey: pk,
7573
}
7674
return &pb.Certificate_Config{
7775
Config: config,
@@ -86,15 +84,15 @@ func createPublicKey(key crypto.PublicKey) (*pb.PublicKey, error) {
8684
return nil, errors.Wrap(err, "error marshaling public key")
8785
}
8886
return &pb.PublicKey{
89-
Type: pb.PublicKey_PEM_EC_KEY,
87+
Format: pb.PublicKey_PEM,
9088
Key: pem.EncodeToMemory(&pem.Block{
9189
Type: "PUBLIC KEY",
9290
Bytes: asn1Bytes,
9391
}),
9492
}, nil
9593
case *rsa.PublicKey:
9694
return &pb.PublicKey{
97-
Type: pb.PublicKey_PEM_RSA_KEY,
95+
Format: pb.PublicKey_PEM,
9896
Key: pem.EncodeToMemory(&pem.Block{
9997
Type: "RSA PUBLIC KEY",
10098
Bytes: x509.MarshalPKCS1PublicKey(key),
@@ -107,7 +105,9 @@ func createPublicKey(key crypto.PublicKey) (*pb.PublicKey, error) {
107105

108106
func createSubject(cert *x509.Certificate) *pb.Subject {
109107
sub := cert.Subject
110-
ret := new(pb.Subject)
108+
ret := &pb.Subject{
109+
CommonName: sub.CommonName,
110+
}
111111
if len(sub.Country) > 0 {
112112
ret.CountryCode = sub.Country[0]
113113
}
@@ -196,7 +196,7 @@ func createSubjectAlternativeNames(cert *x509.Certificate) *pb.SubjectAltNames {
196196
return ret
197197
}
198198

199-
func createReusableConfig(cert *x509.Certificate) *pb.ReusableConfigWrapper {
199+
func createX509Parameters(cert *x509.Certificate) *pb.X509Parameters {
200200
var unknownEKUs []*pb.ObjectId
201201
var ekuOptions = &pb.KeyUsage_ExtendedKeyUsageOptions{}
202202
for _, eku := range cert.ExtKeyUsage {
@@ -241,22 +241,19 @@ func createReusableConfig(cert *x509.Certificate) *pb.ReusableConfigWrapper {
241241
policyIDs = append(policyIDs, createObjectID(oid))
242242
}
243243

244-
var caOptions *pb.ReusableConfigValues_CaOptions
244+
var caOptions *pb.X509Parameters_CaOptions
245245
if cert.BasicConstraintsValid {
246-
var maxPathLength *wrapperspb.Int32Value
246+
caOptions = new(pb.X509Parameters_CaOptions)
247+
var maxPathLength int32
247248
switch {
248249
case cert.MaxPathLenZero:
249-
maxPathLength = wrapperspb.Int32(0)
250+
maxPathLength = 0
251+
caOptions.MaxIssuerPathLength = &maxPathLength
250252
case cert.MaxPathLen > 0:
251-
maxPathLength = wrapperspb.Int32(int32(cert.MaxPathLen))
252-
default:
253-
maxPathLength = nil
254-
}
255-
256-
caOptions = &pb.ReusableConfigValues_CaOptions{
257-
IsCa: wrapperspb.Bool(cert.IsCA),
258-
MaxIssuerPathLength: maxPathLength,
253+
maxPathLength = int32(cert.MaxPathLen)
254+
caOptions.MaxIssuerPathLength = &maxPathLength
259255
}
256+
caOptions.IsCa = &cert.IsCA
260257
}
261258

262259
var extraExtensions []*pb.X509Extension
@@ -270,7 +267,7 @@ func createReusableConfig(cert *x509.Certificate) *pb.ReusableConfigWrapper {
270267
}
271268
}
272269

273-
values := &pb.ReusableConfigValues{
270+
return &pb.X509Parameters{
274271
KeyUsage: &pb.KeyUsage{
275272
BaseKeyUsage: &pb.KeyUsage_KeyUsageOptions{
276273
DigitalSignature: cert.KeyUsage&x509.KeyUsageDigitalSignature > 0,
@@ -291,12 +288,6 @@ func createReusableConfig(cert *x509.Certificate) *pb.ReusableConfigWrapper {
291288
AiaOcspServers: cert.OCSPServer,
292289
AdditionalExtensions: extraExtensions,
293290
}
294-
295-
return &pb.ReusableConfigWrapper{
296-
ConfigValues: &pb.ReusableConfigWrapper_ReusableConfigValues{
297-
ReusableConfigValues: values,
298-
},
299-
}
300291
}
301292

302293
// isExtraExtension returns true if the extension oid is not managed in a

0 commit comments

Comments
 (0)