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

controllers: create SCCs on Openshift #52

Merged
merged 3 commits into from
Dec 30, 2021
Merged

controllers: create SCCs on Openshift #52

merged 3 commits into from
Dec 30, 2021

Conversation

nbalacha
Copy link
Contributor

Create SCCs for topolvm-node and vgmanager on openshift.

Signed-off-by: N Balachandran [email protected]

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 27, 2021
@nbalacha
Copy link
Contributor Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 27, 2021
main.go Outdated
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
IsOpenshift: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

  • any possibility to avoid this, since secv1 is just another api, if there's any possibility to check the availability of that api and set this option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Openshift requires that this api be used for security.

Copy link
Contributor

Choose a reason for hiding this comment

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

  • I meant it differently, yes OCP uses this api for security, my ask here is, can this not be hardcoded and set the value based on api availability?

@@ -0,0 +1,169 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

  • please add this as one of resource unit, just reminding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

limitations under the License.
*/

package controllers
Copy link
Contributor

Choose a reason for hiding this comment

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

can you try below once?

diff --git a/controllers/scc.go b/controllers/scc.go
index a987590..f0a9d62 100644
--- a/controllers/scc.go
+++ b/controllers/scc.go
@@ -45,17 +45,17 @@ func (c openshiftSccs) ensureCreated(r *LVMClusterReconciler, ctx context.Contex
 
                sccs := getAllSCCs(lvmCluster.Namespace)
                for _, scc := range sccs {
-                       found, err := r.SecurityClient.SecurityContextConstraints().Get(scc.Name, metav1.GetOptions{})
+                       found, err := r.SecurityClient.SecurityContextConstraints().Get(ctx, scc.Name, metav1.GetOptions{})
                        if err != nil && errors.IsNotFound(err) {
                                r.Log.Info("Creating SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)
-                               _, err := r.SecurityClient.SecurityContextConstraints().Create(scc)
+                               _, err := r.SecurityClient.SecurityContextConstraints().Create(ctx, scc, metav1.CreateOptions{})
                                if err != nil {
                                        return fmt.Errorf("unable to create SCC %+v: %v", scc, err)
                                }
                        } else if err == nil {
                                scc.ObjectMeta = found.ObjectMeta
                                r.Log.Info("Updating SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)
-                               _, err := r.SecurityClient.SecurityContextConstraints().Update(scc)
+                               _, err := r.SecurityClient.SecurityContextConstraints().Update(ctx, scc, metav1.UpdateOptions{})
                                if err != nil {
                                        r.Log.Error(err, "Unable to update SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)
                                        return fmt.Errorf("unable to update SCC %+v: %v", scc, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was what I had originally but that did not match the v3.9 signatures

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does work with the updated packages .

go.mod Outdated
@@ -7,6 +7,8 @@ require (
github.com/google/go-cmp v0.5.6
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.15.0
github.com/openshift/api v3.9.0+incompatible
Copy link
Contributor

Choose a reason for hiding this comment

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

can you try with below?

diff --git a/go.mod b/go.mod
index ddfee36..613087f 100644
--- a/go.mod
+++ b/go.mod
@@ -7,8 +7,8 @@ require (
        github.com/google/go-cmp v0.5.6
        github.com/onsi/ginkgo v1.16.4
        github.com/onsi/gomega v1.15.0
-       github.com/openshift/api v3.9.0+incompatible
-       github.com/openshift/client-go v3.9.0+incompatible
+       github.com/openshift/api v0.0.0-20211028023115-7224b732cc14
+       github.com/openshift/client-go v0.0.0-20210831095141-e19a065e79f7
        github.com/topolvm/topolvm v0.10.3
        gotest.tools/v3 v3.0.3
        k8s.io/api v0.22.2
  • above is the result of
->  go get github.com/openshift/[email protected]
-> go get github.com/openshift/[email protected]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That works. Thanks.

Copy link
Contributor

@sp98 sp98 left a comment

Choose a reason for hiding this comment

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

nit


func (c openshiftSccs) ensureCreated(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error {
if r.IsOpenshift == true {

Copy link
Contributor

Choose a reason for hiding this comment

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

whitespace?

r.Log.Info("Updating SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)
_, err := r.SecurityClient.SecurityContextConstraints().Update(scc)
if err != nil {
r.Log.Error(err, "Unable to update SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
r.Log.Error(err, "Unable to update SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)
r.Log.Error(err, "failed to update SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)

just to be consistent with other error messages.

_, err := r.SecurityClient.SecurityContextConstraints().Update(scc)
if err != nil {
r.Log.Error(err, "Unable to update SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)
return fmt.Errorf("unable to update SCC %+v: %v", scc, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("unable to update SCC %+v: %v", scc, err)
return fmt.Errorf("failed to update SCC %q: %v", scc.Name, err)

}
} else {
r.Log.Error(err, "Something went wrong when checking for SecurityContextConstraint.", "SecurityContextConstraint", scc.Name)
return fmt.Errorf("something went wrong when checking for SCC %+v: %v", scc, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("something went wrong when checking for SCC %+v: %v", scc, err)
return fmt.Errorf("something went wrong when checking for SCC %q: %v", scc.Name, err)

}

func (c openshiftSccs) updateStatus(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error {
// intentionally empty as there'll be no status field on CSIDriver resource
Copy link
Contributor

Choose a reason for hiding this comment

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

need to update this comment for SCC.

@nbalacha nbalacha changed the title WIP: create SCCs on Openshift controllers: create SCCs on Openshift Dec 29, 2021
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 29, 2021
@nbalacha
Copy link
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 29, 2021
@nbalacha
Copy link
Contributor Author

Cannot create SCCs using the ENV tests so skipping that for now.

Comment on lines 21 to 23
#- topolvm_node_scc.yaml
#- topolvm_node_scc_role.yaml
#- topolvm_node_scc_role_bindings.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

as the files are deleted, better remove these lines rather than commenting them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. Missed this.

Kind: "SecurityContextConstraints",
},
}
scc.Name = "odf-lvm-topolvm-node"
Copy link
Contributor

Choose a reason for hiding this comment

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

is the prefix odf intentional 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.

Yes. SCCs will be created only on Openshift so Odf is fine.

Kind: "SecurityContextConstraints",
},
}
scc.Name = "odf-lvm-vgmanager"
Copy link
Contributor

Choose a reason for hiding this comment

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

  • intentional odf prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 30, 2021
// It does this by querying for the "privileged" SCC which exists on all OCP clusters.
func (r *LVMClusterReconciler) checkIfOpenshift(ctx context.Context) error {
if r.ClusterType == "" {
//has not been determined yet
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//has not been determined yet
// has not been determined yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return fmt.Errorf("failed to create SCC %q: %v", scc.Name, err)
}
} else if err == nil {
//Don't update the SCC
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//Don't update the SCC
// Don't update the SCC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


const (
ClusterTypeOCP ClusterType = "openshift"
ClusterTypeOther ClusterType = "other"
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need other option here? I think only ClusterTypeOCP should do the job.

Copy link
Contributor

Choose a reason for hiding this comment

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

other looks a bit ambiguous as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is set to a value to indicate that the check has been performed and a result has been received.


err = r.checkIfOpenshift(ctx)
if err != nil {
//Ignore the error for now
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//Ignore the error for now
// Ignore the error for now

Copy link
Contributor

@sp98 sp98 Dec 30, 2021

Choose a reason for hiding this comment

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

why ignore the error? error should be propagated if we can't detect the platform, IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For non-Openshift clusters it should still work so take a chance and go ahead?

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 30, 2021
Bundle manifests cannot include SCCs.The SCCs required by the
topolvm-node and vgmanager have to be created
post the operator installation by the LVM operator.

Signed-off-by: N Balachandran <[email protected]>
This commit removes the topolvm-node and vgmanager specific
scc related rbacs from config/ and includes the changes
required for the lvm controller to create the required SCCs
programatically.

Signed-off-by: N Balachandran <[email protected]>
Updated the env tests with scc changes.

Signed-off-by: N Balachandran <[email protected]>
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 30, 2021
@nbalacha
Copy link
Contributor Author

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 30, 2021

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: leelavg, nbalacha, sp98

The full list of commands accepted by this bot can be found 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

@nbalacha nbalacha merged commit 9b6bbc8 into openshift:main Dec 30, 2021
@nbalacha nbalacha deleted the scc branch December 31, 2021 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants