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

util: Set safe permissions for data directory and wallets/ subdir #17127

Merged
merged 3 commits into from
Feb 7, 2023

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Oct 13, 2019

On master (1e7564e) docs say:

$ ./src/bitcoind -help | grep -A 3 sysperms
  -sysperms
       Create new files with system default permissions, instead of umask 077
       (only effective with disabled wallet functionality)

Basing on that, one could expect that running bitcoind first time will create data directory and wallets/ subdirectory with safe 0700 permissions.

But that is not the case:

$ stat .bitcoin | grep id
Access: (0775/drwxrwxr-x)  Uid: ( 1000/ hebasto)   Gid: ( 1000/ hebasto)
$ stat .bitcoin/wallets | grep id
Access: (0775/drwxrwxr-x)  Uid: ( 1000/ hebasto)   Gid: ( 1000/ hebasto)

Both directories, in fact, are created with system default permissions.

With this PR:

$ stat .bitcoin/wallets | grep id
Access: (0700/drwx------)  Uid: ( 1000/ hebasto)   Gid: ( 1000/ hebasto)
$ stat .bitcoin/wallets | grep id
Access: (0700/drwx------)  Uid: ( 1000/ hebasto)   Gid: ( 1000/ hebasto)

This PR:

Changes in behavior: removed -sysperms command-line argument / configure option. The related discussions are here:

If users rely on non-default access permissions, they could use chmod.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 13, 2019

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK john-moffett, willcl-ark
Concept ACK laanwj, practicalswift
Stale ACK jonasschnelli

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26863 (test: merge banning test from p2p_disconnect_ban to rpc_setban by brunoerg)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@@ -741,6 +750,10 @@ const fs::path &GetBlocksDir()

const fs::path &GetDataDir(bool fNetSpecific)
{
#ifndef WIN32
Copy link
Member

Choose a reason for hiding this comment

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

GetDataDir, a getter, is not the place to do things such as set the umask. Please don't add these kind of side-effects.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe GetDataDir is not a proper name for this function as it already has an intended side-effect:

bitcoin/src/util/system.cpp

Lines 777 to 780 in ddd3cd3

if (fs::create_directories(path)) {
// This is the first run, create wallets subdirectory too
fs::create_directories(path / "wallets");
}

Copy link
Member

@laanwj laanwj Oct 14, 2019

Choose a reason for hiding this comment

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

I know. I kind of want to get rid of that too. But don't add any more

(edit: also I think setting umask is the worst kind of side effect possible, it's global state of the program over all threads)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

src/util/system.cpp Outdated Show resolved Hide resolved
@laanwj
Copy link
Member

laanwj commented Oct 14, 2019

Concept ACK on removing -sysperms.

@hebasto
Copy link
Member Author

hebasto commented Oct 14, 2019

@laanwj
Thank you for your review. All your comments have been addressed.

@hebasto
Copy link
Member Author

hebasto commented Oct 16, 2019

Rebased after #17138 has been merged.

@@ -35,6 +35,10 @@

#include <boost/thread/condition_variable.hpp> // for boost::thread_interrupted

#ifndef WIN32
void SetDefaultUmask();
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't SetupEnvironment be the right place for this? Or is that too early?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, SetDefaultUmask() is called just before the first possible disk write.

SetupEnvironment() seems too broad, as it is called in utilities too. And, yes, I think it is too early. But I could be wrong ;)

Copy link
Member

Choose a reason for hiding this comment

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

But does that matter? What would be the consequences of setting it too early? Why wouldn't we want to set the umask for the utilties?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't SetupEnvironment be the right place for this?

Agree.

@hebasto
Copy link
Member Author

hebasto commented Oct 26, 2019

@laanwj Thank you for review. Your comment has been addressed.

@hebasto
Copy link
Member Author

hebasto commented Nov 25, 2019

@promag Would you mind reviewing this PR?

@hebasto
Copy link
Member Author

hebasto commented Apr 20, 2020

Rebased 7213e8c -> 67b1209 (pr17127.04 -> pr17127.05) due to the conflict with #15761.

@hebasto
Copy link
Member Author

hebasto commented May 9, 2020

Rebased 67b1209 -> 297e61c (pr17127.05 -> pr17127.06) due to the conflict with #16224.

@jonasschnelli
Copy link
Contributor

utACK 297e61c

Copy link
Member

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

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

ACK 9b105d7

The test datadir will have the following files created in it after node shutdown:

banlist.json, debug.log, fee_estimates.dat, mempool.dat, peers.dat, settings.json

Would it be worth adding a permissions test for e.g debug.log to check that the correct umask is also being applied to files?

@hebasto
Copy link
Member Author

hebasto commented Nov 30, 2022

@willcl-ark

The test datadir will have the following files created in it after node shutdown:

banlist.json, debug.log, fee_estimates.dat, mempool.dat, peers.dat, settings.json

Would it be worth adding a permissions test for e.g debug.log to check that the correct umask is also being applied to files?

Sorry, but I didn't quite get your suggestion. Mind elaborating it?

@willcl-ark
Copy link
Member

Sorry, but I didn't quite get your suggestion. Mind elaborating it?

My fault for not being clearer!

You added a test for directory permissions, but not not one for files. As files and folders will be created with different permissions, it might make sense to add this at the same time?

For directories the test covers datadir and walletsdir. For files I was suggesting we could test debug.log.

@willcl-ark
Copy link
Member

This also fixes #22595

@hebasto
Copy link
Member Author

hebasto commented Dec 9, 2022

Updated 9b105d7 -> 07c496d (pr17127.11 -> pr17127.12):

Copy link
Member

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

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

ACK 07c496d

Might want to add this to the release notes too?

src/util/system.cpp Outdated Show resolved Hide resolved
This change effectively reverts commits from
bitcoin#4286.

Users, who rely on non-default access permissions, should use `chmod`
command.
@hebasto
Copy link
Member Author

hebasto commented Feb 5, 2023

Updated 07c496d -> 15c7105 (pr17127.12 -> pr17127.13):

Copy link
Contributor

@john-moffett john-moffett left a comment

Choose a reason for hiding this comment

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

Approach ACK 15c7105

I agree that this may warrant an explicit release note considering a command line option is being dropped.

src/i2p.cpp Outdated Show resolved Hide resolved
src/rpc/request.cpp Outdated Show resolved Hide resolved
This change makes all filesystem artifacts--files and directories--being
created with the default umask.
@hebasto
Copy link
Member Author

hebasto commented Feb 6, 2023

Updated 15c7105 -> c9ba4f9 (pr17127.13 -> pr17127.14, diff):

@john-moffett
Copy link
Contributor

ACK c9ba4f9

Copy link
Member

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

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

ACK c9ba4f9

@fanquake fanquake merged commit 6e08e5c into bitcoin:master Feb 7, 2023
@hebasto hebasto deleted the 20191013-permissions branch February 7, 2023 11:36
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 7, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
8 participants