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.
Address https://github.com/goodwithtech/dockle/blob/master/CHECKPOINT.md#cis-di-0008 by removing all
setuid
andsetgid
permissions after installing packages.Testing:
This is an esoteric corner of image security, so here's a background link as well as a summary and breakdown of the command (both courtesy of Claude):
https://www.scaler.com/topics/special-permissions-in-linux/
Here's the breakdown of the command:
The command
find / -path /proc -prune -o -perm /6000 -type f -exec chmod a-s {} + || true
consists of several key components that work together to find and modify files with special permissions. Let's examine each part:find /
This initiates a search starting from the root directory (/), which means it will scan the entire filesystem hierarchy.
-path /proc -prune
This tells find to skip the /proc directory. The /proc filesystem is virtual and contains process information that we don't need to scan. Pruning it improves efficiency and avoids potential errors.
-o
This is the OR operator. It connects our instruction to prune /proc with the rest of our search conditions. Think of it as saying "either prune /proc OR process this file according to our other conditions."
-perm /6000
This matches files with SUID (4000) and/or SGID (2000) bits set. The forward slash means we're matching files that have either or both bits set, not just files that have exactly these permissions.
-type f
This restricts our search to regular files only. We're not interested in directories, symbolic links, or other special file types when dealing with SUID/SGID permissions.
-exec chmod a-s {} +
This executes the chmod command on our matched files:
a-s
unsets the SUID and SGID bits for all users{}
is a placeholder that gets replaced with the filenames find discovers+
at the end means find will pass multiple filenames to chmod at once, making the operation more efficient than processing one file at a time|| true
This ensures our command returns a success status (exit code 0) even if some operations fail. We want to continue execution even if some permissions can't be modified.