Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could vault have a mode where it just outputs the shell completion code ? #22784

Open
teto opened this issue Sep 5, 2023 · 2 comments
Open
Labels

Comments

@teto
Copy link

teto commented Sep 5, 2023

Is your feature request related to a problem? Please describe.

Most programs output the completion scripts and the user can load them. vault -autocomplete-install (added in https://github.com/hashicorp/vault/pull/3223/files) tries to do the install but this fails in my instance since my .bashrc is read-only (for security reasons, and I can't ):

 vault -autocomplete-install
Error executing CLI: 1 error occurred:
	* open /home/teto/.bashrc: permission denied

Describe the solution you'd like
I would like vault to just output the autocompletion code and let the user install the completion, it works better for package managers too such as apt or nix where you can add the autocompletion next to the software

Describe alternatives you've considered
I've tried export HOME=/tmp to run the command but vault still attempted to write to /home/teto/.bashrc which seems to be another error ?

Explain any additional use-cases
My main shell is zsh so it would be nice to have zsh completion too though it seems like this can be done through a zsh compatibility layer #9901 (comment)

Additional context
If the change is done here, I will update the nix package https://github.com/NixOS/nixpkgs/blob/d9811d585a4e967c3883f11b7653b44121c25f62/pkgs/tools/security/vault/default.nix#L35

@d-z-m
Copy link
Contributor

d-z-m commented Sep 12, 2023

It seems vault uses the github.com/posener/complete package to generate completions. That package uses os/user to find information about the user's home directory. os/user parses /etc/passwd to find the home directory for a given user. If using the pure go implementation it parses /etc/passwd directly, otherwise it calls getpwuid_r to get the same information. You may be able to change the location of your home directory via usermod to get the completion code to write out, and then change it back. (Disclaimer: this may have unintended consequences)

@teto
Copy link
Author

teto commented Sep 13, 2023

thanks for confirming it looks in /etc/passwd. It's a bit insane to have to change a user's $HOME to access the completion, especially as the solution is to do less: just output the completion, dont install it. I am not able to say if github.com/posener/complete can do that but seems like it doesn't considering the issues users have:
posener/complete#71
posener/complete#119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants