object: allow creating an object user in different namespace

The object user was previously required to be created in the
same namespace as the object store and the cluster. Now,
the object user can be reconciled even in a different namespace
from the cluster and object store. The namespace would be specified
in the object user CR.

Signed-off-by: travisn <tnielsen@redhat.com>
This commit is contained in:
travisn committed 2023-08-25 11:54:57 -06:00
1 parent 0432e0977f
commit 2b1cc4c7b8
10 files changed
+217 -15

No files matched your search

@@ -82,7 +82,13 @@ When the `zone` section is set pools with the object stores name will not be cre
* `metadataPool`: The settings used to create all of the object store metadata pools. Must use replication.
* `dataPool`: The settings to create the object store data pool. Can use replication or erasure coding.
* `preservePoolsOnDelete`: If it is set to 'true' the pools used to support the object store will remain when the object store will be deleted. This is a security measure to avoid accidental loss of data. It is set to 'false' by default. If not specified is also deemed as 'false'.
* `preservePoolsOnDelete`: If it is set to 'true' the pools used to support the object store will remain when the object store
will be deleted. This is a security measure to avoid accidental loss of data. It is set to 'false' by default. If not specified
is also deemed as 'false'.
* `allowUsersInNamespaces`: If a CephObjectStoreUser is created in a namespace other than the Rook cluster namespace,
the namespace must be added to this list of allowed namespaces, or specify "*" to allow all namespaces.
This is useful for applications that need object store credentials to be created in their own namespace,
where neither OBCs nor COSI is being used to create buckets. The default is empty.
## Gateway Settings
@@ -36,6 +36,9 @@ spec:
* `store`: The object store in which the user will be created. This matches the name of the objectstore CRD.
* `displayName`: The display name which will be passed to the `radosgw-admin user create` command.
* `clusterNamespace`: The namespace where the parent CephCluster and CephObjectStore are found. If not specified,
the user must be in the same namespace as the cluster and object store.
To enable this feature, the CephObjectStore allowUsersInNamespaces must include the namespace of this user.
* `quotas`: This represents quota limitation can be set on the user. Please refer [here](https://docs.ceph.com/en/latest/radosgw/admin/#quota-management) for details.
* `maxBuckets`: The maximum bucket limit for the user.
* `maxSize`: Maximum size limit of all objects across all the user's buckets.
+58
View File
@@ -1872,6 +1872,23 @@ ObjectStoreSecuritySpec
<p>Security represents security settings</p>
</td>
</tr>
<tr>
<td>
<code>allowUsersInNamespaces</code><br/>
<em>
[]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The list of allowed namespaces in addition to the object store namespace
where ceph object store users may be created. Specify &ldquo;*&rdquo; to allow all
namespaces, otherwise list individual namespaces that are to be allowed.
This is useful for applications that need object store credentials
to be created in their own namespace, where neither OBCs nor COSI
is being used to create buckets. The default is empty.</p>
</td>
</tr>
</table>
</td>
</tr>
@@ -1996,6 +2013,18 @@ ObjectUserQuotaSpec
<em>(Optional)</em>
</td>
</tr>
<tr>
<td>
<code>clusterNamespace</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The namespace where the parent CephCluster and CephObjectStore are found</p>
</td>
</tr>
</table>
</td>
</tr>
@@ -8616,6 +8645,23 @@ ObjectStoreSecuritySpec
<p>Security represents security settings</p>
</td>
</tr>
<tr>
<td>
<code>allowUsersInNamespaces</code><br/>
<em>
[]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The list of allowed namespaces in addition to the object store namespace
where ceph object store users may be created. Specify &ldquo;*&rdquo; to allow all
namespaces, otherwise list individual namespaces that are to be allowed.
This is useful for applications that need object store credentials
to be created in their own namespace, where neither OBCs nor COSI
is being used to create buckets. The default is empty.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="ceph.rook.io/v1.ObjectStoreStatus">ObjectStoreStatus
@@ -8774,6 +8820,18 @@ ObjectUserQuotaSpec
<em>(Optional)</em>
</td>
</tr>
<tr>
<td>
<code>clusterNamespace</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The namespace where the parent CephCluster and CephObjectStore are found</p>
</td>
</tr>
</tbody>
</table>
<h3 id="ceph.rook.io/v1.ObjectStoreUserStatus">ObjectStoreUserStatus
@@ -9907,6 +9907,11 @@ spec:
spec:
description: ObjectStoreSpec represent the spec of a pool
properties:
allowUsersInNamespaces:
description: The list of allowed namespaces in addition to the object store namespace where ceph object store users may be created. Specify "*" to allow all namespaces, otherwise list individual namespaces that are to be allowed. This is useful for applications that need object store credentials to be created in their own namespace, where neither OBCs nor COSI is being used to create buckets. The default is empty.
items:
type: string
type: array
dataPool:
description: The data pool settings
nullable: true
@@ -11442,6 +11447,9 @@ spec:
- read, write
type: string
type: object
clusterNamespace:
description: The namespace where the parent CephCluster and CephObjectStore are found
type: string
displayName:
description: The display name for the ceph users
type: string
+8
View File
@@ -9898,6 +9898,11 @@ spec:
spec:
description: ObjectStoreSpec represent the spec of a pool
properties:
allowUsersInNamespaces:
description: The list of allowed namespaces in addition to the object store namespace where ceph object store users may be created. Specify "*" to allow all namespaces, otherwise list individual namespaces that are to be allowed. This is useful for applications that need object store credentials to be created in their own namespace, where neither OBCs nor COSI is being used to create buckets. The default is empty.
items:
type: string
type: array
dataPool:
description: The data pool settings
nullable: true
@@ -11432,6 +11437,9 @@ spec:
- read, write
type: string
type: object
clusterNamespace:
description: The namespace where the parent CephCluster and CephObjectStore are found
type: string
displayName:
description: The display name for the ceph users
type: string
+12 -8
View File
@@ -13,13 +13,17 @@ spec:
displayName: "my display name"
# Quotas set on the user
# quotas:
# maxBuckets: 100
# maxSize: 10G
# maxObjects: 10000
# maxBuckets: 100
# maxSize: 10G
# maxObjects: 10000
# Additional permissions given to the user
# capabilities:
# user: "*"
# bucket: "*"
# metadata: "*"
# usage: "*"
# zone: "*"
# user: "*"
# bucket: "*"
# metadata: "*"
# usage: "*"
# zone: "*"
# If the CephObjectStoreUser is created in a namespace other than the Rook cluster namespace,
# specify the namespace where the cluster and object store are found.
# "allowUsersInNamespaces" must include this namespace to enable this feature.
# clusterNamespace: rook-ceph
+4
View File
@@ -109,6 +109,10 @@ spec:
disabled: false
readinessProbe:
disabled: false
# If a CephObjectStoreUser is created in a namespace other than the Rook cluster namespace,
# the namespace must be added to the list of allowed namespaces, or specify "*" to allow all namespaces.
# allowUsersInNamespaces:
# - other-namespace
# security oriented settings
# security:
# To enable the Server Side Encryption configuration properly don't forget to uncomment the Secret at the end of the file
+12
View File
@@ -1387,6 +1387,15 @@ type ObjectStoreSpec struct {
// +optional
// +nullable
Security *ObjectStoreSecuritySpec `json:"security,omitempty"`
// The list of allowed namespaces in addition to the object store namespace
// where ceph object store users may be created. Specify "*" to allow all
// namespaces, otherwise list individual namespaces that are to be allowed.
// This is useful for applications that need object store credentials
// to be created in their own namespace, where neither OBCs nor COSI
// is being used to create buckets. The default is empty.
// +optional
AllowUsersInNamespaces []string `json:"allowUsersInNamespaces,omitempty"`
}
// ObjectHealthCheckSpec represents the health check of an object store
@@ -1597,6 +1606,9 @@ type ObjectStoreUserSpec struct {
// +optional
// +nullable
Quotas *ObjectUserQuotaSpec `json:"quotas,omitempty"`
// The namespace where the parent CephCluster and CephObjectStore are found
// +optional
ClusterNamespace string `json:"clusterNamespace,omitempty"`
}
// Additional admin-level capabilities for the Ceph object store user
+38 -6
View File
@@ -162,13 +162,16 @@ func (r *ReconcileObjectStoreUser) reconcile(request reconcile.Request) (reconci
return reconcile.Result{}, *cephObjectStoreUser, errors.Wrap(err, "failed to add finalizer")
}
clusterNamespace := request.NamespacedName
clusterNamespace.Namespace = clusterStoreNamespace(cephObjectStoreUser)
// The CR was just created, initializing status fields
if cephObjectStoreUser.Status == nil {
r.updateStatus(k8sutil.ObservedGenerationNotAvailable, request.NamespacedName, k8sutil.EmptyStatus)
}
// Make sure a CephCluster is present otherwise do nothing
cephCluster, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.opManagerContext, r.client, request.NamespacedName, controllerName)
cephCluster, isReadyToReconcile, cephClusterExists, reconcileResponse := opcontroller.IsReadyToReconcile(r.opManagerContext, r.client, clusterNamespace, controllerName)
if !isReadyToReconcile {
// This handles the case where the Ceph Cluster is gone and we want to delete that CR
// We skip the deleteUser() function since everything is gone already
@@ -191,7 +194,7 @@ func (r *ReconcileObjectStoreUser) reconcile(request reconcile.Request) (reconci
r.cephClusterSpec = &cephCluster.Spec
// Populate clusterInfo during each reconcile
r.clusterInfo, _, _, err = opcontroller.LoadClusterInfo(r.context, r.opManagerContext, request.NamespacedName.Namespace, r.cephClusterSpec)
r.clusterInfo, _, _, err = opcontroller.LoadClusterInfo(r.context, r.opManagerContext, clusterNamespace.Namespace, r.cephClusterSpec)
if err != nil {
return reconcile.Result{}, *cephObjectStoreUser, errors.Wrap(err, "failed to populate cluster info")
}
@@ -211,7 +214,7 @@ func (r *ReconcileObjectStoreUser) reconcile(request reconcile.Request) (reconci
return reconcile.Result{}, *cephObjectStoreUser, nil
}
logger.Debugf("ObjectStore resource not ready in namespace %q, retrying in %q. %v",
request.NamespacedName.Namespace, opcontroller.WaitForRequeueIfCephClusterNotReady.RequeueAfter.String(), err)
clusterNamespace.Namespace, opcontroller.WaitForRequeueIfCephClusterNotReady.RequeueAfter.String(), err)
r.updateStatus(k8sutil.ObservedGenerationNotAvailable, request.NamespacedName, k8sutil.ReconcileFailedStatus)
return opcontroller.WaitForRequeueIfCephClusterNotReady, *cephObjectStoreUser, err
}
@@ -222,7 +225,7 @@ func (r *ReconcileObjectStoreUser) reconcile(request reconcile.Request) (reconci
// DELETE: the CR was deleted
if !cephObjectStoreUser.GetDeletionTimestamp().IsZero() {
logger.Debugf("deleting pool %q", cephObjectStoreUser.Name)
logger.Debugf("deleting object store user %q", request.NamespacedName)
r.recorder.Eventf(cephObjectStoreUser, v1.EventTypeNormal, string(cephv1.ReconcileStarted), "deleting CephObjectStoreUser %q", cephObjectStoreUser.Name)
err := r.deleteUser(cephObjectStoreUser)
@@ -383,6 +386,16 @@ func (r *ReconcileObjectStoreUser) initializeObjectStoreContext(u *cephv1.CephOb
return errors.Wrapf(err, "failed to get object store %q", u.Spec.Store)
}
// Check if the object store allows users to be created in any namespace
if u.Spec.ClusterNamespace != "" && u.Spec.ClusterNamespace != u.Namespace {
if !userInNamespaceAllowed(u.Namespace, store.Spec.AllowUsersInNamespaces) {
return fmt.Errorf(
"object store %q does not allow creating users namespace %q, the namespace must first be added to allowUsersInNamespaces",
u.Spec.Store,
u.Namespace)
}
}
objContext, err := object.NewMultisiteContext(r.context, r.clusterInfo, store)
if err != nil {
return errors.Wrapf(err, "Multisite failed to set on object context for object store user")
@@ -397,6 +410,17 @@ func (r *ReconcileObjectStoreUser) initializeObjectStoreContext(u *cephv1.CephOb
return nil
}
func userInNamespaceAllowed(requestedNamespace string, allowedNamespaces []string) bool {
// Check if there is access to create the user in another namespace
for _, allowedNamespace := range allowedNamespaces {
if allowedNamespace == "*" || allowedNamespace == requestedNamespace {
logger.Debugf("allow creating object user in namespace %q", requestedNamespace)
return true
}
}
return false
}
func generateUserCaps(user admin.User) string {
var caps string
for _, c := range user.Caps {
@@ -556,7 +580,7 @@ func (r *ReconcileObjectStoreUser) objectStoreInitialized(cephObjectStoreUser *c
// check if at least one pod is running
if len(pods.Items) > 0 {
logger.Debugf("CephObjectStore %q is running with %d pods", cephObjectStoreUser.Name, len(pods.Items))
logger.Debugf("%d RGW pods found where object store user %q is created", len(pods.Items), cephObjectStoreUser.Name)
return nil
}
@@ -590,7 +614,7 @@ func (r *ReconcileObjectStoreUser) getRgwPodList(cephObjectStoreUser *cephv1.Cep
// check if ObjectStore is initialized
// rook does this by starting the RGW pod(s)
listOpts := []client.ListOption{
client.InNamespace(cephObjectStoreUser.Namespace),
client.InNamespace(clusterStoreNamespace(cephObjectStoreUser)),
client.MatchingLabels(labelsForRgw(cephObjectStoreUser.Spec.Store)),
}
@@ -605,6 +629,14 @@ func (r *ReconcileObjectStoreUser) getRgwPodList(cephObjectStoreUser *cephv1.Cep
return pods, nil
}
// Namespace where the object store and cluster are expected to be found
func clusterStoreNamespace(user *cephv1.CephObjectStoreUser) string {
if user.Spec.ClusterNamespace != "" {
return user.Spec.ClusterNamespace
}
return user.Namespace
}
// Delete the user
func (r *ReconcileObjectStoreUser) deleteUser(u *cephv1.CephObjectStoreUser) error {
err := r.objContext.AdminOpsClient.RemoveUser(r.opManagerContext, admin.User{ID: u.Name})
@@ -329,6 +329,73 @@ func TestCephObjectStoreUserController(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "Ready", objectUser.Status.Phase, objectUser)
})
t.Run("cluster and object store in different namespace", func(t *testing.T) {
cephCluster = &cephv1.CephCluster{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
Namespace: namespace,
},
Status: cephv1.ClusterStatus{
Phase: k8sutil.ReadyStatus,
CephStatus: &cephv1.CephStatus{
Health: "HEALTH_OK",
},
},
}
cephObjectStore.Spec.AllowUsersInNamespaces = []string{"*"}
// Create a fake client to mock API calls.
objectUser.Spec.ClusterNamespace = namespace
objectUser.Namespace = "foo"
req.Namespace = "foo"
object = []runtime.Object{cephObjectStore, objectUser, cephCluster}
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(object...).Build()
rgwPod := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{
Name: "rook-ceph-rgw-my-store-a-5fd6fb4489-xv65v",
Namespace: namespace,
Labels: map[string]string{k8sutil.AppAttr: appName, "rgw": "my-store"}}}
// Create a user in a different namespace, and where the cephcluster does exist
r = &ReconcileObjectStoreUser{client: cl, scheme: s, context: c, opManagerContext: ctx, recorder: record.NewFakeRecorder(5)}
err := r.client.Create(context.TODO(), rgwPod)
assert.NoError(t, err)
res, err := r.Reconcile(ctx, req)
assert.NoError(t, err)
assert.False(t, res.Requeue)
// Disallow creating a user in a different namespace
cephObjectStore.Spec.AllowUsersInNamespaces = []string{}
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(object...).Build()
r = &ReconcileObjectStoreUser{client: cl, scheme: s, context: c, opManagerContext: ctx, recorder: record.NewFakeRecorder(5)}
res, err = r.Reconcile(ctx, req)
assert.NoError(t, err)
assert.True(t, res.Requeue)
objectUser.Spec.ClusterNamespace = ""
object = []runtime.Object{objectUser, cephCluster}
cl = fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(object...).Build()
// Create a user in a different namespace, but where the cephcluster doesn't exist
r = &ReconcileObjectStoreUser{client: cl, scheme: s, context: c, opManagerContext: ctx, recorder: record.NewFakeRecorder(5)}
res, err = r.Reconcile(ctx, req)
assert.NoError(t, err)
assert.True(t, res.Requeue)
req.Namespace = namespace
objectUser.Namespace = namespace
})
t.Run("users allowed in other namespace", func(t *testing.T) {
assert.False(t, userInNamespaceAllowed("foo", []string{}))
assert.False(t, userInNamespaceAllowed("foo", []string{"bar"}))
assert.False(t, userInNamespaceAllowed("foo", []string{"bar", "baz"}))
assert.True(t, userInNamespaceAllowed("foo", []string{"*"}))
assert.True(t, userInNamespaceAllowed("foo", []string{"bar", "*"}))
assert.True(t, userInNamespaceAllowed("foo", []string{"foo"}))
assert.True(t, userInNamespaceAllowed("foo", []string{"bar", "foo"}))
})
}
func TestBuildUpdateStatusInfo(t *testing.T) {