Compare commits

..

1 Commits

Author SHA1 Message Date
t.behrendt 6d9496185e feat: vertical slice proxy provider (#2)
CD / Create tag (push) Successful in 25s
CD / Build and push (amd64) (push) Successful in 1m31s
CD / Create manifest (push) Successful in 7s
Reviewed-on: #2
Co-authored-by: Timo Behrendt <t.behrendt@t00n.de>
Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
2026-05-17 21:02:00 +02:00
3 changed files with 21 additions and 28 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ type PolicyBinding struct {
type PolicyBindingSpec struct { type PolicyBindingSpec struct {
Policy string `json:"policy,omitempty"` Policy string `json:"policy,omitempty"`
Group string `json:"group,omitempty"` Group string `json:"group,omitempty"`
User int32 `json:"user,omitempty"` User int32 `json:"user"`
Target string `json:"target"` Target string `json:"target"`
Order int32 `json:"order"` Order int32 `json:"order"`
} }
+16 -24
View File
@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"slices" "slices"
"strconv"
"time" "time"
"golang.org/x/time/rate" "golang.org/x/time/rate"
@@ -201,11 +202,16 @@ func (c *Controller) ensureFinalizers(ctx context.Context, pb *v1alpha1.PolicyBi
} }
func (c *Controller) reconcileDelete(ctx context.Context, pb *v1alpha1.PolicyBinding) error { func (c *Controller) reconcileDelete(ctx context.Context, pb *v1alpha1.PolicyBinding) error {
r, err := c.authentik.PoliciesApi.PoliciesBindingsDestroy(ctx, pb.Status.PK).Execute() pk, err := strconv.ParseInt(pb.Status.PK, 10, 32)
if err != nil { if err != nil {
// This handles an edge-case, where when the PolicyBinding on Authentik has already been deleted, but the finalizer is still present. We just remove the finalizer and return. return fmt.Errorf("error parsing PK: %v", err)
}
r, err := c.authentik.ProvidersApi.ProvidersProxyDestroy(ctx, int32(pk)).Execute()
if err != nil {
// This handles an edge-case, where when the ProxyProvider on Authentik has already been deleted, but the finalizer is still present. We just remove the finalizer and return.
if r != nil && r.StatusCode != http.StatusNotFound { if r != nil && r.StatusCode != http.StatusNotFound {
return fmt.Errorf("error when calling `PoliciesAPI.PoliciesBindingsDestroy`: %w with response %v", err, r) return fmt.Errorf("error when calling `ProvidersAPI.ProvidersProxyDestroy`: %w with response %v", err, r)
} }
} }
@@ -226,22 +232,15 @@ func (c *Controller) reconcileUpdate(ctx context.Context, pb *v1alpha1.PolicyBin
} }
patchedPolicyBindingRequest := &authentikapi.PatchedPolicyBindingRequest{ patchedPolicyBindingRequest := &authentikapi.PatchedPolicyBindingRequest{
Policy: *authentikapi.NewNullableString(&pb.Spec.Policy),
Group: *authentikapi.NewNullableString(&pb.Spec.Group),
User: *authentikapi.NewNullableInt32(&pb.Spec.User),
Target: &pb.Spec.Target, Target: &pb.Spec.Target,
Order: &pb.Spec.Order, Order: &pb.Spec.Order,
} }
if pb.Spec.Policy != "" {
patchedPolicyBindingRequest.SetPolicy(pb.Spec.Policy)
}
if pb.Spec.Group != "" {
patchedPolicyBindingRequest.SetGroup(pb.Spec.Group)
}
if pb.Spec.User != 0 {
patchedPolicyBindingRequest.SetUser(pb.Spec.User)
}
resp, r, err := c.authentik.PoliciesApi.PoliciesBindingsPartialUpdate(ctx, pb.Status.PK).PatchedPolicyBindingRequest(*patchedPolicyBindingRequest).Execute() resp, r, err := c.authentik.PoliciesApi.PoliciesBindingsPartialUpdate(ctx, pb.Status.PK).PatchedPolicyBindingRequest(*patchedPolicyBindingRequest).Execute()
if err != nil { if err != nil {
return fmt.Errorf("error when calling `PoliciesAPI.PoliciesBindingsPartialUpdate`: %w with response %v", err, r) return fmt.Errorf("error when calling `ProvidersAPI.ProvidersProxyPartialUpdate`: %w with response %v", err, r)
} }
pb.Status.PK = resp.Pk pb.Status.PK = resp.Pk
@@ -250,19 +249,12 @@ func (c *Controller) reconcileUpdate(ctx context.Context, pb *v1alpha1.PolicyBin
func (c *Controller) reconcileCreate(ctx context.Context, pb *v1alpha1.PolicyBinding) error { func (c *Controller) reconcileCreate(ctx context.Context, pb *v1alpha1.PolicyBinding) error {
policyBindingRequest := &authentikapi.PolicyBindingRequest{ policyBindingRequest := &authentikapi.PolicyBindingRequest{
Policy: *authentikapi.NewNullableString(&pb.Spec.Policy),
Group: *authentikapi.NewNullableString(&pb.Spec.Group),
User: *authentikapi.NewNullableInt32(&pb.Spec.User),
Target: pb.Spec.Target, Target: pb.Spec.Target,
Order: pb.Spec.Order, Order: pb.Spec.Order,
} }
if pb.Spec.Policy != "" {
policyBindingRequest.SetPolicy(pb.Spec.Policy)
}
if pb.Spec.Group != "" {
policyBindingRequest.SetGroup(pb.Spec.Group)
}
if pb.Spec.User != 0 {
policyBindingRequest.SetUser(pb.Spec.User)
}
resp, r, err := c.authentik.PoliciesApi.PoliciesBindingsCreate(ctx).PolicyBindingRequest(*policyBindingRequest).Execute() resp, r, err := c.authentik.PoliciesApi.PoliciesBindingsCreate(ctx).PolicyBindingRequest(*policyBindingRequest).Execute()
if err != nil { if err != nil {
return fmt.Errorf("error when calling `PoliciesAPI.PoliciesBindingsCreate`: %w with response %v", err, r) return fmt.Errorf("error when calling `PoliciesAPI.PoliciesBindingsCreate`: %w with response %v", err, r)
@@ -363,8 +363,9 @@ func schema_pkg_apis_policybinding_v1alpha1_PolicyBindingSpec(ref common.Referen
}, },
"user": { "user": {
SchemaProps: spec.SchemaProps{ SchemaProps: spec.SchemaProps{
Type: []string{"integer"}, Default: 0,
Format: "int32", Type: []string{"integer"},
Format: "int32",
}, },
}, },
"target": { "target": {
@@ -382,7 +383,7 @@ func schema_pkg_apis_policybinding_v1alpha1_PolicyBindingSpec(ref common.Referen
}, },
}, },
}, },
Required: []string{"target", "order"}, Required: []string{"user", "target", "order"},
}, },
}, },
} }