Skip to content

Commit 61acdc0

Browse files
committed
Introduce jwks url flag to be published in oauth metadata
1 parent 775fa21 commit 61acdc0

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type StaticConfig struct {
2424
DisabledTools []string `toml:"disabled_tools,omitempty"`
2525
RequireOAuth bool `toml:"require_oauth,omitempty"`
2626
AuthorizationURL string `toml:"authorization_url,omitempty"`
27+
JwksURL string `toml:"jwks_url,omitempty"`
2728
ServerURL string `toml:"server_url,omitempty"`
2829
}
2930

pkg/http/http.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func Serve(ctx context.Context, mcpServer *mcp.Server, staticConfig *config.Stat
6060

6161
response := map[string]interface{}{
6262
"authorization_servers": authServers,
63+
"authorization_server": authServers[0],
6364
"scopes_supported": []string{},
6465
"bearer_methods_supported": []string{"header"},
6566
}
@@ -68,6 +69,10 @@ func Serve(ctx context.Context, mcpServer *mcp.Server, staticConfig *config.Stat
6869
response["resource"] = staticConfig.ServerURL
6970
}
7071

72+
if staticConfig.JwksURL != "" {
73+
response["jwks_uri"] = staticConfig.JwksURL
74+
}
75+
7176
w.WriteHeader(http.StatusOK)
7277
if err := json.NewEncoder(w).Encode(response); err != nil {
7378
http.Error(w, err.Error(), http.StatusInternalServerError)

pkg/kubernetes-mcp-server/cmd/root.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type MCPServerOptions struct {
5959
DisableDestructive bool
6060
RequireOAuth bool
6161
AuthorizationURL string
62+
JwksURL string
6263
ServerURL string
6364

6465
ConfigPath string
@@ -116,6 +117,8 @@ func NewMCPServer(streams genericiooptions.IOStreams) *cobra.Command {
116117
cmd.Flags().MarkHidden("require-oauth")
117118
cmd.Flags().StringVar(&o.AuthorizationURL, "authorization-url", o.AuthorizationURL, "OAuth authorization server URL for protected resource endpoint. If not provided, the Kubernetes API server host will be used. Only valid if require-oauth is enabled.")
118119
cmd.Flags().MarkHidden("authorization-url")
120+
cmd.Flags().StringVar(&o.JwksURL, "jwks-url", o.JwksURL, "OAuth JWKS server URL for protected resource endpoint. Only valid if require-oauth is enabled.")
121+
cmd.Flags().MarkHidden("jwks-url")
119122
cmd.Flags().StringVar(&o.ServerURL, "server-url", o.ServerURL, "Server URL of this application. Optional. If set, this url will be served in protected resource metadata endpoint and tokens will be validated with this audience. If not set, expected audience is kubernetes-mcp-server. Only valid if require-oauth is enabled.")
120123
cmd.Flags().MarkHidden("server-url")
121124
return cmd
@@ -174,6 +177,9 @@ func (m *MCPServerOptions) loadFlags(cmd *cobra.Command) {
174177
if cmd.Flag("authorization-url").Changed {
175178
m.StaticConfig.AuthorizationURL = m.AuthorizationURL
176179
}
180+
if cmd.Flag("jwks-url").Changed {
181+
m.StaticConfig.JwksURL = m.JwksURL
182+
}
177183
if cmd.Flag("server-url").Changed {
178184
m.StaticConfig.ServerURL = m.ServerURL
179185
}
@@ -195,8 +201,8 @@ func (m *MCPServerOptions) Validate() error {
195201
if m.Port != "" && (m.SSEPort > 0 || m.HttpPort > 0) {
196202
return fmt.Errorf("--port is mutually exclusive with deprecated --http-port and --sse-port flags")
197203
}
198-
if !m.StaticConfig.RequireOAuth && (m.StaticConfig.AuthorizationURL != "" || m.StaticConfig.ServerURL != "") {
199-
return fmt.Errorf("authorization-url and server-url are only valid if require-oauth is enabled")
204+
if !m.StaticConfig.RequireOAuth && (m.StaticConfig.AuthorizationURL != "" || m.StaticConfig.ServerURL != "" || m.StaticConfig.JwksURL != "") {
205+
return fmt.Errorf("authorization-url, server-url and jwks-url are only valid if require-oauth is enabled. Missing --port may implicitly set require-oauth to false")
200206
}
201207
if m.StaticConfig.AuthorizationURL != "" {
202208
u, err := url.Parse(m.StaticConfig.AuthorizationURL)
@@ -222,6 +228,18 @@ func (m *MCPServerOptions) Validate() error {
222228
klog.Warningf("server-url is using http://, this is not recommended production use")
223229
}
224230
}
231+
if m.StaticConfig.JwksURL != "" {
232+
u, err := url.Parse(m.StaticConfig.JwksURL)
233+
if err != nil {
234+
return err
235+
}
236+
if u.Scheme != "https" && u.Scheme != "http" {
237+
return fmt.Errorf("--jwks-url must be a valid URL")
238+
}
239+
if u.Scheme == "http" {
240+
klog.Warningf("jwks-url is using http://, this is not recommended production use")
241+
}
242+
}
225243
return nil
226244
}
227245

0 commit comments

Comments
 (0)