Skip to content

Commit

Permalink
fix: forbid install namepsace (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
hysyeah authored Jun 21, 2024
1 parent 1609e3e commit 17a11d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/apiserver/handler_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (h *Handler) install(req *restful.Request, resp *restful.Response) {
return
}

if utils.IsProtectedNamespace(appConfig.Namespace) {
if utils.IsForbidNamespace(appConfig.Namespace) {
api.HandleBadRequest(resp, req, fmt.Errorf("unsupported namespace: %s", appConfig.Namespace))
return
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/utils/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ var protectedNamespace = []string{
"os-system",
}

var forbidNamespace = []string{
"default",
"kube-node-lease",
"kube-public",
"kube-system",
"kubekey-system",
"kubesphere-controls-system",
"kubesphere-monitoring-federated",
"kubesphere-monitoring-system",
"kubesphere-system",
}

// GetClient returns versioned ClientSet.
func GetClient() (*versioned.Clientset, error) {
config, err := ctrl.GetConfig()
Expand Down Expand Up @@ -365,3 +377,12 @@ func IsProtectedNamespace(namespace string) bool {
}
return false
}

func IsForbidNamespace(namespace string) bool {
for _, n := range forbidNamespace {
if namespace == n {
return true
}
}
return false
}

0 comments on commit 17a11d5

Please sign in to comment.