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

type ClusterRoleBinding Subjects serializer should omitEmpty or be empty array #60026

Closed
ntfrnzn opened this issue Feb 19, 2018 · 2 comments
Closed
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/auth Categorizes an issue or PR as relevant to SIG Auth.

Comments

@ntfrnzn
Copy link
Contributor

ntfrnzn commented Feb 19, 2018

/kind bug

Using kubectl + jsonpath to report the names of the groups, users or serviceaccounts that are in play in a cluster:

$ kubectl get clusterrolebinding -o jsonpath='{.items[:].subjects[?(@.kind=="Group")].name}'

Get error message when jsonpath sees a nil instead of an array

error: error executing jsonpath "{.items[:].subjects[?(@.kind==\"Group\")].name}": <nil> is not array or slice and cannot be filtered

I expect to see the list of groups

system:masters system:authenticated system:unauthenticated system:authenticated system:unauthenticated

Accessing a v1.9.2 rbac-enabled cluster

# (A) fails:
$ kubectl get clusterrolebinding -o jsonpath='{.items[:].subjects[?(@.kind=="Group")].name}'

# (B) fails:
$ kubectl get clusterrolebinding -o jsonpath='{.items[?(@.subjects)].subjects[?(@.kind=="Group")].name}'

# (C) succeeds:
$ kubectl get clusterrolebinding -o jsonpath='{.items[?(@.metadata.name!="system:node")].subjects[?(@.kind=="Group")].name}'

The system:node ClusterRoleBinding doesn't have any subjects, and it serializes the field as"subjects": null, which leads to the error.

Case (B) above tries to filter out the elements where subjects doesn't exist, but subjects does exist and it's nil. Case (C) shows that if the filter is applied and the offending element is gone, then the rest of the kubectl statement works fine.

This isn't a great user experiences, so the problem is one of

  • the jsonpath utility existence filter should filter out fields where the value is nil (? or is false?? or is default???)
  • the subjects field should not appear in the serialization, i.e. omitEmpty
  • the subjects field should be serialized as an empty array and not as nil.

If it seems that the problem is with the jsonPath filter rather than ClusterRoleBinding, please retitle the issue.

@k8s-ci-robot k8s-ci-robot added needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. kind/bug Categorizes issue or PR as related to a bug. labels Feb 19, 2018
@dims
Copy link
Member

dims commented Mar 7, 2018

/sig auth

@k8s-ci-robot k8s-ci-robot added sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 7, 2018
@liggitt
Copy link
Member

liggitt commented May 13, 2018

fixed in #60741

/close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/auth Categorizes an issue or PR as relevant to SIG Auth.
Projects
None yet
Development

No branches or pull requests

4 participants