2021-03-10 18:30:06 +00:00
|
|
|
// Copyright 2021 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package issuer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/errors"
|
|
|
|
|
|
|
|
"go.pinniped.dev/internal/constable"
|
|
|
|
)
|
|
|
|
|
|
|
|
const defaultCertIssuerErr = constable.Error("failed to issue cert")
|
|
|
|
|
2021-03-13 00:09:16 +00:00
|
|
|
type ClientCertIssuer interface {
|
|
|
|
IssueClientCertPEM(username string, groups []string, ttl time.Duration) (certPEM, keyPEM []byte, err error)
|
2021-03-10 18:30:06 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 00:09:16 +00:00
|
|
|
var _ ClientCertIssuer = ClientCertIssuers{}
|
2021-03-10 18:30:06 +00:00
|
|
|
|
2021-03-13 00:09:16 +00:00
|
|
|
type ClientCertIssuers []ClientCertIssuer
|
2021-03-10 18:30:06 +00:00
|
|
|
|
2021-03-13 00:09:16 +00:00
|
|
|
func (c ClientCertIssuers) IssueClientCertPEM(username string, groups []string, ttl time.Duration) ([]byte, []byte, error) {
|
2021-03-10 18:30:06 +00:00
|
|
|
var errs []error
|
|
|
|
|
|
|
|
for _, issuer := range c {
|
2021-03-13 00:09:16 +00:00
|
|
|
certPEM, keyPEM, err := issuer.IssueClientCertPEM(username, groups, ttl)
|
2021-03-10 18:30:06 +00:00
|
|
|
if err != nil {
|
|
|
|
errs = append(errs, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return certPEM, keyPEM, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := errors.NewAggregate(errs); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil, defaultCertIssuerErr
|
|
|
|
}
|