-
Notifications
You must be signed in to change notification settings - Fork 359
Fixed the issue in sysinfo where the dmidecode and fdisk - l commands were executed. #6179
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
Fixed the issue in sysinfo where the dmidecode and fdisk - l commands were executed. #6179
Conversation
… were executed. Description: Fixed the issue in sysinfo where the dmidecode and fdisk - l commands were executed. In the uos/deepin/openEuler desktop environment, data could not be obtained and had to be executed with sudo privilege.
Dear contributor, |
WalkthroughThe changes introduce a Changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Pylint (3.3.7)avocado/utils/sysinfo.pyavocado/core/sysinfo.py✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (1)
avocado/utils/sysinfo.py (1)
179-180
: Remove commented code.Clean up the commented line to improve code readability.
Apply this diff:
- # self.cmd, cmd_run,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
avocado/core/sysinfo.py
(1 hunks)avocado/utils/sysinfo.py
(2 hunks)
🧰 Additional context used
🪛 Flake8 (7.2.0)
avocado/utils/sysinfo.py
[error] 173-173: multiple spaces after operator
(E222)
⏰ Context from checks skipped due to timeout of 90000ms (24)
- GitHub Check: rpm-build:fedora-41-s390x
- GitHub Check: rpm-build:fedora-42-x86_64
- GitHub Check: rpm-build:centos-stream-9-x86_64
- GitHub Check: rpm-build:fedora-41-ppc64le
- GitHub Check: rpm-build:fedora-41-x86_64
- GitHub Check: rpm-build:fedora-rawhide-x86_64
- GitHub Check: rpm-build:fedora-41-aarch64
- GitHub Check: rpm-build:epel-9-x86_64
- GitHub Check: rpm-build:fedora-41-s390x
- GitHub Check: rpm-build:centos-stream-9-x86_64
- GitHub Check: rpm-build:fedora-rawhide-x86_64
- GitHub Check: rpm-build:epel-9-x86_64
- GitHub Check: rpm-build:fedora-41-aarch64
- GitHub Check: rpm-build:fedora-42-x86_64
- GitHub Check: rpm-build:fedora-41-ppc64le
- GitHub Check: rpm-build:fedora-41-x86_64
- GitHub Check: rpm-build:fedora-41-s390x
- GitHub Check: rpm-build:epel-9-x86_64
- GitHub Check: rpm-build:fedora-41-aarch64
- GitHub Check: rpm-build:fedora-41-x86_64
- GitHub Check: rpm-build:fedora-rawhide-x86_64
- GitHub Check: rpm-build:fedora-42-x86_64
- GitHub Check: rpm-build:centos-stream-9-x86_64
- GitHub Check: rpm-build:fedora-41-ppc64le
🔇 Additional comments (3)
avocado/utils/sysinfo.py (2)
135-141
: LGTM: Parameter addition is well-implemented.The
use_sudo
parameter is properly added with a sensible default value and correctly stored as an instance attribute.
209-210
: ```shell
#!/bin/bashDisplay the Daemon class definition including its init method
rg -A20 -n "class Daemon" avocado/utils/sysinfo.py
</details> <details> <summary>avocado/core/sysinfo.py (1)</summary> `135-135`: **Verify profiler daemon compatibility with sudo.** Ensure that profiler daemons work correctly when run with sudo privileges, as this may affect their ability to monitor user processes or access certain system resources. ```web What are the implications of running system profiler daemons (like perf, sar, iostat) with sudo privileges? Do they still properly monitor user processes and system resources?
|
||
cmd_run = self.cmd | ||
if self.use_sudo: | ||
cmd_run = f"sudo {self.cmd}" | ||
|
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.
🛠️ Refactor suggestion
Fix formatting issue and consider edge cases.
The implementation has a formatting issue and should handle edge cases better.
Apply this diff to fix the formatting and improve robustness:
-
- cmd_run = self.cmd
- if self.use_sudo:
- cmd_run = f"sudo {self.cmd}"
-
+ cmd_run = self.cmd
+ if self.use_sudo and not self.cmd.strip().startswith('sudo '):
+ cmd_run = f"sudo {self.cmd}"
This change:
- Fixes the formatting issue (multiple spaces after operator)
- Prevents duplicate sudo prefixes if the command already contains sudo
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
cmd_run = self.cmd | |
if self.use_sudo: | |
cmd_run = f"sudo {self.cmd}" | |
cmd_run = self.cmd | |
if self.use_sudo and not self.cmd.strip().startswith('sudo '): | |
cmd_run = f"sudo {self.cmd}" |
🧰 Tools
🪛 Flake8 (7.2.0)
[error] 173-173: multiple spaces after operator
(E222)
🤖 Prompt for AI Agents
In avocado/utils/sysinfo.py around lines 172 to 176, fix the formatting issue by
removing extra spaces around the assignment operator and improve robustness by
checking if the command already starts with "sudo" before prefixing it with
"sudo". Update the code to conditionally add "sudo" only if it is not already
present at the start of the command string.
self.start_collectibles.add(sysinfo.Daemon(cmd, locale=locale, use_sudo=True)) | ||
|
||
for cmd in self.sysinfo_files["commands"]: | ||
self.start_collectibles.add( | ||
sysinfo.Command(cmd, timeout=timeout, locale=locale) | ||
sysinfo.Command(cmd, timeout=timeout, locale=locale, use_sudo=True) | ||
) | ||
self.end_collectibles.add( | ||
sysinfo.Command(cmd, timeout=timeout, locale=locale) | ||
sysinfo.Command(cmd, timeout=timeout, locale=locale, use_sudo=True) | ||
) | ||
|
||
for fail_cmd in self.sysinfo_files["fail_commands"]: | ||
self.end_fail_collectibles.add( | ||
sysinfo.Command(fail_cmd, timeout=timeout, locale=locale) | ||
sysinfo.Command(fail_cmd, timeout=timeout, locale=locale, use_sudo=True) |
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.
🛠️ Refactor suggestion
Consider security implications of blanket sudo usage.
While the changes address the PR objective, running ALL system information commands with sudo privileges raises security concerns and may cause authentication prompts in automated environments.
Consider these improvements:
- Selective sudo usage: Only apply sudo to commands that actually require it (dmidecode, fdisk, etc.)
- Configuration option: Make sudo usage configurable rather than hardcoded
- Passwordless sudo: Document the need for passwordless sudo configuration for automation
Example selective approach:
# Commands that typically require elevated privileges
+SUDO_REQUIRED_COMMANDS = ['dmidecode', 'fdisk', 'lshw', 'smartctl']
+
+def _needs_sudo(cmd):
+ return any(cmd.strip().startswith(sudo_cmd) for sudo_cmd in SUDO_REQUIRED_COMMANDS)
+
for cmd in self.sysinfo_files["commands"]:
+ use_sudo = _needs_sudo(cmd)
self.start_collectibles.add(
- sysinfo.Command(cmd, timeout=timeout, locale=locale, use_sudo=True)
+ sysinfo.Command(cmd, timeout=timeout, locale=locale, use_sudo=use_sudo)
)
This approach minimizes security risk while still addressing the specific commands mentioned in the PR.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In avocado/core/sysinfo.py around lines 135 to 147, the current code applies
sudo to all system information commands indiscriminately, which poses security
risks and may trigger authentication prompts. Modify the code to apply sudo only
to specific commands that require elevated privileges, such as dmidecode or
fdisk. Implement a configuration option to control sudo usage instead of
hardcoding it, allowing flexibility for different environments. Additionally,
document the requirement for passwordless sudo setup to ensure smooth automation
without manual password entry.
Hi @richtja, Please help review the code and see if it needs to be optimized according to AI suggestions. It seems that the code has become more complex. |
Hi @xianglongfei-8888, sure thing, I can look into it. Unfortunately, I am unavailable right now, I will be able to do the review in two weeks. |
Hi @richtja, Thanks for your reply! |
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.
Hi @xianglongfei-8888, IMO using sudo as option for all sysinfo commands is not good idea, because those commands are configurable, and you can basically run anything through sysinfo commands which has potential security risks.
Probably specifying the commands which can be run with sudo and can't be rewritten would be a possible solution. @clebergnu, what do you think?
Hi @xianglongfei-8888, have you considered writing a wrapper script that uses sudo to collect the data you want? Since you'll have to configure your system anyway, you can add the sudo configuration, this wrapper script and the Avocado sysinfo configuration "at once". Let me know what you think. |
@richtja You're absolutely right! |
@richtja @clebergnu |
Fixed the issue in sysinfo where the dmidecode and fdisk - l commands were executed. In the uos/deepin/openEuler desktop environment, data could not be obtained and had to be executed with sudo privilege.
Before repair:
After repair:
Both the 'post' and 'pre' directories have been verified, and regular users have the ability to perform authorization operations and need to enter a password.
Summary by CodeRabbit
New Features
Bug Fixes