Skip to content

Commit 7fa97be

Browse files
committed
Remove OIDC user regexp check
This commit removes the regular expression check on OIDC usernames. Although it is not recommended to use any character in a username, it is possible to create and use them. The tool useradd has the flag --badname and adduser has --allow-badname and --allow-all-names to create new users with any character. Moreover, it is possible to create any username with the rest of provisioners. Fixes #1436
1 parent cbc46d1 commit 7fa97be

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

@@ -115,20 +114,18 @@ func DefaultIdentityFunc(_ context.Context, p Interface, email string) (*Identit
115114
switch k := p.(type) {
116115
case *OIDC:
117116
// OIDC principals would be:
118-
// ~~1. Preferred usernames.~~ Note: Under discussion, currently disabled
119-
// 2. Sanitized local.
120-
// 3. Raw local (if different).
121-
// 4. Email address.
117+
// ~~1. Preferred usernames.~~ Note: Under discussion, currently disabled
118+
// 2. Sanitized local.
119+
// 3. Raw local (if different).
120+
// 4. Email address.
122121
name := SanitizeSSHUserPrincipal(email)
123-
if !sshUserRegex.MatchString(name) {
124-
return nil, errors.Errorf("invalid principal '%s' from email '%s'", name, email)
125-
}
126122
usernames := []string{name}
127123
if i := strings.LastIndex(email, "@"); i >= 0 {
128124
usernames = append(usernames, email[:i])
129125
}
130126
usernames = append(usernames, email)
131127
return &Identity{
128+
// Remove duplicated and empty usernames.
132129
Usernames: SanitizeStringSlices(usernames),
133130
}, nil
134131
default:
@@ -178,8 +175,6 @@ func DefaultAuthorizeSSHRenew(_ context.Context, p *Controller, cert *ssh.Certif
178175
return nil
179176
}
180177

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

authority/provisioner/controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ func TestController_GetIdentity(t *testing.T) {
167167
}}, args{ctx, "[email protected]"}, &Identity{
168168
Usernames: []string{"jane"},
169169
}, false},
170+
{"ok badname", fields{&OIDC{}, nil}, args{ctx, "[email protected]"}, &Identity{
171+
Usernames: []string{"1000", "[email protected]"},
172+
}, false},
173+
{"ok sanitized badname", fields{&OIDC{}, nil}, args{ctx, "[email protected]"}, &Identity{
174+
Usernames: []string{"1000_10", "1000+10", "[email protected]"},
175+
}, false},
170176
{"fail provisioner", fields{&JWK{}, nil}, args{ctx, "[email protected]"}, nil, true},
171177
{"fail custom", fields{&OIDC{}, func(ctx context.Context, p Interface, email string) (*Identity, error) {
172178
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)