Skip to content

Introduce new full-safe profile with a default resource deny list #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/kubernetes-mcp-server/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestProfile(t *testing.T) {
rootCmd := NewMCPServer(ioStreams)
rootCmd.SetArgs([]string{"--help"})
o, err := captureOutput(rootCmd.Execute) // --help doesn't use logger/klog, cobra prints directly to stdout
if !strings.Contains(o, "MCP profile to use (one of: full) ") {
if !strings.Contains(o, "MCP profile to use (one of: full, full-safe) ") {
t.Fatalf("Expected all available profiles, got %s %v", o, err)
}
})
Expand Down
16 changes: 16 additions & 0 deletions pkg/mcp/configs/full-safe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# A list of denied Kubernetes resources in Group/Version/Kind format.
# If a resource is in this list, MCP server should deny all operations
# on that resource type across all namespaces.
[[denied_resources]]
group = ""
version = "v1"
kind = "ServiceAccount"

[[denied_resources]]
group = ""
version = "v1"
kind = "Secret"

[[denied_resources]]
group = "rbac.authorization.k8s.io"
version = "v1"
Empty file added pkg/mcp/configs/full.toml
Empty file.
11 changes: 10 additions & 1 deletion pkg/mcp/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package mcp

import (
"context"
"github.com/manusa/kubernetes-mcp-server/pkg/config"
"net/http"

"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"k8s.io/utils/ptr"

"github.com/manusa/kubernetes-mcp-server/pkg/config"
"github.com/manusa/kubernetes-mcp-server/pkg/kubernetes"
"github.com/manusa/kubernetes-mcp-server/pkg/output"
"github.com/manusa/kubernetes-mcp-server/pkg/version"
Expand Down Expand Up @@ -44,6 +44,15 @@ func NewServer(configuration Configuration) (*Server, error) {
server.WithLogging(),
),
}

if configuration.StaticConfig == nil {
staticConfig, err := configuration.Profile.GetDefaultConfig()
if err != nil {
return nil, err
}
configuration.StaticConfig = staticConfig
}

if err := s.reloadKubernetesClient(); err != nil {
return nil, err
}
Expand Down
57 changes: 57 additions & 0 deletions pkg/mcp/profiles.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package mcp

import (
"embed"
"io/fs"
"slices"

"github.com/BurntSushi/toml"
"github.com/mark3labs/mcp-go/server"

"github.com/manusa/kubernetes-mcp-server/pkg/config"
)

//go:embed configs/full.toml
var defaultFullConfigFile embed.FS

//go:embed configs/full-safe.toml
var defaultFullSafeConfigFile embed.FS

type Profile interface {
GetName() string
GetDescription() string
GetTools(s *Server) []server.ServerTool
GetDefaultConfig() (*config.StaticConfig, error)
}

var Profiles = []Profile{
&FullProfile{},
&FullSafeProfile{},
}

var ProfileNames []string
Expand Down Expand Up @@ -45,6 +58,50 @@ func (p *FullProfile) GetTools(s *Server) []server.ServerTool {
s.initHelm(),
)
}
func (p *FullProfile) GetDefaultConfig() (*config.StaticConfig, error) {
data, err := fs.ReadFile(defaultFullConfigFile, "configs/full.toml")
if err != nil {
return nil, err
}

var cfg *config.StaticConfig
err = toml.Unmarshal(data, &cfg)
if err != nil {
return nil, err
}
return cfg, nil
}

type FullSafeProfile struct{}

func (p *FullSafeProfile) GetName() string {
return "full-safe"
}
func (p *FullSafeProfile) GetDescription() string {
return "Complete profile with all tools and extended outputs"
}
func (p *FullSafeProfile) GetTools(s *Server) []server.ServerTool {
return slices.Concat(
s.initEvents(),
s.initNamespaces(),
s.initPods(),
s.initResources(),
s.initHelm(),
)
}
func (p *FullSafeProfile) GetDefaultConfig() (*config.StaticConfig, error) {
data, err := fs.ReadFile(defaultFullSafeConfigFile, "configs/full-safe.toml")
if err != nil {
return nil, err
}

var cfg *config.StaticConfig
err = toml.Unmarshal(data, &cfg)
if err != nil {
return nil, err
}
return cfg, nil
}

func init() {
ProfileNames = make([]string, 0)
Expand Down
Loading