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

Setting $home wrong can cause data loss, but managehome is required for SSH key setup to work, apparently. #84

Open
oranenj opened this issue Jul 25, 2017 · 3 comments

Comments

@oranenj
Copy link

oranenj commented Jul 25, 2017

If managehome = true, the module will unconditionally remove the user's home directory. Unfortunately, there is no validation that the removed path makes sense at all; the module will happily rm -rf /, which might be catastrophic.

There also seems to be no way to opt out of the rm -rf behaviour; if you set managehome to false, ssh key management stops working (in fact, combined with purge_ssh_keys, turns out it will simply remove every managed user's ssh keys)

Something as simple as the following demonstrates the issue

class {"accounts":
    users          => {
        anuser     => {
            ensure => 'absent',
            home   => '/someimportantdata',
        }
    }
}

You could set home to /, but I don't have a disposable virtual machine to test that scenario. Obviously, this kind of a mistake would be catastrophic if you were to use this module to manage users across a large fleet of servers.

At the very least, the code ought to be much more paranoid about what it removes. I'd prefer it not run any such commands at all.

@oranenj
Copy link
Author

oranenj commented Jul 25, 2017

As an addendum, the module does not quote the value of ${home_dir} when it runs the test and rm -rf commands, so there is a potential injection vulnerability.

It seems test -d / home/user fails, so a simple typo won't rm -rf /, but that's just luck, really.

@deric
Copy link
Owner

deric commented Jul 25, 2017

Would it be ok to remove home directory only $force_removal is set to true? (default would be false). In #23 we've introduced executing pkill which might be safer to disable by default.

@oranenj
Copy link
Author

oranenj commented Jul 25, 2017

Kiling the user's processes is fine and even necessary IMO. It's the rm -rf that is scary. Hmm.

You should at least quote the commands properly, run the exec as the user you're removing (never as root), and whitelist path patterns eligible for autoremoval.

I'd also call the option something like destroy_homedir_on_remove to make it clear it destroys data.

deric added a commit that referenced this issue Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants