-
Notifications
You must be signed in to change notification settings - Fork 120
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
Bugfix/151- Ensure all scripts use UTC time instead of local time #203
base: Development
Are you sure you want to change the base?
Bugfix/151- Ensure all scripts use UTC time instead of local time #203
Conversation
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.
I've been reviewing your pull request for a few hours and will be kicking it back to you for some modifications:
Files That Need Modification
After taking a closer look at all of the functions that are using get-date across the code base and getting a better understanding this morning Initialize-HawkGlobalObject , it looks like there are only two files that need to be modified to use UTC across the code base those are: Initialize-HawkGlobalObject and Out-LogFile
The reason for this is, Initialize-HawkGlobalObject initializes the global StartDate and EndDate variables, which are used across the code base, meaning that all of the other functions that we saw using the local time Get-Time and thought needed to be changed as well, do not, bc they obtain those dates from Initialize-HawkGlobalObject , which once you make those changes will be in UTC. One very important thing to note is at first glance, making these changes should not affect existing functionality of other functions getting StartDate / EndDate from Initialize-HawkGlobalObject , but once you do update that, you will want to give Hawk some test runs to make sure the updated code doesn't break anything elsewhere
With that being said, you'll want to revert uncecessary UTC changes in the following files:
Hawk/functions/Message/Get-HawkMessageHeader.ps1
Hawk/functions/Tenant/Get-HawkTenantAuthHistory.ps1
Hawk/internal/functions/Get-AllUnifiedAuditLogEntry.ps1
Hawk/internal/functions/Import-AzureAuthenticationLogs.ps1
Incorrect UTC Conversion Syntax
After running the code changes you made, it errored out bc of the -AsUTC parameter being using in Get-Date , doing some more research, it looks like the ppropriate way to convert local to UTC is by using .ToUniversalTime, see examples below
Incorrect example
Return ("Agreed " + (Get-Date -AsUTC)).ToString()
Correct example
Return ("Agreed " + (Get-Date).ToUniversalTime()).ToString()
Deleted Files
I am not sure what happend here, but it looks liek you deleted multipel legimtiate files across the code base, those being:
hawk\tests\functions\readme.md
hawk\tests\general\FileIntegrity.Exceptions.ps1
hawk\tests\general\FileIntegrity.Tests.ps1
hawk\tests\general\Help.Exceptions.ps1
hawk\tests\general\Help.Tests.ps1
hawk\tests\general\Manifest.Tests.ps1
hawk\tests\general\strings.Exceptions.ps1
hawk\tests\general\strings.Tests.ps1
hawk\tests\general\Test-PreCommitHook.ps1
hawk\tests\general\readme.md
hawk\tests\pester.ps1
You will need to restore those on your next pull request
Uncessary Files in the Code Base
The word doc you uploaded was very helpfult to the PSSA scan being ran, but next time you should upload it to the ticket or add it to your pull request. We don't want to pollute the repo with our internal docs / tests as other users who downlaod hawk will see this.
Log files generated during program execution were also committed. These files should not be included in the repository:
hawk\internal\functions\AuditLog.csv
hawk\internal\functions\AuditLog_Updated.csv
hawk\internal\functions\AuditLogs.csv
Please remove these files from the repository.
To avoid this from haepping in the future, I recommend updating your .gitignore file with the following:
Ignore all .csv, .json, .docx, and .xlsx files
*.csv
*.json
*.docx
*.doc
*.xlsx
License File
The file Hawk/internal/scripts/license.ps1 does not need to be converted to UTC. This script is purely for generating license files and is not used for forensic analysis.
Additional guidance
While reviewing your changes, I realized the scope of files needing updates for UTC conversion was more limited than initially thought. This was not clear to me until I reviewed the code base more thoroughly. If in the future you are working a ticket / issue that doesn’t seem correct or makes you uncertain, please don’t hesitate to ask me for clarification. I’m always happy to discuss and adjust the scope of work as needed.
Before submitting a pull request, please ensure you test the code changes by running the scripts. For example, the -AsUTC parameter you used is invalid and causes the code to break. Running the code would have revealed this issue. Keep in mind that Invoke-ScriptAnalyzer performs static code analysis to check for formatting and best practices but does not validate runtime functionality. Always execute the modified code to confirm it works as intended.
if you want to hop on a video chat later today i wil be avaialble around 3 - 6 to discuss and more than happy to help out.
…-time-instead-of-local-time
…ze-HawkGlobalObject.ps1
…nitialize-HawkGlobalObject.ps1
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.
Thanks for adding back all the test files, and reverting some of the -AsUTC chnages.
I am in your branch right now with the most current changes, and upon trying to import the module I received this error...
Looking at the error, it mentiosn 'AsUTC' paramter not being recongized, so I did a quick search and found that paramters still being used in Get-AllUnifiedAuditLogEntry and throghout Initialize-HawkGLobalObject. Instead of using that you will need to convert all local times to UTC using (Get-Date).ToUniversalTime()
Also, the only files that shouldddd need to be changed to use UTC based upon my review yesterday is Initialize-HawkGLobalObject and Out-Logfile . You will still want to import the porgram and give it a test run though to verify.
I also noticed license.ps1 is using ASUTC still, that file does not need to be modified at all, is its only a license file.
im going to send this merge request back your way for now.
6:44
Lastly, the one thing I am maybe thinking is perhaps you made all the changes to Initialize-HawkGLobalObject locally, but maybe didnt push them in your commit? I would verify the status of what you have locally and vs whats in the repo
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.
These changes are good. No issues here.
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.
Curious as to what these changes are for? This doesn't fix UTC issues, please let me know what the changes are for.
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.
I did not modify any code here; I simply aligned the # characters, which resolved the following issue:
calling "InvokeScript" with "4" argument(s): "The term '<#' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again."
At C:\Projects\hawk\Hawk\hawk.psm1:76 char:9
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.
Changes were made to this file that were not associated with this ticket, please revert these changes.
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.
didn't change
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.
This should not be in the repo, this is an output file from hawk being ran.
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.
This should not be in the repo, this is an output file from hawk being ran.
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.
This should not be in the repo, this is an output file from hawk being ran.
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.
This should not be in the repo, this is an output file from hawk being ran.
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.
This should not be in the repo, this is an output file from hawk being ran.
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.
This should not be in the repo, this is an output file from hawk being ran.
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.
This should not be in the repo, this is an output file from hawk being ran.
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.
This should not be in the repo, this is an output file from hawk being ran.
Pull Request Template
Description
This pull request updates all scripts to ensure that UTC time is used instead of local time. This change addresses the issue of inconsistent time formats and aligns with the project's global standards.
Fixes # (issue)
Type of change
The changes include:
Replacing all instances of local time usage with UTC time in scripts.
Running PSScriptAnalyzer (PSSA) scans to ensure code quality and compliance.
Please delete options that are not relevant.
How Has This Been Tested?
All modified scripts were scanned using PSScriptAnalyzer with the project's configuration to ensure compliance.
Manual testing was performed to verify the correct use of UTC time in outputs.
The changes were validated by running the existing test cases to confirm no regressions were introduced.
Checklist: