mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-23 22:46:59 +00:00
* fix(controller): decode old object for delete requests Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * fix: preserve ca-bundles injected from external providers Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: abstract ruling Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api --------- Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
// Copyright 2020-2026 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package handlers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
|
|
|
"github.com/projectcapsule/capsule/pkg/runtime/configuration"
|
|
"github.com/projectcapsule/capsule/pkg/runtime/events"
|
|
"github.com/projectcapsule/capsule/pkg/users"
|
|
)
|
|
|
|
func IsNotPrivileged(configuration configuration.Configuration, handlers ...Handler) Handler {
|
|
return &isNotPrivileged{
|
|
configuration: configuration,
|
|
handlers: handlers,
|
|
}
|
|
}
|
|
|
|
type isNotPrivileged struct {
|
|
configuration configuration.Configuration
|
|
handlers []Handler
|
|
}
|
|
|
|
func (h *isNotPrivileged) OnCreate(client client.Client, reader client.Reader, decoder admission.Decoder, recorder events.EventRecorder) Func {
|
|
return func(ctx context.Context, req admission.Request) *admission.Response {
|
|
if users.IsAdminUser(req, h.configuration.Administrators()) {
|
|
return nil
|
|
}
|
|
|
|
for _, hndl := range h.handlers {
|
|
if response := hndl.OnCreate(client, reader, decoder, recorder)(ctx, req); response != nil {
|
|
return response
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (h *isNotPrivileged) OnDelete(client client.Client, reader client.Reader, decoder admission.Decoder, recorder events.EventRecorder) Func {
|
|
return func(ctx context.Context, req admission.Request) *admission.Response {
|
|
if users.IsAdminUser(req, h.configuration.Administrators()) {
|
|
return nil
|
|
}
|
|
|
|
for _, hndl := range h.handlers {
|
|
if response := hndl.OnDelete(client, reader, decoder, recorder)(ctx, req); response != nil {
|
|
return response
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (h *isNotPrivileged) OnUpdate(client client.Client, reader client.Reader, decoder admission.Decoder, recorder events.EventRecorder) Func {
|
|
return func(ctx context.Context, req admission.Request) *admission.Response {
|
|
if users.IsAdminUser(req, h.configuration.Administrators()) {
|
|
return nil
|
|
}
|
|
|
|
for _, hndl := range h.handlers {
|
|
if response := hndl.OnUpdate(client, reader, decoder, recorder)(ctx, req); response != nil {
|
|
return response
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|