Просмотр исходного кода

Use only the IID template on IID provisioners.

Use always sshutil.DefaultIIDCertificate and require at least one
principal on IID provisioners.
Mariano Cano 6 лет назад
Родитель
Сommit
9822305bb6

+ 14 - 13
authority/provisioner/aws.go

@@ -468,6 +468,12 @@ func (p *AWS) AuthorizeSSHSign(ctx context.Context, token string) ([]SignOption,
 	}
 	}
 
 
 	doc := claims.document
 	doc := claims.document
+	signOptions := []SignOption{}
+
+	// Enforce host certificate.
+	defaults := SignSSHOptions{
+		CertType: SSHHostCert,
+	}
 
 
 	// Validated principals.
 	// Validated principals.
 	principals := []string{
 	principals := []string{
@@ -475,21 +481,14 @@ func (p *AWS) AuthorizeSSHSign(ctx context.Context, token string) ([]SignOption,
 		fmt.Sprintf("ip-%s.%s.compute.internal", strings.Replace(doc.PrivateIP, ".", "-", -1), doc.Region),
 		fmt.Sprintf("ip-%s.%s.compute.internal", strings.Replace(doc.PrivateIP, ".", "-", -1), doc.Region),
 	}
 	}
 
 
-	// Default to cert type to host
-	defaults := SignSSHOptions{
-		CertType: SSHHostCert,
-	}
-	defaultTemplate := sshutil.DefaultIIDCertificate
-
 	// Only enforce known principals if disable custom sans is true.
 	// Only enforce known principals if disable custom sans is true.
 	if p.DisableCustomSANs {
 	if p.DisableCustomSANs {
 		defaults.Principals = principals
 		defaults.Principals = principals
-		defaultTemplate = sshutil.DefaultCertificate
-	}
-
-	// Validate user options
-	signOptions := []SignOption{
-		sshCertOptionsValidator(defaults),
+	} else {
+		// Check that at least one principal is sent in the request.
+		signOptions = append(signOptions, &sshCertOptionsRequireValidator{
+			Principals: true,
+		})
 	}
 	}
 
 
 	// Certificate templates.
 	// Certificate templates.
@@ -498,13 +497,15 @@ func (p *AWS) AuthorizeSSHSign(ctx context.Context, token string) ([]SignOption,
 		data.SetToken(v)
 		data.SetToken(v)
 	}
 	}
 
 
-	templateOptions, err := CustomSSHTemplateOptions(p.Options, data, defaultTemplate)
+	templateOptions, err := CustomSSHTemplateOptions(p.Options, data, sshutil.DefaultIIDCertificate)
 	if err != nil {
 	if err != nil {
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "aws.AuthorizeSSHSign")
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "aws.AuthorizeSSHSign")
 	}
 	}
 	signOptions = append(signOptions, templateOptions)
 	signOptions = append(signOptions, templateOptions)
 
 
 	return append(signOptions,
 	return append(signOptions,
+		// Validate user SignSSHOptions.
+		sshCertOptionsValidator(defaults),
 		// Set the validity bounds if not set.
 		// Set the validity bounds if not set.
 		&sshDefaultDuration{p.claimer},
 		&sshDefaultDuration{p.claimer},
 		// Validate public key
 		// Validate public key

+ 13 - 11
authority/provisioner/azure.go

@@ -340,24 +340,24 @@ func (p *Azure) AuthorizeSSHSign(ctx context.Context, token string) ([]SignOptio
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "azure.AuthorizeSSHSign")
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "azure.AuthorizeSSHSign")
 	}
 	}
 
 
-	// Validated principals
-	principals := []string{name}
+	signOptions := []SignOption{}
 
 
-	// Default options and template
+	// Enforce host certificate.
 	defaults := SignSSHOptions{
 	defaults := SignSSHOptions{
 		CertType: SSHHostCert,
 		CertType: SSHHostCert,
 	}
 	}
-	defaultTemplate := sshutil.DefaultIIDCertificate
+
+	// Validated principals.
+	principals := []string{name}
 
 
 	// Only enforce known principals if disable custom sans is true.
 	// Only enforce known principals if disable custom sans is true.
 	if p.DisableCustomSANs {
 	if p.DisableCustomSANs {
 		defaults.Principals = principals
 		defaults.Principals = principals
-		defaultTemplate = sshutil.DefaultCertificate
-	}
-
-	// Validate user options
-	signOptions := []SignOption{
-		sshCertOptionsValidator(defaults),
+	} else {
+		// Check that at least one principal is sent in the request.
+		signOptions = append(signOptions, &sshCertOptionsRequireValidator{
+			Principals: true,
+		})
 	}
 	}
 
 
 	// Certificate templates.
 	// Certificate templates.
@@ -366,13 +366,15 @@ func (p *Azure) AuthorizeSSHSign(ctx context.Context, token string) ([]SignOptio
 		data.SetToken(v)
 		data.SetToken(v)
 	}
 	}
 
 
-	templateOptions, err := CustomSSHTemplateOptions(p.Options, data, defaultTemplate)
+	templateOptions, err := CustomSSHTemplateOptions(p.Options, data, sshutil.DefaultIIDCertificate)
 	if err != nil {
 	if err != nil {
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "azure.AuthorizeSSHSign")
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "azure.AuthorizeSSHSign")
 	}
 	}
 	signOptions = append(signOptions, templateOptions)
 	signOptions = append(signOptions, templateOptions)
 
 
 	return append(signOptions,
 	return append(signOptions,
+		// Validate user SignSSHOptions.
+		sshCertOptionsValidator(defaults),
 		// Set the validity bounds if not set.
 		// Set the validity bounds if not set.
 		&sshDefaultDuration{p.claimer},
 		&sshDefaultDuration{p.claimer},
 		// Validate public key
 		// Validate public key

+ 15 - 14
authority/provisioner/gcp.go

@@ -379,28 +379,27 @@ func (p *GCP) AuthorizeSSHSign(ctx context.Context, token string) ([]SignOption,
 	}
 	}
 
 
 	ce := claims.Google.ComputeEngine
 	ce := claims.Google.ComputeEngine
+	signOptions := []SignOption{}
 
 
-	// Validated principals
+	// Enforce host certificate.
+	defaults := SignSSHOptions{
+		CertType: SSHHostCert,
+	}
+
+	// Validated principals.
 	principals := []string{
 	principals := []string{
 		fmt.Sprintf("%s.c.%s.internal", ce.InstanceName, ce.ProjectID),
 		fmt.Sprintf("%s.c.%s.internal", ce.InstanceName, ce.ProjectID),
 		fmt.Sprintf("%s.%s.c.%s.internal", ce.InstanceName, ce.Zone, ce.ProjectID),
 		fmt.Sprintf("%s.%s.c.%s.internal", ce.InstanceName, ce.Zone, ce.ProjectID),
 	}
 	}
 
 
-	// Default options and template
-	defaults := SignSSHOptions{
-		CertType: SSHHostCert,
-	}
-	defaultTemplate := sshutil.DefaultIIDCertificate
-
 	// Only enforce known principals if disable custom sans is true.
 	// Only enforce known principals if disable custom sans is true.
 	if p.DisableCustomSANs {
 	if p.DisableCustomSANs {
 		defaults.Principals = principals
 		defaults.Principals = principals
-		defaultTemplate = sshutil.DefaultCertificate
-	}
-
-	// Validate user options
-	signOptions := []SignOption{
-		sshCertOptionsValidator(defaults),
+	} else {
+		// Check that at least one principal is sent in the request.
+		signOptions = append(signOptions, &sshCertOptionsRequireValidator{
+			Principals: true,
+		})
 	}
 	}
 
 
 	// Certificate templates.
 	// Certificate templates.
@@ -409,13 +408,15 @@ func (p *GCP) AuthorizeSSHSign(ctx context.Context, token string) ([]SignOption,
 		data.SetToken(v)
 		data.SetToken(v)
 	}
 	}
 
 
-	templateOptions, err := CustomSSHTemplateOptions(p.Options, data, defaultTemplate)
+	templateOptions, err := CustomSSHTemplateOptions(p.Options, data, sshutil.DefaultIIDCertificate)
 	if err != nil {
 	if err != nil {
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "gcp.AuthorizeSSHSign")
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "gcp.AuthorizeSSHSign")
 	}
 	}
 	signOptions = append(signOptions, templateOptions)
 	signOptions = append(signOptions, templateOptions)
 
 
 	return append(signOptions,
 	return append(signOptions,
+		// Validate user SignSSHOptions.
+		sshCertOptionsValidator(defaults),
 		// Set the validity bounds if not set.
 		// Set the validity bounds if not set.
 		&sshDefaultDuration{p.claimer},
 		&sshDefaultDuration{p.claimer},
 		// Validate public key
 		// Validate public key

+ 1 - 1
authority/provisioner/sign_ssh_options.go

@@ -306,7 +306,7 @@ type sshCertOptionsRequireValidator struct {
 	Principals bool
 	Principals bool
 }
 }
 
 
-func (v sshCertOptionsRequireValidator) Valid(got SignSSHOptions) error {
+func (v *sshCertOptionsRequireValidator) Valid(got SignSSHOptions) error {
 	switch {
 	switch {
 	case v.CertType && got.CertType == "":
 	case v.CertType && got.CertType == "":
 		return errors.New("ssh certificate certType cannot be empty")
 		return errors.New("ssh certificate certType cannot be empty")