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

admission: wire through validating-only admission #54484

Merged
merged 7 commits into from
Nov 2, 2017

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Oct 24, 2017

Based on #54232.

This is important and required for beta because it affects the shape of the webhook admission plugins that are going to be produced and is needed to make sure that our existing chain continues to properly verify and protect the API objects based on their final state after webhook admission mutators run.

We discussed this in the October 11 API machinery call with @erictune and @caesarxuchao and we agreed to do this as a requirement for beta. See this part of the recording: https://www.youtube.com/watch?v=mrgDPHyr4VY#t=325 .

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 24, 2017
@sttts sttts assigned liggitt and deads2k and unassigned hongchaodeng and nhlfr Oct 24, 2017
@sttts sttts added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 24, 2017
@deads2k
Copy link
Contributor

deads2k commented Oct 24, 2017

/assign caesarxuchao
@lavalamp

@k8s-ci-robot
Copy link
Contributor

@sttts: Adding do-not-merge/release-note-label-needed because the release note process has not been followed.

One of the following labels is required "release-note", "release-note-action-required", or "release-note-none".
Please see: https://github.com/kubernetes/community/blob/master/contributors/devel/pull-requests.md#write-release-notes-if-needed.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Oct 24, 2017
@@ -73,15 +73,15 @@ func (s *storage) GetStatefulSet(ctx genericapirequest.Context, statefulSetID st
}

