-
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
[authpolicy-v2] route selectors #256
Conversation
c17b098
to
56fa684
Compare
56fa684
to
f609da2
Compare
Codecov Report
@@ Coverage Diff @@
## authpolicy-v2 #256 +/- ##
=================================================
+ Coverage 62.76% 63.77% +1.00%
=================================================
Files 34 35 +1
Lines 3242 3776 +534
=================================================
+ Hits 2035 2408 +373
- Misses 1036 1172 +136
- Partials 171 196 +25
Flags with carried forward coverage won't be shown. Click here to find out more.
|
f609da2
to
e3fbe03
Compare
02ebab4
to
d60089d
Compare
87a7f27
to
7bd3f8e
Compare
d60089d
to
afa63b1
Compare
b97e4d4
to
53f7a6d
Compare
afa63b1
to
6491b20
Compare
a77a220
to
68019ec
Compare
7982c80
to
d259f99
Compare
2f8ae9b
to
4820025
Compare
d259f99
to
d1dc7f4
Compare
4820025
to
8818edb
Compare
d1dc7f4
to
07ad6be
Compare
07ad6be
to
6d48bd6
Compare
…y) into all Istio AuthorizationPolicy rules that do not include hostnames already built from the route selectors, so we don't send a request to authorino for hosts that are not in the scope of the policy
…Rule and between HTTPRouteRules themselves
Skips creation of Istio AuthorizationPolicies and Authorino AuthConfigs for gateways without any accepted HTTPRoutes.
…entRefs of the route and finds all policies that target one of its parent resources, thus yielding events for those policies.
…sion and HeaderMatchRegularExpression
…or full HTTPRoute only (i.e. ignore config-level conditions)
+ unit tests from Istio AuthorizationPolicy rules from HTTPRouteRules and hostnames
… attached to HTTPRoutes
7101dd3
to
702e821
Compare
6d48bd6
to
09d0dff
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.
Verification steps work and nothing in the code is standing.
Group: "gateway.networking.k8s.io", | ||
Kind: "HTTPRoute", | ||
Name: testHTTPRouteName, | ||
Namespace: ptr.To(gatewayapiv1beta1.Namespace(testNamespace)), |
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 have seen this in a few places and I don't have a problem with it but my question is more of a why. The ptr.To
returns a pointer to what ever objects but putting &
before the object would be the same and is what ptr.To
does. Why bring in the extra dependency? It feels very like the js isOdd saga.
We may have found a bug that needs clearing up
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.
Initially I was not 100% on the intended behaviour of the AuthPolicy
in step 7 of the verification as it didn't seem entirely intuitive but after some more investigation and discussion with @Boomatang and @alexsnaps I'm happy that it's expected. Code all looks good as far as I can tell also.
requests := mapper.MapToAuthPolicy(route) | ||
for i := range requests { | ||
request := requests[i] | ||
go r.Reconcile(context.Background(), request) |
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 seems odd. Are we not dropping errors and reconcile requests being returned from this this way? Should it be done as part of a Watches in the NewControllerManagedBy
?
We have something "like this "
Watches(&source.Kind{Type: &workv1.ManifestWork{}}, handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {
log.V(3).Info("enqueuing gateways based on manifest work change ", "work namespace", o.GetNamespace())
requests := []reconcile.Request{}
annotations := o.GetAnnotations()
if annotations == nil {
log.V(3).Info("no parent or anotations on manifest work ", "work ns", o.GetNamespace(), "name", o.GetName())
return requests
}
key := annotations["kuadrant.io/parent"]
ns, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
log.Error(err, "failed to parse namespace and name from maifiest work")
return requests
}
log.Info("requeuing gateway ", "namespace", ns, "name", name)
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{Namespace: ns, Name: name},
})
return requests
}), builder.OnlyMetadata).
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.
What kind of resource should we watch and map to AuthPolicies, @maleck13?
The intent here is, after reconciling an AuthPolicy attached to a HTTPRoute, to trigger the reconciliation of all AuthPolicies attached to Gateways that are parents of the HTTPRoute.
A few constraints are:
- Neither HTTPRoute nor the Gateways are touched during any of those reconciliation loops. Only the internal custom resources might (i.e.
AuthorizationPolicy
,AuthConfig
.) - We do not want to rely on back-ref annotations for this, as order matters here and therefore we want the latest state possible.
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.
Right. Prob wrong place to start figuring this out here. It would seem we need to trigger an event on the HTTPRoute (status update / annotation) or we need to track the parent policies. Do we have an issue for looking into a better option? I know it was discussed. IE have an in mem structure that we maintain of the policy hierarchy. Trigger a reconcile on parents on child change (or something along those lines) so I guess if we have an issue for that we could settle with this for now?
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'll make sure to open one and add it here for ref.
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.
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 have given this a review as best I can without knowing the code base well. I have one question about how we are triggering a reconcile other than that it looks reasonable
[authpolicy-v2] Well-known attributes in the generated AuthConfigs
[authpolicy-v2] route selectors
[authpolicy-v2] route selectors
[authpolicy-v2] route selectors
Closes:
routeSelectors
fields to the AuthPolicy #248TODOs
QueryParamMatchRegularExpression
typePathMatchRegularExpression
andHeaderMatchRegularExpression
types respectivelyReport (in the logs, status, etc) about route selectors that match no HTTPRouteRule(separate PR)Verification steps
Setup
① Create the cluster, install & deploy Kuadrant:
② Request an instance of Kuadrant:
③ Deploy a sample API:
(Optional) Test the API unprotected:
Create AuthPolicies
④ Create a trivial AuthPolicy:
⑤ Create an AuthPolicy with auth rules:
⑥ Create an AuthPolicy with top-level route selectors:
⑦ Create an AuthPolicy with config route selectors:
After each step ④ → ⑦ above,
❶ Check the state of the Istio AuthorizationPolicy:
❷ Check the state of the Authorino AuthConfig:
❸ Send requests to the 3 endpoints of the API:
curl -H 'Host: api.toystore.com' http://localhost:9080/cars -i
curl -H 'Host: api.toystore.com' http://localhost:9080/dolls -i
curl -H 'Host: api.toystore.com' http://localhost:9080/admin -i