Skip to content

Commit 7f9034d

Browse files
committed
Add additional policy options
1 parent def9438 commit 7f9034d

File tree

6 files changed

+112
-23
lines changed

6 files changed

+112
-23
lines changed

acme/account.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ func (p *Policy) GetDeniedNameOptions() *policy.X509NameOptions {
8181
}
8282
}
8383

84+
// IsWildcardLiteralAllowed returns true by default for
85+
// ACME account policies, as authorization is performed on DNS
86+
// level.
87+
func (p *Policy) IsWildcardLiteralAllowed() bool {
88+
return true
89+
}
90+
91+
// ShouldVerifySubjectCommonName returns true by default
92+
// for ACME account policies, as this is embedded in the
93+
// protocol.
94+
func (p *Policy) ShouldVerifySubjectCommonName() bool {
95+
return true
96+
}
97+
8498
// ExternalAccountKey is an ACME External Account Binding key.
8599
type ExternalAccountKey struct {
86100
ID string `json:"id"`

authority/admin/api/policy.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package api
22

33
import (
44
"errors"
5+
"fmt"
56
"net/http"
67

78
"go.step.sm/linkedca"
9+
"google.golang.org/protobuf/types/known/wrapperspb"
810

911
"github.com/smallstep/certificates/acme"
1012
"github.com/smallstep/certificates/api/read"
@@ -85,6 +87,10 @@ func (par *PolicyAdminResponder) CreateAuthorityPolicy(w http.ResponseWriter, r
8587
return
8688
}
8789

90+
fmt.Println("before: ", newPolicy)
91+
applyDefaults(newPolicy)
92+
fmt.Println("after: ", newPolicy)
93+
8894
adm := linkedca.AdminFromContext(ctx)
8995

9096
var createdPolicy *linkedca.Policy
@@ -202,6 +208,8 @@ func (par *PolicyAdminResponder) CreateProvisionerPolicy(w http.ResponseWriter,
202208
return
203209
}
204210

211+
applyDefaults(newPolicy)
212+
205213
prov.Policy = newPolicy
206214

207215
if err := par.auth.UpdateProvisioner(ctx, prov); err != nil {
@@ -366,3 +374,13 @@ func (par *PolicyAdminResponder) DeleteACMEAccountPolicy(w http.ResponseWriter,
366374

367375
render.JSONStatus(w, DeleteResponse{Status: "ok"}, http.StatusOK)
368376
}
377+
378+
func applyDefaults(p *linkedca.Policy) {
379+
if p.GetX509() == nil {
380+
return
381+
}
382+
if p.GetX509().VerifySubjectCommonName == nil {
383+
p.X509.VerifySubjectCommonName = &wrapperspb.BoolValue{Value: true}
384+
}
385+
return
386+
}

authority/policy/options.go

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func (o *Options) GetSSHOptions() *SSHPolicyOptions {
3030
type X509PolicyOptionsInterface interface {
3131
GetAllowedNameOptions() *X509NameOptions
3232
GetDeniedNameOptions() *X509NameOptions
33+
IsWildcardLiteralAllowed() bool
34+
ShouldVerifySubjectCommonName() bool
3335
}
3436

3537
// X509PolicyOptions is a container for x509 allowed and denied
@@ -39,6 +41,13 @@ type X509PolicyOptions struct {
3941
AllowedNames *X509NameOptions `json:"allow,omitempty"`
4042
// DeniedNames contains the x509 denied names
4143
DeniedNames *X509NameOptions `json:"deny,omitempty"`
44+
// AllowWildcardLiteral indicates if literal wildcard names
45+
// such as *.example.com and @example.com are allowed. Defaults
46+
// to false.
47+
AllowWildcardLiteral *bool `json:"allow_wildcard_literal,omitempty"`
48+
// VerifySubjectCommonName indicates if the Subject Common Name
49+
// is verified in addition to the SANs. Defaults to true.
50+
VerifySubjectCommonName *bool `json:"verify_subject_common_name,omitempty"`
4251
}
4352

4453
// X509NameOptions models the X509 name policy configuration.
@@ -58,6 +67,43 @@ func (o *X509NameOptions) HasNames() bool {
5867
len(o.URIDomains) > 0
5968
}
6069

70+
// GetDeniedNameOptions returns the x509 denied name policy configuration
71+
func (o *X509PolicyOptions) GetDeniedNameOptions() *X509NameOptions {
72+
if o == nil {
73+
return nil
74+
}
75+
return o.DeniedNames
76+
}
77+
78+
// GetAllowedUserNameOptions returns the SSH allowed user name policy
79+
// configuration.
80+
func (o *SSHPolicyOptions) GetAllowedUserNameOptions() *SSHNameOptions {
81+
if o == nil {
82+
return nil
83+
}
84+
if o.User == nil {
85+
return nil
86+
}
87+
return o.User.AllowedNames
88+
}
89+
90+
func (o *X509PolicyOptions) IsWildcardLiteralAllowed() bool {
91+
if o == nil {
92+
return true
93+
}
94+
return o.AllowWildcardLiteral != nil && *o.AllowWildcardLiteral
95+
}
96+
97+
func (o *X509PolicyOptions) ShouldVerifySubjectCommonName() bool {
98+
if o == nil {
99+
return false
100+
}
101+
if o.VerifySubjectCommonName == nil {
102+
return true
103+
}
104+
return *o.VerifySubjectCommonName
105+
}
106+
61107
// SSHPolicyOptionsInterface is an interface for providers of
62108
// SSH user and host name policy configuration.
63109
type SSHPolicyOptionsInterface interface {
@@ -84,26 +130,6 @@ func (o *X509PolicyOptions) GetAllowedNameOptions() *X509NameOptions {
84130
return o.AllowedNames
85131
}
86132

87-
// GetDeniedNameOptions returns the x509 denied name policy configuration
88-
func (o *X509PolicyOptions) GetDeniedNameOptions() *X509NameOptions {
89-
if o == nil {
90-
return nil
91-
}
92-
return o.DeniedNames
93-
}
94-
95-
// GetAllowedUserNameOptions returns the SSH allowed user name policy
96-
// configuration.
97-
func (o *SSHPolicyOptions) GetAllowedUserNameOptions() *SSHNameOptions {
98-
if o == nil {
99-
return nil
100-
}
101-
if o.User == nil {
102-
return nil
103-
}
104-
return o.User.AllowedNames
105-
}
106-
107133
// GetDeniedUserNameOptions returns the SSH denied user name policy
108134
// configuration.
109135
func (o *SSHPolicyOptions) GetDeniedUserNameOptions() *SSHNameOptions {

authority/policy/policy.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ func NewX509PolicyEngine(policyOptions X509PolicyOptionsInterface) (X509Policy,
5050
return nil, nil
5151
}
5252

53-
// enable x509 Subject Common Name validation by default
54-
options = append(options, policy.WithSubjectCommonNameVerification())
53+
if policyOptions.ShouldVerifySubjectCommonName() {
54+
options = append(options, policy.WithSubjectCommonNameVerification())
55+
}
56+
57+
if policyOptions.IsWildcardLiteralAllowed() {
58+
options = append(options, policy.WithAllowLiteralWildcardNames())
59+
}
5560

5661
return policy.New(options...)
5762
}

authority/provisioner/options.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ type X509Options struct {
6565

6666
// DeniedNames contains the SANs the provisioner is not authorized to sign
6767
DeniedNames *policy.X509NameOptions `json:"-"`
68+
69+
// AllowWildcardLiteral indicates if literal wildcard names
70+
// such as *.example.com and @example.com are allowed. Defaults
71+
// to false.
72+
AllowWildcardLiteral *bool `json:"-"`
73+
// VerifySubjectCommonName indicates if the Subject Common Name
74+
// is verified in addition to the SANs. Defaults to true.
75+
VerifySubjectCommonName *bool `json:"-"`
6876
}
6977

7078
// HasTemplate returns true if a template is defined in the provisioner options.
@@ -90,6 +98,23 @@ func (o *X509Options) GetDeniedNameOptions() *policy.X509NameOptions {
9098
return o.DeniedNames
9199
}
92100

101+
func (o *X509Options) IsWildcardLiteralAllowed() bool {
102+
if o == nil {
103+
return true
104+
}
105+
return o.AllowWildcardLiteral != nil && *o.AllowWildcardLiteral
106+
}
107+
108+
func (o *X509Options) ShouldVerifySubjectCommonName() bool {
109+
if o == nil {
110+
return false
111+
}
112+
if o.VerifySubjectCommonName == nil {
113+
return true
114+
}
115+
return *o.VerifySubjectCommonName
116+
}
117+
93118
// TemplateOptions generates a CertificateOptions with the template and data
94119
// defined in the ProvisionerOptions, the provisioner generated data, and the
95120
// user data provided in the request. If no template has been provided,

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
github.com/go-kit/kit v0.10.0 // indirect
2121
github.com/go-piv/piv-go v1.7.0
2222
github.com/golang/mock v1.6.0
23+
github.com/golang/protobuf v1.5.2
2324
github.com/google/go-cmp v0.5.7
2425
github.com/google/uuid v1.3.0
2526
github.com/googleapis/gax-go/v2 v2.1.1
@@ -52,4 +53,4 @@ require (
5253
// replace github.com/smallstep/nosql => ../nosql
5354
// replace go.step.sm/crypto => ../crypto
5455
// replace go.step.sm/cli-utils => ../cli-utils
55-
// replace go.step.sm/linkedca => ../linkedca
56+
replace go.step.sm/linkedca => ../linkedca

0 commit comments

Comments
 (0)