oscap-ssh: simplify to allow limited sudo rule#1881
Open
maage wants to merge 8 commits intoOpenSCAP:maint-1.3from
Open
oscap-ssh: simplify to allow limited sudo rule#1881maage wants to merge 8 commits intoOpenSCAP:maint-1.3from
maage wants to merge 8 commits intoOpenSCAP:maint-1.3from
Conversation
Handle options conversions up to 2nd last arg as last is input and is
handled next.
(( ..., 1 )) ensures return value is ok.
arr[-1] is last element
From shellcheck:
In utils/oscap-ssh line 217:
for i in $(seq 0 `expr $# - 1`); do
^-----------^ SC2046: Quote this to prevent word splitting.
^-----------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
^--^ SC2003: expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].
Did you mean:
for i in $(seq 0 $(expr $# - 1)); do
In utils/oscap-ssh line 218:
let j=i+1
^-------^ SC2219: Instead of 'let expr', prefer (( expr )) .
In utils/oscap-ssh line 267:
LOCAL_CONTENT_PATH="${oscap_args[`expr $# - 1`]}"
^-----------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
^--^ SC2003: expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].
Did you mean:
LOCAL_CONTENT_PATH="${oscap_args[$(expr $# - 1)]}"
In utils/oscap-ssh line 268:
oscap_args[`expr $# - 1`]="$REMOTE_TEMP_DIR/input.xml"
^-----------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
^--^ SC2003: expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].
Did you mean:
oscap_args[$(expr $# - 1)]="$REMOTE_TEMP_DIR/input.xml"
- use printf %q instead of home made implementation
- use $@
- there is no point using fancy array arrayref and eval in this simple
use case
- printf just iterates parameters and "$@" works just fine
- changes usage:
from: command_array_to_string arref
to: command_array_to_string "${array[@]}"
Change OSCAP_SUDO as array and after this there is no need to test it.
Fail if can not cd into a directory. Shellcheck would warn about this.
This ensures whole command is quoted.
This is needed sometimes when debugging.
Contributor
Author
|
Two test enva failed at |
Contributor
|
Hey, @maage. Can you please rebase the PR? |
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.
With this patch set I can use very limited sudo rule when running
oscap xccdf eval.Also address some shellcheck warnings.
Without this to try to limit how sudo needs to be configured, sudoers rule needs to have
/usr/bin/shpermission, exec permission (sh -c), and runchownwithout known path. This is too broad.chownis not needed asumask 022+rm -rf diris enough to remove files as directory is user owned.My example rule:
xccdf evalunder sudo, example user is namedoscap-eval-user.evalare accepted, tune for your solutionoscapasunconfined_t. This is default, but rule just ensures it works even if SELinux user (staff_u) are used.requirettyonly for this user, so there is no issues, but not expose other users.