Skip to content

Conversation

n2yen
Copy link

@n2yen n2yen commented Jun 4, 2018

When the option -sysperms=false (default) is enabled, the created datadirs doesn't take into account the default umask setting of '077'.
The fix moves the umask operation to just after parameters are parsed during AppInit()

@laanwj
Copy link
Member

laanwj commented Jun 4, 2018

There's a few problems with this:

  • -sysperms can no longer be set in the configuration file
  • by moving it to bitcoind.cpp, it's no longer heeded for the GUI

Tend toward NACK. Better to set the permissions on the data directory once, manually, it's not going to touch them after that.

@laanwj
Copy link
Member

laanwj commented Jun 4, 2018

Or, if this is a big issue, maybe do it in both places?

@maflcko
Copy link
Member

maflcko commented Jun 4, 2018

Would be nice to know when this regression was introduced. If it never did anything, I guess it can be removed?

If it is not going to be removed, this must come with functional tests that verify the behavior.

@n2yen
Copy link
Author

n2yen commented Jun 4, 2018

Appreciate the feedback, I will look into these later - please let me know if you have any other suggestion as well. Thank you!

@n2yen
Copy link
Author

n2yen commented Jun 5, 2018

Had a look at the bitcoin-qt as suggested - it looks like if there was a regression it could be because it potentially generates datadir on its own, without calling GetDefaultDataDir(), see comments in the commit above. Tested by running bitcoind, and bitcoin-qt and checking datadir. The existing unit tests, don't appear to rely on either of the above utility function calls - should I still go ahead and add unit tests for this anyway? thanks!

@ken2812221
Copy link
Contributor

@n2yen You can add a python script into functional test, it allow you to run a node to test this.

@laanwj
Copy link
Member

laanwj commented Jun 5, 2018

If it is not going to be removed, this must come with functional tests that verify the behavior.

It definitely works, but not for the initial directory creation. It works for files created after that, and that's what it's intended for (block file data sharing, basically).

@n2yen
Copy link
Author

n2yen commented Jun 5, 2018

@Iaanwj can you clarify if we should also leave the old the old code where it was also (in AppInitBasicSetup )? i'm not sure, thank you for your feedback!

@maflcko
Copy link
Member

maflcko commented Jun 5, 2018

@n2yen I haven't looked, but according to the issue #13371 the old code is doing nothing. Having useless code is useless, so please remove if it is useless.

@laanwj
Copy link
Member

laanwj commented Jun 7, 2018

Oh I get the problem now, it's not -sysperms option that's broken, but the default umask setting. It isn't effective yet when the data directory is created, but is by the time when e.g. the wallet is created (as that's later in the init process). I strongly disagree that it does nothing, though.

OK, yes, it should definitely be moved so that the data directory is also created with that umask too.

I'm still not sure bitcoind.cpp is the right place to move it though, because that wouldn't make umask setting apply at all to bitcoin-qt.

There's an inherent chicken-and-egg problem with the -sysperms option, because by the time bitcoin.conf is read, the data directory is already created.

Also agree this needs a test, because apperently this is another initialization issue with strict ordering requirements.

@laanwj
Copy link
Member

laanwj commented Jun 7, 2018

So to show the current code should not naively be removed (nor applied for bitcoind only), this affects wallet default permissions:

$ src/bitcoind -datadir=/tmp/wallet1 -regtest
$ stat /tmp/wallet1/regtest/wallets/wallet.dat 
Access: (0600/-rw-------)

After removing the umask setting code from AppInitBasicSetup:

$ src/bitcoind -datadir=/tmp/wallet2 -regtest
$ stat /tmp/wallet2/regtest/wallets/wallet.dat
Access: (0660/-rw-rw----)

(wallet is group-readable now, the exact result depends on the umask in the user's environment of course, but this is undesirable)

@n2yen
Copy link
Author

n2yen commented Jun 8, 2018

@Iaanwj ok, so we're in agreement, that the umask in AppInitBasicSetup() may not be early enough. I agree that the umask cannot just be in bitcoind.cpp, but also in bitcoin-qt or some common code that can be called earlier... I will also be adding tests in the way suggested by @ken2812221.

@n2yen n2yen force-pushed the 13371 branch 4 times, most recently from af589c6 to e429ba8 Compare June 8, 2018 14:16
@n2yen
Copy link
Author

n2yen commented Jun 9, 2018

Updated commit with tests to verify permissions of regtest directory, and umask is set as early as sensible in both bitcoind and bitcoin-qt. @laanwj , @MarcoFalke can I please get your feedback?

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 26, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@DrahtBot
Copy link
Contributor

The last travis run for this pull request was 50 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

@n2yen
Copy link
Author

n2yen commented Sep 11, 2018

Rebased on top of:
eb2f1bd - Merge #14189: qa: Fix silent merge conflict in wallet_importmulti...
On sept 10, 2018

@n2yen
Copy link
Author

n2yen commented Sep 30, 2018

@practicalswift thank you!

@n2yen
Copy link
Author

n2yen commented Oct 1, 2018

@practicalswift timed out again, this time, didn't even get a chance to run the feature tests!

self.restart_node(0)
datadir = self.nodes[0].datadir

self.log.info("Running test without -sysperms option - assuming umask of '0o77'")
Copy link
Member

Choose a reason for hiding this comment

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

'0o77' - typo?

Copy link
Author

Choose a reason for hiding this comment

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

you're right, should be '077'. What did you make of -sysperm option, is it still needed?

Copy link
Member

Choose a reason for hiding this comment

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

What did you make of -sysperm option, is it still needed?

My concerns about -sysperms are in the note here #15902.

Copy link
Author

Choose a reason for hiding this comment

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

does it makes sense to close this PR - perhaps replace it with simply removing the option? i suppose the tests might still be useful...

@maflcko
Copy link
Member

maflcko commented May 20, 2019

Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits

@n2yen
Copy link
Author

n2yen commented Jul 27, 2019

rebased!

@jonasschnelli
Copy link
Contributor

jonasschnelli commented Oct 9, 2019

utACK 09072f7

@laanwj
Copy link
Member

laanwj commented Oct 9, 2019

I don't think my original comments have been addressed (edit: the GUI one is). This still doesn't allow setting sysperm in the configuration file, only on the command line.

It also complicates the initialization order.

I'm starting to think it would be better to remove the sysperm setting.

@jonasschnelli
Copy link
Contributor

I underestimated the fact that one can no longer use the sysperm setting in the config file after this. I just retrieved my ACK.

@jonasschnelli
Copy link
Contributor

@n2yen: what is the status of this PR? Can you have a look in addressing/commenting @laanwj comment?

@n2yen
Copy link
Author

n2yen commented May 29, 2020

ok, will have a look.

n2yen added 2 commits May 30, 2020 08:48
…cSetup() as it is too late there.

When the option -sysperms=false (default) is enabled, the created datadirs does not take into account the default umask setting of '077'.
Fix moves the umask operation as early as possible inside of bitcoind, and bitcoin-qt. This was needed because by the time AppInitBasicSetup()
is called, datadir, has typically already been created. Calling umask earlier ensures any filesystem writes that follows has the correct umask set.

Tests: feature_sysperms.py - validates datadir permissions where -sysperms=false (default)
Notes:
'-sysperms' option requires '-disablewallet'
- add check for windows platform, feature_nosysperms.py will explicitly skip the test if
  'Windows' platform is detected.

if bitcoind is built with NO_WALLET=1. That is -sysperms will fail if
not accompanied with -disablewallet option
@jonasschnelli
Copy link
Contributor

Closing in favour of #17127 (which is probably superior).

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants