Report a malformed SSO config instead of panicking - #7327
Open
omlahore wants to merge 2 commits into
Open
Conversation
SharedSSOConfig.UnmarshalJSON decodes into map[string]interface{} and then
asserts on two lookups without the comma-ok. A control-plane config whose
provider is absent or not a string, or whose name is not a string, panics the
process during config load rather than being reported.
The name case is the clearer omission: the code already checks that the key is
present and then asserts its type unchecked.
Both copies of the file are fixed, pkg/config and pkg/configv1.
Signed-off-by: Om <omlahore47@gmail.com>
✅ Deploy Preview for pipecd-site canceled.
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new test file is missing the required license header and the malformed-config test currently ignores the unmarshal error (and there’s no equivalent regression coverage for the configv1 copy).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens control-plane Shared SSO config JSON unmarshalling so malformed user config is reported as a validation error instead of triggering a panic during config load.
Changes:
- Replace unchecked type assertions for
providerandnamewith comma-ok assertions and return descriptive errors on mismatch (in bothpkg/configandpkg/configv1). - Add a regression test ensuring malformed SharedSSO configs do not panic during
json.Unmarshal.
File summaries
| File | Description |
|---|---|
| pkg/config/control_plane.go | Makes SharedSSOConfig.UnmarshalJSON robust to missing/wrong-typed provider and name fields by returning errors instead of panicking. |
| pkg/configv1/control_plane.go | Mirrors the same safer unmarshalling logic in the v1 config package. |
| pkg/config/shared_sso_config_test.go | Adds a regression test intended to cover malformed SharedSSO configs during JSON unmarshalling. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review feedback on the regression test:
- the test discarded the json.Unmarshal error, so it only proved the
process did not panic. It now requires an error, which is the behaviour
the fix introduces.
- pkg/configv1 carries the same UnmarshalJSON, so it gets the same test.
- add the Apache 2.0 header the package uses.
Verified against the pre-fix code: all three cases fail there with
interface conversion: interface {} is float64, not string.
Signed-off-by: Om <omlahore47@gmail.com>
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.
What happens
SharedSSOConfig.UnmarshalJSONdecodes the control-plane config intomap[string]interface{}and then asserts on two lookups out of it without the comma-ok, so a malformed config panics during load instead of being reported.pkg/config/control_plane.go:The
namecase is the clearer omission: the code already checks that the key is present, then asserts its type unchecked.Reproduction
The change
Both lookups use the checked form and return an error naming the field and the type that was there. The same fix is applied to
pkg/configv1/control_plane.go, which carries an identical copy.go test ./pkg/config/ ./pkg/configv1/is green.Separate from #7326, which fixes the same class in
pipectl migrate.