2021-05-03 19:48:20 +00:00
|
|
|
package config
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
import (
|
2023-08-04 00:52:02 +00:00
|
|
|
"bytes"
|
2018-10-05 21:48:36 +00:00
|
|
|
"encoding/json"
|
2019-03-07 02:32:56 +00:00
|
|
|
"fmt"
|
2018-12-21 23:27:22 +00:00
|
|
|
"net"
|
2018-10-05 21:48:36 +00:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2022-03-31 14:12:29 +00:00
|
|
|
|
2022-08-09 00:58:18 +00:00
|
|
|
kms "go.step.sm/crypto/kms/apiv1"
|
2022-03-31 14:12:29 +00:00
|
|
|
"go.step.sm/linkedca"
|
|
|
|
|
2022-03-08 12:26:07 +00:00
|
|
|
"github.com/smallstep/certificates/authority/policy"
|
2019-03-06 22:49:25 +00:00
|
|
|
"github.com/smallstep/certificates/authority/provisioner"
|
2020-09-09 02:26:32 +00:00
|
|
|
cas "github.com/smallstep/certificates/cas/apiv1"
|
2019-03-05 08:07:13 +00:00
|
|
|
"github.com/smallstep/certificates/db"
|
2019-12-10 00:54:48 +00:00
|
|
|
"github.com/smallstep/certificates/templates"
|
2018-10-05 21:48:36 +00:00
|
|
|
)
|
|
|
|
|
2021-05-03 19:48:20 +00:00
|
|
|
const (
|
|
|
|
legacyAuthority = "step-certificate-authority"
|
|
|
|
)
|
|
|
|
|
2018-10-19 05:26:39 +00:00
|
|
|
var (
|
2021-05-07 00:03:12 +00:00
|
|
|
// DefaultBackdate length of time to backdate certificates to avoid
|
|
|
|
// clock skew validation issues.
|
|
|
|
DefaultBackdate = time.Minute
|
|
|
|
// DefaultDisableRenewal disables renewals per provisioner.
|
2021-05-06 06:02:42 +00:00
|
|
|
DefaultDisableRenewal = false
|
2022-04-13 22:11:54 +00:00
|
|
|
// DefaultAllowRenewalAfterExpiry allows renewals even if the certificate is
|
2022-03-14 22:40:01 +00:00
|
|
|
// expired.
|
2022-04-13 22:11:54 +00:00
|
|
|
DefaultAllowRenewalAfterExpiry = false
|
2021-05-07 00:03:12 +00:00
|
|
|
// DefaultEnableSSHCA enable SSH CA features per provisioner or globally
|
|
|
|
// for all provisioners.
|
|
|
|
DefaultEnableSSHCA = false
|
2023-07-27 20:01:42 +00:00
|
|
|
// DefaultDisableSmallstepExtensions is the default value for the
|
|
|
|
// DisableSmallstepExtensions provisioner claim.
|
2023-07-20 17:59:38 +00:00
|
|
|
DefaultDisableSmallstepExtensions = false
|
2022-09-14 18:43:58 +00:00
|
|
|
// DefaultCRLCacheDuration is the default cache duration for the CRL.
|
|
|
|
DefaultCRLCacheDuration = &provisioner.Duration{Duration: 24 * time.Hour}
|
2022-10-27 01:55:24 +00:00
|
|
|
// DefaultCRLExpiredDuration is the default duration in which expired
|
|
|
|
// certificates will remain in the CRL after expiration.
|
|
|
|
DefaultCRLExpiredDuration = time.Hour
|
|
|
|
// GlobalProvisionerClaims is the default duration that expired certificates
|
|
|
|
// remain in the CRL after expiration.
|
2021-05-03 19:48:20 +00:00
|
|
|
GlobalProvisionerClaims = provisioner.Claims{
|
2023-07-20 17:59:38 +00:00
|
|
|
MinTLSDur: &provisioner.Duration{Duration: 5 * time.Minute}, // TLS certs
|
|
|
|
MaxTLSDur: &provisioner.Duration{Duration: 24 * time.Hour},
|
|
|
|
DefaultTLSDur: &provisioner.Duration{Duration: 24 * time.Hour},
|
|
|
|
MinUserSSHDur: &provisioner.Duration{Duration: 5 * time.Minute}, // User SSH certs
|
|
|
|
MaxUserSSHDur: &provisioner.Duration{Duration: 24 * time.Hour},
|
|
|
|
DefaultUserSSHDur: &provisioner.Duration{Duration: 16 * time.Hour},
|
|
|
|
MinHostSSHDur: &provisioner.Duration{Duration: 5 * time.Minute}, // Host SSH certs
|
|
|
|
MaxHostSSHDur: &provisioner.Duration{Duration: 30 * 24 * time.Hour},
|
|
|
|
DefaultHostSSHDur: &provisioner.Duration{Duration: 30 * 24 * time.Hour},
|
|
|
|
EnableSSHCA: &DefaultEnableSSHCA,
|
|
|
|
DisableRenewal: &DefaultDisableRenewal,
|
|
|
|
AllowRenewalAfterExpiry: &DefaultAllowRenewalAfterExpiry,
|
|
|
|
DisableSmallstepExtensions: &DefaultDisableSmallstepExtensions,
|
2018-10-19 05:26:39 +00:00
|
|
|
}
|
2018-10-05 21:48:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents the CA configuration and it's mapped to a JSON object.
|
|
|
|
type Config struct {
|
2019-10-04 02:03:38 +00:00
|
|
|
Root multiString `json:"root"`
|
|
|
|
FederatedRoots []string `json:"federatedRoots"`
|
|
|
|
IntermediateCert string `json:"crt"`
|
|
|
|
IntermediateKey string `json:"key"`
|
|
|
|
Address string `json:"address"`
|
2021-05-03 19:48:20 +00:00
|
|
|
InsecureAddress string `json:"insecureAddress"`
|
2019-10-04 02:03:38 +00:00
|
|
|
DNSNames []string `json:"dnsNames"`
|
2020-01-10 02:42:26 +00:00
|
|
|
KMS *kms.Options `json:"kms,omitempty"`
|
2019-10-04 02:03:38 +00:00
|
|
|
SSH *SSHConfig `json:"ssh,omitempty"`
|
|
|
|
Logger json.RawMessage `json:"logger,omitempty"`
|
|
|
|
DB *db.Config `json:"db,omitempty"`
|
|
|
|
Monitoring json.RawMessage `json:"monitoring,omitempty"`
|
|
|
|
AuthorityConfig *AuthConfig `json:"authority,omitempty"`
|
2020-08-10 22:29:18 +00:00
|
|
|
TLS *TLSOptions `json:"tls,omitempty"`
|
2019-10-04 02:03:38 +00:00
|
|
|
Password string `json:"password,omitempty"`
|
|
|
|
Templates *templates.Templates `json:"templates,omitempty"`
|
2022-01-13 19:30:54 +00:00
|
|
|
CommonName string `json:"commonName,omitempty"`
|
2021-11-04 06:05:07 +00:00
|
|
|
CRL *CRLConfig `json:"crl,omitempty"`
|
2022-08-16 21:04:04 +00:00
|
|
|
SkipValidation bool `json:"-"`
|
2022-10-11 12:12:06 +00:00
|
|
|
|
|
|
|
// Keeps record of the filename the Config is read from
|
2022-10-24 13:22:37 +00:00
|
|
|
loadedFromFilepath string
|
2018-10-05 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 01:55:24 +00:00
|
|
|
// CRLConfig represents config options for CRL generation
|
|
|
|
type CRLConfig struct {
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
GenerateOnRevoke bool `json:"generateOnRevoke,omitempty"`
|
|
|
|
CacheDuration *provisioner.Duration `json:"cacheDuration,omitempty"`
|
|
|
|
RenewPeriod *provisioner.Duration `json:"renewPeriod,omitempty"`
|
2022-11-30 19:07:07 +00:00
|
|
|
IDPurl string `json:"idpURL,omitempty"`
|
2022-10-27 01:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsEnabled returns if the CRL is enabled.
|
|
|
|
func (c *CRLConfig) IsEnabled() bool {
|
|
|
|
return c != nil && c.Enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates the CRL configuration.
|
|
|
|
func (c *CRLConfig) Validate() error {
|
|
|
|
if c == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.CacheDuration != nil && c.CacheDuration.Duration < 0 {
|
|
|
|
return errors.New("crl.cacheDuration must be greater than or equal to 0")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RenewPeriod != nil && c.RenewPeriod.Duration < 0 {
|
|
|
|
return errors.New("crl.renewPeriod must be greater than or equal to 0")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RenewPeriod != nil && c.CacheDuration != nil &&
|
|
|
|
c.RenewPeriod.Duration > c.CacheDuration.Duration {
|
|
|
|
return errors.New("crl.cacheDuration must be greater than or equal to crl.renewPeriod")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TickerDuration the renewal ticker duration. This is set by renewPeriod, of it
|
|
|
|
// is not set is ~2/3 of cacheDuration.
|
|
|
|
func (c *CRLConfig) TickerDuration() time.Duration {
|
|
|
|
if !c.IsEnabled() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RenewPeriod != nil && c.RenewPeriod.Duration > 0 {
|
|
|
|
return c.RenewPeriod.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
return (c.CacheDuration.Duration / 3) * 2
|
|
|
|
}
|
|
|
|
|
2020-08-10 22:29:18 +00:00
|
|
|
// ASN1DN contains ASN1.DN attributes that are used in Subject and Issuer
|
|
|
|
// x509 Certificate blocks.
|
|
|
|
type ASN1DN struct {
|
2021-05-03 19:48:20 +00:00
|
|
|
Country string `json:"country,omitempty"`
|
|
|
|
Organization string `json:"organization,omitempty"`
|
|
|
|
OrganizationalUnit string `json:"organizationalUnit,omitempty"`
|
|
|
|
Locality string `json:"locality,omitempty"`
|
|
|
|
Province string `json:"province,omitempty"`
|
|
|
|
StreetAddress string `json:"streetAddress,omitempty"`
|
2021-07-28 02:19:58 +00:00
|
|
|
SerialNumber string `json:"serialNumber,omitempty"`
|
2021-05-03 19:48:20 +00:00
|
|
|
CommonName string `json:"commonName,omitempty"`
|
2020-08-10 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 01:08:51 +00:00
|
|
|
// AuthConfig represents the configuration options for the authority. An
|
|
|
|
// underlaying registration authority can also be configured using the
|
|
|
|
// cas.Options.
|
2018-10-05 21:48:36 +00:00
|
|
|
type AuthConfig struct {
|
2020-10-20 01:08:51 +00:00
|
|
|
*cas.Options
|
2021-07-12 13:31:05 +00:00
|
|
|
AuthorityID string `json:"authorityId,omitempty"`
|
2021-08-11 00:07:15 +00:00
|
|
|
DeploymentType string `json:"deploymentType,omitempty"`
|
2021-08-02 22:34:39 +00:00
|
|
|
Provisioners provisioner.List `json:"provisioners,omitempty"`
|
2021-05-25 23:52:06 +00:00
|
|
|
Admins []*linkedca.Admin `json:"-"`
|
2020-08-10 22:29:18 +00:00
|
|
|
Template *ASN1DN `json:"template,omitempty"`
|
2020-01-03 01:48:28 +00:00
|
|
|
Claims *provisioner.Claims `json:"claims,omitempty"`
|
2022-03-08 12:26:07 +00:00
|
|
|
Policy *policy.Options `json:"policy,omitempty"`
|
2020-01-03 01:48:28 +00:00
|
|
|
DisableIssuedAtCheck bool `json:"disableIssuedAtCheck,omitempty"`
|
|
|
|
Backdate *provisioner.Duration `json:"backdate,omitempty"`
|
2021-05-03 19:48:20 +00:00
|
|
|
EnableAdmin bool `json:"enableAdmin,omitempty"`
|
2022-08-05 01:44:44 +00:00
|
|
|
DisableGetSSHHosts bool `json:"disableGetSSHHosts,omitempty"`
|
2018-10-05 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 20:00:42 +00:00
|
|
|
// init initializes the required fields in the AuthConfig if they are not
|
|
|
|
// provided.
|
|
|
|
func (c *AuthConfig) init() {
|
|
|
|
if c.Provisioners == nil {
|
|
|
|
c.Provisioners = provisioner.List{}
|
|
|
|
}
|
|
|
|
if c.Template == nil {
|
2020-08-10 22:29:18 +00:00
|
|
|
c.Template = &ASN1DN{}
|
2020-05-06 20:00:42 +00:00
|
|
|
}
|
|
|
|
if c.Backdate == nil {
|
|
|
|
c.Backdate = &provisioner.Duration{
|
2021-05-06 06:02:42 +00:00
|
|
|
Duration: DefaultBackdate,
|
2020-05-06 20:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-05 01:52:18 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 21:48:36 +00:00
|
|
|
// Validate validates the authority configuration.
|
2023-05-10 06:47:28 +00:00
|
|
|
func (c *AuthConfig) Validate(provisioner.Audiences) error {
|
2018-10-09 06:25:18 +00:00
|
|
|
if c == nil {
|
2018-10-05 21:48:36 +00:00
|
|
|
return errors.New("authority cannot be undefined")
|
2018-10-09 06:25:18 +00:00
|
|
|
}
|
2018-10-19 05:26:39 +00:00
|
|
|
|
2020-05-06 20:00:42 +00:00
|
|
|
// Initialize required fields.
|
|
|
|
c.init()
|
|
|
|
|
2019-11-09 01:43:54 +00:00
|
|
|
// Check that only one K8sSA is enabled
|
|
|
|
var k8sCount int
|
|
|
|
for _, p := range c.Provisioners {
|
|
|
|
if p.GetType() == provisioner.TypeK8sSA {
|
|
|
|
k8sCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if k8sCount > 1 {
|
|
|
|
return errors.New("cannot have more than one kubernetes service account provisioner")
|
|
|
|
}
|
|
|
|
|
2020-05-06 20:00:42 +00:00
|
|
|
if c.Backdate.Duration < 0 {
|
|
|
|
return errors.New("authority.backdate cannot be less than 0")
|
2020-01-03 01:48:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 06:25:18 +00:00
|
|
|
return nil
|
2018-10-05 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LoadConfiguration parses the given filename in JSON format and returns the
|
|
|
|
// configuration struct.
|
|
|
|
func LoadConfiguration(filename string) (*Config, error) {
|
|
|
|
f, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "error opening %s", filename)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
var c Config
|
|
|
|
if err := json.NewDecoder(f).Decode(&c); err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "error parsing %s", filename)
|
|
|
|
}
|
|
|
|
|
2022-10-11 12:12:06 +00:00
|
|
|
// store filename that was read to populate Config
|
2022-10-24 13:22:37 +00:00
|
|
|
c.loadedFromFilepath = filename
|
2022-10-11 12:12:06 +00:00
|
|
|
|
|
|
|
// initialize the Config
|
2021-05-07 00:03:12 +00:00
|
|
|
c.Init()
|
2021-05-04 21:45:11 +00:00
|
|
|
|
2018-10-05 21:48:36 +00:00
|
|
|
return &c, nil
|
|
|
|
}
|
|
|
|
|
2021-05-03 19:48:20 +00:00
|
|
|
// Init initializes the minimal configuration required to create an authority. This
|
2020-05-06 20:00:42 +00:00
|
|
|
// is mainly used on embedded authorities.
|
2021-05-03 19:48:20 +00:00
|
|
|
func (c *Config) Init() {
|
2020-05-06 20:00:42 +00:00
|
|
|
if c.DNSNames == nil {
|
|
|
|
c.DNSNames = []string{"localhost", "127.0.0.1", "::1"}
|
|
|
|
}
|
|
|
|
if c.TLS == nil {
|
|
|
|
c.TLS = &DefaultTLSOptions
|
|
|
|
}
|
|
|
|
if c.AuthorityConfig == nil {
|
|
|
|
c.AuthorityConfig = &AuthConfig{}
|
|
|
|
}
|
2022-01-13 19:30:54 +00:00
|
|
|
if c.CommonName == "" {
|
|
|
|
c.CommonName = "Step Online CA"
|
|
|
|
}
|
2022-10-27 01:55:24 +00:00
|
|
|
if c.CRL != nil && c.CRL.Enabled && c.CRL.CacheDuration == nil {
|
2022-09-14 18:43:58 +00:00
|
|
|
c.CRL.CacheDuration = DefaultCRLCacheDuration
|
|
|
|
}
|
2020-05-06 20:00:42 +00:00
|
|
|
c.AuthorityConfig.init()
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:48:36 +00:00
|
|
|
// Save saves the configuration to the given filename.
|
|
|
|
func (c *Config) Save(filename string) error {
|
2023-08-04 00:52:02 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
enc := json.NewEncoder(&b)
|
2018-10-05 21:48:36 +00:00
|
|
|
enc.SetIndent("", "\t")
|
2023-08-04 00:52:02 +00:00
|
|
|
if err := enc.Encode(c); err != nil {
|
|
|
|
return fmt.Errorf("error encoding configuration: %w", err)
|
|
|
|
}
|
|
|
|
if err := os.WriteFile(filename, b.Bytes(), 0600); err != nil {
|
|
|
|
return fmt.Errorf("error writing %q: %w", filename, err)
|
|
|
|
}
|
|
|
|
return nil
|
2018-10-05 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 12:12:06 +00:00
|
|
|
// Commit saves the current configuration to the same
|
|
|
|
// file it was initially loaded from.
|
|
|
|
//
|
|
|
|
// TODO(hs): rename Save() to WriteTo() and replace this
|
|
|
|
// with Save()? Or is Commit clear enough.
|
|
|
|
func (c *Config) Commit() error {
|
|
|
|
if !c.WasLoadedFromFile() {
|
|
|
|
return errors.New("cannot commit configuration if not loaded from file")
|
|
|
|
}
|
2022-10-24 13:22:37 +00:00
|
|
|
return c.Save(c.loadedFromFilepath)
|
2022-10-11 12:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WasLoadedFromFile returns whether or not the Config was
|
2022-10-24 13:22:37 +00:00
|
|
|
// loaded from a file.
|
2022-10-11 12:12:06 +00:00
|
|
|
func (c *Config) WasLoadedFromFile() bool {
|
2022-10-24 13:22:37 +00:00
|
|
|
return c.loadedFromFilepath != ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filepath returns the path to the file the Config was
|
|
|
|
// loaded from.
|
|
|
|
func (c *Config) Filepath() string {
|
|
|
|
return c.loadedFromFilepath
|
2022-10-11 12:12:06 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 21:48:36 +00:00
|
|
|
// Validate validates the configuration.
|
|
|
|
func (c *Config) Validate() error {
|
|
|
|
switch {
|
2022-08-16 21:04:04 +00:00
|
|
|
case c.SkipValidation:
|
|
|
|
return nil
|
2018-10-05 21:48:36 +00:00
|
|
|
case c.Address == "":
|
|
|
|
return errors.New("address cannot be empty")
|
|
|
|
case len(c.DNSNames) == 0:
|
|
|
|
return errors.New("dnsNames cannot be empty")
|
2021-07-28 20:56:05 +00:00
|
|
|
case c.AuthorityConfig == nil:
|
|
|
|
return errors.New("authority cannot be nil")
|
2018-10-05 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 01:08:51 +00:00
|
|
|
// Options holds the RA/CAS configuration.
|
|
|
|
ra := c.AuthorityConfig.Options
|
|
|
|
// The default RA/CAS requires root, crt and key.
|
|
|
|
if ra.Is(cas.SoftCAS) {
|
2020-09-21 22:27:20 +00:00
|
|
|
switch {
|
|
|
|
case c.Root.HasEmpties():
|
|
|
|
return errors.New("root cannot be empty")
|
|
|
|
case c.IntermediateCert == "":
|
|
|
|
return errors.New("crt cannot be empty")
|
|
|
|
case c.IntermediateKey == "":
|
|
|
|
return errors.New("key cannot be empty")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-21 23:27:22 +00:00
|
|
|
// Validate address (a port is required)
|
|
|
|
if _, _, err := net.SplitHostPort(c.Address); err != nil {
|
|
|
|
return errors.Errorf("invalid address %s", c.Address)
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:48:36 +00:00
|
|
|
if c.TLS == nil {
|
|
|
|
c.TLS = &DefaultTLSOptions
|
|
|
|
} else {
|
|
|
|
if len(c.TLS.CipherSuites) == 0 {
|
|
|
|
c.TLS.CipherSuites = DefaultTLSOptions.CipherSuites
|
|
|
|
}
|
|
|
|
if c.TLS.MaxVersion == 0 {
|
|
|
|
c.TLS.MaxVersion = DefaultTLSOptions.MaxVersion
|
|
|
|
}
|
|
|
|
if c.TLS.MinVersion == 0 {
|
2021-08-11 22:33:45 +00:00
|
|
|
c.TLS.MinVersion = DefaultTLSOptions.MinVersion
|
2018-10-05 21:48:36 +00:00
|
|
|
}
|
|
|
|
if c.TLS.MinVersion > c.TLS.MaxVersion {
|
|
|
|
return errors.New("tls minVersion cannot exceed tls maxVersion")
|
|
|
|
}
|
|
|
|
c.TLS.Renegotiation = c.TLS.Renegotiation || DefaultTLSOptions.Renegotiation
|
|
|
|
}
|
|
|
|
|
2020-01-10 02:42:26 +00:00
|
|
|
// Validate KMS options, nil is ok.
|
|
|
|
if err := c.KMS.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-20 01:08:51 +00:00
|
|
|
// Validate RA/CAS options, nil is ok.
|
|
|
|
if err := ra.Validate(); err != nil {
|
2020-09-09 02:26:32 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-10-09 01:09:41 +00:00
|
|
|
// Validate ssh: nil is ok
|
|
|
|
if err := c.SSH.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-10-04 02:03:38 +00:00
|
|
|
// Validate templates: nil is ok
|
|
|
|
if err := c.Templates.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-10-27 01:55:24 +00:00
|
|
|
// Validate crl config: nil is ok
|
|
|
|
if err := c.CRL.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-05-03 19:48:20 +00:00
|
|
|
return c.AuthorityConfig.Validate(c.GetAudiences())
|
2019-03-07 02:32:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 19:48:20 +00:00
|
|
|
// GetAudiences returns the legacy and possible urls without the ports that will
|
2019-03-07 02:32:56 +00:00
|
|
|
// be used as the default provisioner audiences. The CA might have proxies in
|
|
|
|
// front so we cannot rely on the port.
|
2021-05-03 19:48:20 +00:00
|
|
|
func (c *Config) GetAudiences() provisioner.Audiences {
|
2019-03-05 08:07:13 +00:00
|
|
|
audiences := provisioner.Audiences{
|
2019-10-28 18:50:43 +00:00
|
|
|
Sign: []string{legacyAuthority},
|
|
|
|
Revoke: []string{legacyAuthority},
|
|
|
|
SSHSign: []string{},
|
|
|
|
SSHRevoke: []string{},
|
|
|
|
SSHRenew: []string{},
|
2019-03-05 08:07:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 02:32:56 +00:00
|
|
|
for _, name := range c.DNSNames {
|
2022-03-11 04:21:01 +00:00
|
|
|
hostname := toHostname(name)
|
2019-03-05 08:07:13 +00:00
|
|
|
audiences.Sign = append(audiences.Sign,
|
2022-03-11 04:21:01 +00:00
|
|
|
fmt.Sprintf("https://%s/1.0/sign", hostname),
|
|
|
|
fmt.Sprintf("https://%s/sign", hostname),
|
|
|
|
fmt.Sprintf("https://%s/1.0/ssh/sign", hostname),
|
|
|
|
fmt.Sprintf("https://%s/ssh/sign", hostname))
|
|
|
|
audiences.Renew = append(audiences.Renew,
|
|
|
|
fmt.Sprintf("https://%s/1.0/renew", hostname),
|
|
|
|
fmt.Sprintf("https://%s/renew", hostname))
|
2019-03-05 08:07:13 +00:00
|
|
|
audiences.Revoke = append(audiences.Revoke,
|
2022-03-11 04:21:01 +00:00
|
|
|
fmt.Sprintf("https://%s/1.0/revoke", hostname),
|
|
|
|
fmt.Sprintf("https://%s/revoke", hostname))
|
2019-10-28 18:50:43 +00:00
|
|
|
audiences.SSHSign = append(audiences.SSHSign,
|
2022-03-11 04:21:01 +00:00
|
|
|
fmt.Sprintf("https://%s/1.0/ssh/sign", hostname),
|
|
|
|
fmt.Sprintf("https://%s/ssh/sign", hostname),
|
|
|
|
fmt.Sprintf("https://%s/1.0/sign", hostname),
|
|
|
|
fmt.Sprintf("https://%s/sign", hostname))
|
2019-10-28 18:50:43 +00:00
|
|
|
audiences.SSHRevoke = append(audiences.SSHRevoke,
|
2022-03-11 04:21:01 +00:00
|
|
|
fmt.Sprintf("https://%s/1.0/ssh/revoke", hostname),
|
|
|
|
fmt.Sprintf("https://%s/ssh/revoke", hostname))
|
2019-10-28 18:50:43 +00:00
|
|
|
audiences.SSHRenew = append(audiences.SSHRenew,
|
2022-03-11 04:21:01 +00:00
|
|
|
fmt.Sprintf("https://%s/1.0/ssh/renew", hostname),
|
|
|
|
fmt.Sprintf("https://%s/ssh/renew", hostname))
|
2019-10-28 18:50:43 +00:00
|
|
|
audiences.SSHRekey = append(audiences.SSHRekey,
|
2022-03-11 04:21:01 +00:00
|
|
|
fmt.Sprintf("https://%s/1.0/ssh/rekey", hostname),
|
|
|
|
fmt.Sprintf("https://%s/ssh/rekey", hostname))
|
2019-03-07 02:32:56 +00:00
|
|
|
}
|
2019-03-05 08:07:13 +00:00
|
|
|
|
2019-03-07 02:32:56 +00:00
|
|
|
return audiences
|
2018-10-05 21:48:36 +00:00
|
|
|
}
|
2022-01-19 16:14:45 +00:00
|
|
|
|
2022-04-08 01:14:43 +00:00
|
|
|
// Audience returns the list of audiences for a given path.
|
|
|
|
func (c *Config) Audience(path string) []string {
|
|
|
|
audiences := make([]string, len(c.DNSNames)+1)
|
|
|
|
for i, name := range c.DNSNames {
|
|
|
|
hostname := toHostname(name)
|
|
|
|
audiences[i] = "https://" + hostname + path
|
|
|
|
}
|
|
|
|
// For backward compatibility
|
|
|
|
audiences[len(c.DNSNames)] = path
|
|
|
|
return audiences
|
|
|
|
}
|
|
|
|
|
2022-01-19 16:14:45 +00:00
|
|
|
func toHostname(name string) string {
|
|
|
|
// ensure an IPv6 address is represented with square brackets when used as hostname
|
|
|
|
if ip := net.ParseIP(name); ip != nil && ip.To4() == nil {
|
|
|
|
name = "[" + name + "]"
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|