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

selinux permission denied, change mv to cp to maintain file context #2080

Closed
wants to merge 1 commit into from

Conversation

sahilbadla
Copy link

What type of PR is this?
bug

Which issue does this PR fix:
#2079

What does this PR do / Why do we need it:
This fixes the permissions issue experienced when SELinux enforcing mode is enabled. Entrypoint.sh script uses mv command(link) to write to host file system. When the aws-node container is killed or restarted it tries to write to the same file while has a different context(from the old container) and its not allowed by policies in SeLinux. To make it work with SeLinux, changing the mv command to cp works as cp maintains the context of file while writing.

Testing done on this change:
Unit testing
Tested with custom container image for amazon-k8s-cni

Automation added to e2e:

Will this PR introduce any new dependencies?:

Will this break upgrades or downgrades. Has updating a running cluster been tested?:

Does this change require updates to the CNI daemonset config files to work?:

Does this PR introduce any user-facing change?:
No

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sahilbadla sahilbadla requested a review from a team as a code owner September 9, 2022 21:49
@jayanthvn jayanthvn requested a review from achevuru September 9, 2022 23:27
@@ -196,7 +196,7 @@ if [[ "$ENABLE_BANDWIDTH_PLUGIN" == "true" ]]; then
mv "$TMP_AWS_BW_CONFLIST_FILE" "$TMP_AWS_CONFLIST_FILE"
fi

mv "$TMP_AWS_CONFLIST_FILE" "$HOST_CNI_CONFDIR_PATH/10-aws.conflist"
cp "$TMP_AWS_CONFLIST_FILE" "$HOST_CNI_CONFDIR_PATH/10-aws.conflist" && rm -rf "$TMP_AWS_CONFLIST_FILE"

Choose a reason for hiding this comment

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

Can you please a comment here explaining why we need to do this for SELinux? That way, folks looking at this later on wont optimize cp && rm for a mv and break SELinux

@sahilbadla
Copy link
Author

looks like this solutions unblocks the crashloop problem but issue still persists. Even though the pods get restarted fine, the file /host/etc/cni/net.d/10-aws.conflist never gets replaced. Logs are something like this:
type=AVC msg=audit(1663054943.599:343637): avc: denied { write } for pid=851535 comm="cp" name="10-aws.conflist" dev="nvme0n1p1" ino=36708256 scontext=system_u:system_r:container_t:s0:c880,c964 tcontext=system_u:object_r:container_file_t:s0:c241,c852 tclass=file permissive=0
that means even cp is not working with enforcing mode as the file to be written is in the host. Closing this PR.

@sahilbadla sahilbadla closed this Sep 13, 2022
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.

2 participants