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

SCC can't be patched via JSONPatch because users is nil #17185

Merged

Conversation

smarterclayton
Copy link
Contributor

@smarterclayton smarterclayton commented Nov 4, 2017

When users or groups are nil, standard JSONPatch can't be used to add a
new item to the list because the array is nil instead of empty. Alter
the serialization of SCC so that there is always a user or group
array returned.

oc patch "securitycontextconstraints.v1.security.openshift.io" "hostnetwork" --type=json --patch="[{\"op\":\"add\",\"path\":\"/users/-\",\"value\":\"system:serviceaccount:myproject:router\"}]"
Error from server: jsonpatch add operation does not apply: doc is missing path: /users/-

This allows us to do declarative patching against SCC until we move to
PSP in a future release.

@liggitt realized this while trying to switch router to a declarative model - patch is our best option for update, but you can't actually do a safe addition without JSONPatch and without this change.

/kind bug

When users or groups are nil, standard JSONPatch can't be used to add a
new item to the list because the array is nil instead of empty. Alter
the serialization of SCC so that there is always a user or group
array returned.

This allows us to do declarative patching against SCC until we move to
PSP in a future release.
@openshift-ci-robot openshift-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 4, 2017
@openshift-merge-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: smarterclayton

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-api-review labels Nov 4, 2017
@smarterclayton smarterclayton added this to the 3.7.0 milestone Nov 4, 2017
@smarterclayton
Copy link
Contributor Author

Targeting 3.7

@openshift-ci-robot openshift-ci-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 4, 2017
People patching SCCs in a declarative fashion can cause unbounded struct
growth. Strike a balance between simple code and efficient (since some
SCCs can have hundreds of users).
Copy link
Contributor

@enj enj left a comment

Choose a reason for hiding this comment

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

Minor comments.

@@ -50,7 +50,27 @@ func (strategy) PrepareForCreate(_ genericapirequest.Context, obj runtime.Object
func (strategy) PrepareForUpdate(_ genericapirequest.Context, obj, old runtime.Object) {
}

// Canonicalize removes duplicate user and group values, preserving order.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to preserve order, or do you just need consistent order? If you only need the latter, you could just use StringKeySet.List which would sort and dedupe.

Copy link
Contributor

Choose a reason for hiding this comment

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

order is better in case you have a patch that removes a specific index

@@ -518,8 +518,16 @@ func autoConvert_security_SecurityContextConstraints_To_v1_SecurityContextConstr
}
out.ReadOnlyRootFilesystem = in.ReadOnlyRootFilesystem
out.SeccompProfiles = *(*[]string)(unsafe.Pointer(&in.SeccompProfiles))
out.Users = *(*[]string)(unsafe.Pointer(&in.Users))
out.Groups = *(*[]string)(unsafe.Pointer(&in.Groups))
if in.Users == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Generated files in their own commit?

@enj
Copy link
Contributor

enj commented Nov 5, 2017

Looks backwards compatible as far as I can tell.

@smarterclayton
Copy link
Contributor Author

Afaict we had nothing that depended on nil vs empty lists. It does highlight how frustrating cfg mgmt is here

@php-coder
Copy link
Contributor

LGTM.

@@ -79,9 +79,11 @@ type SecurityContextConstraints struct {
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem" protobuf:"varint,17,opt,name=readOnlyRootFilesystem"`

// The users who have permissions to use this security context constraints
Users []string `json:"users,omitempty" protobuf:"bytes,18,rep,name=users"`
// +optional
Copy link
Contributor

Choose a reason for hiding this comment

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

surprised this didn't regenerate the proto files

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, it did. surprised that didn't regenerate the fileDescriptorGenerated blob

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generated strips comments (last I checked)

@liggitt
Copy link
Contributor

liggitt commented Nov 6, 2017

this lgtm, but is just a band-aid on one particular nullable list field (we have lots and lots)

@smarterclayton
Copy link
Contributor Author

Yes, important but not sufficient. I’m going to open an upstream.

@smarterclayton smarterclayton added lgtm Indicates that a PR is ready to be merged. api-approved labels Nov 6, 2017
@openshift-merge-robot
Copy link
Contributor

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

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 17160, 17185).

@openshift-merge-robot openshift-merge-robot merged commit b343ec5 into openshift:master Nov 6, 2017
@smarterclayton
Copy link
Contributor Author

smarterclayton commented Nov 7, 2017 via email

@openshift-ci-robot
Copy link

@smarterclayton: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/openshift-jenkins/extended_conformance_gce 8f9995b link /test extended_conformance_gce
ci/openshift-jenkins/extended_conformance_install_update 8f9995b link /test extended_conformance_install_update

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. needs-api-review priority/P1 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

7 participants