Skip to content

Conversation

danielpacak
Copy link
Contributor

@danielpacak danielpacak commented Jun 28, 2019

This one is supposed to resolve #31 . I took also the opportunity to refactor and add more unit tests to the functionality of mapping [Cluster]RoleBindings to [Cluster]Roles.
At the end I've added the scenario to our integration test suite which reproduced the actual issue reported by @raesene

I suggest review this PR commit by commit.

@codecov-io
Copy link

codecov-io commented Jun 28, 2019

Codecov Report

Merging #34 into master will increase coverage by 10.05%.
The diff coverage is 82.1%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #34       +/-   ##
===========================================
+ Coverage   65.33%   75.39%   +10.05%     
===========================================
  Files           4        5        +1     
  Lines         375      382        +7     
===========================================
+ Hits          245      288       +43     
+ Misses        124       83       -41     
- Partials        6       11        +5
Impacted Files Coverage Δ
pkg/cmd/list.go 65.08% <71.73%> (+9.24%) ⬆️
pkg/cmd/policy_rule_matcher.go 91.83% <91.83%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7430706...9c7b517. Read the comment docs.

@danielpacak danielpacak requested a review from lizrice June 29, 2019 16:25
Copy link
Contributor

@lizrice lizrice left a comment

Choose a reason for hiding this comment

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

Nice :-) Couple of tiny comments, so I won't merge till you're ready, but I am happy.

@@ -395,6 +397,7 @@ func (w *whoCan) GetClusterRolesFor(action Action) (clusterRoles, error) {

// GetRoleBindings returns the RoleBindings that refer to the given set of Role names or ClusterRole names.
func (w *whoCan) GetRoleBindings(roleNames roles, clusterRoleNames clusterRoles) (roleBindings []rbac.RoleBinding, err error) {
// TODO I'm wondering if GetRoleBindings should be invoked at all when the --all-namespaces flag is specified?
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting! I think this comes down to the semantics of --all-namespaces, which I now think is ambiguous:

  • If it means "who can verb resource in any namespace" then yes, I think we should be looking at all the possible rolebindings.
  • If it means "who can verb resource in all namespace" then we could limit to just clusterRoles, but then we'd be missing the possibility of someone who has this ability, not through a clusterRole but by being bound to a Role for every namespace

The first of these options seems more useful to me anyway. Either way, we should clarify it in the usage.

Copy link
Contributor Author

@danielpacak danielpacak Jul 3, 2019

Choose a reason for hiding this comment

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

So maybe we should have a dedicated flags --any-namespace and --all-namespaces to make it less ambiguous? Plus what you mentioned a better usage docs. Anyway I'll file an issue for that to consider it carefully.

Rules: []rbac.PolicyRule{
{
Verbs: []string{"get"},
NonResourceURLs: []string{"/logs"},
APIGroups: []string{""},
Copy link
Contributor

Choose a reason for hiding this comment

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

If we wanted to support CRDs, would we need to allow the user to specify the APIGroup?

Copy link
Contributor Author

@danielpacak danielpacak Jul 3, 2019

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. We do not currently resolve APIGroup so that's another improvement we might want to put in place.

$ kubectl auth can-i get deployments.extensions
yes

$ kubectl who-can get deployments.extensions
Error: resolving resource: the server doesn't have a resource type "deployments.extensions"

@@ -49,6 +49,11 @@ NONRESOURCEURL is a partial URL that starts with "/".`

# List who can access the URL /logs/
kubectl who-can get /logs`

// RoleKind is the RoleRef's Kind referencing a Role.
RoleKind = "Role"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm OK with this as it's unlikely to change, but is there not a definition we could pull in from kubernetes somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not. I did search in project's dependencies and it seems that it's common to repeatedly type in "Role" and "CusterRole" literals all over the place ;)

pkg/cmd/list.go Outdated
glog.V(1).Info(fmt.Sprintf("Match found: roleRef: %v", roleBinding.RoleRef))
for _, roleBinding := range list.Items {
if _, ok := clusterRoleNames[roleBinding.RoleRef.Name]; ok {
//if w.clusterRoleBindingMatches(&roleBinding, clusterRoleNames) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I doubt you meant to leave this comment here

@danielpacak
Copy link
Contributor Author

Hey @lizrice thanks for the review. Let's merge this bulky PR. I have created dedicated issues #38 #39 to follow up on you comments.

@lizrice lizrice merged commit 01427bc into aquasecurity:master Jul 3, 2019
@danielpacak danielpacak deleted the issue_31_fix_rolebinding_bound_to_clusterrole branch July 8, 2019 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible gap where rolebindings are used with clusterroles
3 participants