Add ownership checks for storage directories#46725
Add ownership checks for storage directories#46725rads-1996 wants to merge 7 commits intoAzure:mainfrom
Conversation
6dd46aa to
48418a3
Compare
There was a problem hiding this comment.
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.tmpfiles. - 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. |
| return True | ||
| # Unix | ||
| else: | ||
| dir_stat = os.lstat(self._path) |
There was a problem hiding this comment.
Is the windows path not able to have an ownership check?
There was a problem hiding this comment.
You mean I should add a check in the if as well?
There was a problem hiding this comment.
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.
7c886c3 to
8aef93a
Compare
8aef93a to
f241334
Compare
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines