-
Notifications
You must be signed in to change notification settings - Fork 27
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
Unable to autocomplete with sudo #71
Comments
Can you please write exact commands you're using and username you login with, that has hook installed for? |
For example:
|
I've just tested that bash-completion for |
So in my case it is as follows: local user: occ (calling console.php) has the following section: $user = posix_getpwuid(posix_getuid());
$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
if ($user['name'] !== $configUser['name']) {
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
exit(1);
} owner of I guess the only way is to "ignore" the user check for the RESULT="$(/var/www/nextcloud/occ _completion </dev/null)"; |
Since ignoring the user check does not work, because we can not get a connection to the database because we can not read the config,... I tried to continue with the other route. With:
I receive:
I guess this is, because www-data has |
I haven't tested, but does
? If this is the 2nd case, then I don't see possible workaround for |
So it lists the config file which I cannot read/open. |
It will work if you have entered password previously or you're allowed to run |
Yeah, so any idea how to fix this? entering sudo password before doesnt seem to help |
Not really. You can create basic bash autocomplete hook using
|
I have: _nhs()
{
local cur
# Pointer to current completion word.
# By convention, it's named "cur" but this isn't strictly necessary.
COMPREPLY=() # Array variable storing the possible completions.
cur=${COMP_WORDS[COMP_CWORD]}
case "$COMP_CWORD" in
1)
SERVERS='9 10 11 12'
COMPREPLY=( $( compgen -W "$SERVERS" -- $cur ) );;
esac
return 0
}
complete -F _nhs nhs and can do:
The problem is the RESULT call in your script that needs sudo as well RESULT="$(/home/nickv/Nextcloud/12/server/occ _completion </dev/null)"; So I replaced https://github.com/nextcloud/3rdparty/blob/b6ef8a42ae8c7d4d69c6acdf919072a7989648d7/stecman/symfony-console-completion/src/HookFactory.php#L44-L44
but then
Not fixabled? |
I know that Does |
@nickvergessen can you provide any more detail about your environment? I've just tested this on my machine and completion works fine calling with
|
Same issue:
System info:
I guess the most important thing is the changed owner ship. I made config.php owned by www-data:www-data, but I guess you have that as well. Not sure what could be of interest other then that.
|
Seeing you ran your
|
Okay, I got it working using the following instead of https://github.com/nextcloud/3rdparty/blob/b6ef8a42ae8c7d4d69c6acdf919072a7989648d7/stecman/symfony-console-completion/src/HookFactory.php#L44-L44:
Would be nice if this could make it into your repo in a clean way 😃 |
I guess we can specify
|
I just noticed, that now only commands can be autocompleted:
But I guess that is because I only forwarded some of the enviroment variables? |
You can do
|
👍 that one works |
I guess you can send PR, that will add |
@nickvergessen to be honest this seems like a permissions / design issue with Nextcloud, not the completion system. A few suggestions for working around this:
|
Well most enviroments don't have an application-user, also all docs and tutorials out there mention www-data to be used, but for that one The patch is already done (see #73 ) and we will be easily able to use this, if you don't want to merge it, we will just add the |
Sorry, I was meaning $ sudo useradd --system nextcloud
$ sudo su nextcloud
# or
$ sudo -u nextcloud I appreciate that you've made a PR for this, but I think it adds unnecessary complexity for something that's very specific to the way Nextcloud currently works, and can be avoided with a small change to filesystem permissions. If you couldn't fix this any other clean way I wouldn't have a problem with it, but it looks like there are quite a few good solutions that don't require changes to this library. In addition to the two suggestions above, another relatively clean solution might be extending |
We think that adding a user is too complicated, because sometimes permissions might change and all the docs would need adjustment and so on. So if you don't want to merge this because it adds too much parameters ( I get and see that as well), I will try to extend your classes and see how that works. As far as I can see you use protected everywhere (no private) so that should work. |
PS: okay the |
Hmm, so it is.. I think I did that with the intention that Is my second suggestion feasible? Seems like completion shouldn't need write access to run:
|
@nickvergessen: were you able to find a reliable procedure to enable autocompletion yet? i am struggeling around ... |
Not really |
Have a look at a pull request for full bash tab completion via aliasing Will create valid alias, run it, add it to |
@RonaldBarnes thanks, good to see how you're handling it there. Does completion actually need to run as that user though? I believe the underlying issue in this ticket is/was that permissions checks were running during the completion command, which seems like something that could be skipped intelligently. However, if you need to run as a different user to read config files that have locked down permissions, this would make sense. |
Thanks! Yes,
The permission checks seem like a good idea that shouldn't be skipped -- let the OS enforce access restrictions in another layer of security. But the |
Thanks a lot for all the work @RonaldBarnes |
I got it working like this: $ . <(sudo -u www-data --preserve-env=SHELL php /var/www/nextcloud/occ _completion -g | sed 's|/var/www/nextcloud/occ|sudo -u www-data --preserve-env=CMDLINE_CONTENTS,CMDLINE_CURSOR_INDEX,CMDLINE_WORDBREAKS php /var/www/nextcloud/occ|')
$ alias occ='sudo -u www-data php /var/www/nextcloud/occ'
$ occ
Display all 124 possibilities? (y or n)
activity:send-mails config:app:get dav:sync-system-addressbook encryption:status integrity:sign-core notification:test-push tag:edit user:delete
app:disable config:app:set db:add-missing-columns files:cleanup l10n:createjs notify_push:log tag:list user:disable
app:enable config:import db:add-missing-indices files:repair-tree list notify_push:metrics theming:config user:enable
app:getpath config:list db:add-missing-primary-keys files:scan log:file notify_push:reset trashbin:cleanup user:info
app:install config:system:delete db:convert-filecache-bigint files:scan-app-data log:manage notify_push:self-test trashbin:expire user:lastseen
app:list config:system:get db:convert-mysql-charset files:transfer-ownership log:tail notify_push:setup trashbin:restore user:list
app:remove config:system:set db:convert-type group:add log:watch preview:repair trashbin:size user:report
app:update dav:create-addressbook encryption:change-key-storage-root group:adduser maintenance:data-fingerprint preview:reset-rendered-texts twofactorauth:cleanup user:resetpassword
background-job:execute dav:create-calendar encryption:decrypt-all group:delete maintenance:mimetype:update-db ransomware_protection:block twofactorauth:disable user:setting
background-job:list dav:delete-calendar encryption:disable group:info maintenance:mimetype:update-js security:bruteforce:reset twofactorauth:enable versions:cleanup
background:ajax dav:list-calendars encryption:enable group:list maintenance:mode security:certificates twofactorauth:enforce versions:expire
background:cron dav:move-calendar encryption:encrypt-all group:removeuser maintenance:repair security:certificates:import twofactorauth:state workflows:list
background:webcron dav:remove-invalid-shares encryption:list-modules help maintenance:repair-share-owner security:certificates:remove update:check
broadcast:test dav:retention:clean-up encryption:migrate-key-storage-format integrity:check-app maintenance:theme:update status upgrade
check dav:send-event-reminders encryption:set-default-module integrity:check-core maintenance:update:htaccess tag:add user:add
config:app:delete dav:sync-birthday-calendar encryption:show-key-storage-root integrity:sign-app notification:generate tag:delete user:add-app-password
What indeed would help is:
|
Hi there,
we from Nextcloud started using the completion and it works quite fine in general.
The only problem is, that it is impossible to run the stuff with e.g.
sudo -u www-data
.This is the recommanded easy-default for Nextcloud, to simply have all code and files owned by the
www-data
user. But I am unable to--generate-hook
in this case.I'm not sure if this is fixable, but would be very cool if so. I tried adding a copy of a generated hook script manually in
/etc/bash_completion.d/
but when trying to modify the script to addsudo -u www-data
on the calls, it seems to not execute properly anymore.Any idea/workaround?
Cheers and keep it up
The text was updated successfully, but these errors were encountered: