Skip to content

Add ownership checks for storage directories#46725

Open
rads-1996 wants to merge 7 commits intoAzure:mainfrom
rads-1996:fix-tmp-path-permissions
Open

Add ownership checks for storage directories#46725
rads-1996 wants to merge 7 commits intoAzure:mainfrom
rads-1996:fix-tmp-path-permissions

Conversation

@rads-1996
Copy link
Copy Markdown
Member

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI review requested due to automatic review settings May 5, 2026 19:57
@rads-1996 rads-1996 force-pushed the fix-tmp-path-permissions branch from 6dd46aa to 48418a3 Compare May 5, 2026 19:59
@github-actions github-actions Bot added the Monitor - Exporter Monitor OpenTelemetry Exporter label May 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds hardening for local storage by verifying directory ownership on Unix-like systems and using atomic file creation to mitigate race-condition style attacks.

Changes:

  • Switch temp-file writes to os.open(..., O_CREAT | O_EXCL, ...) to prevent overwrite/race conditions when creating .tmp files.
  • Add Unix directory ownership validation (must be owned by current uid or root) before enabling local storage.
  • Expand unit tests to cover ownership outcomes and attacker scenarios (pre-created dirs, symlinks, pre-created temp files).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_storage.py Updates existing tests for os.open and adds new tests for directory ownership and attack scenarios.
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_storage.py Implements atomic .tmp creation via O_EXCL and adds Unix ownership checks using lstat/getuid.
sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md Documents the new ownership-check behavior in the unreleased changelog.

Comment thread sdk/monitor/azure-monitor-opentelemetry-exporter/tests/test_storage.py Outdated
Comment thread sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md
return True
# Unix
else:
dir_stat = os.lstat(self._path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the windows path not able to have an ownership check?

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.

You mean I should add a check in the if as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like the Windows ownership check might be significantly more involved (at least according to copilot). This PR is fine without it, but might be good to include in the future if we're getting flagged for not having this ownership check in Linux.

@rads-1996 rads-1996 force-pushed the fix-tmp-path-permissions branch 2 times, most recently from 7c886c3 to 8aef93a Compare May 5, 2026 23:14
@rads-1996 rads-1996 force-pushed the fix-tmp-path-permissions branch from 8aef93a to f241334 Compare May 5, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Monitor - Exporter Monitor OpenTelemetry Exporter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants