-
Notifications
You must be signed in to change notification settings - Fork 105
Fix windows redaction clean #1876
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
Closed
Closed
Conversation
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
- Add Windows-specific copy+delete file replacement strategy - Preserve original Linux/macOS behavior exactly (no changes) - Use runtime.GOOS detection for platform-specific handling only - Fixes GitHub issue #1607 without affecting other platforms Windows changes: - replaceFileWindows() with retry logic and copy+delete approach - copyAndDeleteWindows() for robust file operations - isWindowsFileLockError() for smart error detection Linux/macOS unchanged: - Still uses original os.Rename() behavior - Still uses system temp directory - Zero functional impact
- Windows: Use working directory for bundle extraction temp files - Linux/macOS: Preserve original system temp behavior exactly - Prevents antivirus file locking during bundle processing on Windows - Zero impact on Linux/macOS functionality Complete Windows-only solution for GitHub issue #1607
NoaheCampbell
requested changes
Oct 3, 2025
} else { | ||
// Linux/macOS: EXACT original behavior - DO NOT CHANGE | ||
err = os.Rename(tmpFile.Name(), filepath.Join(bundlePath, relativePath)) | ||
} |
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.
It looks like bugbot is right about this to me, the file is removed and then its copied? Shouldnt it be copied before its deleted?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description, Motivation and Context
Fixes Windows redaction file locking failures that completely prevented support bundle redaction from working on Windows systems.
Problem: Support bundle redaction consistently failed on Windows with "Access is denied" and "file is being used by another process" errors during file operations, making redaction unusable for Windows users.
Solution: Implemented Windows-specific file handling that uses destination directory temp files and copy+delete operations instead of system temp and rename operations, which are more compatible with Windows file system behavior and antivirus software.
Impact: Windows users can now successfully run support bundle redaction without file locking crashes.
Fixes: #1607
Checklist
Does this PR introduce a breaking change?
Technical Changes:
runtime.GOOS
for Windows-specific handling onlyTest commands for redaction
Multiline Redaction
Use unnamed capture group for the key, named capture for the value
@"
apiVersion: troubleshoot.sh/v1beta2
kind: Redactor
metadata:
name: multiline-regex-test
spec:
redactors:
name: Redact password value
removals:
regex:
redactor: '(password:\s*)(?P.*)'
name: Redact api_secret value
removals:
regex:
redactor: '(api_secret:\s*)(?P.*)'
"@ | Out-File -FilePath C:\Users\Public\Downloads\test-troubleshoot\multiline-redactor.yaml -Encoding UTF8 -Force
.\bin\troubleshoot.exe redact --bundle C:\Users\Public\Downloads\test-troubleshoot\multiline-test.tar.gz C:\Users\Public\Downloads\test-troubleshoot\multiline-redactor.yaml
Check results
$latest = Get-Item redacted-support-bundle-*.tar.gz | Sort-Object LastWriteTime | Select-Object -Last 1
tar -xzf $latest.Name
Get-Content multiline-test\credentials.txt
Single-line redaction
Create a redactor using VALUES (literal string replacement)
@"
apiVersion: troubleshoot.sh/v1beta2
kind: Redactor
metadata:
name: test-redactor
spec:
redactors:
removals:
values:
"@ | Out-File -FilePath C:\Users\Public\Downloads\test-troubleshoot\values-redactor.yaml -Encoding UTF8
Test with values redactor
.\bin\troubleshoot.exe redact --bundle C:\Users\Public\Downloads\test-troubleshoot\test-bundle.tar.gz C:\Users\Public\Downloads\test-troubleshoot\values-redactor.yaml
Extract and check - the word "password" and "token" should be replaced with "HIDDEN"
tar -xzf (Get-Item redacted-support-bundle-*.tar.gz | Sort-Object LastWriteTime | Select-Object -Last 1).Name
Get-Content test-bundle\cluster-resources\secret.json