Commit Graph

36 Commits

Author SHA1 Message Date
Marc Nuri
f3a446676f refactor(kubernetes): keep Provider as only external Kubernetes interface (#372)
* refactor(kubernetes): keep Provider as only external Kubernetes interface

Initial phase to unify-merge the Provider interface with the Manager struct.

- Renamed ManagerProvider to Provider (i.e. kubernets.Provider)
- Moved Manager related logic to specific files
- Exposed relevant method through Provider interface (GetDerivedKubernetes, IsOpenShift, VerifyToken)

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* Update pkg/kubernetes/provider_kubeconfig.go

Co-authored-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>

---------

Signed-off-by: Marc Nuri <marc@marcnuri.com>
Co-authored-by: Calum Murray <cmurray@redhat.com>
2025-10-14 15:25:49 +02:00
Harshal Patil
65cc304c3c feat(kubernetes): expose AccessControlClientset to enable its usage in toolsets (#364)
Signed-off-by: Harshal Patil <12152047+harche@users.noreply.github.com>
2025-10-10 09:31:19 +02:00
Marc Nuri
48cf204a89 feat(toolsets): add support for multiple toolsets in configuration (#323)
Users can now enable or disable different toolsets either by providing
a command-line flag or by setting the toolsets array field in the TOML
configuration.

Downstream Kubernetes API developers can declare toolsets for their
APIs by creating a new nested package in pkg/toolsets and registering
it in pkg/mcp/modules.go

Signed-off-by: Marc Nuri <marc@marcnuri.com>
2025-09-17 10:53:56 +02:00
Marc Nuri
cad863ff22 fix(migration): rebranded from manusa/kubernetes-mcp-server to containers/kubernetes-mcp-server (#202)
Signed-off-by: Marc Nuri <marc@marcnuri.com>
2025-07-25 09:53:04 +02:00
Marc Nuri
3fbfd8d7cb fix(lint): add golangci-lint make target + lint
Signed-off-by: Marc Nuri <marc@marcnuri.com>
2025-07-22 14:22:19 +02:00
Arda Güçlü
275b91a00d feat(auth): introduce require-oauth flag to comply with OAuth in MCP specification (170)
Introduce require-oauth flag

When this flag is enabled, authorization middleware will be turned on.
When this flag is enabled, Derived which is generated based on the client
token will not be used.
---
Wire Authorization middleware to http mux

This commit adds authorization middleware. Additionally, this commit
rejects the requests if the bearer token is absent in Authorization
header of the request.
---
Add offline token validation for expiration and audience

Per Model Context Protocol specification, MCP Servers must check the
audience field of the token to ensure that they are generated specifically
for them.

This commits parses the JWT token and asserts that audience is correct
and token is not expired.
---
Add online token verification via TokenReview request to API Server

This commit sends online token verification by sending request to
TokenReview endpoint of API Server with the token and expected audience.

If API Server returns the status as authenticated, that means this token
can be used to generate a new ad hoc token for MCP Server.

If API Server returns the status as not authenticated, that means this token
is invalid and MCP Server returns 401 to force the client to initiate OAuth flow.
---
Serve oauth protected resource metadata endpoint
---
Introduce server-url to be represented in protected resource metadata
---
Add error return type in Derived function
---
Return error if error occurs in Derived, when require-oauth
---
Add test cases for authorization-url and server-url
---
Wire server-url to audience, if it is set
---
Remove redundant ssebaseurl parameter from http
2025-07-14 06:31:17 +02:00
Arda Güçlü
114726fb7c test(config): add new test case to increase the test coverage of Derived Config (167)
Add new unit tests to check the values in Derived config
---
Rely on kubeconfig in staticConfig instead of a separate but equal one
2025-07-08 06:07:18 +02:00
Arda Güçlü
00e4f1816f fix(auth): isolate bearer token config from kubeconfig 2025-07-07 07:09:26 +02:00
Arda Güçlü
9ffb818ab2 feat(auht): accept standard oauth authorization header by keeping the current header 2025-07-03 06:57:42 +02:00
Arda Güçlü
ebe0ba9816 fix(kubernetes): wire static config to Derived object 2025-07-02 14:27:31 +02:00
Marc Nuri
af2a8cd19d feat(config): deny resources by using RESTMapper as an interceptor (149)
feat(config): deny resources by using RESTMapper as an interceptor

This approach ensures that resources in the deny list are **always**
processed regardless of the implementation.

The RESTMapper takes care of verifying that the requested Group Version Kind
complies with the deny list while checking for the REST endpoint.
---
feat(config): provide a limited clientset which check access
---
review: addressed PR comments
---
feat(config): provide a limited metrics clientset to check access
---
review: addressed PR comments regarding pods_exec
2025-07-01 14:44:22 +02:00
Arda Güçlü
754da19d81 feat(config): introduce toml configuration file with a set of deny list 2025-06-19 13:41:47 +02:00
Marc Nuri
25608daf4a fix(kubernetes): remove unneeded CacheInvalidate() method (127)
fix(kubernetes): remove unneeded CacheInvalidate() method
---
test(output): improve age regex
---
test(kubernetes): remove unneeded CacheInvalidate() method (mutex lock)
---
test(kubernetes): split TestPodsTop to avoid discovery client cache issues
2025-06-18 12:51:09 +02:00
Marc Nuri
f138b06ba8 refactor(kubernetes): force usage of Derived kubernetes (125)
refactor(kubernetes): force usage of Derived kubernetes

Prevents consumers of the kubernetes package the usage of
public methods on a non-derived config instance.
---
review(kubernetes): force usage of Derived kubernetes

Addresses comment by ardaguclu
2025-06-18 06:46:05 +02:00
Marc Nuri
155fe6847f feat(output): configurable output architecture 2025-06-11 12:13:23 +02:00
Marc Nuri
6da90015a1 feat(auth)!: use generic kubernetes-authorization header 2025-06-05 12:22:07 +02:00
Marc Nuri
9b517585fb feat(auth): minor optimization + logging 2025-05-30 09:30:52 +02:00
Marc Nuri
f80d8df3c4 feat(auth): authorize user from custom SSE header (96)
feat(auth): Authorize user from custom SSE header

PoC to show how we can propagate an Authorization Bearer token
from the MCP client up to the Kubernetes API by passing a custom
header (Kubernetes-Authorization-Bearer-Token).

A new Derived client is necessary for each request due to the incompleteness
of some of the client-go clients.
This might add some overhead for each prompt.
Ideally, the issue with the discoveryclient and others should be fixed to
allow reading the authorization header from the request context.

To use the feature, the MCP Server still needs to be started with a basic
configuration (either provided InCluster by a service account or locally by
 a .kube/config file) so that it's able to infer the server settings.
---
test(auth): added tests to verify header propagation
---
refactor(auth): minor improvements for derived client
2025-05-29 17:07:28 +02:00
Marc Nuri
9830e2249d refactor(auth): oidc auth plugin import location 2025-05-29 11:21:46 +02:00
Marc Nuri
22669e72be feat(helm): initial support for helm install 2025-05-12 18:15:30 +02:00
Marc Nuri
b4928f8230 refactor(helm): adapt Helm contribution to project structure 2025-05-10 07:04:30 +02:00
bussyjd
34eabdef13 feat(helm): share kubeconfig/context/namespace with Hel 2025-05-10 07:04:30 +02:00
Marc Nuri
fa5bb81fe5 feat(kubernetes): added --kubeconfig flag option 2025-04-19 10:01:41 +02:00
Marc Nuri
2a11784688 refactor: Kubernetes struct init 2025-03-30 19:30:05 +02:00
Marc Nuri
cbf0299e97 test: pods_exec tests executed from mcp client 2025-03-30 19:25:31 +02:00
Marc Nuri
61289cf1df test: initial approach to pods_exec 2025-03-30 10:03:50 +02:00
Marc Nuri
b08fe66d56 fix: InClusterConfig uses kubernetes.default.svc as host 2025-03-28 15:38:11 +01:00
Marc Nuri
d5cacb9527 feat: pods_exec minimal implementation 2025-03-28 10:49:21 +01:00
Marc Nuri
a98e69102c feat: watch for configuration changes
Watch kube config files for changes.
Automatically reload kubernetes client and list of tools.

Useful for logins or context changes after an MCP session has started.
2025-03-21 18:05:41 +01:00
Marc Nuri
32b388aab3 feat: configuration view works in cluster 2025-03-21 14:57:41 +01:00
Marc Nuri
3522e4fb44 feat(kubernetes): fallback to configured namespace when listing from all namespaces
Fixes #4

If user is not authorized to list from all namespaces try to list from the configured namespace only.
2025-02-20 16:52:16 +01:00
Marc Nuri
d3754585ec feat(kubernetes): reusable Kubernetes clients
Improve cache performance
2025-02-20 06:33:42 +01:00
Marc Nuri
3bf7a0fd63 feat(kubernetes): pods_log for explicit or nil namespace 2025-02-17 09:16:28 +01:00
Marc Nuri
f591e2b06b feat(kubernetes): pods_get for explicit or nil namespace 2025-02-17 08:52:22 +01:00
Marc Nuri
183f72522c feat: use clientcmd instead of kubectl to minimize binary size 2025-02-17 05:40:01 +01:00
Marc Nuri
80488ef6ee feat(resources): initial support for resource listing 2025-02-13 16:06:06 +01:00