-
Notifications
You must be signed in to change notification settings - Fork 8
Changes for Duplicate IP detection script for Rokos #19
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
Open
rishu1102
wants to merge
13
commits into
main
Choose a base branch
from
user/rishusingh/duplicateIPdetection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eb18aed
Changes for Duplicate IP detection script. Contains PS1 script and YA…
c2d13ca
Addressing review comments. removed .ps1 script and embedded the scri…
beeff95
Adding ps1 script as multiline powershell does not work in YAML. Tryi…
648a6ed
removed testIndex that was being used for simulation
82c0832
Printing duplicate IP at the end.
c79589f
Coorecting the duplicate IP log dump.
e7e247f
Adding HNS trace collection ability to catch the dulpicate endpoint c…
d98f80d
Removing the test code
cc7936a
Embedding the script in YAML, removing --capture from pktmon.
7958b49
Reduced sleep time in loop. Added prestop hook for graceful pktmon stop.
060b15e
Changing trace size to 2048
0444b01
Changed the sleep time in while loop to 60 secs
4dc9f7d
removing endpoint IP dump logs in the loop
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| Write-Host "Detecting duplicate IP addresses on the node..." | ||
|
|
||
| $BaseDir = "c:\k\debug" | ||
|
|
||
| Write-Host "Trying to load HNS module..." | ||
|
|
||
| ipmo $BaseDir\hns.v2.psm1 -Force | Write-Host | ||
|
|
||
| $iter = 1 | ||
|
|
||
| pktmon stop # Stopping if pktmon is already running | ||
|
|
||
| # Start pktmon | ||
| Write-Host "Starting pktmon with trace level 6 for HNS" | ||
| pktmon start --trace -p Microsoft-Windows-Host-Network-Service -l 6 -f traces.etl -s 2048 | ||
|
|
||
| while($true){ | ||
| $ipAddresses = ((Get-HnsEndpoint).IpConfigurations).IpAddress | ||
|
|
||
| Write-Host "Checking for duplicate IP addresses inside the loop..." | ||
| $duplicateIpAddr = $ipAddresses | Group-Object | Where-Object { $_.Count -gt 1 } | ||
|
|
||
| if($duplicateIpAddr.Count -gt 0){ | ||
| break | ||
| } | ||
|
|
||
| $iter++ | ||
|
|
||
| Start-Sleep -Seconds 60 | ||
| } | ||
|
|
||
| Write-Host "Duplicate IP addresses found on the node, Duplicate IP addresses are:" | ||
|
|
||
| foreach($ipGroup in $duplicateIpAddr){ | ||
| Write-Host $ipGroup.Name | ||
| } | ||
|
|
||
| Write-Host "Stopping pktmon..." | ||
| # Stop pktmon | ||
| pktmon stop | ||
|
|
||
| Write-Host "Collecting Windows logs..." | ||
| $collectWindowsLogs = "$BaseDir\collect-windows-logs.ps1" | ||
| powershell $collectWindowsLogs | Write-Host | ||
|
|
||
| Write-Host "Collected Windows logs and trace are at $PWD" | ||
|
|
||
| while($true){ | ||
| if ($iter -Eq 1) { | ||
| Write-Host "The issue was detected in the first iteration and it may have happened already, and log rotation may have occurred." | ||
| } else { | ||
| Write-Host "Issue detected. Please download and review the collected Windows logs and also traces from the following path: $PWD\traces.etl" | ||
| } | ||
| Start-Sleep -Seconds 3600 | ||
| } |
39 changes: 39 additions & 0 deletions
39
scripts/duplicateIpDetection/DetectDuplicateIpAddress.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| apiVersion: apps/v1 | ||
| kind: DaemonSet | ||
| metadata: | ||
| name: detect-dup-ip | ||
| labels: | ||
| app: detect-dup-ip | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| name: detect-dup-ip | ||
| template: | ||
| metadata: | ||
| labels: | ||
| name: detect-dup-ip | ||
| spec: | ||
| securityContext: | ||
| windowsOptions: | ||
| hostProcess: true | ||
| runAsUserName: "NT AUTHORITY\\SYSTEM" | ||
| hostNetwork: true | ||
rishu1102 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| containers: | ||
| - name: detect-dup-ip | ||
| image: mcr.microsoft.com/dotnet/framework/samples:aspnetapp | ||
| command: | ||
| - powershell.exe | ||
| - -command | ||
| - | | ||
| Write-Host "Detecting duplicate IP addresses on the node..."; $BaseDir = "c:\k\debug"; Write-Host "Trying to load HNS module..."; ipmo $BaseDir\hns.v2.psm1 -Force | Write-Host; $iter = 1; pktmon stop; Write-Host "Starting pktmon with trace level 6 for HNS"; pktmon start --trace -p Microsoft-Windows-Host-Network-Service -l 6 -f traces.etl -s 2048; while($true){ $ipAddresses = ((Get-HnsEndpoint).IpConfigurations).IpAddress; Write-Host "Checking for duplicate IP addresses inside the loop..."; $duplicateIpAddr = $ipAddresses | Group-Object | Where-Object { $_.Count -gt 1 }; if($duplicateIpAddr.Count -gt 0){ break }; $iter++; Start-Sleep -Seconds 60 }; Write-Host "Duplicate IP addresses found on the node, Duplicate IP addresses are:"; foreach($ipGroup in $duplicateIpAddr){ Write-Host $ipGroup.Name }; Write-Host "Stopping pktmon..."; pktmon stop; Write-Host "Collecting Windows logs..."; $collectWindowsLogs = "$BaseDir\collect-windows-logs.ps1"; powershell $collectWindowsLogs | Write-Host; Write-Host "Collected Windows logs and trace are at $PWD"; while($true){ if ($iter -Eq 1) { Write-Host "The issue was detected in the first iteration and it may have happened already, and log rotation may have occurred." } else { Write-Host "Issue detected. Please download and review the collected Windows logs and also traces from the following path: $PWD\traces.etl" }; Start-Sleep -Seconds 3600 } | ||
| lifecycle: | ||
| preStop: | ||
| exec: | ||
| command: | ||
| - powershell.exe | ||
| - -Command | ||
| - "pktmon stop;sleep 20" | ||
| securityContext: | ||
| privileged: true | ||
| nodeSelector: | ||
| kubernetes.azure.com/os-sku: Windows2022 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| The script uses the Get-HnsEndpoint cmdlet to retrieve all IP addresses associated with the endpoints on the host. It then groups the IP addresses by value and filters the groups to include only those with more than one IP address. | ||
|
|
||
| To run the script, open a PowerShell window and run the following command: | ||
| PS> .\DetectDuplicateIpAddrs.ps1 | ||
|
|
||
| Once a duplicate IP address is detected, it breaks out of the while loop and then collects Windows logs on the node. | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.