func (s *storage) CreateStatefulSet(ctx genericapirequest.Context, statefulSet *apps.StatefulSet) (*apps.StatefulSet, error) {
obj, err := s.Create(ctx, statefulSet, false)
obj, err := s.Create(ctx, statefulSet, rest.ValidateAllObjectFunc, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

So I've been reading through this code. I think it is a mistake to make this intermediate registry for use by the scale client. It makes what is happening far less obvious. Your choice here is safe, but only because of how this is used.

Please open an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's boilerplate code essentially doing a type cast, not more. I agree this complicates more than it helps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following the old behaviour, I wired the validation functions through now from the subresource registries via the intermediate registries to the storage.

@@ -56,12 +56,12 @@ func (s *storage) ListCSRs(ctx genericapirequest.Context, options *metainternalv
}

func (s *storage) CreateCSR(ctx genericapirequest.Context, csr *certificates.CertificateSigningRequest) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

file looks dead. please delete instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have plenty of these which are not called. This will be fixed in a follow-up via #54693.

@@ -69,7 +69,7 @@ func (s *storage) GetConfigMap(ctx genericapirequest.Context, name string, optio
}

func (s *storage) CreateConfigMap(ctx genericapirequest.Context, cfg *api.ConfigMap) (*api.ConfigMap, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks dead, please delete instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up via #54693

@@ -66,7 +66,7 @@ func (s *storage) GetEndpoints(ctx genericapirequest.Context, name string, optio
}

func (s *storage) UpdateEndpoints(ctx genericapirequest.Context, endpoints *api.Endpoints) error {
_, _, err := s.Update(ctx, endpoints.Name, rest.DefaultUpdatedObjectInfo(endpoints))
_, _, err := s.Update(ctx, endpoints.Name, rest.DefaultUpdatedObjectInfo(endpoints), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
Copy link
Contributor

Choose a reason for hiding this comment

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

only safe because of how it is called. Needs a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -67,12 +67,12 @@ func (s *storage) GetNamespace(ctx genericapirequest.Context, namespaceName stri
}

func (s *storage) CreateNamespace(ctx genericapirequest.Context, namespace *api.Namespace) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

appears dead. please delete instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up via #54693

@@ -56,12 +56,12 @@ func (s *storage) ListNodes(ctx genericapirequest.Context, options *metainternal
}

func (s *storage) CreateNode(ctx genericapirequest.Context, node *api.Node) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

appears dead. please delete instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up via #54693

@@ -74,15 +74,15 @@ func (s *storage) GetController(ctx genericapirequest.Context, controllerID stri
}

func (s *storage) CreateController(ctx genericapirequest.Context, controller *api.ReplicationController) (*api.ReplicationController, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment about scale here. Needs a big warning and a followup issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -67,12 +67,12 @@ func (s *storage) GetSecret(ctx genericapirequest.Context, name string, options
}

func (s *storage) CreateSecret(ctx genericapirequest.Context, secret *api.Secret) (*api.Secret, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

comment that its only safe due to usage and that we need to move to a loopback connection for SA token authentication.

Copy link
Contributor

Choose a reason for hiding this comment

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

issue for the loopback thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also dead code fixed via #54693

@@ -58,7 +58,7 @@ func (s *storage) ListServices(ctx genericapirequest.Context, options *metainter
}

func (s *storage) CreateService(ctx genericapirequest.Context, svc *api.Service) (*api.Service, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

only safe due to usage. Issue to move this one to point of use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually used. Wired through the createValidation from service REST Create.

@@ -67,12 +67,12 @@ func (s *storage) GetServiceAccount(ctx genericapirequest.Context, name string,
}

func (s *storage) CreateServiceAccount(ctx genericapirequest.Context, serviceAccount *api.ServiceAccount) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

only safe due to usage. This one should be removed in favor of loopback too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also dead code fixed via #54693

@@ -225,6 +225,7 @@ func (r *ScaleREST) Update(ctx genericapirequest.Context, name string, objInfo r
return nil, false, err
}

// TODO: should we pass admission here?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but you should do it by eliminating the use of the registry or changing the registry signature to accept the validation functions.

Copy link
Member

Choose a reason for hiding this comment

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

Are the validation/update validation functions passed into this function going to be about Deployments or Scale types? I would naively expect the latter, in which case this code probably needs some drastic revision. (file an issue "scale (all?) subresources evade admission checking") rather than fix it in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would naively expect the former. As a webhook author, should I care about the way a user changes the replicas value? I would naively add an admission step for the full resource.

Copy link
Contributor

Choose a reason for hiding this comment

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

lavalamp 20 hours ago
Are the validation/update validation functions passed into this function going to be about Deployments or Scale types? I would naively expect the latter, in which case this code probably needs some drastic revision. (file an issue "scale (all?) subresources evade admission checking") rather than fix it in this PR.

sttts 2 hours ago
I would naively expect the former. As a webhook author, should I care about the way a user changes the replicas value? I would naively add an admission step for the full resource.

In our code today, the same admission chain is called for subresources as is called for normal resources. This gives admission plugins the flexibility to decide if they care about subresource modifications (not all will), but if they do, it gives the full before/after context.

I think for now we should preserve the existing behavior (which I called out in a comment). I'm open to discussing a change in behavior, but I'd like to do it outside the context of this pull. @lavalamp I think you agree based on "(file an issue "scale (all?) subresources evade admission checking") rather than fix it in this PR."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment is outdated. Will remove the TODO.

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 1, 2017
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

2 similar comments
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 2, 2017
@sttts sttts added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 2, 2017
@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 40212c1 into kubernetes:master Nov 2, 2017
k8s-github-robot pushed a commit that referenced this pull request Nov 9, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of #54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.
sttts pushed a commit to sttts/apiserver that referenced this pull request Nov 9, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of kubernetes/kubernetes#54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.

Kubernetes-commit: ee7f1b6e74fab4ed77592f29264575c634e4f2c1
sttts pushed a commit to sttts/apiserver that referenced this pull request Nov 27, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of kubernetes/kubernetes#54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.

Kubernetes-commit: ee7f1b6e74fab4ed77592f29264575c634e4f2c1
sttts pushed a commit to sttts/apiserver that referenced this pull request Nov 28, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of kubernetes/kubernetes#54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.

Kubernetes-commit: ee7f1b6e74fab4ed77592f29264575c634e4f2c1
sttts pushed a commit to sttts/apiserver that referenced this pull request Nov 28, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of kubernetes/kubernetes#54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.

Kubernetes-commit: ee7f1b6e74fab4ed77592f29264575c634e4f2c1
sttts pushed a commit to sttts/apiserver that referenced this pull request Nov 28, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of kubernetes/kubernetes#54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.

Kubernetes-commit: ee7f1b6e74fab4ed77592f29264575c634e4f2c1
sttts pushed a commit to sttts/apiserver that referenced this pull request Nov 28, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of kubernetes/kubernetes#54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.

Kubernetes-commit: ee7f1b6e74fab4ed77592f29264575c634e4f2c1
k8s-publishing-bot pushed a commit to k8s-publishing-bot/apiserver that referenced this pull request Nov 29, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of kubernetes/kubernetes#54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.

Kubernetes-commit: ee7f1b6e74fab4ed77592f29264575c634e4f2c1
k8s-publishing-bot pushed a commit to k8s-publishing-bot/apiserver that referenced this pull request Dec 7, 2017
Automatic merge from submit-queue (batch tested with PRs 55331, 55272, 55228, 49763, 55242). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: add validating admission tests

Follow-up of kubernetes/kubernetes#54484

This includes tests
- in endpoint tests,
- in generic registry,
- in patch handler,
- in admission chain.

Kubernetes-commit: ee7f1b6e74fab4ed77592f29264575c634e4f2c1
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/admission-control 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-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.