Skip to content

feat: tedge diag collect security enhancement#3698

Merged
rina23q merged 1 commit intothin-edge:mainfrom
rina23q:improve/3646/tedge-diag-collect-security-enhancement
Jun 23, 2025
Merged

feat: tedge diag collect security enhancement#3698
rina23q merged 1 commit intothin-edge:mainfrom
rina23q:improve/3646/tedge-diag-collect-security-enhancement

Conversation

@rina23q
Copy link
Copy Markdown
Member

@rina23q rina23q commented Jun 20, 2025

Proposed changes

To enhance the security, if the process is run by root, the plugin must meet those conditions:

  • owned by root
  • not writable by other users

Otherwise, these files will be skipped.

warning: Skipping file: /setup/diag-plugins/owned_by_non_root.sh (not owned by root)
warning: Skipping file: /setup/diag-plugins/writable_by_other_users.sh (writable by non-root users)

(P.S. This is the last follow-up task for tedge diag collect!)

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#3646

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 20, 2025

Codecov Report

Attention: Patch coverage is 60.60606% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/core/tedge/src/cli/diag/collect.rs 60.60% 10 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 20, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
652 0 3 652 100 1h53m1.390300999s

@rina23q rina23q force-pushed the improve/3646/tedge-diag-collect-security-enhancement branch from 9954a42 to 152d74d Compare June 20, 2025 16:10
@rina23q rina23q temporarily deployed to Test Pull Request June 20, 2025 16:11 — with GitHub Actions Inactive
@rina23q rina23q marked this pull request as draft June 20, 2025 22:57
@rina23q rina23q force-pushed the improve/3646/tedge-diag-collect-security-enhancement branch from 152d74d to 8b12358 Compare June 21, 2025 13:11
@rina23q rina23q temporarily deployed to Test Pull Request June 21, 2025 13:11 — with GitHub Actions Inactive
@rina23q rina23q marked this pull request as ready for review June 21, 2025 13:40
}

// extra metadata check when the process is running by the root user for the security
if get_current_uid() == 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need the additional uzers crate to fetch the uid? Could have fetched it from MetadataExt, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need the additional uzers crate to fetch the uid? Could have fetched it from MetadataExt, right?

The point is to get the id of the current user, not the id of the file owner.

As two kinds of user id are used here, I would be explicit:

Suggested change
if get_current_uid() == 0 {
if uzers.get_current_uid() == 0 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The point is to get the id of the current user, not the id of the file owner.

This is correct.

Changed as suggested in 8b7b787

logger.warning(&format!("Skipping file: {path} (not owned by root)"));
return false;
}
if metadata.permissions().mode() & 0o022 != 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't really understand the reasoning behind this restriction. Even the one above. What if the normal user on the device created the script? Why reject that? Do we have similar restrictions for the software management plugins as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The goal is to prevent a user from misleading the root user, i.e. to write a malware script that would be executed with admin privileges by sudo tedge diag collect.

Software management plugins are not executed directly by the agent but delegated to sudo.

}

// extra metadata check when the process is running by the root user for the security
if get_current_uid() == 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need the additional uzers crate to fetch the uid? Could have fetched it from MetadataExt, right?

The point is to get the id of the current user, not the id of the file owner.

As two kinds of user id are used here, I would be explicit:

Suggested change
if get_current_uid() == 0 {
if uzers.get_current_uid() == 0 {

Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Approved

If the process is run by root, the plugin must meet those conditions:
* owned by root
* not writable by other users

Signed-off-by: Rina Fujino <rina.fujino.23@gmail.com>
@rina23q rina23q force-pushed the improve/3646/tedge-diag-collect-security-enhancement branch from 8b7b787 to 72e4e95 Compare June 23, 2025 11:57
@rina23q rina23q temporarily deployed to Test Pull Request June 23, 2025 11:57 — with GitHub Actions Inactive
@reubenmiller reubenmiller added the theme:troubleshooting Theme: Troubleshooting and remote control label Jun 23, 2025
@reubenmiller reubenmiller added the skip-release-notes Don't include the ticket in the auto generated release notes label Jun 23, 2025
Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

LGTM

@rina23q rina23q added this pull request to the merge queue Jun 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 23, 2025
@rina23q rina23q added this pull request to the merge queue Jun 23, 2025
Merged via the queue into thin-edge:main with commit bff20b2 Jun 23, 2025
34 checks passed
@rina23q rina23q deleted the improve/3646/tedge-diag-collect-security-enhancement branch August 8, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-release-notes Don't include the ticket in the auto generated release notes theme:troubleshooting Theme: Troubleshooting and remote control

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants