Skip to content

Commit 231552c

Browse files
committed
add validation for --oidc-issuer-url when using embedded OIDC
Signed-off-by: olalekan odukoya <odukoyaonline@gmail.com>
1 parent 8b330f5 commit 231552c

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

backend/options/oidc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"net"
2323
"os"
24+
"strings"
2425

2526
"github.com/spf13/pflag"
2627

@@ -130,6 +131,10 @@ func (options *OIDC) Validate() error {
130131
return fmt.Errorf("invalid OIDC provider type: %s", options.Type)
131132
}
132133

134+
if options.Type == string(kubebindv1alpha2.OIDCProviderTypeEmbedded) && !strings.HasSuffix(options.IssuerURL, "/oidc") {
135+
return fmt.Errorf("--oidc-issuer-url must end with '/oidc' when using embedded OIDC provider")
136+
}
137+
133138
if options.Type == string(kubebindv1alpha2.OIDCProviderTypeExternal) && len(options.AllowedGroups) == 0 && len(options.AllowedUsers) == 0 {
134139
return fmt.Errorf("when using external OIDC provider, at least one of allowed groups or allowed users must be specified")
135140
}

backend/options/oidc_test.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
Copyright 2026 The Kube Bind Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package options
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/require"
23+
24+
kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2"
25+
)
26+
27+
func TestOIDCValidate(t *testing.T) {
28+
tests := []struct {
29+
name string
30+
options *OIDC
31+
wantErr bool
32+
errMsg string
33+
}{
34+
{
35+
name: "embedded OIDC with valid issuer URL ending in /oidc",
36+
options: &OIDC{
37+
Type: string(kubebindv1alpha2.OIDCProviderTypeEmbedded),
38+
IssuerClientID: "test-client-id",
39+
IssuerClientSecret: "test-client-secret",
40+
IssuerURL: "http://localhost:8080/oidc",
41+
CallbackURL: "http://localhost:8080/callback",
42+
},
43+
wantErr: false,
44+
},
45+
{
46+
name: "embedded OIDC with invalid issuer URL not ending in /oidc",
47+
options: &OIDC{
48+
Type: string(kubebindv1alpha2.OIDCProviderTypeEmbedded),
49+
IssuerClientID: "test-client-id",
50+
IssuerClientSecret: "test-client-secret",
51+
IssuerURL: "http://localhost:8080",
52+
CallbackURL: "http://localhost:8080/callback",
53+
},
54+
wantErr: true,
55+
errMsg: "--oidc-issuer-url must end with '/oidc' when using embedded OIDC provider",
56+
},
57+
{
58+
name: "embedded OIDC with trailing slash /oidc/",
59+
options: &OIDC{
60+
Type: string(kubebindv1alpha2.OIDCProviderTypeEmbedded),
61+
IssuerClientID: "test-client-id",
62+
IssuerClientSecret: "test-client-secret",
63+
IssuerURL: "http://localhost:8080/oidc/",
64+
CallbackURL: "http://localhost:8080/callback",
65+
},
66+
wantErr: true,
67+
errMsg: "--oidc-issuer-url must end with '/oidc' when using embedded OIDC provider",
68+
},
69+
{
70+
name: "external OIDC does not require /oidc suffix",
71+
options: &OIDC{
72+
Type: string(kubebindv1alpha2.OIDCProviderTypeExternal),
73+
IssuerClientID: "test-client-id",
74+
IssuerClientSecret: "test-client-secret",
75+
IssuerURL: "http://localhost:8080",
76+
CallbackURL: "http://localhost:8080/callback",
77+
AllowedGroups: []string{"admins"},
78+
},
79+
wantErr: false,
80+
},
81+
}
82+
83+
for _, tt := range tests {
84+
t.Run(tt.name, func(t *testing.T) {
85+
err := tt.options.Validate()
86+
87+
if !tt.wantErr {
88+
require.NoError(t, err)
89+
return
90+
}
91+
92+
require.Error(t, err)
93+
if tt.errMsg != "" {
94+
require.EqualError(t, err, tt.errMsg)
95+
}
96+
})
97+
}
98+
}

0 commit comments

Comments
 (0)