Skip to content

Commit

Permalink
policyengine/PolicyDispatcher: allow to delete unprivileged policy
Browse files Browse the repository at this point in the history
Signed-off-by: Kfir Toledo <[email protected]>
  • Loading branch information
kfirtoledo committed Mar 31, 2024
1 parent 146f19d commit 453881e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/controlplane/authz/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func CreateControllers(mgr *Manager, controllerManager ctrl.Manager, crdMode boo
return mgr.addAccessPolicy(object.(*v1alpha1.AccessPolicy))
},
DeleteHandler: func(ctx context.Context, name types.NamespacedName) error {
mgr.deleteAccessPolicy(name)
return nil
return mgr.deleteAccessPolicy(name)

Check failure on line 38 in pkg/controlplane/authz/controllers.go

View workflow job for this annotation

GitHub Actions / static-checks

File is not `gofumpt`-ed (gofumpt)

Check failure on line 38 in pkg/controlplane/authz/controllers.go

View workflow job for this annotation

GitHub Actions / static-checks

unnecessary trailing newline (whitespace)
},
})
if err != nil {
Expand Down
19 changes: 17 additions & 2 deletions pkg/controlplane/authz/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/clusterlink-net/clusterlink/pkg/api"
Expand Down Expand Up @@ -216,8 +217,22 @@ func (m *Manager) addPod(pod *v1.Pod) {
}
}

func (m *Manager) deleteAccessPolicy(_ types.NamespacedName) {
// TODO: call policy decider
func (m *Manager) deleteAccessPolicy(name types.NamespacedName) error {
accessPolicy := v1alpha1.AccessPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: name.Name,
Namespace: name.Namespace,
}}

Check failure on line 225 in pkg/controlplane/authz/manager.go

View workflow job for this annotation

GitHub Actions / static-checks

File is not `gofumpt`-ed (gofumpt)

policyData, err := json.Marshal(accessPolicy)
if err != nil {
return err
}

return m.policyDecider.DeleteAccessPolicy(&api.Policy{
Name: accessPolicy.Name,
Spec: api.PolicySpec{Blob: policyData},
})
}

func (m *Manager) addAccessPolicy(accessPolicy *v1alpha1.AccessPolicy) error {
Expand Down

0 comments on commit 453881e

Please sign in to comment.