Skip to content

Report a malformed SSO config instead of panicking - #7327

Open
omlahore wants to merge 2 commits into
pipe-cd:masterfrom
omlahore:fix/sso-config-panics
Open

Report a malformed SSO config instead of panicking#7327
omlahore wants to merge 2 commits into
pipe-cd:masterfrom
omlahore:fix/sso-config-panics

Conversation

@omlahore

@omlahore omlahore commented Sep 6, 2026

Copy link
Copy Markdown

What happens

SharedSSOConfig.UnmarshalJSON decodes the control-plane config into map[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:

provider := m["provider"].(string)
...
name, ok := m["name"]
if !ok {
    return fmt.Errorf("name field in SharedSSOConfig is required")
}
s.Name = name.(string)

The name case is the clearer omission: the code already checks that the key is present, then asserts its type unchecked.

Reproduction

--- FAIL: TestSharedSSOConfigMalformed/provider_missing
    panicked on user config: interface conversion: interface {} is nil, not string
--- FAIL: TestSharedSSOConfigMalformed/provider_a_number
    panicked on user config: interface conversion: interface {} is float64, not string
--- FAIL: TestSharedSSOConfigMalformed/name_a_number
    panicked on user config: interface conversion: interface {} is float64, not string

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.

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>
Copilot AI lite review requested due to automatic review settings September 6, 2026 20:14
@omlahore
omlahore requested a review from a team as a code owner September 6, 2026 20:14
@netlify

netlify Bot commented Sep 6, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit 9177ce0
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a9e72e295f7f20009cb3cfa

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 provider and name with comma-ok assertions and return descriptive errors on mismatch (in both pkg/config and pkg/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.

Comment thread pkg/config/shared_sso_config_test.go
Comment thread pkg/configv1/control_plane.go
Comment thread pkg/config/shared_sso_config_test.go
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants