fix: tighten GitLab host matching and request handling in helm values fetch#1157
fix: tighten GitLab host matching and request handling in helm values fetch#1157edgarbellot wants to merge 1 commit into
Conversation
… fetch Make fetchFromGitlabIfNecessary match the configured GitLab host (from --utilities-git-url) by exact hostname instead of a "git" prefix, require HTTPS for outbound calls to that host, send the token using the standard PRIVATE-TOKEN header, and route requests through a dedicated http.Client that does not follow redirects and applies a request timeout. Add unit tests covering the host match, scheme requirement, header propagation and redirect behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR restricts GitLab Helm values fetching to configured hosts over HTTPS only. It introduces a shared HTTP client with timeout and redirect suppression, validates hostnames against the configured GitOps repository, constructs authenticated requests using the ChangesGitLab Helm Values Fetch Security
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/provisioner/utility/helm_utils.go (1)
346-358:⚠️ Potential issue | 🟠 Major | ⚡ Quick winClose the file handle from
os.CreateTempbefore writing.
os.CreateTempreturns an open file handle that is never closed. Whileos.WriteFileworks by path, the original descriptor fromCreateTempremains open, causing a file descriptor leak.🐛 Proposed fix to close the temp file handle
temporaryValuesFile, err := os.CreateTemp(os.TempDir(), "helm-values-file-") if err != nil { return "", nil, errors.Wrap(err, "failed to create temporary file for Helm values file") } + temporaryValuesFile.Close() content, err := base64.StdEncoding.DecodeString(valuesFileBytes.Content)Alternatively, write directly to the open file handle instead of using
os.WriteFile:temporaryValuesFile, err := os.CreateTemp(os.TempDir(), "helm-values-file-") if err != nil { return "", nil, errors.Wrap(err, "failed to create temporary file for Helm values file") } + defer temporaryValuesFile.Close() content, err := base64.StdEncoding.DecodeString(valuesFileBytes.Content) if err != nil { return "", nil, errors.Wrap(err, "failed to decode base64-encoded YAML file") } - err = os.WriteFile(temporaryValuesFile.Name(), content, 0600) + _, err = temporaryValuesFile.Write(content) if err != nil { return "", nil, errors.Wrap(err, "failed to write values file to disk for Helm to read") }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/provisioner/utility/helm_utils.go` around lines 346 - 358, The temporary file handle returned by os.CreateTemp (variable temporaryValuesFile) is never closed, leaking a file descriptor; either close temporaryValuesFile before calling os.WriteFile(temporaryValuesFile.Name(), ...) or, better, write to the open file handle (temporaryValuesFile.Write or io.WriteString) and then close it (temporaryValuesFile.Close())—apply this change in the function that creates the temp file and writes the Helm values so the descriptor is always closed even on error (use defer temporaryValuesFile.Close() immediately after successful CreateTemp).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@internal/provisioner/utility/helm_utils.go`:
- Around line 346-358: The temporary file handle returned by os.CreateTemp
(variable temporaryValuesFile) is never closed, leaking a file descriptor;
either close temporaryValuesFile before calling
os.WriteFile(temporaryValuesFile.Name(), ...) or, better, write to the open file
handle (temporaryValuesFile.Write or io.WriteString) and then close it
(temporaryValuesFile.Close())—apply this change in the function that creates the
temp file and writes the Helm values so the descriptor is always closed even on
error (use defer temporaryValuesFile.Close() immediately after successful
CreateTemp).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a62c190b-e25d-4274-941f-51f8eaabdb56
📒 Files selected for processing (2)
internal/provisioner/utility/helm_utils.gointernal/provisioner/utility/helm_utils_test.go
Summary
Small cleanup around
fetchFromGitlabIfNecessaryso it lines up with the way--utilities-git-urlis meant to be used:"git"prefix.https://when reaching out to the configured host.PRIVATE-TOKENheader instead of appending it to the query string.http.Clientwith redirects disabled and a request timeout, so a misbehaving upstream cannot stall the supervisor goroutine.Adds a unit test file for the function (none existed before), covering the host match, scheme requirement, header propagation, redirect behavior, and the no-token-configured path.
JIRA ticket: https://mattermost.atlassian.net/browse/MM-69024
Thank you to Samy Ghannad for letting us know about this issue.