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

Controller should check authorization for /debug/pprof #12907

Merged
merged 3 commits into from
Feb 13, 2017

Conversation

smarterclayton
Copy link
Contributor

@smarterclayton smarterclayton commented Feb 10, 2017

Make standalone controllers be debuggable securely by exposing the pprof handlers and adding remote authz and authn filters with small caches.

Also fixes SAR to support Non resource URLs like upstream.

@smarterclayton
Copy link
Contributor Author

[test]

@smarterclayton
Copy link
Contributor Author

@liggitt

Still need to make the change to have a short-circuit authorizer for /healthz (which always needs to be unauthenticated).

if len(review.Action.Path) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("path"), ""))
}
if len(review.Action.Resource) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

disallow all the resource-related fields (namespace, group, resource, resourcename) for non-resource urls

@@ -48,7 +55,14 @@ func ValidateResourceAccessReview(review *authorizationapi.ResourceAccessReview)
if len(review.Action.Verb) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("verb"), ""))
}
if len(review.Action.Resource) == 0 {
if review.Action.IsNonResourceURL {
Copy link
Contributor

Choose a reason for hiding this comment

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

heh, that makes ResourceAccessReview slightly nonsensical. oh well

if len(review.Action.Path) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("path"), ""))
}
if len(review.Action.Resource) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

prevent all resource-related attributes

if len(review.Action.Path) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("path"), ""))
}
if len(review.Action.Resource) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

prevent all resource-related attributes

if len(review.Action.Path) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("path"), ""))
}
if len(review.Action.Resource) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

prevent all resource-related attributes

return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
user, ok, err := authenticator.AuthenticateRequest(req)
if err != nil || !ok {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, hope everyone deals with non-API responses well

return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
user, ok, err := authenticator.AuthenticateRequest(req)
if err != nil || !ok {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
Copy link
Contributor

@liggitt liggitt Feb 10, 2017

Choose a reason for hiding this comment

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

surprised we were returning this from the API... I thought only the node did unstructured errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

@liggitt
Copy link
Contributor

liggitt commented Feb 10, 2017

assuming the big blocks were straight moves, seems mostly sane. still not quite sure about controller manager as a serviceaccount

@smarterclayton
Copy link
Contributor Author

smarterclayton commented Feb 10, 2017 via email

@smarterclayton
Copy link
Contributor Author

smarterclayton commented Feb 10, 2017 via email

@smarterclayton
Copy link
Contributor Author

All big blocks were moves.

@smarterclayton smarterclayton force-pushed the split_handlers branch 3 times, most recently from 27819ab to ae9da74 Compare February 10, 2017 18:04
@smarterclayton smarterclayton changed the title WIP - Controller should check authorization for /debug/pprof Controller should check authorization for /debug/pprof Feb 10, 2017
@smarterclayton
Copy link
Contributor Author

Ok, added a quick test and the /healthz and /healthz/ready bypass and tested locally.

@smarterclayton smarterclayton force-pushed the split_handlers branch 2 times, most recently from b24b58e to 94a1f12 Compare February 10, 2017 20:10
@stevekuznetsov
Copy link
Contributor

[test]

os::cmd::expect_success 'oc login -u system:admin'
os::cmd::expect_failure_and_text 'oc get --raw /debug/pprof/ --as=user3' 'Forbidden'
os::cmd::expect_failure_and_text 'oc get --raw /metrics --as=user3' 'Forbidden'
os::cmd::expect_success 'oadm policy add-cluster-role-to-user cluster-debugger user3'
Copy link
Contributor

Choose a reason for hiding this comment

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

needs wait_for to avoid flakes in the gets below

os::cmd::expect_success_and_text 'oc login -u user3 -p pw' 'Login successful'
os::cmd::expect_success 'oc login -u system:admin'
os::cmd::expect_failure_and_text 'oc get --raw /debug/pprof/ --as=user3' 'Forbidden'
os::cmd::expect_failure_and_text 'oc get --raw /metrics --as=user3' 'Forbidden'
Copy link
Contributor

Choose a reason for hiding this comment

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

test /healthz access is allowed even without the role?

handler := serverhandlers.AuthorizationFilter(apiContainer.ServeMux, authz, c.AuthorizationAttributeBuilder, contextMapper)
handler = serverhandlers.AuthenticationHandlerFilter(handler, authn, contextMapper)
handler = kgenericfilters.WithPanicRecovery(handler, contextMapper)
handler = kapiserverfilters.WithRequestInfo(handler, genericapiserver.NewRequestInfoResolver(&genericapiserver.Config{}), contextMapper)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this request info resolver going to try to build API attributes if the path starts with /apis, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it will

@liggitt
Copy link
Contributor

liggitt commented Feb 11, 2017

a few nits, LGTM

@stevekuznetsov
Copy link
Contributor

Not a flake:

[WARNING] While the jUnit report found no failed tests, the `go test` process failed.
[WARNING] This usually means that the unit test suite failed to compile.
[WARNING] `go test` had the following output to stderr:
# github.com/openshift/origin/pkg/cmd/server/origin
pkg/cmd/server/origin/handlers_test.go:289: config.impersonationFilter undefined (type MasterConfig has no field or method impersonationFilter)

Will be replaced in a future release with generic upstream filters.
Give the controller the profiler endpoints and put it behind a remote
authn|z story. Move the node authenticator to a reusable spot. Set a
small cache size.
@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 50fa90e

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_future/145/) (Base Commit: cb863ae)

@smarterclayton
Copy link
Contributor Author

Comments addressed, green [merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 50fa90e

@openshift-bot
Copy link
Contributor

openshift-bot commented Feb 13, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_future/148/) (Base Commit: e9c6020) (Image: devenv-rhel7_5905)

@openshift-bot openshift-bot merged commit bc3a0cc into openshift:master Feb 13, 2017
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.

4 participants