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

Audit support resource wildcard matching #55306

Merged
merged 3 commits into from
Feb 13, 2018

Conversation

hzxuzhonghu
Copy link
Member

@hzxuzhonghu hzxuzhonghu commented Nov 8, 2017

What this PR does / why we need it:

audit policy support "resource/subresources" wildcard matching "resource/", "/subresource","*"

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #55305

Special notes for your reviewer:

Release note:

[advanced audit] support subresources wildcard matching.

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 8, 2017
@hzxuzhonghu hzxuzhonghu changed the title Audit Audit support subresources wildcard matching Nov 8, 2017
@hzxuzhonghu
Copy link
Member Author

/assign @sttts @crassirostris

@hzxuzhonghu
Copy link
Member Author

/cc @CaoShuFeng

@CaoShuFeng
Copy link
Contributor

/asign @ericchiang

@CaoShuFeng
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 8, 2017
@@ -220,8 +220,9 @@ type GroupResources struct {
// +optional
Group string
// Resources is a list of resources within the API group. Subresources are
// matched using a "/" to indicate the subresource. For example, "pods/log"
// would match request to the log subresource of pods. The top level resource
// matched using a "/" to indicate the subresource. Also "/*" can be used
Copy link
Contributor

Choose a reason for hiding this comment

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

Please run:
hack/update-all.sh

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@@ -163,6 +161,11 @@ func ruleMatchesResource(r *audit.PolicyRule, attrs authorizer.Attributes) bool
return true
}
}
if strings.HasSuffix(res, "/*") {
if strings.HasPrefix(resource, strings.TrimRight(res, "/*")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than check the prefix, I think this is more safe:
attrs.GetResource() == strings.TrimRight(res, "/*")

Copy link
Member Author

Choose a reason for hiding this comment

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

I think they are the same

	resource := attrs.GetResource()
	// If subresource, the resource in the policy must match "(resource)/(subresource)"
	if sr := attrs.GetSubresource(); sr != "" {
		resource = resource + "/" + sr
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

They are not 100% same.
What if user has such illegal resource in policy: "pods/log/*" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we support this illegal resource? I think we should not support wrong config.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we support this illegal resource? I think we should not support wrong config.

With attrs.GetResource() == strings.TrimRight(res, "/*") we can avoid this, so why not?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I know your meaning .

@CaoShuFeng
Copy link
Contributor

CaoShuFeng commented Nov 8, 2017

Just for reference:
We had some talk here #48836

@CaoShuFeng
Copy link
Contributor

This is a change which has effect to users.
So, a release note would be better.

@hzxuzhonghu
Copy link
Member Author

This is a change which has effect to users.
So, a release note would be better.

OK, thanks

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Nov 8, 2017
@ericchiang
Copy link
Contributor

ericchiang commented Nov 8, 2017

FYI RBAC supports "*/(subresource)" for resources like "*/scale" but not "(resource)/*" because we didn't identify a valid use case.

What's the use case here? Subresources can have dramatically different characteristics.

@hzxuzhonghu
Copy link
Member Author

FYI RBAC supports "/(subresource)" for resources like "/scale" but not "(resource)/*" because we didn't identify a valid use case.
What's the use case here? Subresources can have dramatically different characteristics.

How about "pods/log" "pods/status"? By the way, // TODO: consider adding options like "pods/*" to match all subresources.` exist .

@hzxuzhonghu
Copy link
Member Author

/retest

@hzxuzhonghu
Copy link
Member Author

@ericchiang Also I find in #48836 (comment)

@ericchiang
Copy link
Contributor

ericchiang commented Nov 9, 2017

How about "pods/log" "pods/status"?

This seems hypothetical. Why not be explicit and enumerate them? "pod/status" and "pod/exec" have dramatically different security implications. Are there any resources where this would be useful since almost everything else just has /status and /scale.

Not that this couldn't be useful, but do we even want to encourage pods/*? Which seems like obvious way to use this feature.

@hzxuzhonghu
Copy link
Member Author

hzxuzhonghu commented Nov 9, 2017

@ericchiang Compared to other policy rules,such as rbac/initializer, etc. They all have Resources, but have little difference, some match "/subresource", some match "resource/" and some match "". I think we should support "resource/" wildcard matching at least, if not match all patterns.

@hzxuzhonghu hzxuzhonghu force-pushed the audit branch 3 times, most recently from 7011b3a to 3e0963c Compare November 9, 2017 07:36
@crassirostris
Copy link

Contents of the PR look reasonable, but the implications of this change are questionable from the security perspective

@deads2k
Copy link
Contributor

deads2k commented Jan 10, 2018

FYI RBAC supports "/(subresource)" for resources like "/scale" but not "(resource)/*" because we didn't identify a valid use case.

What's the use case here? Subresources can have dramatically different characteristics.

@ericchiang This is a strong point for RBAC, but is it as strong an argument for auditing? For authorization decisions, we don't want to accidentally expose anything, but for auditing there's an argument for "I want to record all activity on pods". If a new subresource is added for pods, I probably do want to start recording activity for it.

The power to use those endpoints (RBAC) should remain an explicit opt-in, but the power to record activity on those endpoints could reasonably desire to default on.

@ericchiang
Copy link
Contributor

The power to use those endpoints (RBAC) should remain an explicit opt-in, but the power to record activity on those endpoints could reasonably desire to default on.

@deads2k sure I can go for that.

@soltysh
Copy link
Contributor

soltysh commented Jan 16, 2018

Imagine a new subresource comes around that's not covered by this policy. It requires manual intervention to silence this resource, which is far from optimal.

I was about to stress what @deads2k wrote above. If a new subresource comes in, you do want to know about it and react. I agree with majority here, I don't think there's a strong use-case for this. None of the resources we have already has that many subresources that it's a problem to list them. I'm in the camp for 'explicit is better than implicit'.

@hzxuzhonghu
Copy link
Member Author

@soltysh audit is different from RBAC, I think @deads2k mean to support it.

The power to use those endpoints (RBAC) should remain an explicit opt-in, but the power to record activity on those endpoints could reasonably desire to default on.

@hzxuzhonghu
Copy link
Member Author

/assign @deads2k

@hzxuzhonghu
Copy link
Member Author

Does this make sense, if so we should take it a step forward.

@hzxuzhonghu
Copy link
Member Author

@deads2k @ericchiang @soltysh Have you achieve an consensus? I would like this pr being merged in v1.10.

@soltysh
Copy link
Contributor

soltysh commented Feb 7, 2018

@deads2k kind ping?

@deads2k
Copy link
Contributor

deads2k commented Feb 7, 2018

@deads2k @ericchiang @soltysh Have you achieve an consensus? I would like this pr being merged in v1.10.

I think we're there. pods/* is ok for audit, but not ok for rbac

// 'pods/*' means all subresources of pods.
// '*/scale' means all scale subresources.
//
// If wildcard is present, the validation rule will ensure resources do not
Copy link
Contributor

Choose a reason for hiding this comment

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

If wildcard is present, the validation rule will ensure resources do not overlap with each other.

A little confused by this statement. What's it trying to indicate?

Copy link
Member Author

Choose a reason for hiding this comment

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

It means Resources []string elements should not indicate same resource.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's wrong with when they overlap?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any validation you're talking about.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I don't see this either. Can you drop this sentence?

// Resources is a list of resources this rule applies to.
//
// For example:
// 'pods' means pods.
Copy link
Contributor

@ericchiang ericchiang Feb 8, 2018

Choose a reason for hiding this comment

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

nit: Use "matches" instead of "means"?

  • 'pods' matches requests to pods
  • 'pods/logs' matches requests to the logs subresource of pods
  • '*' matches requests to all resources and subresources
  • 'pods/*' matches requests to all subresources of pods
  • '*/scale' matches requests to the scale subresource of any resource

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@ericchiang
Copy link
Contributor

Just doc questions, other than that lgtm

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm

// 'pods/*' means all subresources of pods.
// '*/scale' means all scale subresources.
//
// If wildcard is present, the validation rule will ensure resources do not
Copy link
Contributor

Choose a reason for hiding this comment

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

What's wrong with when they overlap?

// 'pods/*' means all subresources of pods.
// '*/scale' means all scale subresources.
//
// If wildcard is present, the validation rule will ensure resources do not
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any validation you're talking about.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 8, 2018
@hzxuzhonghu
Copy link
Member Author

@deads2k for approval.

@hzxuzhonghu
Copy link
Member Author

/retest
@deads2k need your approve.

@sttts
Copy link
Contributor

sttts commented Feb 13, 2018

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu, soltysh, sttts

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 OWNERS Files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 13, 2018
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 10f2544 into kubernetes:master Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/audit cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[advanced audit] audit policy should support “/*” matching all subresources