-
-
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
Full-Policy integration for Whonix/Kicksecure - And also everyone else #249
Conversation
Looks interesting. But could it be done without w^x violation? |
Actually, with the amount of profiles here, I think yes. This profile was designed to work with around 150 'selected' profiles from this repo. |
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
|
||
abi <abi/3.0>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: add a new line after the abi definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
owner /media/** rw, | ||
|
||
## Or what is mounted | ||
owner /mnt/** rw, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use @{MOUNTDIR}
instead of /media/
and /mnt/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing.
## Running stuff is fine here | ||
## Modifying requires ownership | ||
@{lib}/** rPix, | ||
owner @{lib}/** rwmlkPix, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not ideal. But acceptable as all important programs already have a profile and will therefore transition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be more acceptable. Having all the profiles, I can actually strip a lot more capabilities.
## This blocks what Kicksecure security-misc package blocks. | ||
deny /**System.map* rw, | ||
|
||
## No accessing the disk in other ways to circumvent the policy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note sure about this. systemd really does not need disks access?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is, only select services do, which have their respective profiles. Because this caused no breakage or slowdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should test it again. With earlypolicy
, it prevents udevd to start, and the boot cannot finish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooof. I see. Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why systemd-udevd tries to run under full-policy eventhough we have a dedicated profile for it. I think this migght be the cause of the issue. Is this a bug, or is it about how we load the profile? The installer seems to skip this profile for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without earlypolicy
, this is because the old initframfs hook only load the profile for systemd. So at very early stage (when udevd is started) there is no profile for udevd yet. earlypolicy
fix it as all profiles are available from the cache from the very moment systemd starts.
Then, it moves to the second issue. It is a due to a no_new_privs error. If you look at the apparmor log with aa-log -s | grep error
you should see that it cannot transition to some profile due to no_new_privs, and therefore the transition fails and the program runs inside the parent profile. As the parent profile currently denies disk access, the boot is broken.
Thanks, full system policy is part of the goal of this project, so this as definitely a place here. It has not been implemented because of time constrain, and due to some technical issue in apparmor. To sum up my view of your PR:
High level comments:
Did you tested it on other system than Whonix? How much did you tested it on whonix?
This is a no go: doing this will most likely break everyone system. Writing normal profile is already a very complex tasks as one have to carefully check all normal feature of a software, then to tests the profile over a long period of time on multiple distribution. Even with this I very often get report with issues in profiles. Now a full system policy is a VERY special profile that goes way beyond normal profile. So we will need a considerable amount of tests, redesign, and fixes before to have it as default solution. It is good to also mention that for such a profile, the security model of the target distribution may change some design (for example I remember that for Whonix UDP can be blocked as TOR does not support it). What I can do however, is to add a new
That simple to do, the builder system can handle this.
This is not possible, they are some programs that generate and reload mac on resource creation: all sandbox manager. For example: libvirtd, docker, snap. They generate new profile on VM/container creation tailored to the VM/container. Also, the profiles are currently compiled on the host at install/update time for the specific kernel version that is installed, so this would be an issue too (but we can think of workaround). Let's go deeper:
It goes the same for
This is really a must for full policy profile that may be extended by application and admin.
|
A yessir but far as I understand it is being added mostly for the new unprivileged userspaces feature. And it is still wastly limited because unconfined profiles are also bound to a path just like normal profiles. So this doesn't make away the need of a full-system policy.
The inherit options is there only as a fallback option. So long there is a seperate profile this should not happen anyway. And even it is inherited, the default policy is in many senses more restrictive that the the program cannot achieve anything malicious anyway. I am pretty sure I can get rid of the attach_disconnected flag, which is more problematic that others probably.
Yes, as point out in the comments. This was done for clearance for the reader. I will hande this in comments and get rid of the deny lines. This is would be better as you said.
Of course. Conventions are important.
If anything and everything grub has its own profile, then yes you may be right. But this way I want a way for the root user to edit the files there with its privileges. This profile is meant to confine everything. No utilities, not nano, not vim, not bash, not anything has any escape.
You are absolutely right. That's why I suggested to add this as an opt-in option. Ideally, this would be the default when building a
Right. This is actually not that hard. Just running a bunch of As pointed out, I can also get rid of the
I did not test this in whonix. I tested it in a stock debian, with gnome, with KDE, with xfce, with xorg and with wayland, and all of the same also in a kicksecure distromorphed debian. I did basic browsing with firefox, downloaded repositories, compiled binaries, and ran them in the downloads directory, to see that they work well, which they did. I tested the unconfined processes with the
Was my initial intention. But your make process looks for two seperate files, init and systemd, with those specific names. I will do as you say, but you have to fix that. In the future, as tests results a ok, we can split the profile way you want. But for now we have one profile. Please adjust the the thing so that it looks for
I see where you are coming from. Would you consider this with the complain flag and no deny lines? It will be like unconfined space for practicality. But, the project will be ready for the future, it will be just switching the mode from complaining to enforcing. Eliminating all possibility to go into unconfined space is the main goal. Because as I said in my repo, given enough privileges, it is really not a genius' game to circumvent AppArmor policies. Paths are the only thing it uses for 'authentication'. That's why many people rightfully point out SELinux is more solid. But with a full-policy, we make AppArmor not only as good as SELinux, but better in a sense, because it is maintainable by human beings. |
Tests So I did a lot of tests on your profile, and they are a few issues. However, they are quite common for this kind of profile.
Additionally, the profile is missing some rule like (I can add them later don't worry about them):
Design I have added Whonix support in the build system & in Gilab CI. Also, we are going to merge your
Furthermore, even if we call it full system policy, this is mostly a profile for systemd (PID 1). Not for a random user or system program. Therefore, it has to include everything that systemd needs (in other words: a lot). This is also why the future unconfined profile will change a lot of things. My initial idea was to split this in multiple profiles:
As much as I like this structure, it will have to wait for apparmor 4 to be implemented realistically. Other
This will have to be tested, but as you say some
The default policy is more restrictive? More restrictive compared to what? If you compare next to an unconfined program, yes obviously. Now, thanks to this project, you should not see a lot of this program (cf the concept page) My main concern is that the default policy may still be too large because let's be honest, the
This is highly unlikely, this flag is needed for all programs running (and starting) sandbox, and systemd starts a lot of services inside sandbox...
Most of the time, this would not work as it is here for a reason... (but they might be some exception)
Nope... as you can see, having a profile ready to go on all distributions is not an easy task. I won't make it the default until it is fully tested. However, help is more than welcome on the test part of the project. |
Roger. Will fix and replace systemd/** with systemd/systemd. My reason to choose this was this wiki page. I tried following the instructions.
By this do you mean carefully limit the transition rules?
Good to hear. I am positive I can wastly lock down the profile further. Will do today. But my question is, in what sense do you think the profile is too permissive? I will focus on that more. Is it the capabilities or the allowed paths? I am planning to pretty much lock down most capabilities that can be used by non-root users to escalate privileges. But I think you are more bothered with my slack file permissions than the capabilities. Is this the case? And also, how is the nonewprivs a problem? I do not unterstand this.
This is awesome. Will do.
Well, it is large enough to accomodate most functionality but still limiting in a sense that it is a huge improvement.
Only if you design it that way. My initial goal is to create a severely limited root. But just not yet and not as the default, as you pointed out the issues. I don't want to cripple root but I don't a root process to have means of circumventing the policy.
Thanks for pointing out. Will try adding them.
I would love this. But I couldn't even manage to make two profiles work, and I don't even know how to approach implementing this, due to lack of resources or my unability find them. |
I addressed all the little and medium things you mentioned. They are now fixed. Profiles is also vastly restricted further. And I am planning to further restrict it in terms of mount capabilities. I also will try removing the Also would it be possible to add new tunables in your project? Stuff like @{etc} for /{,usr/local/}etc/ or @{tmp} for /{,var/}tmp/. These would improve readability. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing sys_chroot might have some adverse side effects. I hoped everything would be covered within the profiles we already have here.
The installer still explicitly looks for init and systemd profiles and does not care for the full policy, when the option --full is given. Changing the name causes other issues because the installer still looks for init too, which breaks everything. This needs to be addressed within the installer. |
You probably need to update your branch from master, I updated this recently. Also, filename and profile name must be
We need to test it, it might generate other issue (I will come back on this later, I need to do some tests on my side). But right now there are a lot of issue regarding no-new-privs (see No New Privileges Flag) |
This doc is deprecated (4 years old), newest method is: https://gitlab.com/apparmor/apparmor/-/wikis/AppArmorInSystemd#early-policy-and-boot. Btw, as systemd directly loads the |
What are some of these specifically and how would I go about fixing them? I can't observe any practical problems out of the box. Also, this does not seem to be going anywhere even in apparmor version 4, so we would need to find a better way here if necessary. |
Yes, nnp has been a pain for a long time for all LSM (so selinux too) - and it is the main reason why full system policy has not been implemented earlier in this project. To sum it up:
The possible solutions (we might use all of them depending of the program):
See https://apparmor.narkive.com/lTYA7lIk/question-about-no-new-privs & https://apparmor.narkive.com/gz6XOZ39/avc-allowed-operation-exec-info-no-new-privs-error-1 |
Manually disabling |
I am going to do some tests and see what is the best option depending of the program. I think stacking could be a better solution for some program. |
I got it working fine. They will have some improvement to do later, but it is a start. Can you rename the profile, so I can merge it and add update it. |
Good to hear. Will do. There are obviously a lot of improvements to be made. Not just further restricting the profile, but it seems to break some little stuff here and there. These are mostly related to file permissions in /etc in my observation. Anyway, it is on the way. |
I did the name change but the path in profile remains |
I also want to address some questions I have in my mind. I couldn't find answers to these no where. First: None of your profiles have The same applies to And also
Can you comment on this part. I get all the names options from the man pages. And it seems network unix is just the same as unix but not quite? Like what is the difference. And also network local should be a thing technically reading the man pages, but it seems it isn't for some reason. Can you comment on these please? |
Per the manual, audit_read allows reading the audit log via a multicast netlink socket. This means, the cap allow reading the kernel logs, not software log (in some Therefore, It goes the same for
|
* 'main' of github.com:roddhjav/apparmor.d: Full-Policy integration for Whonix/Kicksecure - And also everyone else (#249)
Merged! I have integrated my latest tests, and kind of rewritten everything as the architecture changed quite a lot. Please have a look at the new doc page. I have started #252 to follow up on this matter as this is clearly only a wip. Also, for future test, I encourage you to use one of the test VM provided: https://apparmor.pujol.io/development/integration/#test-virtual-machines |
Hello good sir. Full policy is here. Fresh and ready to eat. Doesn't break one thing, and is rather restrictive for a general policy. There are some other things that are necessary before a possible merge, that I didn't do, either because I couldn't or because I wasn't sure you would play along.
First of all, this policy does not break most anything. Can be further restrticted, but then it will break stuff on desktop environment that are not gnome. So for now, in progress, getting there, more capabilities will be stripped away, for sure.
Now, your make process has an option
--full
. For the seamless integration of a full policy, this need to a go go and the full policy has to be included in any case. No option to choose, since this is a rather lack policy that protects what is important and protects the integrity of the policy itself. For that, you would have to play along and do the stuff ingo
so that the _full folder can be abolished.All the fallbacks to unconfined space also have to go. This is not the utmost priority, but I will most definetely create pull requests eliminating those escapes to unconfined space one by one, if you accept this full policy in. You don't have to worry about this yourself. Just check my pulls to see if they are a ok.
Also at some point I would want to strip mac capabilities alltogether from all binaries in all paths. Then we would have an immutable mac policy, in a real sense. But this is of course, a little overkill to be the default. But I am willing to implement a special installation mode in the makefile that would make sure of this. I plan to call this option automaticaly when the operating system is Whonix or Kicksecure. With time I will create the pulls, don't know if you would accept.
So what say you good sir. These sound reasonable to you? Kicksecure's full system policy is better developed directly here. But if you prefer, Kicksecure can also do on its own, tho it would be infinetely more difficult.