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

Error on manipulation for cluster services / add-ons #17740

Closed

Conversation

janetkuo
Copy link
Member

@janetkuo janetkuo commented Nov 24, 2015

Fixes #17532.

Stops the users from manipulating cluster services (add-ons, i.e. resources with the label kubernetes.io/cluster-service: "true") in kubectl.

For example, if we have an rc "addon" with such label:

$ kubectl delete rc addon
error: "addon" is a cluster service and should not be mutated. See http://releases.k8s.io/HEAD/cluster/addons for more info.
$ kubectl rolling-update rc addon -f addon2.yaml
error: replication controller "addon" is a cluster service and should not be mutated. See http://releases.k8s.io/HEAD/cluster/addons for more info.

We only do this check when delete, stop, rolling-update, and replace --force (which does delete) a resource.

For testing purpose, added a flag --write-protect[=true] to bypass the check if set to false.

cc @kubernetes/kubectl @kubernetes/goog-ux @nikhiljindal @erictune


This change is Reviewable

@k8s-github-robot k8s-github-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 24, 2015
@janetkuo
Copy link
Member Author

Should we have a cmd flag that allows the user to bypass this check? Something like --overwrite-addon=true, or --addon-check=false? In this PR, if you create a resource with that label manually (or edit/label a resource with that label), you can never update/delete it.

@j3ffml
Copy link
Contributor

j3ffml commented Nov 25, 2015

I think we probably should have a way to bypass it, since we may want to for testing purposes. Case in point, #17614.

@janetkuo
Copy link
Member Author

I added a flag --addon-check for bypassing it. Added tests in hack/test-cmd.sh too.

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 25, 2015
@smarterclayton
Copy link
Contributor

Couple of design points:

Why are services special? Why isn't this kubernetes.io/cluster-resource:
true or kubernetes.io/delete-protection: true and it just can apply to all
resources? And then we use --confirm to override delete protection?

We have several types of auto resources - endpoints, services, secrets,
service accounts, namespaces which all need this.

I don't think this is specific to cluster scoped resources.

@smarterclayton
Copy link
Contributor

@liggitt this would solve several deletion related problems.


// AddMutateClusterServiceFlag adds a flag that prevents the manipulation on add-ons. Used by mutations only.
func AddMutateClusterServiceFlag(cmd *cobra.Command) {
cmd.Flags().BoolP("addon-check", "", true, "If true, prevents the users from manipulating add-ons / cluster services. See http://releases.k8s.io/HEAD/cluster/addons for more info. Default true.")
Copy link
Member

Choose a reason for hiding this comment

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

deletion protection seems like something we'd want in general, and this seems like a too-specific application of it... can we make this flag more general?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@liggitt
Copy link
Member

liggitt commented Nov 26, 2015

Why are services special? Why isn't this kubernetes.io/cluster-resource: true or kubernetes.io/delete-protection: true and it just can apply to all resources? And then we use --confirm to override delete protection?

That requires a GET before DELETE, which at the very least doubles requests. In other cases, someone could be allowed to delete something they cannot get... what would you do with that?

@smarterclayton
Copy link
Contributor

Go ahead and do the delete. If the admin wants you to blindly delete, you
can blindly delete.

On Nov 25, 2015, at 9:07 PM, Jordan Liggitt notifications@github.com
wrote:

Why are services special? Why isn't this kubernetes.io/cluster-resource:
true or kubernetes.io/delete-protection: true and it just can apply to all
resources? And then we use --confirm to override delete protection?

That requires a GET before DELETE, which at the very least doubles
requests. In other cases, someone could be allowed to delete something they
cannot get... what would you do with that?


Reply to this email directly or view it on GitHub
#17740 (comment)
.

@janetkuo janetkuo force-pushed the manipulate-cluster-services branch 2 times, most recently from ac47c28 to e6bbd32 Compare November 30, 2015 22:35
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 30, 2015
@janetkuo
Copy link
Member Author

Changed the flag from --addon-check to --write-protect:

--write-protect[=true]: If true, prevents the users from manipulating resources that shouldn't be changed, such as add-ons and auto-generated resources. Note that changing this flag may cause problems to your cluster. Default true.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2015
@janetkuo janetkuo removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2015
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2015
@janetkuo
Copy link
Member Author

janetkuo commented Dec 3, 2015

Rebased. @jlowdermilk @smarterclayton @liggitt PTAL.

@@ -70,7 +70,7 @@ func TestDeleteNamedObject(t *testing.T) {
Codec: codec,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch p, m := req.URL.Path, req.Method; {
case p == "/namespaces/test/replicationcontrollers/redis-master-controller" && m == "DELETE":
case p == "/namespaces/test/replicationcontrollers/redis-master-controller" && (m == "DELETE" || m == "GET"):
return &http.Response{StatusCode: 200, Body: objBody(codec, &rc.Items[0])}, nil
default:
// Ensures no GET is performed when deleting by name
Copy link
Member

Choose a reason for hiding this comment

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

these tests were explicitly here to make sure deletes succeed when GET fails (the case where a user is allowed to DELETE something they cannot GET)... we still need to test those scenarios.

Copy link
Member

Choose a reason for hiding this comment

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

so I think we need the following tests:

  • GET succeeds, and is followed by DELETE
  • GET returns 404... not sure if DELETE should be performed or not
  • GET returns 403, and is followed by DELETE, which succeeds

Copy link
Member

Choose a reason for hiding this comment

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

Comment still applies

Copy link
Member Author

Choose a reason for hiding this comment

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

Originally I added GET here because I needed to GET a resource to check if it's a cluster service (check its label) before deleting it.

Copy link
Member

Choose a reason for hiding this comment

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

I understand, but we need tests that ensure a DELETE can succeed even when the GET does not

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 11, 2015
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 18, 2015
@janetkuo
Copy link
Member Author

Just rebased. Ping for another look.

@liggitt
Copy link
Member

liggitt commented Dec 18, 2015

It doesn't look like my last set of comments were addressed. Please take another look

@janetkuo
Copy link
Member Author

@liggitt I missed your comments. Will update accordingly.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 22, 2015
@nikhiljindal
Copy link
Contributor

Ping!
Another user on slack mentioned being tripped on this.

@janetkuo
Copy link
Member Author

janetkuo commented Jan 8, 2016

@liggitt I'm not sure if I understand you correctly. If we're making a new annotation, say kubernetes.io/write-protect=true, to mark resources as write-protected, how does that solve issue #17532? The users will need to add kubernetes.io/write-protect=true to their cluster services (i.e., resources with kubernetes.io/cluster-service=true label) to avoid mutating cluster services accidentally. But the users who ran into this problem didn't know that they shouldn't manipulate cluster services.

cmdutil.AddOutputFlagsForMutation(cmd)
cmdutil.AddWriteProtectFlag(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

stop is deprecated, should we update it?

@j3ffml j3ffml assigned 0xmichalis and unassigned j3ffml Jan 8, 2016
@0xmichalis
Copy link
Contributor

Needs a rebase

@liggitt
Copy link
Member

liggitt commented Jan 29, 2016

@liggitt I'm not sure if I understand you correctly. If we're making a new annotation, say kubernetes.io/write-protect=true, to mark resources as write-protected, how does that solve issue #17532? The users will need to add kubernetes.io/write-protect=true to their cluster services (i.e., resources with kubernetes.io/cluster-service=true label) to avoid mutating cluster services accidentally.

I'm saying we should additionally set the kubernetes.io/write-protect=true annotation on cluster-services to gain this behavior. Hints to clients to write protect something is a generally useful thing, independent of whether something is a cluster-service.

@k8s-bot
Copy link

k8s-bot commented May 5, 2016

GCE e2e build/test failed for commit c5c557e.

Please reference the list of currently known flakes when examining this failure. If you request a re-test, you must reference the issue describing the flake.

@smarterclayton
Copy link
Contributor

I think we want the general annotation, because it aligns with a bunch of other author -> user communication we will want. We have use cases for a "do not reconcile automatically" annotation that I would like to make kubernetes.io/reconcile-protect that would potentially apply to kubectl apply. We may have a distinct delete protection in the future.

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 18, 2016
@k8s-github-robot
Copy link
Contributor

This PR hasn't been active in 90 days. Closing this PR. Please reopen if you would like to work towards merging this change, if/when the PR is ready for the next round of review.

cc @janetkuo @kargakis

You can add 'keep-open' label to prevent this from happening again, or add a comment to keep it open another 90 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants