Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1515703

Summary: [free-int][free-stg]'cannot list cronjobs.batch' shown when do 'oc get all' or 'oc delete all --all' in project
Product: OpenShift Container Platform Reporter: XiuJuan Wang <xiuwang>
Component: ocAssignee: Jan Chaloupka <jchaloup>
oc sub component: oc QA Contact: zhou ying <yinzhou>
Status: CLOSED CURRENTRELEASE Docs Contact:
Severity: low    
Priority: medium CC: akostadi, aos-bugs, deads, ffranz, jchaloup, jupierce, ldipotet.job, maszulik, mfojtik, mmccomas, vlaad, xiuwang
Version: unspecifiedKeywords: OnlineStarter, Reopened
Target Milestone: ---Flags: xiuwang: needinfo-
xiuwang: needinfo-
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-08-25 20:25:10 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description XiuJuan Wang 2017-11-21 09:13:31 UTC
Description of problem:
Error from server (Forbidden): User "****" cannot list cronjobs.batch in the namespace "**": User "***" cannot list cronjobs.batch in project "**" (get cronjobs.batch)
Above error shown when do 'oc get  all' or 'oc  delete  all --all' in project
And 3.7 OCP works well.

Version-Release number of selected component (if applicable):

oc v3.7.5
kubernetes v1.7.6+a08f5eeb62
features: Basic-Auth GSSAPI Kerberos SPNEGO

Server https://api.free-int.openshift.com:443
openshift v3.7.0-0.191.0
kubernetes v1.7.6+a08f5eeb62

How reproducible:
always

Steps to Reproduce:
1.Create a project and create some apps
2.Get all resources
$oc get all
3.Delete all resources
$oc delete all --all 

Actual results:
$ oc  get  all 
Error from server (Forbidden): User "***" cannot list cronjobs.batch in the namespace "**": User "***" cannot list cronjobs.batch in project "**" (get cronjobs.batch)

$oc  delete  all  --all 
Error from server (Forbidden): User "***" cannot list cronjobs.batch in the namespace "**": User "***" cannot list cronjobs.batch in project "**" (get cronjobs.batch)
Expected results:
Should no error shown

Additional info:

Comment 1 Juan Vallejo 2017-11-30 22:49:55 UTC
Fabiano, I believe we disabled the use of cronjobs in free-int, which is why this error is being shown (when otherwise cronjobs would be shown as part of "all").

If the above assumption is correct, then this is not a bug, but rather the command failing to list cronjobs due to the current policy on the cluster.

If you try listing all (or even just cronjobs on a local cluster, this error does not happen).

Tagging as NOTABUG, but feel free to reopen if I have missed something.

Comment 2 Xingxing Xia 2017-12-01 10:12:24 UTC
Better to adjust and improve the UX for ONLINE, because:
For customer, such trailing printing is messy, no matter the project has app or not
$ oc new-project xxia21-proj
$ oc get all
Error from server (Forbidden): User "xxia-21" cannot list cronjobs.batch in the namespace "xxia21-proj": User "xxia-21" cannot list cronjobs.batch in project "xxia21-proj" (get cronjobs.batch)
$ echo $?
1
$ oc delete all --all
Error from server (Forbidden): User "xxia-21" cannot list cronjobs.batch in the namespace "xxia21-proj": User "xxia-21" cannot list cronjobs.batch in project "xxia21-proj" (get cronjobs.batch)
$ echo $?
1

And for QE, "1" will make existing automated scenarios fail which have used oc get/delete all and expected success of cmd execution status

Comment 3 Maciej Szulik 2017-12-01 11:49:01 UTC
Juan, Fabiano `oc get all` should never fail on access rights. It should silently ignore these errors (eventually appropriate message instead of empty list) should appear. I agree that this should be fixed, we can't expect every cluster have exactly same `all` resources but the command should just work.

Comment 4 Juan Vallejo 2017-12-01 22:48:47 UTC
Thanks Maciej,
Will go ahead and open a PR that hides permission errors from "oc get"

Comment 5 Juan Vallejo 2017-12-04 17:02:43 UTC
Upstream PR: https://github.com/kubernetes/kubernetes/pull/56801

Comment 6 Fabiano Franz 2017-12-07 18:44:44 UTC
When fixed upstream it will come with an upcoming rebase.

Comment 10 Juan Vallejo 2017-12-21 19:00:55 UTC
> How about just a warning next to the resources you can't see that clearly states you don't have access? 

Doesn't this already happen with the forbidden error that is show? Users are notified of the resource that could not be listed, and why

Comment 11 Maciej Szulik 2017-12-22 10:23:53 UTC
Yeah, we've talked about it with David and I also double checked on my own. This is how it should work.

Comment 12 Juan Vallejo 2018-01-09 14:53:45 UTC
Thanks Maciej, closing this as notabug

Comment 13 Xingxing Xia 2018-01-11 03:39:13 UTC
Saw above comments.
But considered UX and gathered use experience from other guys, the multiple error lines are not friendly. Some guys give feedback that they were confused when they saw the messages at first glance, they thought "I didn't create resource 'cronjob', why it shows me 'cannot list cronjobs.batch'".

As a solution suggestion in terms of UX, do you think it is feasible to fix as belows:
When going though each resource type included in alias `all`, first check whether it is configured "forbidden" by master, if yes, ignore this resource type, remember it, and continue to process next resource type. Finally, after all resource types in alias `all` are processed, rather than multiple error lines, print a single warning line that states the remembered types are configured-forbidden by master, and make command return '0' if no other error happens.

Comment 15 Xingxing Xia 2018-01-16 02:36:10 UTC
Thanks for long time discussion and patient explanation. OK, let it as it is

Comment 19 XiuJuan Wang 2018-02-09 02:17:25 UTC
Could reproduce this bug only on starter clusters.
[1] api.free-int.openshift.com
[2] api.free-stg.openshift.com

In an empty project,try 'oc get all', show below error:
$ oc get all
Error from server (Forbidden): daemonsets.apps is forbidden: User "xiuwang-7" cannot list daemonsets.apps in the namespace "xiu1": User "xiuwang-7" cannot list daemonsets.apps in project "xiu1"
Error from server (Forbidden): replicasets.apps is forbidden: User "xiuwang-7" cannot list replicasets.apps in the namespace "xiu1": User "xiuwang-7" cannot list replicasets.apps in project "xiu1"
Error from server (Forbidden): cronjobs.batch is forbidden: User "xiuwang-7" cannot list cronjobs.batch in the namespace "xiu1": User "xiuwang-7" cannot list cronjobs.batch in project "xiu1"

Comment 21 Luis Dipotet 2018-02-25 10:11:02 UTC
(In reply to XiuJuan Wang from comment #19)
> Could reproduce this bug only on starter clusters.
> [1] api.free-int.openshift.com
> [2] api.free-stg.openshift.com
> 
> In an empty project,try 'oc get all', show below error:
> $ oc get all
> Error from server (Forbidden): daemonsets.apps is forbidden: User
> "xiuwang-7" cannot list daemonsets.apps in the namespace "xiu1": User
> "xiuwang-7" cannot list daemonsets.apps in project "xiu1"
> Error from server (Forbidden): replicasets.apps is forbidden: User
> "xiuwang-7" cannot list replicasets.apps in the namespace "xiu1": User
> "xiuwang-7" cannot list replicasets.apps in project "xiu1"
> Error from server (Forbidden): cronjobs.batch is forbidden: User "xiuwang-7"
> cannot list cronjobs.batch in the namespace "xiu1": User "xiuwang-7" cannot
> list cronjobs.batch in project "xiu1"

It fail for an empty project too. It fail for every where :(

Comment 22 David Eads 2018-02-26 13:22:45 UTC
@justin  still looks like permissions are messed up.  Why doesn't a user with access have read rights?

Comment 29 Justin Pierce 2018-02-28 13:51:21 UTC
The procedure dakini defined for removing scheduledjobs/cronjobs/custom-host from starter is no longer accurate for 3.9. These roles are now split across multiple reources due to role aggregation. 

Assigning this back to me since a failure to reconcile is presently impacting CD deployments. I'm writing a script that will reconcile roles after an upgrade, but it is not complex enough preserve listing permissions. This may need to wait until 3.10.

Comment 30 Justin Pierce 2018-03-06 22:08:17 UTC
Mo provided an idea to address this with role aggregation. I've run the following on free-int to eliminate the error:

cat <<EOF | oc apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: system:openshift:cicd:aggregate-to-all-cronjobs-read-and-del
  labels:
    rbac.authorization.k8s.io/aggregate-to-admin: "true"
    rbac.authorization.k8s.io/aggregate-to-edit: "true"
rules:
- apiGroups:
  - batch
  resources:
  - cronjobs
  verbs:
  - get
  - list
  - watch
  - delete
  - deletecollection
EOF

cat <<EOF | oc apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: system:openshift:cicd:aggregate-to-all-cronjobs-read
  labels:
    rbac.authorization.k8s.io/aggregate-to-view: "true"
rules:
- apiGroups:
  - batch
  resources:
  - cronjobs
  verbs:
  - get
  - list
  - watch
EOF

Comment 31 XiuJuan Wang 2018-03-07 03:28:38 UTC
This bug has fixed in free-int (openshift v3.9.1 kubernetes v1.9.1+a0ce1bc657).

However, there is still a little issue in free-stg(openshift v3.9.1 kubernetes v1.9.1+a0ce1bc657).
In an empty project, try 'oc get all' and "oc delete all --all"
#oc get all       
Error from server (Forbidden): cronjobs.batch is forbidden: User "xiuwang-7" cannot list cronjobs.batch in the namespace "xiu1": User "xiuwang-7" cannot list cronjobs.batch in project "xiu1"

Comment 32 XiuJuan Wang 2018-03-07 03:30:47 UTC
Sorry,my mistake,I should assign this bug back

Comment 33 Maciej Szulik 2019-04-09 14:16:10 UTC
Based on previous discussion I don't see what else needs fixing here. Moving back to QA.

Comment 34 XiuJuan Wang 2019-04-10 05:52:39 UTC
https://api.free-stg.openshift.com:443
openshift v3.11.69
kubernetes v1.11.0+d4cacc0

Can't reproduce this issue in free-stg with current version.