File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 4
4
"fmt"
5
5
"github.com/sirupsen/logrus"
6
6
"os/user"
7
+ "regexp"
7
8
"sync"
8
-
9
- "github.com/containerd/containerd/identifiers"
10
9
)
11
10
12
11
const (
@@ -24,9 +23,12 @@ func LimaUser(warn bool) (*user.User, error) {
24
23
cache .Do (func () {
25
24
cache .u , cache .err = user .Current ()
26
25
if cache .err == nil {
27
- if err := identifiers .Validate (cache .u .Username ); err != nil {
28
- cache .warning = fmt .Sprintf ("local user %q is not a valid Linux username: %v; using %q username instead" ,
29
- cache .u .Username , err , fallbackUser )
26
+ // `useradd` only allows user and group names matching the following pattern:
27
+ // (it allows a trailing '$', but it feels prudent to map those to the fallback user as well)
28
+ validName := "^[a-z_][a-z0-9_-]*$"
29
+ if ! regexp .MustCompile (validName ).Match ([]byte (cache .u .Username )) {
30
+ cache .warning = fmt .Sprintf ("local user %q is not a valid Linux username (must match %q); using %q username instead" ,
31
+ cache .u .Username , validName , fallbackUser )
30
32
cache .u .Username = fallbackUser
31
33
}
32
34
}
You can’t perform that action at this time.
0 commit comments