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

Allow rootless AppArmor #1572

Merged
merged 2 commits into from
Aug 16, 2023

Conversation

kernelmethod
Copy link
Contributor

Related issues:

This PR re-implements #960, allowing containers to execute under a specified AppArmor profile when run rootlessly. In addition, it changes the default AppArmor profile used by containers to unconfined.

The current implementation of Podman compiles and loads the default AppArmor profile at runtime. However, this is incompatible with providing rootless AppArmor compatibility, as loading an AppArmor profile requires root privileges. As discussed in containers/podman#15874, the ideal mechanism by which a default profile should be loaded is to add a profile to /etc/apparmor.d at installation time, by individual distributions. This profile should then be specified in a default containers.conf provided by the distribution.

Set the default AppArmor profile to unconfined; see the following
issues:

- containers#958
- containers/podman#15874

Based on the discussion there, distros that use AppArmor should supply
their own AppArmor profile and set it in a default containers.conf,
since there is no way to load AppArmor profiles rootlessly.

Signed-off-by: Will Shand <[email protected]>
@kernelmethod
Copy link
Contributor Author

As noted in containers/podman#15874, as it currently stands, all rootless containers currently run unconfined anyways, which limits the downstream security impacts of this change. Nonetheless, it would be nice if we could coordinate with Debian and OpenSUSE package maintainers to try to get in a default profile sooner rather than later.

I've also opened containers/podman#19303, which will need to be merged in after this.

@rhatdan
Copy link
Member

rhatdan commented Jul 20, 2023

I am fine with this change, although it seems to be contradictory. You are allowing rootless podman to use apparmor but you comment above the rootless processes can not set apparmor profiles.

@kernelmethod
Copy link
Contributor Author

kernelmethod commented Jul 21, 2023

I am fine with this change, although it seems to be contradictory. You are allowing rootless podman to use apparmor but you comment above the rootless processes can not set apparmor profiles.

To clarify, I meant that rootless processes cannot load AppArmor profiles into the kernel; i.e., you can't run apparmor_parser -r ... without root privileges. But with this change (and containers/podman#19303) it's now possible for rootless users to specify --security-opt $profile_name with an actual effect (for profiles that are already loaded into the kernel).

@XSpielinbox
Copy link

In addition, it changes the default AppArmor profile used by containers to unconfined.

Why this change? This seems like a step backwards to me. Also: If you want to encourage distributions to ship a different default profile, why not ship it directly?

@Luap99
Copy link
Member

Luap99 commented Jul 21, 2023

I know nothing apparmor but I agree changing the default to unconfined seems like a regression in the rootful case.
If you want distros to ship a profile by default I think it is best to have a profile file here then the packagers can just ship it and modify if needed.

@kernelmethod
Copy link
Contributor Author

I'm happy to provide a default profile (although it seems that it would be better suited to the other PR containers/podman#15874 than here), but actually getting it installed will need some additional cooperation with whoever is in charge of the Debian and OpenSUSE repos.

In any case, it doesn't make sense for the default profile to be specified inline in this library; that job should be deferred to containers.conf. Moreover, there isn't any good way (as best as I can tell) to specified a non-unconfined AppArmor profile by default here that won't subsequently break Podman's CI/CD pipeline, which was exactly the reason why my original attempt to fix this issue was reverted.

@Luap99
Copy link
Member

Luap99 commented Jul 21, 2023

Having a containers.conf option like apparmor_profile sounds good to me, this could work the same as seccomp_profile for example.

As far as breaking podman CI goes we can always add something in our CI setup where we load the profile at the start as root. The important things is to not cause regressions for users who you use a released version so it must be clear for effected distro packagers that they have to ship this profile when in order to not cause regressions.

@XSpielinbox
Copy link

XSpielinbox commented Jul 21, 2023

There is the template in this repository from which the current default for the rootfull podman gets generated: https://github.com/containers/common/blob/main/pkg/apparmor/apparmor_linux_template.go

This default should be a good compromise between security and convenience.
Assuming that it is so, one could just write the result of this template to disk, from where loading it automatically should not be an issue as far as I understand it - all the other applications also get their profiles loaded without difficulties.
If then this makes your CI/CD pipeline fail, you either have a special case, where you need a special profile, that is not worth integrating in the default or your pipelines is doings things, it should not do and you need to fix your CI/CD pipeline to adhere to the profile.

If the default profile isn't a good compromise at the moment, it would need adjusting anyway. It may be, that one has to make a separate default for rootless, but it should work the same in principal, right?

Having a containers.conf option like apparmor_profile sounds good to me, this could work the same as seccomp_profile for example.

According to the containers.conf (5) man page, apparmor_profile already exists as an config option with the default value container-default. So, if one default profile for rootfull and rootless podman is enough/feasible, no changes would be needed, if separate defaults exist, one should of course be able to configure them separately.

@rhatdan
Copy link
Member

rhatdan commented Jul 24, 2023

@kernelmethod @XSpielinbox @saschagrunert @vrothberg @siretart PTAL

I don't think this should be decided by engineers who do not/have not worked with AppArmor

@kernelmethod
Copy link
Contributor Author

I'll follow @XSpielinbox 's suggestion and use the existing template, and see where that takes us.

@rhatdan
Copy link
Member

rhatdan commented Aug 16, 2023

@kernelmethod @XSpielinbox @saschagrunert @vrothberg @siretart any update on this?

@XSpielinbox
Copy link

I have nothing to add to what I said before. I am looking forward to an implementation using the template.
Is there any way I can help with that?

@rhatdan
Copy link
Member

rhatdan commented Aug 16, 2023

/approve
/lgtm

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 16, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kernelmethod, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit f2437f3 into containers:main Aug 16, 2023
@XSpielinbox
Copy link

It was now merged without usage of the template, but rather weakening it to unconfined.

What was the reasoning behind that?

@kernelmethod
Copy link
Contributor Author

kernelmethod commented Aug 17, 2023

@XSpielinbox Go is unfortunately not a language I'm terribly good with, and I've had other obligations take priority over this so I've fallen a bit behind on getting this PR and containers/podman#19303 ready (particularly the latter). I'm still working on it; however, if it's high-priority for you and you want to help out, feel free to make a PR to https://github.com/kernelmethod/podman and I'll merge your changes into mine.

@rhatdan -- unfortunately as @XSpielinbox said I don't think that this PR was ready to be merged, at least per the previous discussion. Are we now okay with defaulting to making Podman containers unconfined? (Technically already the default for rootless containers, but not for rootful ones.)

@vrothberg
Copy link
Member

I'll revert the commit. I am not sure it was on purpose since merging requires ACKs from at least two maintainers.

@vrothberg vrothberg mentioned this pull request Aug 17, 2023
@vrothberg
Copy link
Member

#1620

openshift-merge-robot added a commit that referenced this pull request Aug 17, 2023
@XSpielinbox
Copy link

@XSpielinbox Go is unfortunately not a language I'm terribly good with, and I've had other obligations take priority over this so I've fallen a bit behind on getting this PR and containers/podman#19303 ready (particularly the latter). I'm still working on it; however, if it's high-priority for you and you want to help out, feel free to make a PR to https://github.com/kernelmethod/podman and I'll merge your changes into mine.

Unfortunately, it is more or less the same for me. I will see what I can do. I would really like to see this feature implemented some day. I wanted to learn Go programming for month now, but haven't found the time yet.

@XSpielinbox
Copy link

@kernelmethod What OS are you using to test the AppArmor support?

@kernelmethod kernelmethod deleted the rootless_apparmor branch August 20, 2023 20:59
@kernelmethod kernelmethod restored the rootless_apparmor branch August 20, 2023 20:59
@kernelmethod
Copy link
Contributor Author

@kernelmethod What OS are you using to test the AppArmor support?

Debian (Bookworm)

@kernelmethod
Copy link
Contributor Author

I'll revert the commit. I am not sure it was on purpose since merging requires ACKs from at least two maintainers.

Thanks @vrothberg; I'll open a new PR once everything's ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants