Skip to content

Add allow-env and block-env option for limactl shell#4483

Open
vax-r wants to merge 1 commit intolima-vm:masterfrom
vax-r:shell_option
Open

Add allow-env and block-env option for limactl shell#4483
vax-r wants to merge 1 commit intolima-vm:masterfrom
vax-r:shell_option

Conversation

@vax-r
Copy link
Copy Markdown
Contributor

@vax-r vax-r commented Dec 21, 2025

Summary

Implement allow-env and block-env option for limactl shell command, which is equivalent of setting
environment variable "LIMA_SHELLENV_ALLOW" and
"LIMA_SHELLENV_BLOCK".

Related issue

#4263

Comment thread cmd/limactl/shell.go Outdated
shellCmd.Flags().Bool("reconnect", false, "Reconnect to the SSH session")
shellCmd.Flags().Bool("preserve-env", false, "Propagate environment variables to the shell")
shellCmd.Flags().Bool("start", false, "Start the instance if it is not already running")
shellCmd.Flags().String("allow-env", "", "Comma-separated list of environment variable patterns to allow when --preserve-env is set (overrides LIMA_SHELLENV_ALLOW)")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda AkihiroSuda added this to the v2.1.0 milestone Dec 21, 2025
@AkihiroSuda AkihiroSuda added the area/cli limactl CLI user experience label Dec 21, 2025
@vax-r vax-r force-pushed the shell_option branch 2 times, most recently from f662f04 to 124a66f Compare December 27, 2025 07:40
Implement allow-env and block-env option for limactl
shell command, which is equivalent of setting
environment variable "LIMA_SHELLENV_ALLOW" and
"LIMA_SHELLENV_BLOCK".

Except that "allow-env" and "block-env" are treated as
StringSlice rather than pure string in these options.

Related issue: lima-vm#4263

Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
@vax-r
Copy link
Copy Markdown
Contributor Author

vax-r commented Dec 27, 2025

@AkihiroSuda
Thanks for your review and suggestion !
I've done the changes you mentioned and use StringSlice() instead of string.
Let me know if anything needs to be added or changes.

Btw, the test starting WSL2 seems to fail, I've read the log I don't think it's triggered by this commit change?

@vax-r vax-r requested a review from AkihiroSuda December 27, 2025 08:23
@AkihiroSuda AkihiroSuda requested a review from jandubois January 15, 2026 03:14
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copy link
Copy Markdown
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does not correctly implement #4263.

It is also missing tests for the new functionality.

Comment thread cmd/limactl/shell.go
shellCmd.Flags().Bool("reconnect", false, "Reconnect to the SSH session")
shellCmd.Flags().Bool("preserve-env", false, "Propagate environment variables to the shell")
shellCmd.Flags().Bool("start", false, "Start the instance if it is not already running")
shellCmd.Flags().StringSlice("allow-env", []string{}, "Comma-separated list of environment variable patterns to allow when --preserve-env is set (overrides LIMA_SHELLENV_ALLOW)")
Copy link
Copy Markdown
Member

@jandubois jandubois Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4263 says:

They would (just for this command) append the pattern to the respective lists and automatically enable --preserve-env.

These options are convenience methods to make it easier to append custom patterns for just a single command (otherwise you would change the env variables if you want the changes to persist for longer). So it makes no sense to require the user to also specify --preserve-env as well.

Suggested change
shellCmd.Flags().StringSlice("allow-env", []string{}, "Comma-separated list of environment variable patterns to allow when --preserve-env is set (overrides LIMA_SHELLENV_ALLOW)")
shellCmd.Flags().StringSlice("allow-env", []string{}, "Comma-separated list of additional environment variable patterns to allow (implies --preserve-env)")

Comment thread cmd/limactl/shell.go
shellCmd.Flags().Bool("preserve-env", false, "Propagate environment variables to the shell")
shellCmd.Flags().Bool("start", false, "Start the instance if it is not already running")
shellCmd.Flags().StringSlice("allow-env", []string{}, "Comma-separated list of environment variable patterns to allow when --preserve-env is set (overrides LIMA_SHELLENV_ALLOW)")
shellCmd.Flags().StringSlice("block-env", []string{}, "Comma-separated list of environment variable patterns to allow when --preserve-env is set (overrides LIMA_SHELLENV_BLOCK)")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the line above, but the description here has a cut&pasto: needs to say to block instead of to allow.

Comment thread pkg/envutil/envutil.go
Comment on lines +62 to +63
if len(patterns) == 0 {
blockEnv := os.Getenv("LIMA_SHELLENV_BLOCK")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are replacing the environment variable with the content of the --block-env option. #4263 specifies that the option has to be appended to the env variable list. In addition, it says it has to be appended to the default block list if the env variable is empty.

Same thing applies to the allow list (with the exception that there is no default allow list).

Please re-read the issue, and implement the functionality as specified. Or start a discussion in the issue if you think the requested semantics are wrong!

@AkihiroSuda
Copy link
Copy Markdown
Member

ping @vax-r

Could you check the comments from @jandubois ?

@vax-r
Copy link
Copy Markdown
Contributor Author

vax-r commented Jan 27, 2026

@jandubois , @AkihiroSuda -
Thanks for your suggestion !
Sorry for the late reply, I am busy at work recently, I'll come back to it during chinese new year, is that acceptable ?

@jandubois
Copy link
Copy Markdown
Member

I'll come back to it during chinese new year, is that acceptable ?

Of course; this is open source. You work on it when you have the time.

You might miss the 2.1 release, but there will always be a 2.2 after that... 😄

@jandubois jandubois removed this from the v2.1.0 milestone Mar 12, 2026
@jandubois
Copy link
Copy Markdown
Member

It is too late now to make it into 2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli limactl CLI user experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants