Skip to content

Commit 95887eb

Browse files
authored
Merge pull request #1481 from smallstep/remove-user-regex
Remove OIDC user regexp check
2 parents a1350b1 + 7fa97be commit 95887eb

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

authority/provisioner/controller.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"crypto/x509"
66
"net/http"
7-
"regexp"
87
"strings"
98
"time"
109

@@ -117,20 +116,18 @@ func DefaultIdentityFunc(_ context.Context, p Interface, email string) (*Identit
117116
switch k := p.(type) {
118117
case *OIDC:
119118
// OIDC principals would be:
120-
// ~~1. Preferred usernames.~~ Note: Under discussion, currently disabled
121-
// 2. Sanitized local.
122-
// 3. Raw local (if different).
123-
// 4. Email address.
119+
// ~~1. Preferred usernames.~~ Note: Under discussion, currently disabled
120+
// 2. Sanitized local.
121+
// 3. Raw local (if different).
122+
// 4. Email address.
124123
name := SanitizeSSHUserPrincipal(email)
125-
if !sshUserRegex.MatchString(name) {
126-
return nil, errors.Errorf("invalid principal '%s' from email '%s'", name, email)
127-
}
128124
usernames := []string{name}
129125
if i := strings.LastIndex(email, "@"); i >= 0 {
130126
usernames = append(usernames, email[:i])
131127
}
132128
usernames = append(usernames, email)
133129
return &Identity{
130+
// Remove duplicated and empty usernames.
134131
Usernames: SanitizeStringSlices(usernames),
135132
}, nil
136133
default:
@@ -180,8 +177,6 @@ func DefaultAuthorizeSSHRenew(_ context.Context, p *Controller, cert *ssh.Certif
180177
return nil
181178
}
182179

183-
var sshUserRegex = regexp.MustCompile("^[a-z][-a-z0-9_]*$")
184-
185180
// SanitizeStringSlices removes duplicated an empty strings.
186181
func SanitizeStringSlices(original []string) []string {
187182
output := []string{}

authority/provisioner/controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ func TestController_GetIdentity(t *testing.T) {
170170
}}, args{ctx, "[email protected]"}, &Identity{
171171
Usernames: []string{"jane"},
172172
}, false},
173+
{"ok badname", fields{&OIDC{}, nil}, args{ctx, "[email protected]"}, &Identity{
174+
Usernames: []string{"1000", "[email protected]"},
175+
}, false},
176+
{"ok sanitized badname", fields{&OIDC{}, nil}, args{ctx, "[email protected]"}, &Identity{
177+
Usernames: []string{"1000_10", "1000+10", "[email protected]"},
178+
}, false},
173179
{"fail provisioner", fields{&JWK{}, nil}, args{ctx, "[email protected]"}, nil, true},
174180
{"fail custom", fields{&OIDC{}, func(ctx context.Context, p Interface, email string) (*Identity, error) {
175181
return nil, fmt.Errorf("an error")

authority/provisioner/provisioner_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ func TestDefaultIdentityFunc(t *testing.T) {
7676
err: errors.New("provisioner type '*provisioner.X5C' not supported by identity function"),
7777
}
7878
},
79-
"fail/bad-ssh-regex": func(t *testing.T) test {
80-
return test{
81-
p: &OIDC{},
82-
email: "$%^#_>@smallstep.com",
83-
err: errors.New("invalid principal '______' from email '$%^#_>@smallstep.com'"),
84-
}
85-
},
8679
"ok": func(t *testing.T) test {
8780
return test{
8881
p: &OIDC{},
@@ -142,6 +135,13 @@ func TestDefaultIdentityFunc(t *testing.T) {
142135
identity: &Identity{Usernames: []string{"john", "[email protected]"}},
143136
}
144137
},
138+
"ok/badname": func(t *testing.T) test {
139+
return test{
140+
p: &OIDC{},
141+
email: "$%^#_>@smallstep.com",
142+
identity: &Identity{Usernames: []string{"______", "$%^#_>", "$%^#_>@smallstep.com"}},
143+
}
144+
},
145145
}
146146
for name, get := range tests {
147147
t.Run(name, func(t *testing.T) {

0 commit comments

Comments
 (0)