-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* AuthPolicies validation * Effective auth policies * Authorino AuthConfigs * Istio/Envoy Gateway cluster patches * Istio/Envoy Gateway wasm extensions * (Most part of) AuthPolicy status update Signed-off-by: Guilherme Cassolato <[email protected]>
- Loading branch information
1 parent
43052b4
commit bc688df
Showing
36 changed files
with
2,000 additions
and
2,330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/kuadrant/policy-machinery/controller" | ||
"github.com/kuadrant/policy-machinery/machinery" | ||
"github.com/samber/lo" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/utils/ptr" | ||
|
||
kuadrantv1beta3 "github.com/kuadrant/kuadrant-operator/api/v1beta3" | ||
kuadrant "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" | ||
) | ||
|
||
type AuthPolicyValidator struct{} | ||
|
||
// AuthPolicyValidator subscribes to events with potential to flip the validity of auth policies | ||
func (r *AuthPolicyValidator) Subscription() controller.Subscription { | ||
return controller.Subscription{ | ||
ReconcileFunc: r.Validate, | ||
Events: []controller.ResourceEventMatcher{ | ||
{Kind: &machinery.GatewayGroupKind}, | ||
{Kind: &machinery.HTTPRouteGroupKind}, | ||
{Kind: &kuadrantv1beta3.AuthPolicyGroupKind, EventType: ptr.To(controller.CreateEvent)}, | ||
{Kind: &kuadrantv1beta3.AuthPolicyGroupKind, EventType: ptr.To(controller.UpdateEvent)}, | ||
}, | ||
} | ||
} | ||
|
||
func (r *AuthPolicyValidator) Validate(ctx context.Context, _ []controller.ResourceEvent, topology *machinery.Topology, _ error, state *sync.Map) error { | ||
logger := controller.LoggerFromContext(ctx).WithName("AuthPolicyValidator") | ||
|
||
policies := topology.Policies().Items(func(o machinery.Object) bool { | ||
return o.GroupVersionKind().GroupKind() == kuadrantv1beta3.AuthPolicyGroupKind | ||
}) | ||
|
||
logger.V(1).Info("validating auth policies", "policies", len(policies)) | ||
defer logger.V(1).Info("finished validating auth policies") | ||
|
||
state.Store(StateAuthPolicyValid, lo.SliceToMap(policies, func(policy machinery.Policy) (string, error) { | ||
var err error | ||
if len(policy.GetTargetRefs()) > 0 && len(topology.Targetables().Children(policy)) == 0 { | ||
ref := policy.GetTargetRefs()[0] | ||
var res schema.GroupResource | ||
switch ref.GroupVersionKind().Kind { | ||
case machinery.GatewayGroupKind.Kind: | ||
res = controller.GatewaysResource.GroupResource() | ||
case machinery.HTTPRouteGroupKind.Kind: | ||
res = controller.HTTPRoutesResource.GroupResource() | ||
} | ||
err = kuadrant.NewErrPolicyTargetNotFound(kuadrantv1beta3.AuthPolicyGroupKind.Kind, ref, apierrors.NewNotFound(res, ref.GetName())) | ||
} | ||
return policy.GetLocator(), err | ||
})) | ||
|
||
return nil | ||
} |
Oops, something went wrong.