Skip to content

Commit 7633c7e

Browse files
authored
Merge pull request #3207 from afbjorklund/user-shell
Make it possible to configure user shell
2 parents 75221d6 + d6462e6 commit 7633c7e

File tree

10 files changed

+36
-9
lines changed

10 files changed

+36
-9
lines changed

pkg/cidata/cidata.TEMPLATE.d/lima.env

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ LIMA_CIDATA_USER={{ .User }}
44
LIMA_CIDATA_UID={{ .UID }}
55
LIMA_CIDATA_COMMENT={{ .Comment }}
66
LIMA_CIDATA_HOME={{ .Home}}
7+
LIMA_CIDATA_SHELL={{ .Shell }}
78
LIMA_CIDATA_HOSTHOME_MOUNTPOINT={{ .HostHomeMountPoint }}
89
LIMA_CIDATA_MOUNTS={{ len .Mounts }}
910
{{- range $i, $val := .Mounts}}

pkg/cidata/cidata.TEMPLATE.d/user-data

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ users:
3434
gecos: {{ printf "%q" .Comment }}
3535
{{- end }}
3636
homedir: "{{.Home}}"
37-
shell: /bin/bash
37+
shell: {{.Shell}}
3838
sudo: ALL=(ALL) NOPASSWD:ALL
3939
lock_passwd: true
4040
ssh-authorized-keys:

