Add support for setting capabilities on the app binary#1271
Merged
imjasonh merged 3 commits intoko-build:mainfrom Apr 3, 2024
mejedi:capabilities
Merged
Add support for setting capabilities on the app binary#1271imjasonh merged 3 commits intoko-build:mainfrom mejedi:capabilities
imjasonh merged 3 commits intoko-build:mainfrom
mejedi:capabilities
Conversation
imjasonh
reviewed
Apr 2, 2024
Member
imjasonh
left a comment
There was a problem hiding this comment.
This looks really good! Thanks for the exhaustive test cases, that makes reviewing this for correctness a lot easier.
Just a few code style things, nothing major.
Build.Config contains LdFlags and Flags, both arrays of strings. For user convenience it should be possible to specify a single string instead. FlagArray (Flags) and StringArray (LdFlags) implement YAMLUnmarshaller interface to handle custom parsing logic. Since build.Config is loaded via viper/mapstructure and not the YAML parser, YAMLUnmarshaller interface was ignored. Wire things up. Signed-off-by: Nick Zavaritsky <mejedi@gmail.com>
Signed-off-by: Nick Zavaritsky <mejedi@gmail.com>
Signed-off-by: Nick Zavaritsky <mejedi@gmail.com>
Contributor
Author
Thank you for taking a look! I've implemented suggestions and fixed issues reported by linters. |
imjasonh
approved these changes
Apr 3, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patchset adds
linux_capabilitiesunderbuildssection in.ko.yaml. Ex:A bit of trivia on capabilities: unless running the app as root user, Docker's
--cap-addalone is insufficient.Requested capabilities are AND-combined with capabilities granted to the app binary (intentionally simplified, see
man capabilitiesfor the full discourse).A running program has multiple sets of capabilities. The most important ones are
effective(used by the kernel for permission checks) andpermitted(a "stash" of capabilities an app can promote to effective). Likewise, file capabilities capture multiple sets of capabilities,permittedbeing the most important.The config above sets
permittedcapabilities on the app binary tobpf,perfmon, andnet_admin. When the app is launched, this set is AND-combined with capabilities requested via--cap-addand the result becomes the running app'spermittedcapabilities. The app should verify if it got all required capabilities and promotepermittedcapabilities toeffective.File capabilities have a bit that tells the kernel to automatically promote
permittedtoeffective. The downside is that the program will fail to start with genericEPERMerror if some capabilities weren't granted. In order to access this feature, and to make transition fromDockerfileeasier, we also support the fullsetcapsyntax inlinux_capabilities, e.g.:Fixes #1246