You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
nixos/nextcloud: nextcloud-occ no longer works with envvars #412675
There are some commands in nextcloud-occ, that can read from a envvar, such as nextcloud-occ user:resetpassword --password-from-env -- root, however it seems like #367433 might have changed that, and now clears all user envvars set.
I assume you've done this before as nextcloud user? Because otherwise you would've used the old sudo code-path which also cleans out all of the env (no -E).
I think we could fix that by doing -p Environment="$OC_PASS" in the script, but this kinda depends on how many other variables are theoretically needed to be passed through. On top of that, I'm not a big fan of that approach anyways: the snippet above invites to forget about unsetting the env after that and every invocation down the road also knows about the password (so yeah, handling secrets via env is problematic).
Either way, it's now impossible to use any command that would benefit from a envvar, no matter how nextcloud-occ is called, which seems inconvenient, as it's meant to be run by a system administrator as well.
I'm however not sure what a "good" solution would be for this,
I'm not a big fan of that approach anyways: the snippet above invites to forget about unsetting the env after that and every invocation down the road also knows about the password (so yeah, handling secrets via env is problematic).
It's a standalone script, so it's not really a worry in this case, and it's just one use-case that I have. Others might have better ones.
So the use-case around this is to make sure that the root user's password is always in sync with what the config says?
which seems inconvenient, as it's meant to be run by a system administrator as well.
yeah, though I'm not aware of anything else that actually needs environment variables. And this use-case never worked before unless you were running as Nextcloud user. The sudo-invocation already filtered out env vars before.
It's a standalone script, so it's not really a worry in this case, and it's just one use-case that I have. Others might have better ones.
That's fair. It wasn't clear to me how this was actually used from the first report and it looked a bit like something, that was intended to be used in an interactive shell.
But yeah, I'm not sure right now. We could probably fix it by injecting OC_PASS everywhere, but this is something I'd like to have a regression test for that and I'd like to have ruled out that we'll have to add 23 additional env vars down the road.
Luckily there doesn't seem to be many cases of envvars in occ command, at least a basic grep gives this:
> grep -r1 'getenv('
Command/User/ResetPassword.php- if ($input->getOption('password-from-env')) {
Command/User/ResetPassword.php: $password = getenv('OC_PASS');
Command/User/ResetPassword.php- if (!$password) {
--
Command/User/AuthTokens/Add.php- if ($input->getOption('password-from-env')) {
Command/User/AuthTokens/Add.php: $password = getenv('NC_PASS') ?? getenv('OC_PASS');
Command/User/AuthTokens/Add.php- if (!$password) {
--
Command/User/Add.php- if ($input->getOption('password-from-env')) {
Command/User/Add.php: $password = getenv('OC_PASS');
Command/User/Add.php-
So, it's OC_PASS and NC_PASS, which seems quite minimal :) There are some others outside of the core folder, but not too many.
But another thing that's annoying, is that it's not really intuitive that the command is filtering out the env. The only way to discover it is to inspect the bin, if you think of that.
I think something like this is the only sensible way forward, yes. I'm not sure wehter to use -p Environment or --setenv here though, the latter seems to set [ON]C_PASS to an empty string unconditionally
On top of that, I'm not a big fan of that approach anyways
I fully agree. It should also be possible to pipe the password to the occ command (and I suppose this will work in any place where a value is taken from stdin or env).
Yes, for example you could change the log level when invoking occ commands for debugging. So it should be either none or all config values that are configurable through the env vars.
We might disagree with how it's done upstream, but at this point we're just breaking occ in a not very intuitive way.
What is the reason for clearing the env before invoking occ?
This only ever worked as nextcloud user because the sudo-invocation existed before already.
sudo clears the env by default. And systemd-run creates a transient unit that doesn't inherit the env from the shell, but from its the service manager.
I'm running into this problem as well now, as I need to write a NixOS test that invokes nextcloud-occ user:add --password-from-env. There is no other way to do this right now.
I would be in favor of applying the changes from @networkException#412675 (comment) as a workaround for now and then we can find a better solution for the future.
Activity
Ma27 commentedon Jun 7, 2025
I assume you've done this before as
nextclouduser? Because otherwise you would've used the oldsudocode-path which also cleans out all of the env (no-E).I think we could fix that by doing
-p Environment="$OC_PASS"in the script, but this kinda depends on how many other variables are theoretically needed to be passed through. On top of that, I'm not a big fan of that approach anyways: the snippet above invites to forget about unsetting the env after that and every invocation down the road also knows about the password (so yeah, handling secrets via env is problematic).cc @networkException @provokateurin for opinions.
eyJhb commentedon Jun 7, 2025
I've done this as part of the
nextcloud-setupsystemd service, which runs asnextcloud:nixpkgs/nixos/modules/services/web-apps/nextcloud.nix
Line 1232 in 4792576
Example of what I have done in the past is here:
Either way, it's now impossible to use any command that would benefit from a envvar, no matter how
nextcloud-occis called, which seems inconvenient, as it's meant to be run by a system administrator as well.I'm however not sure what a "good" solution would be for this,
It's a standalone script, so it's not really a worry in this case, and it's just one use-case that I have. Others might have better ones.
Ma27 commentedon Jun 7, 2025
So the use-case around this is to make sure that the root user's password is always in sync with what the config says?
yeah, though I'm not aware of anything else that actually needs environment variables. And this use-case never worked before unless you were running as Nextcloud user. The sudo-invocation already filtered out env vars before.
That's fair. It wasn't clear to me how this was actually used from the first report and it looked a bit like something, that was intended to be used in an interactive shell.
But yeah, I'm not sure right now. We could probably fix it by injecting OC_PASS everywhere, but this is something I'd like to have a regression test for that and I'd like to have ruled out that we'll have to add 23 additional env vars down the road.
Hence, I'd like to wait for more input first.
eyJhb commentedon Jun 7, 2025
Luckily there doesn't seem to be many cases of envvars in occ command, at least a basic grep gives this:
So, it's
OC_PASSandNC_PASS, which seems quite minimal :) There are some others outside of thecorefolder, but not too many.But another thing that's annoying, is that it's not really intuitive that the command is filtering out the env. The only way to discover it is to inspect the bin, if you think of that.
networkException commentedon Jun 8, 2025
I think something like this is the only sensible way forward, yes. I'm not sure wehter to use
-p Environmentor--setenvhere though, the latter seems to set[ON]C_PASSto an empty string unconditionallyprovokateurin commentedon Jun 9, 2025
Unfortunately this is not true, as any system (config.php) option can be set through env vars with
NC_prefix: https://github.com/nextcloud/server/blob/f25d66008b7af7291b78521708f76bc9da6f2365/lib/private/Config.php#L249-L258I fully agree. It should also be possible to pipe the password to the occ command (and I suppose this will work in any place where a value is taken from stdin or env).
networkException commentedon Jun 9, 2025
Is that relevant to invocations of
occ?provokateurin commentedon Jun 9, 2025
Yes, for example you could change the log level when invoking occ commands for debugging. So it should be either none or all config values that are configurable through the env vars.
eyJhb commentedon Jun 9, 2025
We might disagree with how it's done upstream, but at this point we're just breaking occ in a not very intuitive way.
What is the reason for clearing the env before invoking occ?
Ma27 commentedon Jun 9, 2025
This only ever worked as nextcloud user because the
sudo-invocation existed before already.sudoclears the env by default. Andsystemd-runcreates a transient unit that doesn't inherit the env from the shell, but from its the service manager.provokateurin commentedon Jun 20, 2025
I'm running into this problem as well now, as I need to write a NixOS test that invokes
nextcloud-occ user:add --password-from-env. There is no other way to do this right now.I would be in favor of applying the changes from @networkException #412675 (comment) as a workaround for now and then we can find a better solution for the future.
provokateurin commentedon Jun 20, 2025
See #418378 for the use-case
Ma27 commentedon Jul 5, 2025
@provokateurin convinced me with the reasoning given in #418378: I think this is a desirable goal and making an exception for secrets is OK for me.
I suggest the following approach:
nextcloud-occ, i.e. no env vars are supportedIf somebody is up for the second step, that'd be appreciated. Otherwise I may get to it sooner or later.
provokateurin commentedon Sep 3, 2025
I forgot about this, but here is the PR to apply the diff from @networkException: #439771