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

Include update operation in build admission controller #6576

Merged
merged 1 commit into from
Jan 14, 2016

Conversation

csrwng
Copy link
Contributor

@csrwng csrwng commented Jan 7, 2016

It is possible to update a bc that was created with an allowed type to a type that is not allowed. This change closes that loophole.

Fixes #6556

@csrwng
Copy link
Contributor Author

csrwng commented Jan 7, 2016

@bparees ptal
@jwforres fyi

for _, strategy := range buildStrategyTypes() {
for clientType, client := range clients {
if _, err := updateBuild(t, client.Builds(testutil.Namespace()), builds[string(strategy)+clientType]); !kapierror.IsForbidden(err) {
t.Errorf("epxected forbidden for strategy %s and client %s: got %v", strategy, clientType, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

expected

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

@bparees
Copy link
Contributor

bparees commented Jan 7, 2016

lgtm

@openshift-bot
Copy link
Contributor

[Test]ing while waiting on the merge queue

@deads2k
Copy link
Contributor

deads2k commented Jan 9, 2016

[test]

@deads2k
Copy link
Contributor

deads2k commented Jan 11, 2016

@csrwng Not a known flake:

FAILURE after 0.168s: hack/../test/cmd/builds.sh:79: executing 'oc patch bc/ruby-sample-build -p '{"spec":{"output":{"to":{"name":"different:tag1"}}}}'' expecting success: the command returned the wrong error code
There was no output from the command.
Standard error from the command:
Error from server: resource: required value
!!! Error in hack/../test/cmd/../../hack/cmd_util.sh:195
    'return 1' exited with status 1
Call stack:
    1: hack/../test/cmd/../../hack/cmd_util.sh:195 os::cmd::expect_success(...)
    2: hack/../test/cmd/builds.sh:79 main(...)
Exiting with status 1
!!! Error in hack/test-cmd.sh:288
    '${test}' exited with status 1
Call stack:
    1: hack/test-cmd.sh:288 main(...)
Exiting with status 1
[FAIL] !!!!! Test Failed !!!!

@csrwng
Copy link
Contributor Author

csrwng commented Jan 11, 2016

@deads2k thanks. Just discovered that this is a bug in the upstream API server... patch calls the admission control plugin with an empty object. If it gets permission, then proceeds to patch the stored object. So the admission control plugin never gets a chance to determine whether the patched object is valid or not. https://github.com/openshift/origin/blob/master/Godeps/_workspace/src/k8s.io/kubernetes/pkg/apiserver/resthandler.go#L399-L407

To get this PR in, I can add a check for an empty object and let it go through. However, you'll be able to use patch to change a build config to a type that you're not allowed to use.

@csrwng
Copy link
Contributor Author

csrwng commented Jan 11, 2016

Opened k8s issue: kubernetes/kubernetes#19479

@csrwng
Copy link
Contributor Author

csrwng commented Jan 11, 2016

Added check for an actual update @deads2k ptal

if err != nil {
return false, err
}
return len(accessor.ResourceVersion()) > 0, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't I do a force update without a ResourceVersion? Name would have to be present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ha, you're right... name is a better check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to use name

@deads2k
Copy link
Contributor

deads2k commented Jan 11, 2016

Removing merge tags while I look at how hard proper admission will be. Depending on how bad it is, we may wait and apply this on top. I will update one way or the other this afternoon.

@csrwng
Copy link
Contributor Author

csrwng commented Jan 11, 2016

reverted to not checking object on update - will depend on upstream fix

@deads2k
Copy link
Contributor

deads2k commented Jan 11, 2016

Try building on top of #6608. It should make the update admission chain work how you expect.

@csrwng
Copy link
Contributor Author

csrwng commented Jan 11, 2016

[test]

@csrwng
Copy link
Contributor Author

csrwng commented Jan 11, 2016

[test]

1 similar comment
@csrwng
Copy link
Contributor Author

csrwng commented Jan 12, 2016

[test]

@csrwng
Copy link
Contributor Author

csrwng commented Jan 13, 2016

@deads2k I added a commit to modify the bootstrap policy for the build controller sa. Because we are now checking build update operations, the build controller cannot update builds without having access to the build type virtual resources. How would migration of existing policy be handled in this case?

@liggitt
Copy link
Contributor

liggitt commented Jan 13, 2016

Wait, why didn't the build controller already have those permissions? How was it able to create builds without them?

@csrwng
Copy link
Contributor Author

csrwng commented Jan 13, 2016

@liggitt the build controller doesn't create builds, only the BuildConfig controller does. Looking at the startup code, the BuildImageChangeTriggerController gets a PrivilegedLoopbackOpenShiftClient, not a service account client.

@@ -35,7 +35,7 @@ type buildByStrategy struct {
// on policy based on the build strategy type
func NewBuildByStrategy(client client.Interface) admission.Interface {
return &buildByStrategy{
Handler: admission.NewHandler(admission.Create),
Handler: admission.NewHandler(admission.Create, admission.Update),
Copy link
Contributor

Choose a reason for hiding this comment

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

is it odd that we're gating create and update on create permission on the subresource? I'd sort of expect create to check create, and update to check update

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 had discussed this with @bparees ... I'm fine with either way. Because it is a virtual resource, separating create from update didn't seem to gain us much. You still have separate permission for create or update of the actual resource and requiring that permissions be aligned seemed overkill.

Copy link
Contributor

Choose a reason for hiding this comment

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

fair enough, just reads weird

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe worth a comment in the policy, in case someone is confused

@csrwng
Copy link
Contributor Author

csrwng commented Jan 13, 2016

added comment and updated test fixture

@csrwng
Copy link
Contributor Author

csrwng commented Jan 13, 2016

seems like a flake [test]

@deads2k
Copy link
Contributor

deads2k commented Jan 13, 2016

flake: #6635

@deads2k
Copy link
Contributor

deads2k commented Jan 13, 2016

lgtm. squash and merge at will.

@csrwng
Copy link
Contributor Author

csrwng commented Jan 13, 2016

[merge]

1 similar comment
@csrwng
Copy link
Contributor Author

csrwng commented Jan 13, 2016

[merge]

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/4630/) (Image: devenv-rhel7_3146)

@csrwng
Copy link
Contributor Author

csrwng commented Jan 14, 2016

Failing on #6651

@liggitt
Copy link
Contributor

liggitt commented Jan 14, 2016

[test][merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to abdb4b3

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to abdb4b3

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/8544/)

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.

Can edit a build config to a strategy that isn't allowed by policy - builds still fail correctly
5 participants