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

config: allow multiple configurations #164

Closed
wants to merge 3 commits into from

Conversation

squat
Copy link
Contributor

@squat squat commented Apr 1, 2022

This commit fixes issue #154 by enabling the user to repeat the
--config-file flag multiple times to specify multiple configurations.
Doing so, allows the user to declare that the krp should, e.g., enforce
multiple resource attributes.

fixes: #154

cc @simonpasquier @s-urbaniak

Signed-off-by: Lucas Servén Marín [email protected]

This commit fixes issue brancz#154 by enabling the user to repeat the
`--config-file` flag multiple times to specify multiple configurations.
Doing so, allows the user to declare that the krp should, e.g., enforce
multiple resource attributes.

Signed-off-by: Lucas Servén Marín <[email protected]>
@squat
Copy link
Contributor Author

squat commented Apr 1, 2022

Now that KRP can take multiple config files, it is possible that it will
need to make multiple outbout SubjectAccessReview requests to the
Kubernetes API. In order to keep authorization fast, this commit
modifies the proxy so that all authorizations are concurrent. As soon as
one authorization fails, the context is cancelled and all other
in-flight calls are stopped.

Signed-off-by: Lucas Servén Marín <[email protected]>
@squat
Copy link
Contributor Author

squat commented Apr 5, 2022

cc @ibihim

@ibihim
Copy link
Collaborator

ibihim commented Apr 7, 2022

Thx a lot for the PR. I will try to take a look into it next week. Currently the focus is to make the release and support the transition of this project into a k8s sig-auth maintained project. So please bear with me 😅

@squat
Copy link
Contributor Author

squat commented Apr 7, 2022

Thanks for the ACK, @ibihim

For completeness, it looks like @s-urbaniak is happy with this general approach [0], and it seems like other projects, both in- and outside of Red Hat would be glad for such a feature.

[0] #154 (comment)

@s-urbaniak
Copy link
Collaborator

hey @squat 👋 yes, I recall discussions around this in the past and we concluded that this is a non-breaking useful change 👍 let us add this once we are done with the current release woes :-)

pkg/proxy/proxy.go Outdated Show resolved Hide resolved
@squat
Copy link
Contributor Author

squat commented Apr 22, 2022

ping @s-urbaniak
that concurrency issue is addressed :)

@ibihim
Copy link
Collaborator

ibihim commented May 9, 2022

ok, sorry. I got pretty busy. I will give it a shot this week.

@squat
Copy link
Contributor Author

squat commented May 12, 2022

Looks like your recent PR introduced some conflicts with this branch. I'll rebase this ASAP. Hopefully you have some time to take a look soon. Cc @ibihim @s-urbaniak

Subresource: c.Authorization.ResourceAttributes.Subresource,
Name: c.Authorization.ResourceAttributes.Name,
},
if len(c.Authorizations) != 0 {
Copy link
Collaborator

@ibihim ibihim Jun 2, 2022

Choose a reason for hiding this comment

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

We don't need this any more. DeepCopy was unused and removed.

params = append(params, ps...)
for _, ac := range n.authzConfigs {
if ac.ResourceAttributes == nil {
allAttrs = append(allAttrs, defaultAttributesRecord)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a benefit to having the defaultAttributesRecord several times in the allAttrs?

Path: r.URL.Path,
})
return allAttrs
// Default attributes mirror the API attributes that would allow this access to kube-rbac-proxy
Copy link
Collaborator

@ibihim ibihim Jun 2, 2022

Choose a reason for hiding this comment

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

Maybe I am lazy, but I would've map'ed the old GetRequestAttributes to the new n.authzConfigs list.

func (n krpAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *http.Request) []authorizer.Attributes {
    allAttrs := []authorizer.Attributes{}
    
    for _, ac := range n.authzConfigs{
            allAttrs = append(allAttrs, getRequestAttributes(u, r, ac)...)
    }

    return allAttrs
}

}
wg.Wait()
if authzDone == 1 {
return false
Copy link
Collaborator

@ibihim ibihim Jun 3, 2022

Choose a reason for hiding this comment

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

The solution is pretty effective. And this part is the reason, why it took me ages to make a PR review. I have huge respect for concurrency and the problems it brings.

I would've tried to use something well known like a fan out pattern or tried to separate the threading logic from the rest as much as possible.

There is a very low level of abstraction in the code base and the hierarchy is pretty flat with lengthy functions, so I won't object as it fits existing code.

@@ -37,7 +37,7 @@ Usage of _output/kube-rbac-proxy:
--auth-header-user-field-name string The name of the field inside a http(2) request header to tell the upstream server about the user's name (default "x-remote-user")
--auth-token-audiences strings Comma-separated list of token audiences to accept. By default a token does not have to have any specific audience. It is recommended to set a specific audience.
--client-ca-file string If set, any request presenting a client certificate signed by one of the authorities in the client-ca-file is authenticated with an identity corresponding to the CommonName of the client certificate.
--config-file string Configuration file to configure kube-rbac-proxy.
--config-file strings Configuration file to configure kube-rbac-proxy. Can be specified multiple times to configure multiple resource authorizations.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would string be more appropriate as it is not a comma-separated list, but it can be specified multiple times? In comparison to --ignore-paths below.

@ibihim
Copy link
Collaborator

ibihim commented Jun 3, 2022

Thank you for your contribution and your patience!!! 🎉

@ibihim
Copy link
Collaborator

ibihim commented Nov 28, 2022

I am sorry that there is now even more rebasing issues.

I would close this issue as it is stale. Feel free to reopen it, once you work on it again.

@ibihim
Copy link
Collaborator

ibihim commented Dec 14, 2022

The PR is pretty stale, please reopen it and rebase it, if you want to continue to work on it.

@ibihim ibihim closed this Dec 14, 2022
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.

Ability to configure several resource request authorizations
3 participants