lima icon indicating copy to clipboard operation
lima copied to clipboard

Configuration option for specifying the username

Open panuhorsmalahti opened this issue 2 years ago • 3 comments

Description

lima creates a default user as specified in https://github.com/lima-vm/lima/blob/master/pkg/cidata/cidata.TEMPLATE.d/user-data#L18, where the username is https://github.com/lima-vm/lima/blob/master/pkg/osutil/user.go#L102. In some cases the username and groups can't be created (example: username docker). While these errors could be handled better, it would be useful to support specifying the username of the created user with e.g. environmental variables.

I propose that env variable LIMA_DEFAULT_USERNAME would be used instead of the current user's username for the default user.

panuhorsmalahti avatar Aug 11 '22 13:08 panuhorsmalahti

+1 one for this, my mac username is firstname.lastname which doesn't work with the regex. I would really like to default to this and not lima.

Note I can't seem to find any logs for the warning either.

kwlockwo avatar Aug 12 '22 01:08 kwlockwo

👍

maho avatar Oct 11 '22 06:10 maho

@panuhorsmalahti

I propose that env variable LIMA_DEFAULT_USERNAME would be used instead of the current user's username for the default user.

What is the use case for this? Why would you use a different username than the one on the host? Is the problem that the user already exists inside the OS image you are using?

@kwlockwo

my mac username is firstname.lastname which doesn't work with the regex. I would really like to default to this and not lima.

This would not work with the proposed mechanism; the alternate username would still be subject to the same validation.

The rule exist because many user names from macOS don't work with Linux commands:

$ limactl shell alpine sudo -i
lima-alpine:~# useradd [email protected]
useradd: invalid user name '[email protected]': use --badname to ignore
lima-alpine:~# useradd firstname.lastname
lima-alpine:~# chown firstname.lastname $HOME
chown: unknown user/group firstname:lastname

As you can see, email addresses don't work with useradd, names with a . don't work with chown. These commands are executed by Lima, as part of cloud-init, to initialize the VM. When they fail, it is difficult to figure out why (because you don't have a working VM that you can ssh into).

I've personally spent multiple days helping users with these issues (and learning about all the wild things organizations use for user names). Yes, at least one person uses Five O'Clock as a macOS username...

Since I don't want to waste any more time of my life debugging these issues, I've added the validation found in upstream tools.

The easiest way to have the same user name inside the VM is to use a simple name for your account on the host (you still have a fullname field for the proper name).

jandubois avatar Oct 12 '22 22:10 jandubois

@jandubois we found out that using username "docker" creates some issues, but there is no way to override the username.

panuhorsmalahti avatar Oct 13 '22 06:10 panuhorsmalahti

I have a Vagrant-like use case which could really benefit from a config option for setting the user. In the Vagrant case, it's always vagrant and the benefit is consistency. Makes it easier for docs and tooling since it's always the same. I have a CLI which basically abstracts limactl and I'd rather not try to match Lima's logic for the user.

The original proposal here was for LIMA_DEFAULT_USERNAME, but I assume it could be a config option as well? I'd be happy to try and contribute this if you're open to it.

swalkinshaw avatar Nov 20 '22 00:11 swalkinshaw

What is the use case for this? Why would you use a different username than the one on the host? Is the problem that the user already exists inside the OS image you are using?

I use lima to have ... linux in mac. My username in mac is lukasz.mach and I would like to have maho or lmach or at least lukaszmach as my username.

Otherwise when I do git commit the default commiter is some lima not maho. The same with many other tools.

It's quite important for me to have my own username, not default lima.

maho avatar Nov 20 '22 20:11 maho