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

fix: Add logging to Windows permissions checks #548

Conversation

DaveTryon
Copy link
Contributor

As called out in #444, we need to provide a little more help in debugging some directory permission failures. This PR adds an ILogger to the WindowsFileSystemUtils class, so that we can log the Exceptions that are caught in that class.

There was a //TODO in the original code, suggesting that we would log this at Debug level. This makes total sense, but I encountered a problem when testing this--the Config that exposes the user-configured verbosity level only becomes available after we need to create the WindowsFileSystemUtils, and none of the variations I tried were successful in altering that order. Due to this, I opted to log the error at Warning level, so that it would show up with the default settings but not show up as the key problem.

Testing
I inserted a test Exception inside the DirectoryHasRights method and tested locally to confirm that the Exception appears as a warning in the output. I then removed the test Exception and tested the following scenarios locally to ensure that our "expected" scenarios work without displaying an additional Exception:

  • Trying to write to a protected directory (C:\Windows)
  • Trying to write to a non-existent directory (C:\NotThere)
  • Trying to write to a non-existent network drive (Q:)
  • Trying to write to a non-existent UNC path (\FOO\BAR)

The net result is that the new warning displays only in cases where an Exception is thrown inside WindowsFileSystemUtils.DirectoryHasRights. Flow continues as it did before.

@DaveTryon DaveTryon requested a review from a team as a code owner April 11, 2024 23:08
@DaveTryon DaveTryon requested review from jalkire and edgarrs April 11, 2024 23:08
@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 59.66%. Comparing base (2a08f59) to head (d4e20fc).

Files Patch % Lines
...rc/Microsoft.Sbom.Common/WindowsFileSystemUtils.cs 0.00% 6 Missing ⚠️
...c/Microsoft.Sbom.Common/FileSystemUtilsProvider.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #548      +/-   ##
==========================================
- Coverage   59.70%   59.66%   -0.04%     
==========================================
  Files         248      248              
  Lines        7576     7581       +5     
  Branches      901      902       +1     
==========================================
  Hits         4523     4523              
- Misses       2640     2645       +5     
  Partials      413      413              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DaveTryon DaveTryon merged commit 44dc753 into microsoft:main Apr 12, 2024
6 checks passed
@DaveTryon DaveTryon deleted the add-logging-to-windows-folder-permissions-checks branch April 12, 2024 18:23
tarun06 pushed a commit to tarun06/sbom-tool that referenced this pull request Jul 21, 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.

3 participants