-
Notifications
You must be signed in to change notification settings - Fork 617
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
AppArmor profile includes files if they exist #4173
Conversation
018faab
to
ed04257
Compare
}() | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
if !apparmor.HostSupports() { |
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.
Just curious, could you provide a bit more context as to why we're removing this check? (sorry not quite clear to me)
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.
LoadDefaultProfile
reads/writes files in /etc/apparmor.d
, which only exists from the get-go if the OS ships with AppArmor. The check would normally protect against accessing a directory that doesn't exist, but since we stub out the filesystem functions in the tests, the tests will never fail if the OS doesn't have AppArmor.
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.
Don't forget to change the destination branch to dev
!
@@ -87,19 +101,45 @@ func LoadDefaultProfile(profileName string) error { | |||
return err | |||
} | |||
|
|||
includeTunablesGlobal, err := fileExists(filepath.Join(appArmorProfileDir, "tunables/global")) | |||
if err != nil { | |||
return err |
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.
Q: If we return an error here if tunables/global
doesn't exists, wouldn't this mean we'll never write @{PROC}=/proc/ to the profile? (please correct me if this is incorrect/the expected behavior!)
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.
If the file doesn't exist, fileExists
will return false
and no error, so we will still write the profile.
amazon-ecs-agent/ecs-init/apparmor/apparmor.go
Lines 139 to 141 in ed04257
if errors.Is(err, os.ErrNotExist) { | |
return false, nil | |
} |
These 3 test cases check for this (statErrors
are the errors os.Stat
is stubbed to return, and profileContent
is what's expected to be written to the profile):
amazon-ecs-agent/ecs-init/apparmor/apparmor_test.go
Lines 73 to 97 in ed04257
{ | |
name: "MissingTunablesGlobal", | |
profileName: "testProfile.txt", | |
statErrors: map[string]error{ | |
"tunables/global": os.ErrNotExist, | |
}, | |
profileContent: []string{"@{PROC}=/proc/", "#include <abstractions/base>"}, | |
}, | |
{ | |
name: "MissingAbstractionsBase", | |
profileName: "testProfile.txt", | |
statErrors: map[string]error{ | |
"abstractions/base": os.ErrNotExist, | |
}, | |
profileContent: []string{"#include <tunables/global>"}, | |
}, | |
{ | |
name: "MissingIncludes", | |
profileName: "testProfile.txt", | |
statErrors: map[string]error{ | |
"tunables/global": os.ErrNotExist, | |
"abstractions/base": os.ErrNotExist, | |
}, | |
profileContent: []string{"@{PROC}=/proc/"}, | |
}, |
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.
ah I see, thanks Tiffany!
ed04257
to
ced4bd0
Compare
ced4bd0
to
3d31970
Compare
Summary
ECS agent fails to start on SUSE Linux 15 because AppArmor can't load the ECS agent profile.
This is happening because SUSE Linux 15 doesn't ship with the AppArmor files the ECS agent profile depends on (
/etc/apparmor.d/tunables/global
and/etc/apparmor.d/abstractions/base
).Implementation details
To fix this, only write
#include
statements to the profile if the corresponding AppArmor files exist.Always write
@{PROC}=/proc/
to the profile If/etc/apparmor.d/tunables/global
does not exist, because the profile uses@{PROC}
.Prior art: https://github.com/moby/moby/blob/ac71ac1c92326635fffb5423f70891e53dc769e4/profiles/apparmor/apparmor.go#L38-L42
Testing
Built the .rpm per these instructions.
On a SUSE Linux 15 EC2 instance,
zypper install -y --allow-unsigned-rpm
systemctl start ecs
systemctl status ecs
/etc/apparmor.d/ecs-agent-default
On an AL2 EC2 instance,
yum install -y
systemctl start ecs
systemctl status ecs
/etc/apparmor.d/ecs-agent-default
did not exist (because AL2 does not support AppArmor)Built the .deb per these instructions.
On an Ubuntu 20.04 LTS EC2 instance,
apt install -y
systemctl start ecs
systemctl status ecs
/etc/apparmor.d/ecs-agent-default
New tests cover the changes: yes
Description for the changelog
Bug - Fixed a bug that could prevent ECS agent from starting on SUSE Linux 15
Does this PR include breaking model changes? If so, Have you added transformation functions?
No
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.