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

Bug 1918351: Gather SAP configuration (SCC & ClusterRoleBinding) #291

Merged
merged 3 commits into from
Jan 25, 2021

Conversation

natiiix
Copy link
Contributor

@natiiix natiiix commented Dec 8, 2020

This enhancements gathers anyuid and privileged SCCs, and the corresponding ClusterRoleBindings from clusters running a SAP payload.

Categories

  • Bugfix
  • Enhancement
  • Backporting
  • Others (CI, Infrastructure, Documentation)

Sample archive

  • config/sap_namespaces.json (removed because it's no longer necessary)
  • config/securitycontextconstraint/
  • config/clusterrolebinding/

Documentation

  • docs/gathered-data.md - "SAPConfig" section

Unit Tests

  • pkg/gather/clusterconfig/sap_config_test.go

Privacy

Yes. There are no sensitive data in the newly collected information.

Changelog

No.

References

Jira Task: https://issues.redhat.com/browse/CCXDEV-3485

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 8, 2020
@openshift-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 8, 2020
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 16, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 16, 2020
@natiiix natiiix force-pushed the gather-sap-scc-crb branch 2 times, most recently from 6a02a2e to 6759c8c Compare January 20, 2021 13:52
@natiiix natiiix changed the title WIP: Gather SAP configuration (SCC & ClusterRoleBinding) Gather SAP configuration (SCC & ClusterRoleBinding) Jan 20, 2021
@natiiix natiiix changed the title Gather SAP configuration (SCC & ClusterRoleBinding) Bug 1918351: Gather SAP configuration (SCC & ClusterRoleBinding) Jan 20, 2021
@openshift-ci-robot openshift-ci-robot added bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. labels Jan 20, 2021
@openshift-ci-robot
Copy link
Contributor

@natiiix: This pull request references Bugzilla bug 1918351, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.7.0) matches configured target release for branch (4.7.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1918351: Gather SAP configuration (SCC & ClusterRoleBinding)

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.

@natiiix natiiix marked this pull request as ready for review January 20, 2021 14:15
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 20, 2021
@openshift-ci-robot
Copy link
Contributor

@natiiix: This pull request references Bugzilla bug 1918351, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.7.0) matches configured target release for branch (4.7.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1918351: Gather SAP configuration (SCC & ClusterRoleBinding)

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.

1 similar comment
@openshift-ci-robot
Copy link
Contributor

@natiiix: This pull request references Bugzilla bug 1918351, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.7.0) matches configured target release for branch (4.7.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1918351: Gather SAP configuration (SCC & ClusterRoleBinding)

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.

@natiiix
Copy link
Contributor Author

natiiix commented Jan 21, 2021

/retest


sapNamespaces := map[string]struct{}{}
for _, item := range datahubsList.Items {
sapNamespaces[item.GetNamespace()] = struct{}{}
Copy link
Contributor

Choose a reason for hiding this comment

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

That looks a little unnecessary. Can't we have just a list/array of sapNamespaces names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, the reason behind this is historical. Now we no longer really care about the particular namespace, in which the resource exists, so we don't really need to collected this information at all. Originally, there was a loop iterating over the namespaces a looking for SCCs/CRBs that match them. It would be a problem to use a list if there were multiple datahubs resources in the namespace (not sure if that's even possible at all). I'll change this one to just a boolean value for simplicity. We don't need the actual namespaces anywhere in the code or in the archive. Wdyt?


func gatherSAPConfig(ctx context.Context, dynamicClient dynamic.Interface, coreClient corev1client.CoreV1Interface, securityClient securityv1client.SecurityV1Interface, authClient authclient.AuthorizationV1Interface) ([]record.Record, []error) {
sccFilter := map[string]struct{}{"anyuid": {}, "privileged": {}}
crbFilter := map[string]struct{}{"system:openshift:scc:anyuid": {}, "system:openshift:scc:privileged": {}}
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 need maps for these? Wouldn't be array of string sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. It would work fine, but this syntax ensures that each resource is collected at most once. Originally, there was a name field check when iterating over a list of returned results instead of using Get, which checked if the name existed as a key in this map (which is actually the canonical Go syntax for a set) because it's faster and shorter than iterating over a list. I can change it if you want, but I think this should be fairly clear to anyone aware of this somewhat unusual syntax for sets).

@@ -0,0 +1 @@
{"metadata":{"name":"privileged","selfLink":"/apis/security.openshift.io/v1/securitycontextconstraints/privileged","uid":"8c98d901-ea31-4ad8-8616-f2d2185af2f7","resourceVersion":"40739187","generation":2,"creationTimestamp":"2020-10-29T14:27:37Z","annotations":{"include.release.openshift.io/self-managed-high-availability":"true","kubernetes.io/description":"privileged allows access to all privileged and host features and the ability to run as any user, any group, any fsGroup, and with any SELinux context. WARNING: this is the most relaxed SCC and should be used only for cluster administration. Grant with caution.","release.openshift.io/create-only":"true"},"managedFields":[{"manager":"cluster-version-operator","operation":"Update","apiVersion":"security.openshift.io/v1","time":"2020-10-29T14:27:37Z","fieldsType":"FieldsV1","fieldsV1":{"f:allowHostDirVolumePlugin":{},"f:allowHostIPC":{},"f:allowHostNetwork":{},"f:allowHostPID":{},"f:allowHostPorts":{},"f:allowPrivilegeEscalation":{},"f:allowPrivilegedContainer":{},"f:allowedCapabilities":{},"f:allowedUnsafeSysctls":{},"f:defaultAddCapabilities":{},"f:fsGroup":{".":{},"f:type":{}},"f:groups":{},"f:metadata":{"f:annotations":{".":{},"f:include.release.openshift.io/self-managed-high-availability":{},"f:kubernetes.io/description":{},"f:release.openshift.io/create-only":{}}},"f:priority":{},"f:readOnlyRootFilesystem":{},"f:requiredDropCapabilities":{},"f:runAsUser":{".":{},"f:type":{}},"f:seLinuxContext":{".":{},"f:type":{}},"f:seccompProfiles":{},"f:supplementalGroups":{".":{},"f:type":{}},"f:volumes":{}}},{"manager":"kubectl-edit","operation":"Update","apiVersion":"security.openshift.io/v1","time":"2020-11-26T12:53:56Z","fieldsType":"FieldsV1","fieldsV1":{"f:users":{}}}]},"priority":null,"allowPrivilegedContainer":true,"defaultAddCapabilities":null,"requiredDropCapabilities":null,"allowedCapabilities":["*"],"allowHostDirVolumePlugin":true,"volumes":["*"],"allowHostNetwork":true,"allowHostPorts":true,"allowHostPID":true,"allowHostIPC":true,"allowPrivilegeEscalation":true,"seLinuxContext":{"type":"RunAsAny"},"runAsUser":{"type":"RunAsAny"},"supplementalGroups":{"type":"RunAsAny"},"fsGroup":{"type":"RunAsAny"},"readOnlyRootFilesystem":false,"users":["system:admin","system:serviceaccount:openshift-infra:build-controller","system:serviceaccount:sdi:mlf-deployment-api"],"groups":["system:cluster-admins","system:nodes","system:masters"],"seccompProfiles":["*"],"allowedUnsafeSysctls":["*"]}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is little bit weird. All these resources are gathered without their kind and apiVersion. It's probably not an issue, but it's not very consistent (given the format of all our 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.

That's a very good catch, but we're not doing that anywhere intentionally. It just seems that this client doesn't return those fields when using the Get method for some strange reason.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 22, 2021
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 22, 2021
@openshift-ci-robot
Copy link
Contributor

@natiiix: This pull request references Bugzilla bug 1918351, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.7.0) matches configured target release for branch (4.7.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1918351: Gather SAP configuration (SCC & ClusterRoleBinding)

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.

@tremes
Copy link
Contributor

tremes commented Jan 25, 2021

Unfortunately we don't have the option to verify this directly (because we don't have any cluster with SAP installed). I only checked that nothing is added when the SAP is not installed. We verified this approach in remote RH cluster with SAP installed (by sharing IO image including this change).
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 25, 2021
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: natiiix, tremes

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

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

2 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 95b969d into openshift:master Jan 25, 2021
@openshift-ci-robot
Copy link
Contributor

@natiiix: All pull requests linked via external trackers have merged:

Bugzilla bug 1918351 has been moved to the MODIFIED state.

In response to this:

Bug 1918351: Gather SAP configuration (SCC & ClusterRoleBinding)

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.

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. bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants