-
Notifications
You must be signed in to change notification settings - Fork 2
Add SSH Key Permissions Check #18
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
base: main
Are you sure you want to change the base?
Changes from all commits
7c06316
d678dbb
f1c99f7
0013234
2403c6b
4915d71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,6 +308,55 @@ test_chmod_600() { | |
| [[ "$perms" == "600" ]] | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Test: CHK-PRM-013 auto-fix (SSH private key permissions) | ||
| # --------------------------------------------------------------------------- | ||
| test_prm_013() { | ||
| # Create mock SSH directory | ||
| local ssh_dir="${TEST_DIR}/.ssh" | ||
| mkdir -p "$ssh_dir" | ||
|
|
||
| # Create test SSH private keys | ||
| local test_key="${ssh_dir}/id_test_rsa" | ||
| local test_pem="${ssh_dir}/test.pem" | ||
|
|
||
| cat > "$test_key" <<'EOF' | ||
| -----BEGIN RSA PRIVATE KEY----- | ||
| fake key content | ||
| -----END RSA PRIVATE KEY----- | ||
| EOF | ||
|
|
||
| cat > "$test_pem" <<'EOF' | ||
| -----BEGIN PRIVATE KEY----- | ||
| fake pem content | ||
| -----END PRIVATE KEY----- | ||
| EOF | ||
|
|
||
| for key_file in "$test_key" "$test_pem"; do | ||
| # Set insecure permissions | ||
| chmod 644 "$key_file" | ||
|
|
||
| # Run the auto-fix command | ||
| chmod 600 "$key_file" | ||
|
|
||
| # Verify permissions were fixed | ||
| local perms | ||
| if [[ "$(uname -s)" == "Darwin" ]]; then | ||
| perms=$(stat -f "%Lp" "$key_file") | ||
| else | ||
| perms=$(stat -c "%a" "$key_file") | ||
| fi | ||
|
|
||
| if [[ "$perms" != "600" ]]; then | ||
| return 1 | ||
| fi | ||
| done | ||
| # NOTE: This test verifies the chmod auto-fix command works correctly, but | ||
| # does not exercise the scanner's find/detect logic itself. This is | ||
| # consistent with other integration tests in this file which focus on | ||
| # auto-fix command validation rather than scanner detection coverage. | ||
| } | ||
|
Comment on lines
+314
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test verifies that A more effective integration test would:
While this test is consistent with the existing style in this file, consider enhancing the test strategy to provide stronger guarantees about the scanner's behavior. |
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Main test execution | ||
| # --------------------------------------------------------------------------- | ||
|
|
@@ -336,6 +385,7 @@ run_test "CHK-CFG-010: Enable sensitive data redaction" "test_cfg_010" | |
| run_test "CHK-CFG-011: Enable browser restrictions" "test_cfg_011" | ||
| run_test "CHK-CFG-012: Disable network discovery" "test_cfg_012" | ||
| run_test "File permissions: chmod 600" "test_chmod_600" | ||
| run_test "CHK-PRM-013: Fix SSH key permissions" "test_prm_013" | ||
|
|
||
| echo "─────────────────────────────────────────────────────────────────────────────" | ||
| echo "" | ||
|
|
||
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.
The new test function
test_prm_013contains repeated logic for handling the two separate test key files. The file creation, permission changes, and verification steps are duplicated. To improve readability and maintainability, this can be refactored to use an array and a loop. This approach makes the test cleaner and easier to extend if you need to add more test cases in the future.