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

Add only non-null default pool Security Context values #1403

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

allanrogerr
Copy link
Contributor

@allanrogerr allanrogerr commented Jan 17, 2023

Issue

From [cniackz],
Issue comes from file github.com/minio/operator/pkg/resources/statefulsets/minio-statefulset.go:424 because we cannot longer support securityContext: {} in our Tenant Specification under pools option as before. I think we are trying to get some values from an empty context:

	// Default to Pod values
	if pool.SecurityContext != nil {
		runAsNonRoot = *pool.SecurityContext.RunAsNonRoot
		runAsUser = *pool.SecurityContext.RunAsUser
		runAsGroup = *pool.SecurityContext.RunAsGroup
	}

PR was: #1372

We should fix above issue/panic and still support securityContext: {} under pools in Tenant Specification.

Reproduce

  1. Deploy and maintain a kind cluster with tenant-lite. e.g. with testing/deploy-tenant.sh in the operator repo.
    Ensure that the destroy_kind command is commented out.

  2. Once the tenant pods are online, edit the tenant ensuring the following is under .spec.pools, with k -n tenant-lite edit tenants.minio.min.io:

    securityContext:
      #runAsUser: 1000
      #runAsGroup: 1000
      #runAsNonRoot: true
      fsGroup: 1000
    containerSecurityContext:
      runAsUser: 1000       
      runAsGroup: 1000
      runAsNonRoot: true

image

  1. Restart the tenant pods, and observe them in a non ready state
k -n tenant-lite delete pod/storage-lite-pool-0-0
k -n tenant-lite delete pod/storage-lite-pool-0-1
k -n tenant-lite delete pod/storage-lite-pool-0-2
k -n tenant-lite delete pod/storage-lite-pool-0-3
k -n tenant-lite get pods | grep "pool-0"

image

  1. Add Security Context to tenant
k -n tenant-lite edit tenants.minio.min.io  
    securityContext:
      runAsUser: 1000
      runAsGroup: 1000
      runAsNonRoot: true
      fsGroup: 1000

image

  1. Restart the tenant pods, and observe them in a ready state
k -n tenant-lite delete pod/storage-lite-pool-0-0
k -n tenant-lite delete pod/storage-lite-pool-0-1
k -n tenant-lite delete pod/storage-lite-pool-0-2
k -n tenant-lite delete pod/storage-lite-pool-0-3
k -n tenant-lite get pods | grep "pool-0"

image

Fix

  1. Modify pkg/resources/statefulsets/minio-statefulset.go addingin only non-null fields to avoid the NPE.
        // Default to Pod values
	if pool.SecurityContext != nil {
		if pool.SecurityContext.RunAsNonRoot != nil {
			runAsNonRoot = *pool.SecurityContext.RunAsNonRoot
		}
		if pool.SecurityContext.RunAsUser != nil {
			runAsUser = *pool.SecurityContext.RunAsUser
		}
		if pool.SecurityContext.RunAsGroup != nil {
			runAsGroup = *pool.SecurityContext.RunAsGroup
		}
	}

Test

  1. Clone https://github.com/allanrogerr/operator/tree/fix-security-context-npe
    Deploy and maintain a kind cluster with tenant-lite. e.g. with testing/deploy-tenant.sh in the operator repo.
    Ensure that the destroy_kind command is commented out.

  2. Once the tenant pods are online, edit the tenant ensuring the following is under .spec.pools, with k -n tenant-lite edit tenants.minio.min.io:

    securityContext:
      #runAsUser: 1000
      #runAsGroup: 1000
      #runAsNonRoot: true
      fsGroup: 1000
    containerSecurityContext:
      runAsUser: 1000       
      runAsGroup: 1000
      runAsNonRoot: true

image

  1. Restart the tenant pods, and observe them in a ready state
k -n tenant-lite delete pod/storage-lite-pool-0-0
k -n tenant-lite delete pod/storage-lite-pool-0-1
k -n tenant-lite delete pod/storage-lite-pool-0-2
k -n tenant-lite delete pod/storage-lite-pool-0-3
k -n tenant-lite get pods | grep "pool-0"

image

Copy link
Contributor

@cniackz cniackz left a comment

Choose a reason for hiding this comment

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

LGTM

@pjuarezd
Copy link
Member

🚢 it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants