Skip to content

Feature/wildcard matching#35641

Closed
mstrYoda wants to merge 2 commits intoistio:masterfrom
mstrYoda:feature/wildcard-matching
Closed

Feature/wildcard matching#35641
mstrYoda wants to merge 2 commits intoistio:masterfrom
mstrYoda:feature/wildcard-matching

Conversation

@mstrYoda
Copy link
Contributor

@mstrYoda mstrYoda commented Oct 17, 2021

Please provide a description of this PR:

Add wildcard path matching. This pr makes possible to write authz. paths like:

  • "/test/*/resource"
  • "/test/*/resource/*/subResource"

Resolves: #16585

I've test it locally and it works fine.

Here is the AuthorizationPolicy I wrote:

apiVersion: v1
items:
- apiVersion: security.istio.io/v1beta1
  kind: AuthorizationPolicy
  metadata:
    name: test-auth-policy
  spec:
    action: DENY
    rules:
    - to:
      - operation:
          methods:
          - GET
          paths:
          - "/test/*/example"
          - "/test/*/example/*/subpath"
      when:
      - key: request.headers[test]
        notValues:
        - example
    - to:
      - operation:
          methods:
          - POST
          paths:
          - "/test/*/example"
      when:
      - key: request.headers[test]
        notValues:
        - example
    selector:
      matchLabels:
        app: nginx
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

Here is the example requests and expected behaviors:

istio-authz-ss

@istio-policy-bot
Copy link

😊 Welcome @mstrYoda! This is either your first contribution to the Istio istio repo, or it's been
awhile since you've been here.

You can learn more about the Istio working groups, code of conduct, and contributing guidelines
by referring to Contributing to Istio.

Thanks for contributing!

Courtesy of your friendly welcome wagon.

@google-cla google-cla bot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Oct 17, 2021
@istio-testing istio-testing added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-ok-to-test labels Oct 17, 2021
@istio-testing
Copy link
Collaborator

Hi @mstrYoda. Thanks for your PR.

I'm waiting for a istio member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@mstrYoda
Copy link
Contributor Author

mstrYoda commented Oct 19, 2021

@howardjohn @yangminzhu @shamsher31 @hzxuzhonghu can you guys review it when you have free time? 🙏

Copy link
Member

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned this will lead to another stream of CVEs related to path matching. Path matching is an extremely tricky subject, and this introduces a ton of ambiguities that can lead to unauthorized access.

Additionally, I am concerned about the matching discrepancies with Authz and VirtualService with this. It seems odd I can allow /foo/*/bar but I cannot then route on the same decision.

},
}
case strings.Contains(v, "*"):
return StringMatcherRegex(prefix + strings.ReplaceAll(v, "*", ".+"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not safe. At the very least you need regex.QuoteMeta. Also, is a/*/b supposed to match a/x/y/z/b or only one path element?

Copy link
Contributor Author

@mstrYoda mstrYoda Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that it's up to developer who writes authz policy. If developers want to allow any path between a/.../b it is ok to write a/.+/b but if anyone wants to restrict specific paths, it is need to be specified, am I wrong?

+1 for regex.QuoteMeta I will send the changes 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the dev can chose to write a/.+/b though since we are only allowing wildcard.

Actually looking at it more we are not even providing 'wildcard' support - really we are providing ANY regex support, if it happens to contain a *?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that if anyone want to allow any sub paths between a/.../b is not that ok to write a/*/b in policy? So we can match all paths between that two path. Sorry if I could not understand you exactly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @howardjohn, what is your opinion on my last comment?

Copy link
Contributor

@yangminzhu yangminzhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, this is a very useful feature but it's also very tricky to get it right.

As this changes the semantic of the path field in the authorization policy (beta API), I think we should get approval at least from the security work group. Could you discuss it in work group meeting and probably write a quick doc about the change for collecting feedback and helping discussions?

@sschepens
Copy link
Contributor

@howardjohn we also would need this feature, or be able to specify regexes.

Additionally, I am concerned about the matching discrepancies with Authz and VirtualService with this. It seems odd I can allow /foo/*/bar but I cannot then route on the same decision.

This also comes to mind, why do we handle Authorization matching in a different way that we do Route matching? i seems as though they should be the same or very similar. Shouldn't we just migrate Authorization matching to use StringMatch ?

@istio-policy-bot istio-policy-bot added the lifecycle/stale Indicates a PR or issue hasn't been manipulated by an Istio team member for a while label Nov 19, 2021
@istio-policy-bot istio-policy-bot added the lifecycle/automatically-closed Indicates a PR or issue that has been closed automatically. label Dec 4, 2021
@ognjen-it
Copy link

@yangminzhu Hi, what about securty team? Does anyone sent this PR to tham?

We really need it 💯☺️🚀🎉

@qRainBirdp
Copy link

Has this function already beeHas this function already been available in the official version of istio?
We really need it!

@mstrYoda
Copy link
Contributor Author

mstrYoda commented Jun 16, 2022

@yangminzhu Hi, what about securty team? Does anyone sent this PR to tham?

We really need it 💯☺️🚀🎉

Has this function already beeHas this function already been available in the official version of istio? We really need it!

Is there any Istio Security Team member here? Can anyone mention someone that can review this feature?

@howardjohn @yangminzhu can you make any comments or change suggestions (in ur free time) according to my last comments in review? 🙏

@craigbox
Copy link
Contributor

Are you able to drop by a working group meeting to discuss?

See #35641 (review):

Thanks for the PR, this is a very useful feature but it's also very tricky to get it right.

As this changes the semantic of the path field in the authorization policy (beta API), I think we should get approval at least from the security work group. Could you discuss it in work group meeting and probably write a quick doc about the change for collecting feedback and helping discussions?

@mstrYoda
Copy link
Contributor Author

Are you able to drop by a working group meeting to discuss?

See #35641 (review):

Thanks for the PR, this is a very useful feature but it's also very tricky to get it right.
As this changes the semantic of the path field in the authorization policy (beta API), I think we should get approval at least from the security work group. Could you discuss it in work group meeting and probably write a quick doc about the change for collecting feedback and helping discussions?

Of course, I am willing to attend to wg meeting 🙏

@mstrYoda
Copy link
Contributor Author

Are you able to drop by a working group meeting to discuss?

See #35641 (review):

Thanks for the PR, this is a very useful feature but it's also very tricky to get it right.
As this changes the semantic of the path field in the authorization policy (beta API), I think we should get approval at least from the security work group. Could you discuss it in work group meeting and probably write a quick doc about the change for collecting feedback and helping discussions?

Hi @craigbox, can we reopen this PR? This is a highly wanted feature from community.

I try to attend one of the sec. workgroup meeting 🙏

@craigbox craigbox reopened this Apr 18, 2023
@istio-policy-bot istio-policy-bot removed the lifecycle/stale Indicates a PR or issue hasn't been manipulated by an Istio team member for a while label Apr 18, 2023
@craigbox craigbox added the lifecycle/staleproof Indicates a PR or issue has been deemed to be immune from becoming stale and/or automatically closed label Apr 18, 2023
@nberkley-gp
Copy link
Contributor

Is there any chance of getting this merged? The lack of unanchored string matches in auth policies is an issue for multiple use cases and all the related PRs/Issues seem to have gone silent for a while.

@craigbox
Copy link
Contributor

Did @mstrYoda meet with the working groups?
@howardjohn for further comment

@mstrYoda
Copy link
Contributor Author

Did @mstrYoda meet with the working groups?

@howardjohn for further comment

I did not after I saw that there will be a proposal doc. But I can attend to the closest meeting ASAP if you want to 👍

@howardjohn
Copy link
Member

This PR cannot be accepted as is (not the feature in general, just this PR from a process point of view); this will require an API change - even if not changing the proto, the docs at least.

To keep the discussion focused lets consolidate on istio/api#2173 or the issue #16585

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking area/security area/user experience cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. lifecycle/automatically-closed Indicates a PR or issue that has been closed automatically. lifecycle/staleproof Indicates a PR or issue has been deemed to be immune from becoming stale and/or automatically closed needs-ok-to-test size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support regex for ServiceRole spec.rules.paths

10 participants