Skip to content

fix(install_2fa): additional config checks#107

Merged
coincashew merged 2 commits intocoincashew:mainfrom
Jor-Tech:fix/additional-config-checks
May 10, 2025
Merged

fix(install_2fa): additional config checks#107
coincashew merged 2 commits intocoincashew:mainfrom
Jor-Tech:fix/additional-config-checks

Conversation

@Jor-Tech
Copy link
Copy Markdown
Contributor

@Jor-Tech Jor-Tech commented May 10, 2025

fix(2fa): Improve SSH configuration validation and handling

Changes

  • Added validation for required SSH configuration directives during 2FA installation
  • Improved handling of commented Include directives by uncommenting them instead of adding duplicates
  • Added check for KbdInteractiveAuthentication to ensure it's not disabled

Technical Details

  • Added check for Include /etc/ssh/sshd_config.d/*.conf directive
    • Now properly handles both commented and missing directives
    • Uses sed with pipe delimiter to avoid path escaping issues
  • Added check for KbdInteractiveAuthentication to ensure it's not set to "no"
  • Configuration checks only run during installation, not uninstallation
  • Maintains existing error handling and user feedback patterns

Testing

  • Verified that commented Include directives are properly uncommented
  • Confirmed that missing Include directives are added when needed
  • Tested that KbdInteractiveAuthentication is properly enabled
  • Validated that uninstall process remains unchanged

Security Impact

These changes ensure that all necessary SSH configuration is properly set up for 2FA to work correctly, preventing potential authentication issues while maintaining security best practices.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the SSH 2FA installation process by ensuring necessary SSH configuration directives are present and correctly set, enhancing reliability and compatibility during setup.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 10, 2025

Walkthrough

The installation script for SSH two-factor authentication now includes automated validation and correction of the SSH daemon configuration file. It ensures the Include /etc/ssh/sshd_config.d/*.conf directive is present and active, and sets KbdInteractiveAuthentication yes if missing or incorrectly configured.

Changes

File(s) Change Summary
helpers/install_2fa.sh Added logic to check, uncomment, or append the Include /etc/ssh/sshd_config.d/*.conf directive and to set KbdInteractiveAuthentication yes if needed in sshd_config.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant install_2fa.sh
    participant sshd_config
    participant SSH Service

    User->>install_2fa.sh: Run script
    install_2fa.sh->>sshd_config: Check for Include directive
    alt Include commented out
        install_2fa.sh->>sshd_config: Uncomment Include directive
    else Include missing
        install_2fa.sh->>sshd_config: Append Include directive
    end
    install_2fa.sh->>sshd_config: Check KbdInteractiveAuthentication setting
    alt Setting exists but not yes
        install_2fa.sh->>sshd_config: Change to yes
    else Setting missing
        install_2fa.sh->>sshd_config: Append setting with yes
    end
    install_2fa.sh->>SSH Service: Validate config and restart
Loading

Poem

🐇
With nimble paws I scan and check,
SSH configs—no room for wreck!
Includes are found, or lines restored,
Authentication now assured.
Two factors strong, the script runs through—
Secure and tidy, thanks to you!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91e0c46 and b7f37c2.

📒 Files selected for processing (1)
  • helpers/install_2fa.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • helpers/install_2fa.sh
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
helpers/install_2fa.sh (1)

73-82: Refine Include directive detection and addition
The current logic only matches lines that begin exactly with #Include or Include, missing cases with leading whitespace or commented variants like # Include. We can consolidate the uncomment and append steps into a single, more robust sed invocation that handles whitespace and optional comment characters.

Proposed diff:

-    # Check if Include directive is present and not commented out
-    if grep -q "^#Include /etc/ssh/sshd_config.d/\*.conf" /etc/ssh/sshd_config; then
-        echo "❌ Include directive is commented out in /etc/ssh/sshd_config"
-        echo "✏️  Uncommenting Include directive..."
-        sudo sed -i 's|^#Include /etc/ssh/sshd_config.d/\*.conf|Include /etc/ssh/sshd_config.d/*.conf|' /etc/ssh/sshd_config
-    elif ! grep -q "^Include /etc/ssh/sshd_config.d/\*.conf" /etc/ssh/sshd_config; then
-        echo "❌ Required Include directive not found in /etc/ssh/sshd_config"
-        echo "✏️  Adding Include directive..."
-        echo "Include /etc/ssh/sshd_config.d/*.conf" | sudo tee -a /etc/ssh/sshd_config
-    fi
+    # Ensure the Include directive exists and is active
+    if grep -qE "^[[:space:]]*#?[[:space:]]*Include /etc/ssh/sshd_config.d/\\*\\.conf" /etc/ssh/sshd_config; then
+        echo "✏️  Normalizing Include directive in /etc/ssh/sshd_config"
+        sudo sed -ri 's|^[[:space:]]*#?[[:space:]]*Include /etc/ssh/sshd_config.d/\*\.conf|Include /etc/ssh/sshd_config.d/*.conf|' /etc/ssh/sshd_config
+    else
+        echo "✏️  Adding Include directive to /etc/ssh/sshd_config"
+        echo "Include /etc/ssh/sshd_config.d/*.conf" | sudo tee -a /etc/ssh/sshd_config
+    fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1dc80ac and 91e0c46.

📒 Files selected for processing (1)
  • helpers/install_2fa.sh (1 hunks)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@coincashew
Copy link
Copy Markdown
Owner

👍 👍
Thanks for this improvement!

@coincashew coincashew merged commit b833ab2 into coincashew:main May 10, 2025
1 check passed
@Jor-Tech Jor-Tech deleted the fix/additional-config-checks branch May 10, 2025 22:01
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