-
Notifications
You must be signed in to change notification settings - Fork 12
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
Restrict lookups of cluster-scoped resources #85
Restrict lookups of cluster-scoped resources #85
Conversation
pkg/templates/generic_lookup_func.go
Outdated
if !apiResource.Namespaced && t.config.LookupNamespace != "" { | ||
rsrcIdentifier := ClusterScopedObjectIdentifier{ | ||
Group: apiResource.Group, | ||
Version: apiResource.Version, |
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 don't think the version should be used in the restriction. For instance, if ClusterClaim has an API version bump, I wouldn't want the calling code to be updated.
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.
That's a good point.
pkg/templates/generic_lookup_func.go
Outdated
} | ||
|
||
for _, item := range allowlist { | ||
if item.Group == "*" && item.Version == "*" && item.Kind == "*" && item.Name == "*" { |
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 think something like this would be better:
if item.Group != "*" && item.Group != rsrc.Group {
continue
}
if item.Kind != "*" && item.Kind != rsrc.Kind {
continue
}
if item.Name == "*" || item.Name == rsrc.Name {
return true
}
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.
Just a few comments but this looks good!
In some cases, it was possible to do a cluster-scoped lookup, despite `LookupNamespace` being set on the config, which was intended to prevent this. That is fixed, and more thoroughly tested. A new config field `ClusterScopedAllowList` was added to allow specific cluster-scoped resources to be used in `lookup` when `LookupNamespace` is set. Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
d71ef30
to
76beeea
Compare
Kudos, SonarCloud Quality Gate passed! |
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.
Nice!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JustinKuli, mprahl The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
In some cases, it was possible to do a cluster-scoped lookup, despite
LookupNamespace
being set on the config, which was intended to prevent this. That is fixed, and more thoroughly tested.A new config field
ClusterScopedAllowList
was added to allow specific cluster-scoped resources to be used inlookup
whenLookupNamespace
is set.