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

Grant authenticated users access to read kubevirt-storage-class-defaults #498

Merged
merged 2 commits into from Jul 7, 2020

Conversation

maya-r
Copy link
Contributor

@maya-r maya-r commented Mar 15, 2020

Bugzilla bug report.

Grant authenticated users access to read kubevirt-storage-class-defaults

@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/M labels Mar 15, 2020
Copy link
Member

@aglitke aglitke left a comment

Choose a reason for hiding this comment

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

lgtm

deploy/cluster_role.yaml Outdated Show resolved Hide resolved
kind: Role
metadata:
name: hco.kubevirt.io:config-reader
namespace: kubevirt-hyperconverged
Copy link
Member

Choose a reason for hiding this comment

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

not exactly sure the context in which this manifest is used but the other roles do not specify the namespace. So maybe also shouldn't here?

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 want to give access to the configmap with namespace kubevirt-hyperconverged and name kubevirt-storage-class-defaults.
if I don't restrict the namespace then I'm granting access to an identically named configmap in anu namespace (if someone happens to use that exact name. unlikely, but I shouldn't do it)

@djzager
Copy link
Contributor

djzager commented Mar 18, 2020

In order to make sure that it gets included in all of the places it should (ie. downstream), we need to make it so that ./hack/build-manifests.sh properly creates this Role and RoleBinding.

However, even with that change, I don't think the Role will be installed when the HCO is installed via OLM. How exactly is this Role supposed to 1) make it onto a cluster 2) be used?

@djzager
Copy link
Contributor

djzager commented Mar 18, 2020

Is this something that the HCO should be creating in it's Reconcile()?

@maya-r
Copy link
Contributor Author

maya-r commented Mar 24, 2020

Here's a version creating everything via reconcile. I added a functional test too.
I'm under the impression that we use Reconcile to bridge the gap between upstream vs. downstream namespace.
I might be able to live with a ClusterRoleBinding instead of a RoleBinding, because it does not need to be namespaced. But I don't know where to put it.

@maya-r

This comment has been minimized.

@maya-r
Copy link
Contributor Author

maya-r commented Apr 5, 2020

Rebased to include the latest (unrelated, but fixing the tests issue) commits.

@maya-r
Copy link
Contributor Author

maya-r commented Apr 13, 2020

ping

APIGroups: []string{""},
Resources: []string{"configmaps"},
ResourceNames: []string{"kubevirt-storage-class-defaults"},
Verbs: []string{"get", "watch", "list"},
Copy link
Member

Choose a reason for hiding this comment

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

can you please run go fmt pkg/controller/hyperconverged/hyperconverged_controller.go and commit back the result?

@@ -292,6 +293,8 @@ func (r *ReconcileHyperConverged) Reconcile(request reconcile.Request) (reconcil
for _, f := range []func(*hcov1alpha1.HyperConverged, logr.Logger, reconcile.Request) error{
r.ensureKubeVirtConfig,
r.ensureKubeVirtStorageConfig,
r.ensureKubeVirtStorageRole,
r.ensureKubeVirtStorageRoleBinding,
Copy link
Member

Choose a reason for hiding this comment

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

Why have we to do it at runtime via HCO?
Isn't OLM not enough for this?

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 assume it can. I wasn't sure about how I'm expected to do something like this.
HCO seems to work with kubernetes too, whereas OLM is apparently specific to OpenShift.
Are we expected to add to the OLM files and have the kubernetes bits be generated?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, something like that:
https://github.com/kubevirt/hyperconverged-cluster-operator/blob/master/deploy/cluster_role_binding.yaml and https://github.com/kubevirt/hyperconverged-cluster-operator/blob/master/deploy/cluster_role.yaml are used only on plain k8s deployment.

https://github.com/kubevirt/hyperconverged-cluster-operator/blob/master/deploy/olm-catalog/kubevirt-hyperconverged/1.1.0/kubevirt-hyperconverged-operator.v1.1.0.clusterserviceversion.yaml is instead the CSV for OLM based deployment.

both the set of files are generated running hack/build-manifests.sh according to what's provided by the components operators.
In order to consume a different component you have to patch go.mod and run go mod vendor and hack/config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case HCO is adding the ConfigMap, so it feels like the role should be something HCO adds. Is there somewhere that isn't auto-generated for appending to HCO-specific additions?

@kubevirt-bot
Copy link
Contributor

kubevirt-bot commented Jun 7, 2020

@maya-r: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-hyperconverged-cluster-operator-e2e-k8s-1.17.0 030753652d3fe127ee8a7f5903681d76ca2aa830 link /test pull-hyperconverged-cluster-operator-e2e-k8s-1.17.0

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.

@maya-r maya-r force-pushed the rbac branch 2 times, most recently from 02fd070 to 7365560 Compare June 7, 2020 19:40
@ovirt-infra
Copy link

All tests passed

@maya-r
Copy link
Contributor Author

maya-r commented Jun 9, 2020

This looked like the right thing, I edited pkg/components/components.go and build-manifests.sh regenerated deploy/*.yaml, but the OLM CSV doesn't look like it picked up any changes.

@tiraboschi
Copy link
Member

This looked like the right thing, I edited pkg/components/components.go and build-manifests.sh regenerated deploy/*.yaml, but the OLM CSV doesn't look like it picked up any changes.

You can eventually patch GetInstallStrategyBase functions.
But should this be part of what HCO is going to receive calling the csv-generator tool on CDI operator?

@maya-r
Copy link
Contributor Author

maya-r commented Jun 9, 2020

Right now the configmap is generated by HCO in https://github.com/kubevirt/hyperconverged-cluster-operator/blob/master/pkg/controller/hyperconverged/hyperconverged_controller.go#L1502-L1524

I don't know why it's here (or why anything that it does is useful), but the web UI looks at this information

@maya-r
Copy link
Contributor Author

maya-r commented Jun 16, 2020

So, I'm running into some trouble: OLM only lets me specify a serviceAccountName in a clusterPermissions.
The intention was to do this for the web UI, so maybe I should figure out what serviceAccountName is the web UI instead of trying to allow everyone access to this configMap?

@ovirt-infra
Copy link

All tests passed

@maya-r
Copy link
Contributor Author

maya-r commented Jun 17, 2020

I went back to the version adding the Role and RoleBinding via the reconcile loop, because I don't think it's possible to add them via OLM.

Another option worth considering is granting access to the openshift-console serviceAccountName, that might have the expected effect too.

@orenc1, could you have a look at this pull request? I'm under the impression that @tiraboschi is away on holiday.

@orenc1
Copy link
Collaborator

orenc1 commented Jun 17, 2020

I went back to the version adding the Role and RoleBinding via the reconcile loop, because I don't think it's possible to add them via OLM.

Another option worth considering is granting access to the openshift-console serviceAccountName, that might have the expected effect too.

@orenc1, could you have a look at this pull request? I'm under the impression that @tiraboschi is away on holiday.

Hi @maya-r , we are using the OLM to set the required permissions for the service accounts of HCO's dependent operators. If the access for kubevirt-storage-class-defaults config map is only required by the console (and not a direct access by the user), I think it would be more "granular" to provide this Role&RoleBinding to the console ServiceAccount. That could be configured by OLM by specifying it in the CSV, instead of having HCO manage these permissions in runtime.

@@ -469,6 +470,8 @@ func (r *ReconcileHyperConverged) ensureHco(req *hcoRequest) error {
r.ensureKubeVirtPriorityClass,
r.ensureKubeVirtConfig,
r.ensureKubeVirtStorageConfig,
r.ensureKubeVirtStorageRole,
Copy link
Collaborator

@nunnatsa nunnatsa Jun 17, 2020

Choose a reason for hiding this comment

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

In addition to the general comment about not doing it from reconcile - if there is no other choice, I would call these two methods from within ensureCDI and not as part of this loop. This is something that is not monitors by HCO as other resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review.
My original motivation to write the code this way is that ensureKubeVirtStorageConfig is currently implemented as its own reconcile function.
If the intention in rotating the code is to "don't test if the rolebinding exists in every reconcile iteration", I don't think that this is a good idea.
It would violate our rule to write reconcile such that we reach eventual consistency. This might negatively affect updates, as one example.
If it's just to make things tidy, I should probably combine it with ensureKubeVirtStorageConfig too.

@orenc1
Copy link
Collaborator

orenc1 commented Jun 17, 2020

Hi @maya-r , we are using the OLM to set the required permissions for the service accounts of HCO's dependent operators. If the access for kubevirt-storage-class-defaults config map is only required by the console (and not a direct access by the user), I think it would be more "granular" to provide this Role&RoleBinding to the console ServiceAccount. That could be configured by OLM by specifying it in the CSV, instead of having HCO manage these permissions in runtime.

I would recommend you to test by manually configuring the required Roles&RoleBindings of this configmap for the console ServiceAccount and see if it solves the issue. If so, add the relevant section in csv-generator of CDI so it will end up in HCO's CSV.

@maya-r
Copy link
Contributor Author

maya-r commented Jun 18, 2020

I got a response from Tomas Jelinek that the web interface accesses objects in the cluster as the logged in user (I had some trouble experimenting in the web interface).
It isn't possible to add the rights to the serviceAccountName and get the same result.
So this version of the pull request that is adding it via reconcile is the best I can do, I can't achieve the same result using OLM.

@orenc1
Copy link
Collaborator

orenc1 commented Jun 18, 2020

OK.
I would suggest to nest r.ensureKubeVirtStorageConfig and r.ensureKubeVirtStorageRole executions under ensureCDI, as Nahshon said, because these resources are strictly related to Storage.
I would also wait for @tiraboschi who returns on Monday for another review.

@tiraboschi
Copy link
Member

Yes, I also agree with @nunnatsa comment: all the methods called in the first loop in ensureHco method have a specific signature because the code there will use it to check the conditions reported by component operators and eventually the status of an upgrade.
We don't have anything like that for r.ensureKubeVirtStorageRole and r.ensureKubeVirtStorageRoleBinding so I agree that they should be called from r.ensureCDI so that you can use a simpler signature.
Probably, in a separate PR, we should do the same for r.ensureKubeVirtStorageConfig and other Config Maps created there.

@orenc1
Copy link
Collaborator

orenc1 commented Jun 30, 2020

Yes, I also agree with @nunnatsa comment: all the methods called in the first loop in ensureHco method have a specific signature because the code there will use it to check the conditions reported by component operators and eventually the status of an upgrade.
We don't have anything like that for r.ensureKubeVirtStorageRole and r.ensureKubeVirtStorageRoleBinding so I agree that they should be called from r.ensureCDI so that you can use a simpler signature.
Probably, in a separate PR, we should do the same for r.ensureKubeVirtStorageConfig and other Config Maps created there.

@maya-r ping?

@ovirt-infra
Copy link

All tests passed

@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 6, 2020
- Add a role/rolebinding for this purpose, using reconcile.
This is not done using OLM because OLM clusterPermissions only
allows adding permissions to a serviceAccountName.
- Add a functional test ensuring unprivileged users can read that
configmap but not others.
- Cargo cult add the role/rolebinding to the unit tests wherever
we test all elements created by reconcile

Signed-off-by: Maya Rashish <mrashish@redhat.com>
This means they can use a simpler function signature

Signed-off-by: Maya Rashish <mrashish@redhat.com>
@kubevirt-bot kubevirt-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 7, 2020
@ovirt-infra
Copy link

All tests passed

@orenc1
Copy link
Collaborator

orenc1 commented Jul 7, 2020

/approve
/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 7, 2020
@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: orenc1

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 7, 2020
@kubevirt-bot kubevirt-bot merged commit 67d2eec into kubevirt:master Jul 7, 2020
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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants