-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PolicyAffected condition for AuthPolicy and RateLimitPolicy #536
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #536 +/- ##
===========================================
- Coverage 80.20% 31.95% -48.26%
===========================================
Files 64 65 +1
Lines 4492 4913 +421
===========================================
- Hits 3603 1570 -2033
- Misses 600 3250 +2650
+ Partials 289 93 -196
Flags with carried forward coverage won't be shown. Click here to find out more.
|
controllers/kuadrant_status.go
Outdated
@@ -196,7 +195,7 @@ func BuildPolicyAffectedCondition(conditionType string, policyObject runtime.Obj | |||
return condition | |||
} | |||
|
|||
condition.Message = fmt.Sprintf("policy success. Object affected by policy %s in namespace %s with name %s ", policyObject.GetObjectKind().GroupVersionKind().String(), objectMeta.GetNamespace(), objectMeta.GetName()) | |||
condition.Message = fmt.Sprintf("policy success. Object affected by policy %s in namespace %s with name %s", policyObject.GetObjectKind().GroupVersionKind().String(), objectMeta.GetNamespace(), objectMeta.GetName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikenairn @maleck13, how important would you say having the name of the policy in the message here is?
I guess for gateway policies – which is always the case of DNSPolicy and TLSPolicy – it's probably good?
This doesn't work well though when the gateway can be affected by more than one policy, such as with AuthPolicies and RateLimitPolicies, that can affect gateways by targeting the routes as well, or, in general, when more than one policy of a kind can target the Gateway (not allowed today).
Currently, the message contains the name of the last policy which caused the PolicyAffected condition to be set (to either true or false.) We also have the full list of policies that affect a gateway stored in the back ref annotation of the gateway object.
I guess my actual question is: are we OK with only the last policy mentioned in the message for each and all kinds of policies or I may change the message to make it more generic without mentioning the name of the policy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting question. I don't yet have a strong opinion. If the policy is truly affecting the gateway and not being overridden, does it not make sense to have multiple conditions perhaps at the listener and top level? I guess it comes down to what we want to achieve with the condition. Is it that we want to indicate this gateway is affected by at least one policy or do we want a pointer to say these specific policies are affecting this gateway. Sorry for the late reply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ended applying the following:
-
If only a policy targeting the object indirectly exists (i.e. Gateway policy with no route policy) → this policy will be referred in the PolicyAffected message
-
If a policy targeting the object directly exists → this policy will be referred in the PolicyAffected message even if the policy is being overridden by another. To confirm if a policy referred in PolicyAffected message is being enforced, the user must check the status of the policy object itself.
if err := r.Client.Status().Update(ctx, gw.Gateway); err != nil { | ||
return err | ||
} | ||
// TODO(guicassolato): for inherited policies only – add the policyaffetced status condition on all routes accepted by the gateway |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is assuming that, no matter at level the policy targets an object (gateway or route), all objects (gateways and routes) will be marked as affected by the policy.
Is that really what we want or we want to set this condition only on the object targeted by the policy plus its children (but never upwards)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go for the latter. It makes more sense to me this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I need to change a few things then. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed so direct policies (TLS/DNS) only add to the statuses of the objects they target (Gateways only) and inherited (auth/RL) to the objects they target plus children beneath.
67aa611
to
faf82b0
Compare
ControllerName: controllerName, | ||
ParentRef: gatewayapiv1.ParentReference{ | ||
Kind: ptr.To(gatewayapiv1.Kind(gateway.Kind)), | ||
Name: gatewayapiv1.ObjectName(gateway.GetName()), | ||
Namespace: ptr.To(gatewayapiv1.Namespace(gateway.GetNamespace())), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will create in the route a parent status block with controllerName: kuadrant.io/policy-controller
and targetRef
pointing to the affected gateway.
One can only assume what the actual controllerName
of the gateway is, but this information is omitted here.
Should we instead reuse the same parent status block of the gateway controller and not have one specifically for Kuadrant?
78e0e42
to
850b412
Compare
} | ||
|
||
func (r *TargetStatusReconciler) Reconcile(eventCtx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
logger := r.Logger().WithValues("gateway", req.NamespacedName, "request id", uuid.NewString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about adding request id
at all reconcilers. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also thinking about this but wondering should it follow the guidelines set in opentelemetry, but I am not sure if our current approach fits into that style if parent ids.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I may have seen reconcileID
in some other log trail. No longer sure if this request id
will be useful in the end.
26fd172
to
adb681a
Compare
8c139f5
to
92bc448
Compare
Everything looks good to me. That said I could only run the verification steps for the AuthPolicies. I have a local issue with RateLimiting, unrelated to the changes in this PR. You will need to find someone to do the full verification. |
92bc448
to
3dbe4d4
Compare
Verification steps updated in the description of the PR to:
|
…s for AuthPolicy and RateLimitPolicy
… the gateway controller name Removes the need for authorizing reading gateway classes
…policy status changed only based on simple predicate function instead of custom handler
3dbe4d4
to
e7e8b38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified, works perfectly 💯
Have a minor comment / question on integration test that I'm happy for it to be addressed at a later PR if it's something that was missed since it's very minor 👍
I’m merging this in spite of the integration test failing. It’s unrelated to the PR. In fact, similar ones are currently failing in main as well. |
* PolicyAffected status condition added to Gateway and HTTPRoute objects for AuthPolicy and RateLimitPolicy * refactor: fetch routes accepted by a given gateway without specifying the gateway controller name Removes the need for authorizing reading gateway classes * Trigger target status reconciliation for policies when the policy status changed only * refactor: trigger target status reconciliation for policies when the policy status changed only based on simple predicate function instead of custom handler * tests: fixed integration test for policyaffected condition inherited by the routes
Closes #467 and #468
Verification steps
Setup (1-off step)
Create the cluster:
Request an instance of Kuadrant:
Deploy the sample app:
Check the state (repeat before and after every step of creating/deleting a policy)
Check the state conditions of the Gateway and HTTPRoutes:
Check the enforcement of the policies by sending requests to the app:
To the
api
route without authentication:To the
api
route with authentication:To the
admin
route without authentication:Create/delete policies
❶ Create TLSPolicy
❷ Create Gateway default AuthPolicy
❸ Create Route AuthPolicy
❹ Create Route RateLimitPolicy
❺ Create Gateway override RateLimitPolicy
❻ Delete Gateway default AuthPolicy
❼ Delete Route AuthPolicy
❽ Delete Route RateLimitPolicy
❾ Delete Gateway override RateLimitPolicy
Expected states
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy toystore/api-authn
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy toystore/api-authn
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy toystore/high-limit-api
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy toystore/api-authn
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy toystore/high-limit-api
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy istio-system/default-deny
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/AuthPolicyAffected
Object affected by AuthPolicy toystore/api-authn
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy toystore/high-limit-api
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy toystore/high-limit-api
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/RateLimitPolicyAffected
Object affected by RateLimitPolicy istio-system/low-limit
kuadrant.io/TLSPolicyAffected
Object affected by TLSPolicy istio-system/gw-tls
istio-system/low-limit
. Check the status oftoystore/high-limit-api
to verify it's being overriden by the gateway policy.