Zfs utils + sudo + tab completion?

[user@user-desktop ~]$ sudo zpool trim rustpPermission denied the ZFS utilities must be run as root.

The pool is named ‘rustpool.’ No clue when tab completion quit working for my zfs utilities. No clue if this is a sudo problem, a bash problem, or a zfs problem. Teh Googles are failing me. My sudo “passthru” tabs for other commands seems fine.

Any ideas/thoughts/advice for this sad and lazy camper?

I’m not sure if this is your problem, but have you tried logging in as root and doing this? IIRC, it won’t tab complete super user task commands from a regular user, but that could be my memory failing me.

I’m 95% sure this worked fine in the past… I could tab-complete anything in my zfs world (pools/recordsets/snapshots).

Edit: Just tried tab complete under ‘sudo -i’. Works fine.

sudo -i and sudo -s provide slightly different environments. Nevertheless, tab completion is AFAIK handled by the shell. At the time you’re typing the command, the ZFS command is not actually running.

I can’t rule out that there may be an API that allows the shell to query a command to help with tab completion, but it may just be a Good Idea™ rather than something that’s actually done. (Good idea IMNSHO - I haven’t thought through the implications.)

I’m used to bash with fairly simple tab completion. I’m aware that there are shells that offer more (fish?) but haven’t tried them.

if i remember correctly the ‘correct way’ / ‘acceptable way’ to get this working is to make a special entry for sudoers.

you add a special entry for zfs that makes zpool trim work for a special group without password.

if you only add ‘zpool’ that group can do anything as sudo on zpool but if you add ‘zpool trim’ only trim command of zpool works without password. so its a security issue if making it to broad.

I’m trying this on a VM with a fresh copy of EndeavourOS. In the process of getting zfs installed, running, and creating a pool, my completions went from working with zfs/zpool commands to not working. That is, I could type ‘sudo zpool’ and see a list of the zpool commands. Now I can’t. This is even more broken than my main system.

Test VM:

user@endeavouros-ref ~]$ sudo zpool<tab>
.bash_history  .bashrc        Desktop/       .gtkrc-2.0     Music/         Templates/     
.bash_logout   .cache/        Documents/     .local/        Pictures/      Videos/        
.bash_profile  .config/       Downloads/     .mozilla/      Public/        .Xauthority    

Main system:

[user@user-desktop ~]$ sudo zpool<tab> 
add         clear       detach      get         initialize  list        reguid      replace     set         sync        version
attach      create      events      history     iostat      offline     remove      resilver    split       trim        wait
checkpoint  destroy     export      import      labelclear  online      reopen      scrub       status      upgrade 

The completions file is present:

user@endeavouros-ref /]$ ls /usr/share/bash-completion/completions/zfs

This is becoming tiresome.

I’m going to back off my previous answer. Apparently there is a sort pf API for the shell to identify possible completions. It seems like that’s done by the file you listed. /usr/share/bash-completion/completions/zfs I have it on Debian Bookworm and completions are not working in my user shell or with sudo -i or sudo -s. It seems like either changes to that file or changes to bash have caused this.


ls -l /usr/share/bash-completion/completions/zfs

is the file owned by root and having permissions so you can access it with the regular user?

the printed output seems likely to come from that script, like it could not execute/read it to autocomplete