Skip to content
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

Resolve power permissions issues #35

Closed
wants to merge 2 commits into from
Closed

Conversation

NeonDaniel
Copy link
Member

@NeonDaniel NeonDaniel commented Oct 18, 2024

Add configuration option to use sudo with power commands (default True for backwards-compat)
Reverts behavior change introduced in #21
Closes #34

Summary by CodeRabbit

  • New Features

    • Introduced a new property sudo_power to enhance control over power-related commands.
    • Added a configuration-based property use_sudo_for_power to manage sudo usage for power operations.
  • Bug Fixes

    • Improved command execution for system power operations by ensuring correct sudo usage.

Add configuration option to use `sudo` with power commands
Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The changes introduce two new properties, sudo_power and use_sudo_for_power, in the SystemEventsPlugin class. The use_sudo_for_power property retrieves its value from configuration, defaulting to True, while sudo_power determines the use of sudo for power commands based on use_sudo_for_power. The reboot and shutdown request handling has been modified to conditionally include sudo in the command strings, enhancing control over system power operations without altering the overall structure of the plugin.

Changes

File Change Summary
ovos_PHAL_plugin_system/init.py Added sudo_power and use_sudo_for_power properties to SystemEventsPlugin, modified reboot/shutdown handling to conditionally use sudo.

Assessment against linked issues

Objective Addressed Explanation
Allow running reboot commands with sudo (34)

🐰 In the land of code, where changes bloom,
A new power setting dispels the gloom.
With sudo now ready, commands take flight,
Reboots and shutdowns, all work just right!
Hopping along, we celebrate this feat,
For a smoother journey, our code's now complete! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 81e8ade and 3f30e2a.

📒 Files selected for processing (1)
  • ovos_PHAL_plugin_system/init.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ovos_PHAL_plugin_system/init.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

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 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
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

🧹 Outside diff range and nitpick comments (3)
ovos_PHAL_plugin_system/__init__.py (3)

237-240: Approved: Reboot command now uses sudo based on configuration

The changes to the handle_reboot_request method successfully implement the use of sudo for the reboot command based on the sudo_power property. This aligns with the PR objectives and addresses the issue of reboot commands failing due to lack of interactive authentication.

For consistency with the property name, consider updating the condition:

if self.use_sudo_for_power:
    command = f"sudo {command}"

This assumes you've renamed the property as suggested in the previous comment.


255-258: Approved: Shutdown command now uses sudo based on configuration

The changes to the handle_shutdown_request method successfully implement the use of sudo for the shutdown command based on the sudo_power property. This is consistent with the changes made to the reboot method and aligns with the PR objectives.

For consistency with the property name, consider updating the condition:

if self.use_sudo_for_power:
    command = f"sudo {command}"

This assumes you've renamed the property as suggested in the first comment.


Line range hint 1-358: Summary: Successfully implemented configurable sudo usage for power commands

The changes in this file successfully address the objectives of the PR and the issue described in #34. Here's a summary of the improvements:

  1. A new property sudo_power (suggested to be renamed to use_sudo_for_power) has been added to control the use of sudo for power commands.
  2. Both handle_reboot_request and handle_shutdown_request methods have been updated to use sudo based on this property.
  3. The default behavior maintains compatibility with previous versions by using sudo unless explicitly disabled in the configuration.

These changes resolve the power permissions issues and allow for interactive reboots without encountering hangs, improving the overall user experience and functionality of the system.

Consider adding a brief comment in the code explaining the purpose of the use_sudo_for_power configuration option and its default value. This will help future maintainers understand the rationale behind this feature.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 99f68fa and 81e8ade.

📒 Files selected for processing (1)
  • ovos_PHAL_plugin_system/init.py (3 hunks)
🧰 Additional context used

ovos_PHAL_plugin_system/__init__.py Outdated Show resolved Hide resolved
@JarbasAl
Copy link
Member

JarbasAl commented Oct 18, 2024

wasnt the goal to move all sudo to PHAL admin plugin?


This plugin is a Admin plugin, it needs to run as root and to be explicitly enabled in mycroft.conf

{
"PHAL": {
    "admin": {
        "ovos-PHAL-plugin-system": {"enabled": true}
    }
}
}

if not enabled (omit config above) it will be run as the regular user, you need to ensure polkit policy is set to allow usage of systemctl without sudo. Not yet implemented

@NeonDaniel
Copy link
Member Author

wasnt the goal to move all sudo to PHAL admin plugin?

🤦 Right. Just a missed config change on my part

@NeonDaniel NeonDaniel closed this Oct 18, 2024
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.

Interactive reboot causes Mark2 to hang when rebooting
2 participants