Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ run:
linters:
enable:
- wsl_v5
- gomodguard_v2
default: all
disable:
- wsl
- gomodguard
- revive
- noinlineerr
- depguard
Expand Down Expand Up @@ -39,6 +42,9 @@ linters:
gocognit:
min-complexity: 50
goconst:
ignore-string-values:
- "status"
- "path"
min-len: 2
min-occurrences: 2
inamedparam:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ nwa:
$(call go-install-tool,$(NWA),github.com/$(NWA_LOOKUP)@$(NWA_VERSION))

GOLANGCI_LINT := $(LOCALBIN)/golangci-lint
GOLANGCI_LINT_VERSION := v2.11.4
GOLANGCI_LINT_VERSION := v2.12.1
GOLANGCI_LINT_LOOKUP := golangci/golangci-lint
golangci-lint: ## Download golangci-lint locally if necessary.
@test -s $(GOLANGCI_LINT) && $(GOLANGCI_LINT) -h | grep -q $(GOLANGCI_LINT_VERSION) || \
Expand Down
7 changes: 4 additions & 3 deletions internal/authorization/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (

"github.com/projectcapsule/capsule-proxy/internal/modules/clusterscoped"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

func MutateAuthorization(proxyClusterScoped bool, proxyTenants []*tenant.ProxyTenant, obj *runtime.Object, gvk schema.GroupVersionKind) error {
switch gvk.Kind {
case "SelfSubjectAccessReview":
//nolint:forcetypeassert
accessReview := (*obj).(*authorizationv1.SelfSubjectAccessReview)
if accessReview.Spec.ResourceAttributes.Resource == "namespaces" && accessReview.Spec.ResourceAttributes.Verb == "list" {
if accessReview.Spec.ResourceAttributes.Resource == types.Namespaces && accessReview.Spec.ResourceAttributes.Verb == types.ListVerb {
accessReview.Status.Allowed = true
}

Expand Down Expand Up @@ -57,8 +58,8 @@ func MutateAuthorization(proxyClusterScoped bool, proxyTenants []*tenant.ProxyTe

resourceRules = append(resourceRules, authorizationv1.ResourceRule{
APIGroups: []string{""},
Resources: []string{"namespaces"},
Verbs: []string{"list"},
Resources: []string{types.Namespaces},
Verbs: []string{types.ListVerb},
})
src := authorizationv1.SelfSubjectRulesReview{
Status: authorizationv1.SubjectRulesReviewStatus{
Expand Down
6 changes: 4 additions & 2 deletions internal/modules/errors/bad_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/projectcapsule/capsule-proxy/internal/types"
)

//nolint:errname
Expand All @@ -33,8 +35,8 @@ func (b badRequest) Error() string {
func (b badRequest) Status() *metav1.Status {
return &metav1.Status{
TypeMeta: metav1.TypeMeta{
Kind: "Status",
APIVersion: "v1",
Kind: types.StatusKind,
APIVersion: types.V1,
},
Reason: metav1.StatusReasonBadRequest,
Message: b.message,
Expand Down
6 changes: 4 additions & 2 deletions internal/modules/errors/not_found.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/projectcapsule/capsule-proxy/internal/types"
)

type notFoundError struct {
Expand Down Expand Up @@ -36,8 +38,8 @@ func (e notFoundError) Error() string {
func (e notFoundError) Status() *metav1.Status {
return &metav1.Status{
TypeMeta: metav1.TypeMeta{
Kind: "Status",
APIVersion: "v1",
Kind: types.StatusKind,
APIVersion: types.V1,
},
Reason: metav1.StatusReasonNotFound,
Message: e.message,
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/ingressclass/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type get struct {
Expand All @@ -35,7 +36,7 @@ func Get(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: networkingv1.GroupName,
Version: "*",
Kind: "ingressclasses",
Kind: types.Ingressclasses,
},
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/modules/metric/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type get struct {
Expand All @@ -32,9 +33,9 @@ func Get(client client.Reader) modules.Module {
client: client,
log: ctrl.Log.WithName("metric_get"),
gk: schema.GroupVersionKind{
Group: "metrics.k8s.io",
Group: types.MetricsGroup,
Version: "*",
Kind: "nodes",
Kind: types.Nodes,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/namespace/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/errors"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
ctypes "github.com/projectcapsule/capsule-proxy/internal/types"
)

type get struct {
Expand All @@ -44,7 +45,7 @@ func Get(roleBindingsReflector *controllers.RoleBindingReflector, client client.
gk: schema.GroupVersionKind{
Group: corev1.GroupName,
Version: "*",
Kind: "namespaces",
Kind: ctypes.Namespaces,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/namespace/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/errors"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type list struct {
Expand All @@ -33,7 +34,7 @@ func List(roleBindingsReflector *controllers.RoleBindingReflector) modules.Modul
gk: schema.GroupVersionKind{
Group: corev1.GroupName,
Version: "*",
Kind: "namespaces",
Kind: types.Namespaces,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/node/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type list struct {
Expand All @@ -32,7 +33,7 @@ func List(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: corev1.GroupName,
Version: "*",
Kind: "nodes",
Kind: types.Nodes,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/persistentvolume/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type get struct {
Expand All @@ -36,7 +37,7 @@ func Get(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: corev1.GroupName,
Version: "*",
Kind: "persistentvolumes",
Kind: types.PersistentVolumes,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/persistentvolume/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type list struct {
Expand All @@ -36,7 +37,7 @@ func List(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: corev1.GroupName,
Version: "*",
Kind: "persistentvolumes",
Kind: types.PersistentVolumes,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/priorityclass/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type get struct {
Expand All @@ -35,7 +36,7 @@ func Get(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: schedulingv1.GroupName,
Version: "*",
Kind: "priorityclasses",
Kind: types.PriorityClasses,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/priorityclass/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type list struct {
Expand All @@ -32,7 +33,7 @@ func List(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: schedulingv1.GroupName,
Version: "*",
Kind: "priorityclasses",
Kind: types.PriorityClasses,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/runtimeclass/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type get struct {
Expand All @@ -32,7 +33,7 @@ func Get(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: nodev1.GroupName,
Version: "*",
Kind: "runtimeclasses",
Kind: types.RuntimeClasses,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/runtimeclass/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type list struct {
Expand All @@ -32,7 +33,7 @@ func List(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: nodev1.GroupName,
Version: "*",
Kind: "runtimeclasses",
Kind: types.RuntimeClasses,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/modules/storageclass/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/utils"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type get struct {
Expand All @@ -35,7 +36,7 @@ func Get(client client.Reader) modules.Module {
gk: schema.GroupVersionKind{
Group: storagev1.GroupName,
Version: "*",
Kind: "storageclasses",
Kind: types.StorageClasses,
},
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/modules/tenants/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/errors"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type get struct {
Expand All @@ -36,9 +37,9 @@ func Get(client client.Reader) modules.Module {
client: client,
log: ctrl.Log.WithName("tenant_get"),
gk: schema.GroupVersionKind{
Group: "capsule.clastix.io",
Group: types.CapsuleGroup,
Version: "*",
Kind: "tenants",
Kind: types.Tenants,
},
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/modules/tenants/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/projectcapsule/capsule-proxy/internal/modules/errors"
"github.com/projectcapsule/capsule-proxy/internal/request"
"github.com/projectcapsule/capsule-proxy/internal/tenant"
"github.com/projectcapsule/capsule-proxy/internal/types"
)

type list struct {
Expand All @@ -27,9 +28,9 @@ func List() modules.Module {
return &list{
log: ctrl.Log.WithName("tenant_list"),
gk: schema.GroupVersionKind{
Group: "capsule.clastix.io",
Group: types.CapsuleGroup,
Version: "*",
Kind: "tenants",
Kind: types.Tenants,
},
}
}
Expand Down
4 changes: 3 additions & 1 deletion internal/request/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"k8s.io/apiserver/pkg/authentication/serviceaccount"
"k8s.io/apiserver/pkg/authentication/user"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/projectcapsule/capsule-proxy/internal/types"
)

var websocketBearerTokenRegexp = regexp.MustCompile(`base64url\.bearer\.authorization\.k8s\.io\.([^,]*)`) //nolint:gochecknoglobals
Expand Down Expand Up @@ -127,7 +129,7 @@ func (h http) GetUserAndGroups() (username string, groups []string, err error) {
ac := &authorizationv1.SubjectAccessReview{
Spec: authorizationv1.SubjectAccessReviewSpec{
ResourceAttributes: &authorizationv1.ResourceAttributes{
Verb: "impersonate",
Verb: types.ImprisonateVerb,
Resource: "groups",
Name: impersonateGroup,
},
Expand Down
18 changes: 18 additions & 0 deletions internal/types/constnats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package types

const (
V1 string = "v1"
StatusKind string = "Status"
ListVerb string = "List"
Namespaces string = "namespaces"
ImprisonateVerb string = "impersonate"
Ingressclasses string = "ingressclasses"
MetricsGroup string = "metrics.k8s.io"
CapsuleGroup string = "capsule.clastix.io"
Nodes string = "nodes"
PersistentVolumes string = "persistentvolumes"
PriorityClasses string = "priorityclasses"
RuntimeClasses string = "runtimeclasses"
StorageClasses string = "storageclasses"
Tenants string = "tenants"
)
Loading
Loading