Skip to content

Conversation

@wzshiming
Copy link
Contributor

@wzshiming wzshiming commented May 20, 2021

// hostSupports returns true if apparmor is enabled for the host, if
// apparmor_parser is enabled, and if we are not running docker-in-docker.
//
// It is a modified version of libcontainer/apparmor.IsEnabled(), which does not
// check for apparmor_parser to be present, or if we're running docker-in-docker.
func hostSupports() bool {
checkAppArmor.Do(func() {
// see https://github.com/docker/docker/commit/de191e86321f7d3136ff42ff75826b8107399497
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil && os.Getenv("container") == "" {
if _, err = os.Stat("/sbin/apparmor_parser"); err == nil {
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
appArmorSupported = err == nil && len(buf) > 1 && buf[0] == 'Y'
}
}
})
return appArmorSupported
}

does not check for apparmor_parser to be present

This comment does not match the behavior

https://github.com/opencontainers/runc/blob/0d49470392206f40eaab3b2190a57fe7bb3df458/libcontainer/apparmor/apparmor_linux.go#L13-L27

https://github.com/moby/moby/blob/de191e86321f7d3136ff42ff75826b8107399497/pkg/apparmor/apparmor.go#L15-L21

wzshiming added 2 commits May 20, 2021 11:56
Signed-off-by: Shiming Zhang <[email protected]>
@k8s-ci-robot
Copy link

Hi @wzshiming. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@theopenlab-ci
Copy link

theopenlab-ci bot commented May 20, 2021

Build succeeded.

Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@kzys kzys left a comment

Choose a reason for hiding this comment

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

LGTM!

@neersighted
Copy link
Contributor

Just adding a note here: The comment here was read backwards. It was meant to be understood as "this check is like the one in libcontainer, but that one doesn't check this thing that we additionally do."

This caused a regression in Moby as containerd stopped checking for apparmor_parser as its Godoc stated/still states. The comment was worded poorly, but if the plan is to move forward with this/not revert (as Moby is likely the only consumer that ever cared about the distinction and it wasn't caught up to this point), we probably should just update the Godoc for the new reality and add some errata to the release notes.

@neersighted
Copy link
Contributor

neersighted commented Feb 7, 2023

Also it looks like we knew about this 18 months ago: #5557 (comment)

@thaJeztah:

Ah, hmm.. yes, I think #5519 is wrong, as this implementation was explicitly different than the one in libcontainer, because containerd (and moby/docker) need to set up / load the profile, whereas runc only has to apply it.

@wdoekes
Copy link

wdoekes commented Feb 8, 2023

Yes. Ran into this yesterday.

Assuming that you have a working apparmor just because the module was compiled in, does not seem appropriate here.

  • Either you assume that the kernel calls work, and you use those.
  • Or you check that the userland tools work/exist, and you use those.

we probably should just update the Godoc for the new reality and add some errata to the release notes.

This hybrid where we check for A and do B is wrong. Just updating the comments without removing all Command("apparmor_parser...) is not sufficient.

@thaJeztah
Copy link
Member

So in a (slightly larger) nutshell;

So, yes, the changes in #4715 where specifically intended to preserve the old behavior as it was needed for containerd (CRI); the function was named hostSupportsAppArmor() to be more explicit on intent (but naming is hard), and kept internal to pkg/cri/server/, as the check was specific for that purpose (not a general purpose AppArmor check) at the time (but later move to pkg/apparmor and exported in #4811).

The changes in this PR;

@MichaIng
Copy link

MichaIng commented Feb 8, 2023

Not sure about the background, but I think @wdoekes is perfectly correct, regardless what the background is:

  • First of all, the code comments above the function now do not match what the function does: If the function intentionally is meant to only check whether the kernel feature is available, the comment should reflect this and not still state the previous stage with the reference to libcontainer.
  • Second, if containerd uses this function as condition whether to call apparmor_parser or not, then either a new function needs to be added or this commit reverted, since then obviously containerd uses it differently than libcontainer which makes it wrong to align both. If it is only Docker/moby which runs apparmor_parser, then apparmor: Check if apparmor_parser is available moby/moby#44902 seems to be the right thing.

@thaJeztah
Copy link
Member

If it is only Docker/moby which runs apparmor_parser

Looks like containerd also uses it (apparmor_parser);

func aaParser(args ...string) (string, error) {
out, err := exec.Command("apparmor_parser", args...).CombinedOutput()
return string(out), err
}

which gets invoked by

func WithDefaultProfile() oci.SpecOpts {

(and I think this PR was what led to CI failures investigated in #5557)

@MichaIng
Copy link

MichaIng commented Feb 8, 2023

Generally it seems like hostSupports and other module/package API functions are used not by containerd itself/internally but only by other applications which use containerd, like Docker, to load/control modules, right? Changes to an API hence should be done with care to not break things elsewhere without a major version increment and release note. But, the hostSupports function seems to be generic for all packages/modules to tell API users whether it is supported or not and hence whether it can be loaded, including usage of the other functions it provides, right? So in this case, since using the AppArmor package/module implies the ability to use apparmor_parser, hostSupports now seems to be able to simply tell the wrong thing without checking whether this tool is actually available. The previous behaviour looks pretty correct, since both, the kernel feature as well as the userland tool are required to use this pkg/module/API.

@neersighted
Copy link
Contributor

The million dollar question is what does hostSupports mean. Does it mean "we can use AppArmor profiles (aka the parser + kernel are both present)," or does it mean "kernel is aware of AppArmor?"

If containerd depends on apparmor_parser for anything, it seems like this change should be reverted and the original meaning of the function kept. If containerd needs to only check that the kernel supports AppArmor in other places, it seems like a new check should be added that is much more narrowly scoped. That could reduce containerd's dependence on apparmor_parser to only the places where it is truly needed.

twz123 added a commit to twz123/k0s that referenced this pull request Feb 16, 2023
…ser. Update k0s docs to reflect that."

This reverts commit 9af9db3.

containerd v1.6.18 reverted the removal of the check.

Signed-off-by: Tom Wieczorek <[email protected]>
twz123 added a commit to twz123/k0s that referenced this pull request Feb 16, 2023
…ser. Update k0s docs to reflect that."

This reverts commit 9af9db3.

containerd v1.6.18 reverted the removal of the check.

Signed-off-by: Tom Wieczorek <[email protected]>
twz123 added a commit to twz123/k0s that referenced this pull request Feb 16, 2023
…ser. Update k0s docs to reflect that."

This reverts commit 9af9db3.

containerd v1.6.18 reverted the removal of the check.

Signed-off-by: Tom Wieczorek <[email protected]>
twz123 added a commit to twz123/k0s that referenced this pull request Feb 20, 2023
…ser. Update k0s docs to reflect that."

This reverts commit 9af9db3.

containerd v1.6.18 reverted the removal of the check.

Signed-off-by: Tom Wieczorek <[email protected]>
twz123 added a commit to twz123/k0s that referenced this pull request Feb 21, 2023
…ser. Update k0s docs to reflect that."

This reverts commit 9af9db3.

containerd v1.6.18 reverted the removal of the check.

Signed-off-by: Tom Wieczorek <[email protected]>
(cherry picked from commit 5c4c78c)
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.

8 participants