Skip to content
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

excludedNamespaces wildcard with more than one dashes #3034

Closed
dgabrysch opened this issue Oct 5, 2023 · 6 comments
Closed

excludedNamespaces wildcard with more than one dashes #3034

dgabrysch opened this issue Oct 5, 2023 · 6 comments
Labels
bug Something isn't working stale

Comments

@dgabrysch
Copy link

While trying to create a Constraint we saw that "excludedNamespaces" does not appear to exclude namespaces with more than one dash and wildcards combined, e.g.

    excludedNamespaces:
      - *-test-*

What did you expect to happen:
We expect to have namespaces like user1-test-randomstring being excluded which does not work.
Namespaces, e.g. user1-randomstring, with "excludedNamespaces" with "randomstring-*" are getting excluded.

Environment:

  • Gatekeeper version: One of the later ones
  • Kubernetes version: (use kubectl version):
    Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.2", GitCommit:"31aa3e89a926f81aa0af30320ffcb71acadf3015", GitTreeState:"clean", BuildDate:"2023-04-07T07:26:22Z", GoVersion:"go1.19.6", Compiler:"gc", Platform:"linux/amd64"}
    Kustomize Version: v4.5.7
    Server Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.11+1485cc9", GitCommit:"0c8cb213485c84deb0230cbefa34bf7f1c311418", GitTreeState:"clean", BuildDate:"2023-07-04T08:59:21Z", GoVersion:"go1.19.10 X:strictfipsruntime", Compiler:"gc", Platform:"linux/amd64"}
@dgabrysch dgabrysch added the bug Something isn't working label Oct 5, 2023
Copy link

stale bot commented Dec 4, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 4, 2023
@maxsmythe maxsmythe removed the stale label Dec 6, 2023
@maxsmythe
Copy link
Contributor

user1-randomstring doesn't match randomstring-*. Does this work if you specify *-randomstring for the wildcard?

The *-test-* example should work against user1-test-randomstring. Can you confirm that specific pairing does not work?

Is k8s random name generation involved (e.g. how pod names are generated)?

Relevant code:

func (w Wildcard) Matches(candidate string) bool {
wStr := string(w)
switch {
case strings.HasPrefix(wStr, "*") && strings.HasSuffix(wStr, "*"):
return strings.Contains(candidate, strings.TrimSuffix(strings.TrimPrefix(wStr, "*"), "*"))
case strings.HasPrefix(wStr, "*"):
return strings.HasSuffix(candidate, strings.TrimPrefix(wStr, "*"))
case strings.HasSuffix(wStr, "*"):
return strings.HasPrefix(candidate, strings.TrimSuffix(wStr, "*"))
default:
return wStr == candidate
}
}
func (w Wildcard) MatchesGenerateName(candidate string) bool {
wStr := string(w)
switch {
case strings.HasPrefix(wStr, "*") && strings.HasSuffix(wStr, "*"):
return strings.Contains(candidate, strings.TrimSuffix(strings.TrimPrefix(wStr, "*"), "*"))
case strings.HasSuffix(wStr, "*"):
return strings.HasPrefix(candidate, strings.TrimSuffix(wStr, "*"))
default:
return false
}
}

Copy link

stale bot commented Feb 4, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 4, 2024
@dgabrysch
Copy link
Author

dgabrysch commented Feb 4, 2024

Somehow I did not see the notification. The "-test-" example did not work, this was why I created the issue. Since it is just trimming I guess it matches "-test-" then which is not the desired behavior.

@stale stale bot removed the stale label Feb 4, 2024
@maxsmythe
Copy link
Contributor

It should be a "contains" match, so any namespace with "-test-" as a substring should match.

Can you verify this behavior is still broken with a newer release and give the Gatekeeper version?

If it is still broken, can you give an example constraint, template, and resource that should be exempt but is throwing a violation?

Copy link

stale bot commented Apr 9, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 9, 2024
@stale stale bot closed this as completed Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

2 participants