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

RFC: libcontainer: remove dependency on libapparmor #1675

Merged
merged 1 commit into from
Dec 15, 2017
Merged

RFC: libcontainer: remove dependency on libapparmor #1675

merged 1 commit into from
Dec 15, 2017

Conversation

tklauser
Copy link
Contributor

libapparmor is integrated in libcontainer using cgo but is only used to
call a single function: aa_change_onexec. It turns out this function is
simple enough (writing a string to a file in /proc//attr/...) to be
re-implemented locally in libcontainer in plain Go.

This allows to drop the dependency on libapparmor and the corresponding
cgo integration.

Fixes #1674

Signed-off-by: Tobias Klauser [email protected]

@tklauser tklauser changed the title libcontainer: remove dependency on libapparmor RFC: libcontainer: remove dependency on libapparmor Dec 11, 2017
@tklauser
Copy link
Contributor Author

As noted in #1674, I did not fully test this yet. I'm trying to get runc running with an apparmor profile to test this first.


// mimick aa_change_onexec from libapparmor in Go
value := "exec " + name
if err := setprocattr(unix.Gettid(), "exec", value); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This looks /okay/ overall, but I would prefer if we had a function called ChangeOnExec (or whatever) which wraps these two lines -- to make it clearer what we are mimicing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. Does it need to be exported or could it also be changeOnExec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PTAL

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, there's no need to export it I guess.

_, err = fmt.Fprintf(f, "%s", value)
return err
}

// ApplyProfile will apply the profile with the specified name to the process after
// the next exec.
func ApplyProfile(name string) error {
if name == "" {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Should check !strings.Contains(name, "/")

Copy link
Member

@cyphar cyphar Dec 11, 2017

Choose a reason for hiding this comment

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

Why? Profile names can have / in them IIRC (and they can also not have / in them as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would something like the following be sufficient?

if strings.Contains(name, "/") {
    return fmt.Errorf("apparmor profile name cannot contain '/'")
}

Copy link
Member

Choose a reason for hiding this comment

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

At least ".." should be prohibited to prevent potential filesystem contamination

Copy link
Member

Choose a reason for hiding this comment

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

np, I misread the code

@cyphar
Copy link
Member

cyphar commented Dec 11, 2017

This looks fine. I will test it though (though I imagine it will work fine -- the only really ugly parts of the AppArmor API are related to profile loading and unloading).

@@ -24,16 +21,34 @@ func IsEnabled() bool {
return false
}

func setprocattr(tid int, attr, value string) error {
path := fmt.Sprintf("/proc/%d/attr/%s", tid, attr)
Copy link
Member

Choose a reason for hiding this comment

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

While this works, I think this should be /proc/self/attr/%s. Under AppArmor you can only change your own attr, so I think /proc/self makes more sense than providing a tid argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, PTAL.

libapparmor is integrated in libcontainer using cgo but is only used to
call a single function: aa_change_onexec. It turns out this function is
simple enough (writing a string to a file in /proc/<n>/attr/...) to be
re-implemented locally in libcontainer in plain Go.

This allows to drop the dependency on libapparmor and the corresponding
cgo integration.

Fixes #1674

Signed-off-by: Tobias Klauser <[email protected]>
@cyphar
Copy link
Member

cyphar commented Dec 15, 2017

LGTM. Tested this with a few profiles and they are applied properly.

Approved with PullApprove

@crosbymichael
Copy link
Member

crosbymichael commented Dec 15, 2017

LGTM

Approved with PullApprove

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

Successfully merging this pull request may close these issues.

4 participants