-
Notifications
You must be signed in to change notification settings - Fork 50
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
Restrict umask to 027 except for sudo/root broken #185
Comments
because broken because this also happens for root while it should not #185
Disabled just now in git. |
What happens when you run the command
Expected is:
I don't get how this works normally on a qubes vm but not normal debian. What is the content of /etc/pam.d/common-session under qubes? Does it differ from the normal one? |
Why don't we just set this same umask for the root account too? I don't think it too much of a stretch to assume that a system admin that creates and maintains configurations files can set the file permissions manually. But if we want to keep this thing, we can just do this basically.
This would set the umask value for all non root accounts to 0077 and root to 0022. In addition to this, we should not get rid of the pam module. Keep it and set it also to 0077. It gets overriden by /etc/profile anyway, and I think (not being certain) /etc/profile does not set the umask value for system daemons whereas the pam module does that too. I can create a pull if this works. |
Root creating files not readable by "others" by default is a problem because it breaks many instructions on how to create any config files or scripts as root that exist for Linux. Not only the file creation needs to be done but also file permissions need to changed after that. For example adding an APT source would be ignored by APT because the sandboxed user under which APT is running cannot read the file. By extension it breaks many scripts / installers because these are basically just automation of "touch /etc/file", "echo something > /usr/bin/script" and so forth because these are as if root typed these commands by hand. This can involve many files and the installer doesn't inform the user about each file. Fixing file permissions after that would be very hard even for system administrators. For example, this broke derivative-maker creating an APT sources list file which then APT could not read, which was a confusing and time consuming bug to diagnose. The actual fix was just 1 line to fix the permissions so that doesn't really demonstrate the effort needed to fix it. Pretty much all tools, installers assume default umask except puppet, salt and alike. This is similar to #147 which broke a lot things which nobody could foresee. Most recent example is that it broke Calamares. /etc/profile.d isn't the right mechanism because it is ignored in more situations than I can remember now. Some only come up after an issue is happening. But situations in which /etc/profile.d is ignored include
If we cannot do this reliably so the user can trust that this works, we better shouldn't do a half implementation because a user trusting this to work could end up with a security issue when this is ignored in some environments. PAM seems to be the most suitable mechanism because it's used for all sorts of logins. |
We won't drop pam. Pam will enforce 0077 for everyone, including all these in the list. Then for the human root, we will have 0022. This is not a bug, this is what we want. The only valid concern in the list is ssh, which is also not valid, because we block this functionality anyway, as we should. A workstation should have a remote root login functionality, especially a secure one. But if desired, umask for ssh can be set separately too. |
I still think this needs to be done with PAM as this is the universal way to set this without a lot of application specific exceptions. And the PAM way hasn't been exhausted yet. This is just my general development philosophy to first exhaust the seemingly proper fix before adding lots of workarounds, hacks to accomplish the same. Because all of the exceptions, bug reports coming later are otherwise becoming a unmanageable mess. monsieuremre:
It's a universal OS. Not a desktop-only (workstation) OS.
If changing the defaults for systemd units (how to even do that?) then this could lead to a lot unforeseeable issues. So the scope in your opinion is to change default umask for both human and daemons? related: |
Make the umask 0077 for all daemons and humans, then manually set the umask 0022 for the root account for human logins. |
daemons: Did you ever see a daemon that uses insecure umask / creates files with insecure permissions? -> Please check for / report bug(s) upstream. |
I raise the same logic. Have you ever seen a daemon break because of the system umask because it doesn't set its own umask explicitly whenever its important? No? If yes, we gotta open an issue there. So this is not a blocker. |
monsieuremre:
> daemons: Did you ever see a daemon that uses insecure umask / creates files with insecure permissions? -> Please check for / report bug(s) upstream.
I raise the same logic. Have you ever seen a daemon break because of the system umask because it doesn't set its own umask explicitly whenever its important? No? If yes, we gotta open an issue there.
So this is not a blocker.
I am rejecting the burden of proof reversal in this case.
Evidence is needed that there is an issue instead. If there is an issue,
we can fix it. If there's no issue, no unnecessary system modifications
should be piled up because these might worsen maintainability.
Speaking of evidence for issues. Do you have any use case where the
current home folder lockdown and user private groups (UPGs) is
insufficient. Any cases where users created file somewhere which are
readable by 'others' while these should not be?
|
I don't mean to imply any burden of proof. I just wanted to state that it should not be a problem. And as an example to how it makes sense. Like root privileged services having temp files that are not set with good permissions is just one example. A universal solution is more inclusive than individually setting private tmp folder config for services manually one by one. |
Any specific examples? |
I am not sure what you mean by examples. But I want to at least say this once again, we should set the umask for the root account as well. I do not understand the appeal. I think setting the umask for the root is the most important of them all. Any use cases like system administration requires declaring file permissions when creating them. Any files that are installed with a package are also set with their own umasks not with roots umask. Debian also recommends settings 0077 for the root account in their securing guide. The same goes for redhat too. I think we are just better of with setting 0077 globally, and I don't think any breakage will occur at all. |
I mean sir, these problems are caused because the files are touched without specifying the file permissions, which it should have been done especially the source stuff. The apt problem is caused because there is no file at all, not because the permissions are set wrong. The tor browser is caused because the package should set file permissions but it does not. Like this can be solved within the package easily. Debian packages set file permissions dynamically. I have been using 0077 umask for all accounts and I for one have not experienced any issue so far. Of course, anecdotal evidence, means nothing. But still. |
I am afraid, that's insufficient. Also wasn't expected to cause a lot of breakage as referenced there. And if something breaks in complicated, time-consuming ways, nobody is available to pick up the pieces such as: Hence, I am careful with changes. So what's the way forward? Work with upstream. That is, a feature request against Debian and/or other Linux distributions. Purpose of such a feature request:
Non-purpose of such a feature request:
I'll be sending feature request
The packaging did everything correctly. The user didn't set correct permissions for custom configuration files in /etc. Read right for
Happened because file was not readable because not readable by |
Debian feature request: |
Yeah the cause of the problem there is noexec tho, not libpam-tmpdir. Libpam-tmpdir just makes sure that everyone can only acces their own temp files only. And if it breaks anything (it won't), than that program is very poorly written at best at malicious at worst. There is no legit reason to access other user's tmp files. |
monsieuremre:
> wasn't expected to cause a lot of breakage as referenced there. And if something breaks in complicated, time-consuming ways, nobody is available to pick up the pieces such as:
Yeah the cause of the problem there is noexec tho, not libpam-tmpdir. Libpam-tmpdir just makes sure that everyone can only acces their own temp files only. And if it breaks anything (it won't), than that program is very poorly written at best at malicious at worst. There is no legit reason to access other user's tmp files.
Problem is there's many such programs and we don't have capacity to
patch these programs upstream.
|
After researching this, it looks like this is (obviously) not anywhere near as simple as one would hope. umask is similar to environment variables - it's a pain to manage in a reliable fashion. The basic way in which umask is managed is simple - each process has a umask that it inherits from the process that launched it, and each process can explicitly change its umask if desired. When a process launches a child process, that child inherits the umask of the parent, and if the parent changes its umask prior to launching the child, the child inherits that changed umask. PID 1 has a default umask, thus acting as the "root of umask" for the system. Where this gets sticky is when you're trying to make all processes running under a certain user account use a specific umask. umask isn't an account-level setting, it's an inherited "variable" that processes pass down to their children. There are a lot of ways of getting "into" an account - you can log into it on the console, you can log in graphically, you can ssh in, you can use PAM is an almost ideal tool for this because it has the unique position of being able to get "in the way" of almost all of the entry points into the root account. Since it's a standard thing, most authentication tools use it to at least some degree, so whether you use sudo, ssh, console login, or even graphical login, PAM has an opportunity to do things, including change umask values. Where this breaks down however is that PAM only knows the user that is being authenticated as, and the user that the authenticating process is running as. It does not know what the authenticating process intends to do if authentication succeeds (or fails). PAM's job is to authenticate the user and then tell the authenticating process "the user is who they say they are, do with that info what you will". When using lightdm, this isn't a problem - lightdm intends on starting a graphical session for the user that was authenticated as. Thus if you set the umask based on the authenticated user, you get the right umask. sudo however is a different beast altogether - it authenticates one user, and then runs a command as some other user. PAM has no way of knowing that sudo is going to say "alright, With that in mind, PAM is insufficient on its own. For authenticating processes that grant access to the user authenticated as (i.e., display managers), it's fine, but for privilege escalation utilities like sudo, it just doesn't work. The best we can hope for with PAM is that maybe whatever process is doing the authentication also sets an environment variable (or something similar). Then we could check that environment variable using The other option is to recognize that there are many entry points into each user account and simply handle umask at every entry point. Some of the entry points we'd have to tackle are:
One interesting thing I noticed while writing this comment: apparently systemd-homed can be used to set per-user umasks in certain scenarios? Not sure how this is done, or if systemd-homed is even usable for Kicksecure, but it's another interesting data point. See https://systemd.io/USER_RECORD/ |
Unfortunately we do not use systemd-home. If we did, then as you mentioned this problem would be easy to solve. But most importantly, this problem would not event exist, because systemd-home's main purpose is encrypting home directories of different users. So no matter what the DAC scheme looks like, an encrypted user directory would be protected either way. And as you mentioned, umask is not even close to being sufficient for hardening anything. A full system MAC policy would be the closest we would get into solving this problem without severely limiting the package into desktop-only usage. |
For that, no What this ticket is about is another detail improvement. It's hard to even come up with an example where it still applicable. It's not So this is only about other files user Perhaps Or perhaps some web server running under user However, a hardened Encryption is besides the point. The user might be using full disk encryption. File/folder/disk encryption is supposed to protect data at rest after powering off. File/folder/disk encryption addresses data at rest, while file permissions manage runtime access control. I've searched with google, perplexity, chatgpt, claude...
https://www.baeldung.com/linux/umask seems interesting. Did not read all yet. Quote:
But it has to be tested how many entry points that would cover. MAC is very good too, but not a replacement this more foundational system level hardening using
I don't think it was mentioned that systemd-home would easily solve this. Just something worthwhile to investigate. |
Alright, I did further research on this experimenting in a Kicksecure VM, and found out this actually is really easy. It looked surprisingly tricky, but it turned out to not be so.
The only thing that needs special configuration is
At this point, everything should work as expected. All that needs to be done is the previously removed PAM configuration needs added back, and some config in sudoers needs to be set. (This will come back to bite us when we switch to doas if we manage to switch, since doas doesn't support setting umask to my awareness. We may need a wrapper script or an upstream feature request to help there. Also, technically this doesn't cover non-login shells. I haven't thought of a way to get a non-login shell without going through either sudo or PAM, but it might be worth setting umask in root's .bashrc and .zshrc too just in case.) |
I think ditching sudo for doas might not be the holy grail. It is too standardized and practical. I have done some quick reading. It seems like all vulnerabilities that have been discovered in the last 5 years has been memory vulnerabilities. Correct me if I'm wrong. So maybe switching to a sudo-compatible memory safe implementation would be a good step? I think there is a compatible rust implementation already. |
@monsieuremre I've done a lot of research to see if doas would be suitable for us, and it looks like it's very possible to port over. sudo is standardized and practical, but... is that a good thing? Arguably sudo's widespread use is bad for Kicksecure, since it means it's a much higher profile target than doas. sudo-rs does exist. Writing things in rust doesn't necessarily guarantee they're vulnerability-free though. sudo-rs definitely is doing a good thing I would argue, but given OpenBSD's good security track record, I think I trust their C code more than Trifecta Tech's Rust code. |
Currently umask is set to
027
(read, write for owner and group only).(Group is OK because Debian uses
usergroups
by default,UPG
(UserPrivateGroups)).This however should not be the case for files created by root as this is super confusing, causing issues when creating files in
/etc
(or/usr
) as these won't be readable by applications normally suppose to be able to read these running as non-root. That part is broken.Therefore unfortunately this feature has to be reverted until this can be fixed.
This was discussed before here:
The following unfortunately has to be removed.
/usr/share/pam-configs/umask-security-misc
I cannot even just out-comment it to make it easier to tinker as folder
/usr/share/pam-configs
does not support comments. Populating/etc/pam.d
from/usr/share/pam-configs
is a Debian / Ubunut feature.Command for testing:
I tried various stuff to fix it:
Session-Interactive-Only: yes
This issue is only happening in non-Qubes. Not reproducible in Qubes Debian. This might be because Qubes login session work differently. This is probably also why I did not spot this issue beforehand.
Contributing: I don't necessarily need the config snippet for
/usr/share/pam-configs
as I might be able to figure that out but the config snipped required for/etc/pam.d
would very useful.The text was updated successfully, but these errors were encountered: