zalando-incubator/fabric-gateway

Hierarchical path and multi-method selectors

cbndr opened this issue · 3 comments

cbndr commented

Many APIs implement hierarchical paths, for instance

/customers
/customers/{id}
/customers/{id}/addresses
/customers/{id}/addresses/{id}

In many scenarios, a class of http ops on the full hierarchy shall be accessible with the same set of rules (e.g. POST/PUT/PATCH/DELETE on /customers, /customers/{id}, etc).

The current path selector allows to select multiple segments, e.g. /customers/**, but this would not select the collection endpoint /customers. The method selector can only select a single method. This leads to a lot of unnecessary duplication of access rules under the above scenario.

My proposal therefore is to be able to combine all or any permutation of the above paths and methods in one selector in order to reduce duplication of access rules.

Possible solutions could be to allow the path selector to be a list or to allow the path selector to be a regular expression. For example:

spec:
  paths:
    "/customers|/customers/**":
      "post|patch|delete":
        x-fabric-privileges:
          ...

...but any other solution you come up with to select multiple paths and methods would of course work as well.

Our current CRD is closely modelled on the Open API Spec format. We had intended to keep this close to that format for easier integration with tools like zally and the API portal. If we added this type of route parsing then I think it would make it more difficult to realise these integrations in the future.

I'm going to close this feature as something that we're not going to implement. At least not in the current version of the CRD. If we get to the point where we are doing a version bump of the CRD, we may re-evaluate the OAS format pinning and look at options like this.

Cheers for the feedback though @cbndr . Much appreciated...

Just got the hint from Conor G. to use Yaml anchors:
https://medium.com/@kinghuang/docker-compose-anchors-aliases-extensions-a1e4105d70bd

Cool. I haven't seen any usage of anchors in K8s resources. Let us know if ye run into any issues with it....