pkg/cidata/cidata.go

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func templateArgs(bootScripts bool, instDir, name string, instConfig *limayaml.L
125125
User: *instConfig.User.Name,
126126
Comment: *instConfig.User.Comment,
127127
Home: *instConfig.User.Home,
128+
Shell: *instConfig.User.Shell,
128129
UID: *instConfig.User.UID,
129130
GuestInstallPrefix: *instConfig.GuestInstallPrefix,
130131
UpgradePackages: *instConfig.UpgradePackages,

pkg/cidata/template.go

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type TemplateArgs struct {
6262
User string // user name
6363
Comment string // user information
6464
Home string // home directory
65+
Shell string // login shell
6566
UID uint32
6667
SSHPubKeys []string
6768
Mounts []Mount
@@ -109,6 +110,9 @@ func ValidateTemplateArgs(args *TemplateArgs) error {
109110
if args.Home == "" {
110111
return errors.New("field Home must be set")
111112
}
113+
if args.Shell == "" {
114+
return errors.New("field Shell must be set")
115+
}
112116
if len(args.SSHPubKeys) == 0 {
113117
return errors.New("field SSHPubKeys must be set")
114118
}

pkg/cidata/template_test.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestConfig(t *testing.T) {
1717
UID: 501,
1818
Comment: "Foo",
1919
Home: "/home/foo.linux",
20+
Shell: "/bin/bash",
2021
SSHPubKeys: []string{
2122
"ssh-rsa dummy [email protected]",
2223
},
@@ -35,6 +36,7 @@ func TestConfigCACerts(t *testing.T) {
3536
UID: 501,
3637
Comment: "Foo",
3738
Home: "/home/foo.linux",
39+
Shell: "/bin/bash",
3840
SSHPubKeys: []string{
3941
"ssh-rsa dummy [email protected]",
4042
},
@@ -51,10 +53,11 @@ func TestConfigCACerts(t *testing.T) {
5153

5254
func TestTemplate(t *testing.T) {
5355
args := &TemplateArgs{
54-
Name: "default",
55-
User: "foo",
56-
UID: 501,
57-
Home: "/home/foo.linux",
56+
Name: "default",
57+
User: "foo",
58+
UID: 501,
59+
Home: "/home/foo.linux",
60+
Shell: "/bin/bash",
5861
SSHPubKeys: []string{
5962
"ssh-rsa dummy [email protected]",
6063
},
@@ -86,10 +89,11 @@ func TestTemplate(t *testing.T) {
8689

8790
func TestTemplate9p(t *testing.T) {
8891
args := &TemplateArgs{
89-
Name: "default",
90-
User: "foo",
91-
UID: 501,
92-
Home: "/home/foo.linux",
92+
Name: "default",
93+
User: "foo",
94+
UID: 501,
95+
Home: "/home/foo.linux",
96+
Shell: "/bin/bash",
9397
SSHPubKeys: []string{
9498
"ssh-rsa dummy [email protected]",
9599
},

pkg/limayaml/defaults.go

+9
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
209209
if y.User.Home == nil {
210210
y.User.Home = d.User.Home
211211
}
212+
if y.User.Shell == nil {
213+
y.User.Shell = d.User.Shell
214+
}
212215
if y.User.UID == nil {
213216
y.User.UID = d.User.UID
214217
}
@@ -221,6 +224,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
221224
if o.User.Home != nil {
222225
y.User.Home = o.User.Home
223226
}
227+
if o.User.Shell != nil {
228+
y.User.Shell = o.User.Shell
229+
}
224230
if o.User.UID != nil {
225231
y.User.UID = o.User.UID
226232
}
@@ -236,6 +242,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
236242
y.User.Home = ptr.Of(osutil.LimaUser(existingLimaVersion, warn).HomeDir)
237243
warn = false
238244
}
245+
if y.User.Shell == nil {
246+
y.User.Shell = ptr.Of("/bin/bash")
247+
}
239248
if y.User.UID == nil {
240249
uidString := osutil.LimaUser(existingLimaVersion, warn).Uid
241250
if uid, err := strconv.ParseUint(uidString, 10, 32); err == nil {

pkg/limayaml/defaults_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func TestFillDefault(t *testing.T) {
117117
Name: ptr.Of(user.Username),
118118
Comment: ptr.Of(user.Name),
119119
Home: ptr.Of(user.HomeDir),
120+
Shell: ptr.Of("/bin/bash"),
120121
UID: ptr.Of(uint32(uid)),
121122
},
122123
}
@@ -441,6 +442,7 @@ func TestFillDefault(t *testing.T) {
441442
Name: ptr.Of("xxx"),
442443
Comment: ptr.Of("Foo Bar"),
443444
Home: ptr.Of("/tmp"),
445+
Shell: ptr.Of("/bin/tcsh"),
444446
UID: ptr.Of(uint32(8080)),
445447
},
446448
}
@@ -664,6 +666,7 @@ func TestFillDefault(t *testing.T) {
664666
Name: ptr.Of("foo"),
665667
Comment: ptr.Of("foo bar baz"),
666668
Home: ptr.Of("/override"),
669+
Shell: ptr.Of("/bin/sh"),
667670
UID: ptr.Of(uint32(1122)),
668671
},
669672
}

pkg/limayaml/limayaml.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type User struct {
8888
Name *string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"nullable"`
8989
Comment *string `yaml:"comment,omitempty" json:"comment,omitempty" jsonschema:"nullable"`
9090
Home *string `yaml:"home,omitempty" json:"home,omitempty" jsonschema:"nullable"`
91+
Shell *string `yaml:"shell,omitempty" json:"shell,omitempty" jsonschema:"nullable"`
9192
UID *uint32 `yaml:"uid,omitempty" json:"uid,omitempty" jsonschema:"nullable"`
9293
}
9394

templates/default.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ user:
294294
# It can use the following template variables: {{.Name}}, {{.Hostname}}, {{.UID}}, {{.User}}, and {{.Param.Key}}.
295295
# 🟢 Builtin default: "/home/{{.User}}.linux"
296296
home: null
297+
# Shell. Needs to be an absolute path.
298+
# 🟢 Builtin default: "/bin/bash"
299+
shell: null
297300

298301
vmOpts:
299302
qemu:

website/content/en/docs/dev/internals.md

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ The volume label is "cidata", as defined by [cloud-init NoCloud](https://docs.cl
181181
- `LIMA_CIDATA_UID`: the numeric UID
182182
- `LIMA_CIDATA_COMMENT`: the full name or comment string
183183
- `LIMA_CIDATA_HOME`: the guest home directory
184+
- `LIMA_CIDATA_SHELL`: the guest login shell
184185
- `LIMA_CIDATA_HOSTHOME_MOUNTPOINT`: the mount point of the host home directory, or empty if not mounted
185186
- `LIMA_CIDATA_MOUNTS`: the number of the Lima mounts
186187
- `LIMA_CIDATA_MOUNTS_%d_MOUNTPOINT`: the N-th mount point of Lima mounts (N=0, 1, ...)

0 commit comments

Comments
 (0)