Skip to content

pkg/apparmor: scratch documentation of apparmor - #6559

Closed
zyga wants to merge 2 commits into
canonical:masterfrom
zyga:rfc/pkg-apparmor
Closed

pkg/apparmor: scratch documentation of apparmor#6559
zyga wants to merge 2 commits into
canonical:masterfrom
zyga:rfc/pkg-apparmor

Conversation

@zyga

@zyga zyga commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

We're currently growing support for apparmor 2.13+ and I was thinking
about how we structure the code related to that. I'm worried of the
growing complexity in interfaces/apparmor (and release/apparmor.go) and
would like to move that code to pkg/apparmor where it can be referenced,
as appropriate from original locations. In addition I'd like to clearly
separate old and new apparmor, using the chance to document how it
behaves in each version.

This patch is by no means complete but I'd like to use it to start a
discussion about moving the code out, gardening it a little bit and
dropping it here. I chose the directory pkg/apparmor as we can expect
similar treatment to seccomp code without adding a new top-level element
for each package and the pkg/foo naming scheme seems to be common in the
go ecosystem.

Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com

We're currently growing support for apparmor 2.13+ and I was thinking
about how we structure the code related to that. I'm worried of the
growing complexity in interfaces/apparmor (and release/apparmor.go) and
would like to move that code to pkg/apparmor where it can be referenced,
as appropriate from original locations. In addition I'd like to clearly
separate old and new apparmor, using the chance to document how it
behaves in each version.

This patch is by no means complete but I'd like to use it to start a
discussion about moving the code out, gardening it a little bit and
dropping it here. I chose the directory pkg/apparmor as we can expect
similar treatment to seccomp code without adding a new top-level element
for each package and the pkg/foo naming scheme seems to be common in the
go ecosystem.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
@pedronis

pedronis commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

There is no general agreement about the pkg/ style, I just saw over the weekend people discussing exactly that, I find it a bit low-content as naming style, it would also make us question whether to move more stuff.

@zyga

zyga commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

The name pkg is nice and short. It's used by many go projects though that is not any general endorsement across the ecosystem. To me it looks like a src or include directory and allows us to stash library code away from the, already very busy, top level directory.

This code could, in theory, live in interfaces/apparmor but that location is strictly about interfaces. We already have a similar problem where, for totally historic reasons, apparmor code also lives in the release package.

@pedronis

pedronis commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

I think sandbox/apparmor sandbox/seccomp would follow more our current organisational style (which I don't see pressure to change)

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
@zyga

zyga commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

I've renamed the package to sandbox/apparmor. Depending on feedback I could help move things from the various places that "do" apparmor there.

@jdstrand jdstrand left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't quite understand the purpose of this PR. A lot of the comments aren't quite right and have no bearing on snapd and there is quite a bit of added complexity and assumptions about the apparmor layout. IME, snapd (these days, now that it manages the snap-confine profiles itself) needs to know where the cache directory is for the distribution it is working with (and even this could be removed if snapd wanted to ship its own systemd unit for loading snap profiles from, say /var/lib/snapd/apparmor/cache), and whether or not to support the new-style forest or the old-style flat dir. How profiles are named, what they contain, etc shouldn't be codified in snapd. The main point of profileIsRemovableOnCoreSetup() in PR 6549 is not about the names of other profiles, but about the names of profiles that snapd maintains so codifying things elsewhere seems to add complexity.

That said, I appreciate that it might be useful to understand where distros put things and perhaps that is worth a larger comment (perhaps in dirs/dirs.go though).

"path/filepath"
)

// Legacy represents apparmor user-space version up until 1.12

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2.12*

// /etc/apparmor.d/* (just files): source profiles.
// /etc/apparmor.d/tunables/*: definitions included by source profiles.
// /etc/apparmor.d/abstractions/*: definitions included by source profiles.
// /etc/apparmor.d/cache/*: binary profiles.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This isn't strictly true. A distro could've use /var/cache/apparmor regardless of if it was 2.13 or not. It just happened to coincide with Debian's 2.13 packaging that they cleaned up up and used a unified directory.

// In addition some locations are only used by snapd:
//
// /var/lib/snapd/apparmor/profiles: source profiles (snapd specific)
// /var/cache/apparmor/*: binary profiles (snapd specific)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No-- this was used elsewhere (eg, click on Ubuntu Touch) and could've been used by anyone.

// /var/lib/snapd/apparmor/profiles: source profiles (snapd specific)
// /var/cache/apparmor/*: binary profiles (snapd specific)
//
// Source profiles are typically stored as files in /etc/apparmor.d/.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not really. This is the default and used by convention only. Debian/Ubuntu debs would place profiles here, and administrators would usually put profiles here, but applications are free to manage profiles as needed (eg, snapd and later docker use somewhere else; libvirt is a subdir of /etc/apparmor.d as are apache hats).

//
// Source profiles are typically stored as files in /etc/apparmor.d/.
// The file name is the absolute path of the executable with forward slashes
// replaced with dots. For example the file /etc/apparmor.d/usr.bin.man

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, this is convention and not enforced. No tools should codify this. It is perfectly legal to ship a profile 'foo' that confines /opt/bin/bar. There is no enforced correlation between profile name, the binary it confines and the filename.

//
// Source profiles routinely include definitions from
// /etc/apparmor.d/abstractions as well as tunables that can be adjusted by
// local administrator, from /etc/apparmor.d/tunables.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, this is default behavior but entirely dependent on what the profiles use. Eg Ubuntu Touch would #include files from /usr and the parser supports specifying a different base directory with --base.

//
// Once compiled, binary profiles are typically cached as files in
// /etc/apparmor.d/cache. The cache is based on mtime of the source profile and
// of the cached profile. The cache is unaware of the kernel feature set. This

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's not true. /etc/apparmor.d/cache/.features is present prior to 2.13 and was used as part of the parser's decision to invalidate the cache.

// Apart from the aforementioned directories in /etc/apparmor.d/, at least on
// some distributions, there are more binary profiles present in
// /var/cache/apparmor and more source profiles present in
// /var/lib/snapd/apparmor/profiles. Profiles stored there don't follow the

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Or other places... see above.

@@ -0,0 +1,7 @@
package apparmor

// modern represents apparmor user-space version since 1.13

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2.13*

@zyga

zyga commented Mar 5, 2019

Copy link
Copy Markdown
Contributor Author

@jdstrand thank you for all the comments. I will adjust this for another pass. I think some explanation is in order. I was looking at the 2.13 PR and was somewhat uncomfortable with clustering of apparmor specific logic 2.12 vs 2.13 along with snapd logic. I though it would be nice to abstract apparmor differences behind a new module, taking the opportunity to document how 2.12 and 2.13 differ.

@pedronis

pedronis commented Mar 5, 2019

Copy link
Copy Markdown
Contributor

Legacy and modern are not clear names, Pre2_13 and 21_3Plus or something. Where/how do we pick one or the other?

Also is still a bit unclear to me there is enough actual difference to warrant a full new package, vs a helper.go file in interfaces/apparmor.

@zyga

zyga commented Mar 11, 2019

Copy link
Copy Markdown
Contributor Author

I will return here tomorrow.

@pedronis

Copy link
Copy Markdown
Contributor

I'm closing this, is still a bit unclear if it's a win, and I don't think we have overall bandwidth ATM to work/think through it. It can be reopened later.

@pedronis pedronis closed this Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants