Fix logs forwarding: input validation, missing return bug, and isSafeURL localhost regression#515
Draft
Fix logs forwarding: input validation, missing return bug, and isSafeURL localhost regression#515
Conversation
✅ Deploy Preview for interlink-dev canceled.
|
…ovements Agent-Logs-Url: https://github.com/interlink-hq/interLink/sessions/a4cec72d-3048-4b9f-a71a-721bcb5af05d Co-authored-by: dciangot <4144326+dciangot@users.noreply.github.com>
…feURL Agent-Logs-Url: https://github.com/interlink-hq/interLink/sessions/a4cec72d-3048-4b9f-a71a-721bcb5af05d Co-authored-by: dciangot <4144326+dciangot@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve SLURM plugin logs forwarding implementation
Fix logs forwarding: input validation, missing return bug, and isSafeURL localhost regression
Apr 2, 2026
Signed-off-by: Diego Ciangottini <dciangot@cern.ch>
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
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.
The logs forwarding handler had a silent bug that forwarded requests to the sidecar even after writing a conflict error, missing input validation that left path traversal open, and an
isSafeURLcheck that blocked localhost—breaking allhttptest-based tests and any deployment where the sidecar runs locally.Fixes
logs.goSinceSeconds+SinceTimeconflict wrote an error response but fell through to forward the request anyway. Both conflict checks nowreturnimmediately.validateLogRequest()with regex validation forNamespace(RFC 1123 label),PodUID(UUID), andContainerName(RFC 1123 label). The sidecar constructs file paths from these values—unvalidated input allows path traversal.400 Bad Requestinstead of500.http.NewRequest→http.NewRequestWithContext(r.Context(), ...)so client disconnects cancel the in-flight sidecar request.statusCodevariable and dead commented-out transport code.handler.go/execute.goisSafeURLover-blocked localhost: Removed thelocalhost/127.0.0.1/::1/.internalrestriction. These URLs come from operator config files, not user input; the sidecar and interLink API routinely run on the same host or private network. The scheme check (http/httpsonly) is sufficient.isSafeURLcall inReqWithError.func.go"Docker Sidecar"→"Sidecar".New tests (
logs_test.go)TestValidateLogRequest: valid inputs, path traversal attempts (../../etc/passwd), bad formatsTestGetLogsHandler_Validation: end-to-end handler behavior for valid requests, invalid fields, conflicting optionsTestIsSafeURL: confirmsfile:///ftp://are blocked,http://localhostis allowedOriginal prompt
Overview
The SLURM plugin's logs forwarding implementation currently has several areas that need improvement to ensure reliability, performance, security, and maintainability. This issue tracks a comprehensive list of enhancements across 13 categories.
Critical Issues 🔴
1. Memory Management & Streaming
Problem: Current implementation loads entire log files into memory using
os.ReadFile(), causing memory spikes with large logs (>100MB).Impact: OOM errors, performance degradation with verbose applications
os.ReadFile()with streaming approach using buffered readers2. Follow Mode - Replace Polling with Event-Driven Approach
Problem: Current follow mode uses 4-second polling (lines 63, 134 in GetLogs.go), causing inefficiency and delays.
Impact: High latency in log streaming, unnecessary filesystem stress
fsnotifyinstead of polling3. Connection Lifecycle Management
Problem: No proper handling of client disconnect (line 92 TODO: "handle the Ctrl+C of kubectl logs").
Impact: Orphaned goroutines, resource leaks
4. Container Death Detection - Race Conditions
Problem: Current container death detection uses 3 different signals (JID disappearance, status file, EOF), making logic fragile.
Impact: Lost logs, premature exit or infinite loops
sacct) directly5. Security - Input Validation & Path Traversal
Problem: Container and pod names are concatenated directly without validation (line 195:
path + "/run-" + req.ContainerName + ".out").Impact: Potential path traversal attacks, arbitrary file access
filepath.Join()instead of string concatenation6. Concurrency & File Access
Problem: No file locking or synchronization when multiple requests access same pod logs.
Impact: Partial reads, race conditions, data corruption
High Priority Issues 🟡
7. Timestamp Support Implementation
Problem: Timestamps are only partially supported (line 199 TODO).
Impact: Cannot filter logs by time, feature incomplete
8. Error Handling Edge Cases
Problem: Silent failures when logs not found (lines 210-211), missing bounds checking in slicing operations.
Impact: Difficult debugging, silent data loss
9. Log Concatenation Issues
Problem: Appending job.out + container.out (lines 220-221) may produce malformed logs.
Impact: Confused log output, missing context
10. Multi-Container Pod Support
Problem: Limited support for pods with multiple containers or init containers.
Impact: Hard to debug multi-container applications
Medium Priority Issues 🟠
11. Configuration & Flexibility
Problem: Polling interval, log rotation, and retention are hardcoded or missing.
Impact: Suboptimal for different use cases
LogFollowPollIntervalconfig optionThis pull request was created from Copilot chat.