From 0e335365395fc342b43d09a99f3cecd08fe1442f Mon Sep 17 00:00:00 2001 From: Blaine Gardner Date: Fri, 7 Feb 2025 14:56:24 -0700 Subject: [PATCH] object: disallow unsafe OBC fields by default Implement an allow list mechanism that disables potentially unsafe OBC fields by default. OBC fields beyond `maxObjects` and `maxSize` don't neatly fit into the OBC framework as it was originally envisioned and implemented. Some of the newly added configs could allow users to cause confusion for themselves. Others might allow users to hijack others buckets. Some might allow bricking the entire S3 store. Out of an abundance of safety, allow-list the known-safe options by default, and require administrators to enable potentially troublesome options via the new operator-level config `ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS`. Signed-off-by: Blaine Gardner --- Documentation/Helm-Charts/operator-chart.md | 1 + .../ceph-object-bucket-claim.md | 24 ++++++++--- .../charts/rook-ceph/templates/configmap.yaml | 3 ++ deploy/charts/rook-ceph/values.yaml | 9 +++- deploy/examples/operator-openshift.yaml | 6 +++ deploy/examples/operator.yaml | 6 +++ pkg/operator/ceph/controller.go | 1 + .../ceph/controller/controller_utils.go | 16 +++++++ .../ceph/controller/controller_utils_test.go | 42 +++++++++++++++++++ .../ceph/object/bucket/provisioner_test.go | 37 ++++++++++++++++ pkg/operator/ceph/object/bucket/util.go | 22 ++++++++++ tests/framework/installer/ceph_settings.go | 3 ++ 12 files changed, 164 insertions(+), 6 deletions(-) diff --git a/Documentation/Helm-Charts/operator-chart.md b/Documentation/Helm-Charts/operator-chart.md index c6ae59721..4d946c850 100644 --- a/Documentation/Helm-Charts/operator-chart.md +++ b/Documentation/Helm-Charts/operator-chart.md @@ -157,6 +157,7 @@ The following table lists the configurable parameters of the rook-operator chart | `logLevel` | Global log level for the operator. Options: `ERROR`, `WARNING`, `INFO`, `DEBUG` | `"INFO"` | | `monitoring.enabled` | Enable monitoring. Requires Prometheus to be pre-installed. Enabling will also create RBAC rules to allow Operator to create ServiceMonitors | `false` | | `nodeSelector` | Kubernetes [`nodeSelector`](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) to add to the Deployment. | `{}` | +| `obcAllowAdditionalConfigFields` | Many OBC additional config fields may be risky for administrators to allow users control over. The safe and default-allowed fields are 'maxObjects' and 'maxSize'. Other fields should be considered risky. To allow all additional configs, use this value: "maxObjects,maxSize,bucketMaxObjects,bucketMaxSize,bucketPolicy,bucketLifecycle,bucketOwner" | "maxObjects,maxSize" | | `obcProvisionerNamePrefix` | Specify the prefix for the OBC provisioner in place of the cluster namespace | `ceph cluster namespace` | | `priorityClassName` | Set the priority class for the rook operator deployment if desired | `nil` | | `pspEnable` | If true, create & use PSP resources | `false` | diff --git a/Documentation/Storage-Configuration/Object-Storage-RGW/ceph-object-bucket-claim.md b/Documentation/Storage-Configuration/Object-Storage-RGW/ceph-object-bucket-claim.md index 284b1dba3..b19d38602 100644 --- a/Documentation/Storage-Configuration/Object-Storage-RGW/ceph-object-bucket-claim.md +++ b/Documentation/Storage-Configuration/Object-Storage-RGW/ceph-object-bucket-claim.md @@ -91,11 +91,25 @@ If both `bucketName` and `generateBucketName` are blank or omitted then the stor * `maxObjects`: The maximum number of objects in the bucket as a quota on the user account automatically created for the bucket. * `maxSize`: The maximum size of the bucket as a quota on the user account automatically created for the bucket. Please note minimum recommended value is 4K. - * `bucketMaxObjects`: The maximum number of objects in the bucket as an individual bucket quota. This is useful when the bucket is shared among multiple users. - * `bucketMaxSize`: The maximum size of the bucket as an individual bucket quota. - * `bucketPolicy`: A raw JSON format string that defines an AWS S3 format the bucket policy. If set, the policy string will override any existing policy set on the bucket and any default bucket policy that the bucket provisioner potentially would have automatically generated. - * `bucketLifecycle`: A raw JSON format string that defines an AWS S3 format bucket lifecycle configuration. Note that the rules must be sorted by `ID` in order to be idempotent. - * `bucketOwner`: The name of a pre-existing ceph rgw user account that will own the bucket. A `CephObjectStoreUser` resource may be used to create an ceph rgw user account. If the bucket already exists and is owned by a different user, the bucket will be re-linked to the specified user. + * `bucketMaxObjects`: (disabled by default) The maximum number of objects in the bucket as an individual bucket quota. This is useful when the bucket is shared among multiple users. + * `bucketMaxSize`: (disabled by default) The maximum size of the bucket as an individual bucket quota. + * `bucketPolicy`: (disabled by default) A raw JSON format string that defines an AWS S3 format the bucket policy. If set, the policy string will override any existing policy set on the bucket and any default bucket policy that the bucket provisioner potentially would have automatically generated. + * `bucketLifecycle`: (disabled by default) A raw JSON format string that defines an AWS S3 format bucket lifecycle configuration. Note that the rules must be sorted by `ID` in order to be idempotent. + * `bucketOwner`: (disabled by default) The name of a pre-existing ceph rgw user account that will own the bucket. A `CephObjectStoreUser` resource may be used to create an ceph rgw user account. If the bucket already exists and is owned by a different user, the bucket will be re-linked to the specified user. + +Several OBC `additionalConfig` fields are disabled by default. Default-disabled additional config +fields may be risky for administrators to allow users control over, and they should be enabled only +with caution. + +The default allowed fields are `maxObjects` and `maxSize`. These are designed to fit into the OBC +framework's original design goals. Other fields can be allowed but exert control outside of OBC's +original design goals and should be considered risky. At best, users may be able to break their own +OBCs in unexpected ways. At worst, users may brick the whole S3 object store for all users +(`bucketPolicy` in particular). Administrators should take care to enable features only when they +are personally willing to take on the risks. + +OBC `additionalConfig` fields can be enabled and disabled using the the `rook-ceph-operator-config` +configmap value `ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS`. ### OBC Custom Resource after Bucket Provisioning diff --git a/deploy/charts/rook-ceph/templates/configmap.yaml b/deploy/charts/rook-ceph/templates/configmap.yaml index 1acc2c5e8..576764acc 100644 --- a/deploy/charts/rook-ceph/templates/configmap.yaml +++ b/deploy/charts/rook-ceph/templates/configmap.yaml @@ -14,6 +14,9 @@ data: {{- end }} {{- if .Values.obcProvisionerNamePrefix }} ROOK_OBC_PROVISIONER_NAME_PREFIX: {{ .Values.obcProvisionerNamePrefix | quote }} +{{- end }} +{{- if .Values.obcAllowAdditionalConfigFields }} + ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS: {{ .Values.obcAllowAdditionalConfigFields | quote }} {{- end }} ROOK_CEPH_ALLOW_LOOP_DEVICES: {{ .Values.allowLoopDevices | quote }} ROOK_ENABLE_DISCOVERY_DAEMON: {{ .Values.enableDiscoveryDaemon | quote }} diff --git a/deploy/charts/rook-ceph/values.yaml b/deploy/charts/rook-ceph/values.yaml index 2122ef61f..b75e1f87d 100644 --- a/deploy/charts/rook-ceph/values.yaml +++ b/deploy/charts/rook-ceph/values.yaml @@ -624,7 +624,7 @@ discover: # memory: 128Mi # -- Custom label to identify node hostname. If not set `kubernetes.io/hostname` will be used -customHostnameLabel: +customHostnameLabel: # -- Runs Ceph Pods as privileged to be able to write to `hostPaths` in OpenShift with SELinux restrictions. hostpathRequiresPrivileged: false @@ -652,6 +652,13 @@ enableOBCWatchOperatorNamespace: true # @default -- `ceph cluster namespace` obcProvisionerNamePrefix: +# -- Many OBC additional config fields may be risky for administrators to allow users control over. +# The safe and default-allowed fields are 'maxObjects' and 'maxSize'. +# Other fields should be considered risky. To allow all additional configs, use this value: +# "maxObjects,maxSize,bucketMaxObjects,bucketMaxSize,bucketPolicy,bucketLifecycle,bucketOwner" +# @default -- "maxObjects,maxSize" +obcAllowAdditionalConfigFields: "maxObjects,maxSize" + monitoring: # -- Enable monitoring. Requires Prometheus to be pre-installed. # Enabling will also create RBAC rules to allow Operator to create ServiceMonitors diff --git a/deploy/examples/operator-openshift.yaml b/deploy/examples/operator-openshift.yaml index cea5a6fab..26eead857 100644 --- a/deploy/examples/operator-openshift.yaml +++ b/deploy/examples/operator-openshift.yaml @@ -541,6 +541,12 @@ data: # Custom prefix value for the OBC provisioner instead of ceph cluster namespace, do not set on existing cluster # ROOK_OBC_PROVISIONER_NAME_PREFIX: "custom-prefix" + # Many OBC additional config fields may be risky for administrators to allow users control over. + # The safe and default-allowed fields are 'maxObjects' and 'maxSize'. + # Other fields should be considered risky. To allow all additional configs, use this value: + # "maxObjects,maxSize,bucketMaxObjects,bucketMaxSize,bucketPolicy,bucketLifecycle,bucketOwner" + # ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS: "maxObjects,maxSize" # default allowed configs + # Whether to start the discovery daemon to watch for raw storage devices on nodes in the cluster. # This daemon does not need to run if you are only going to create your OSDs based on StorageClassDeviceSets with PVCs. ROOK_ENABLE_DISCOVERY_DAEMON: "false" diff --git a/deploy/examples/operator.yaml b/deploy/examples/operator.yaml index b15b60e18..5af25f6da 100644 --- a/deploy/examples/operator.yaml +++ b/deploy/examples/operator.yaml @@ -491,6 +491,12 @@ data: # Custom prefix value for the OBC provisioner instead of ceph cluster namespace, do not set on existing cluster # ROOK_OBC_PROVISIONER_NAME_PREFIX: "custom-prefix" + # Many OBC additional config fields may be risky for administrators to allow users control over. + # The safe and default-allowed fields are 'maxObjects' and 'maxSize'. + # Other fields should be considered risky. To allow all additional configs, use this value: + # "maxObjects,maxSize,bucketMaxObjects,bucketMaxSize,bucketPolicy,bucketLifecycle,bucketOwner" + # ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS: "maxObjects,maxSize" # default allowed configs + # Whether to start the discovery daemon to watch for raw storage devices on nodes in the cluster. # This daemon does not need to run if you are only going to create your OSDs based on StorageClassDeviceSets with PVCs. ROOK_ENABLE_DISCOVERY_DAEMON: "false" diff --git a/pkg/operator/ceph/controller.go b/pkg/operator/ceph/controller.go index c674854a5..879a51b2e 100644 --- a/pkg/operator/ceph/controller.go +++ b/pkg/operator/ceph/controller.go @@ -134,6 +134,7 @@ func (r *ReconcileConfig) reconcile(request reconcile.Request) (reconcile.Result opcontroller.SetAllowLoopDevices(r.config.Parameters) opcontroller.SetEnforceHostNetwork(r.config.Parameters) opcontroller.SetRevisionHistoryLimit(r.config.Parameters) + opcontroller.SetObcAllowAdditionalConfigFields(r.config.Parameters) logger.Infof("%s done reconciling", controllerName) return reconcile.Result{}, nil diff --git a/pkg/operator/ceph/controller/controller_utils.go b/pkg/operator/ceph/controller/controller_utils.go index acdf7920b..8cb661d74 100644 --- a/pkg/operator/ceph/controller/controller_utils.go +++ b/pkg/operator/ceph/controller/controller_utils.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "reflect" + "slices" "strconv" "strings" "time" @@ -54,6 +55,9 @@ const ( enforceHostNetworkSettingName string = "ROOK_ENFORCE_HOST_NETWORK" enforceHostNetworkDefaultValue string = "false" + obcAllowAdditionalConfigFieldsSettingName string = "ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS" + obcAllowAdditionalConfigFieldsDefaultValue string = "maxObjects,maxSize" + revisionHistoryLimitSettingName string = "ROOK_REVISION_HISTORY_LIMIT" // UninitializedCephConfigError refers to the error message printed by the Ceph CLI when there is no ceph configuration file @@ -90,6 +94,9 @@ var ( // loopDevicesAllowed indicates whether loop devices are allowed to be used loopDevicesAllowed = false revisionHistoryLimit *int32 = nil + + // allowed OBC additional config fields + obcAllowAdditionalConfigFields = strings.Split(obcAllowAdditionalConfigFieldsDefaultValue, ",") ) func DiscoveryDaemonEnabled(data map[string]string) bool { @@ -159,6 +166,15 @@ func RevisionHistoryLimit() *int32 { return revisionHistoryLimit } +func SetObcAllowAdditionalConfigFields(data map[string]string) { + strval := k8sutil.GetValue(data, obcAllowAdditionalConfigFieldsSettingName, obcAllowAdditionalConfigFieldsDefaultValue) + obcAllowAdditionalConfigFields = strings.Split(strval, ",") +} + +func ObcAdditionalConfigKeyIsAllowed(configField string) bool { + return slices.Contains(obcAllowAdditionalConfigFields, configField) +} + // canIgnoreHealthErrStatusInReconcile determines whether a status of HEALTH_ERR in the CephCluster can be ignored safely. func canIgnoreHealthErrStatusInReconcile(cephCluster cephv1.CephCluster, controllerName string) bool { // Get a list of all the keys causing the HEALTH_ERR status. diff --git a/pkg/operator/ceph/controller/controller_utils_test.go b/pkg/operator/ceph/controller/controller_utils_test.go index 82774c8c7..cda45d991 100644 --- a/pkg/operator/ceph/controller/controller_utils_test.go +++ b/pkg/operator/ceph/controller/controller_utils_test.go @@ -246,3 +246,45 @@ func TestIsReadyToReconcile(t *testing.T) { assert.False(t, clusterExists) }) } + +func TestObcAllowAdditionalConfigFields(t *testing.T) { + tests := []struct { + name string + data map[string]string + shouldAllow []string + shouldDisallow []string + }{ + {"not set", map[string]string{}, + []string{"maxObjects", "maxSize"}, // default allowlist is unlikely to need changing EVER + []string{"bucketMaxObjects", "bucketMaxSize", "bucketPolicy", "bucketLifecycle", "bucketOwner", "random"}}, + {"set to empty", map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": ""}, + []string{}, // admin can allow no quota options if desired + []string{"maxObjects", "maxSize", "bucketMaxObjects", "bucketMaxSize", "bucketPolicy", "bucketLifecycle", "bucketOwner", "random"}}, + {"set to default", map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "maxObjects,maxSize"}, + []string{"maxObjects", "maxSize"}, + []string{"bucketMaxObjects", "bucketMaxSize", "bucketPolicy", "bucketLifecycle", "bucketOwner", "random"}}, + {"all quota fields", map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "maxObjects,maxSize,bucketMaxObjects,bucketMaxSize"}, + []string{"maxObjects", "maxSize", "bucketMaxObjects", "bucketMaxSize"}, + []string{"bucketPolicy", "bucketLifecycle", "bucketOwner", "random"}}, + {"all fields", map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "maxObjects,maxSize,bucketMaxObjects,bucketMaxSize,bucketPolicy,bucketLifecycle,bucketOwner"}, + []string{"maxObjects", "maxSize", "bucketMaxObjects", "bucketMaxSize", "bucketPolicy", "bucketLifecycle", "bucketOwner"}, + []string{"random"}}, + // this mechanism doesn't do any field checking - that isn't it's job - it merely handles + // allow-listing essentially arbitrary config keys + {"all fields including unknown", map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "maxObjects,maxSize,bucketMaxObjects,bucketMaxSize,bucketPolicy,bucketLifecycle,bucketOwner,random"}, + []string{"maxObjects", "maxSize", "bucketMaxObjects", "bucketMaxSize", "bucketPolicy", "bucketLifecycle", "bucketOwner", "random"}, + []string{"otherRandom"}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + SetObcAllowAdditionalConfigFields(tt.data) + + for _, toAllow := range tt.shouldAllow { + assert.True(t, ObcAdditionalConfigKeyIsAllowed(toAllow)) + } + for _, toDisallow := range tt.shouldDisallow { + assert.False(t, ObcAdditionalConfigKeyIsAllowed(toDisallow)) + } + }) + } +} diff --git a/pkg/operator/ceph/object/bucket/provisioner_test.go b/pkg/operator/ceph/object/bucket/provisioner_test.go index 5aad6a940..a098b51f9 100644 --- a/pkg/operator/ceph/object/bucket/provisioner_test.go +++ b/pkg/operator/ceph/object/bucket/provisioner_test.go @@ -31,6 +31,7 @@ import ( rookclient "github.com/rook/rook/pkg/client/clientset/versioned/fake" "github.com/rook/rook/pkg/clusterd" "github.com/rook/rook/pkg/daemon/ceph/client" + opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" "github.com/rook/rook/pkg/operator/ceph/object" "github.com/rook/rook/pkg/operator/test" "github.com/stretchr/testify/assert" @@ -500,6 +501,8 @@ func TestProvisioner_additionalConfigSpecFromMap(t *testing.T) { }) t.Run("maxObjects field should be set", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + spec, err := additionalConfigSpecFromMap(map[string]string{"maxObjects": "2"}) assert.NoError(t, err) var i int64 = 2 @@ -507,6 +510,8 @@ func TestProvisioner_additionalConfigSpecFromMap(t *testing.T) { }) t.Run("maxSize field should be set", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + spec, err := additionalConfigSpecFromMap(map[string]string{"maxSize": "3"}) assert.NoError(t, err) var i int64 = 3 @@ -514,34 +519,66 @@ func TestProvisioner_additionalConfigSpecFromMap(t *testing.T) { }) t.Run("bucketMaxObjects field should be set", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "bucketMaxObjects"}) + defer opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + spec, err := additionalConfigSpecFromMap(map[string]string{"bucketMaxObjects": "4"}) assert.NoError(t, err) assert.Equal(t, additionalConfigSpec{bucketMaxObjects: &(&struct{ i int64 }{4}).i}, *spec) }) t.Run("bucketMaxSize field should be set", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "bucketMaxSize"}) + defer opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + spec, err := additionalConfigSpecFromMap(map[string]string{"bucketMaxSize": "5"}) assert.NoError(t, err) assert.Equal(t, additionalConfigSpec{bucketMaxSize: &(&struct{ i int64 }{5}).i}, *spec) }) t.Run("bucketPolicy field should be set", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "bucketPolicy"}) + defer opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + spec, err := additionalConfigSpecFromMap(map[string]string{"bucketPolicy": "foo"}) assert.NoError(t, err) assert.Equal(t, additionalConfigSpec{bucketPolicy: &(&struct{ s string }{"foo"}).s}, *spec) }) t.Run("bucketLifecycle field should be set", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "bucketLifecycle"}) + defer opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + spec, err := additionalConfigSpecFromMap(map[string]string{"bucketLifecycle": "foo"}) assert.NoError(t, err) assert.Equal(t, additionalConfigSpec{bucketLifecycle: &(&struct{ s string }{"foo"}).s}, *spec) }) t.Run("bucketOwner field should be set", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{"ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS": "bucketOwner"}) + defer opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + spec, err := additionalConfigSpecFromMap(map[string]string{"bucketOwner": "foo"}) assert.NoError(t, err) assert.Equal(t, additionalConfigSpec{bucketOwner: &(&struct{ s string }{"foo"}).s}, *spec) }) + + t.Run("fields disallowed by default", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + + for _, configKey := range []string{"bucketMaxObjects", "bucketMaxSize", "bucketPolicy", "bucketLifecycle", "bucketOwner"} { + _, err := additionalConfigSpecFromMap(map[string]string{configKey: "foo"}) + assert.Error(t, err) + } + }) + + t.Run("does not fail on empty map", func(t *testing.T) { + opcontroller.SetObcAllowAdditionalConfigFields(map[string]string{}) + + spec, err := additionalConfigSpecFromMap(map[string]string{}) + assert.NoError(t, err) + assert.Equal(t, additionalConfigSpec{}, *spec) + }) } func numberOfCallsWithValue(substr string, strs []string) int { diff --git a/pkg/operator/ceph/object/bucket/util.go b/pkg/operator/ceph/object/bucket/util.go index 28953500c..19e294cb9 100644 --- a/pkg/operator/ceph/object/bucket/util.go +++ b/pkg/operator/ceph/object/bucket/util.go @@ -24,6 +24,7 @@ import ( "github.com/kube-object-storage/lib-bucket-provisioner/pkg/provisioner" "github.com/pkg/errors" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" + opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" cephObject "github.com/rook/rook/pkg/operator/ceph/object" storagev1 "k8s.io/api/storage/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" @@ -93,6 +94,9 @@ func additionalConfigSpecFromMap(config map[string]string) (*additionalConfigSpe spec := additionalConfigSpec{} if _, ok := config["maxObjects"]; ok { + if !opcontroller.ObcAdditionalConfigKeyIsAllowed("maxObjects") { + return nil, errors.Errorf("OBC config %q is not allowed", "maxObjects") + } spec.maxObjects, err = quanityToInt64(config["maxObjects"]) if err != nil { return nil, errors.Wrapf(err, "failed to parse maxObjects quota") @@ -100,6 +104,9 @@ func additionalConfigSpecFromMap(config map[string]string) (*additionalConfigSpe } if _, ok := config["maxSize"]; ok { + if !opcontroller.ObcAdditionalConfigKeyIsAllowed("maxSize") { + return nil, errors.Errorf("OBC config %q is not allowed", "maxSize") + } spec.maxSize, err = quanityToInt64(config["maxSize"]) if err != nil { return nil, errors.Wrapf(err, "failed to parse maxSize quota") @@ -107,6 +114,9 @@ func additionalConfigSpecFromMap(config map[string]string) (*additionalConfigSpe } if _, ok := config["bucketMaxObjects"]; ok { + if !opcontroller.ObcAdditionalConfigKeyIsAllowed("bucketMaxObjects") { + return nil, errors.Errorf("OBC config %q is not allowed", "bucketMaxObjects") + } spec.bucketMaxObjects, err = quanityToInt64(config["bucketMaxObjects"]) if err != nil { return nil, errors.Wrapf(err, "failed to parse bucketMaxObjects quota") @@ -114,6 +124,9 @@ func additionalConfigSpecFromMap(config map[string]string) (*additionalConfigSpe } if _, ok := config["bucketMaxSize"]; ok { + if !opcontroller.ObcAdditionalConfigKeyIsAllowed("bucketMaxSize") { + return nil, errors.Errorf("OBC config %q is not allowed", "bucketMaxSize") + } spec.bucketMaxSize, err = quanityToInt64(config["bucketMaxSize"]) if err != nil { return nil, errors.Wrapf(err, "failed to parse bucketMaxSize quota") @@ -121,16 +134,25 @@ func additionalConfigSpecFromMap(config map[string]string) (*additionalConfigSpe } if _, ok := config["bucketPolicy"]; ok { + if !opcontroller.ObcAdditionalConfigKeyIsAllowed("bucketPolicy") { + return nil, errors.Errorf("OBC config %q is not allowed", "bucketPolicy") + } policy := config["bucketPolicy"] spec.bucketPolicy = &policy } if _, ok := config["bucketLifecycle"]; ok { + if !opcontroller.ObcAdditionalConfigKeyIsAllowed("bucketLifecycle") { + return nil, errors.Errorf("OBC config %q is not allowed", "bucketLifecycle") + } lifecycle := config["bucketLifecycle"] spec.bucketLifecycle = &lifecycle } if _, ok := config["bucketOwner"]; ok { + if !opcontroller.ObcAdditionalConfigKeyIsAllowed("bucketOwner") { + return nil, errors.Errorf("OBC config %q is not allowed", "bucketOwner") + } bucketOwner := config["bucketOwner"] spec.bucketOwner = &bucketOwner } diff --git a/tests/framework/installer/ceph_settings.go b/tests/framework/installer/ceph_settings.go index 3fb0e7cb1..d207d1a33 100644 --- a/tests/framework/installer/ceph_settings.go +++ b/tests/framework/installer/ceph_settings.go @@ -86,6 +86,9 @@ func (s *TestCephSettings) replaceOperatorSettings(manifest string) string { manifest = strings.ReplaceAll(manifest, `ROOK_ENABLE_DISCOVERY_DAEMON: "false"`, fmt.Sprintf(`ROOK_ENABLE_DISCOVERY_DAEMON: "%t"`, s.EnableDiscovery)) manifest = strings.ReplaceAll(manifest, `CSI_ENABLE_VOLUME_REPLICATION: "false"`, fmt.Sprintf(`CSI_ENABLE_VOLUME_REPLICATION: "%t"`, s.EnableVolumeReplication)) manifest = strings.ReplaceAll(manifest, `ROOK_CSI_ENABLE_NFS: "false"`, fmt.Sprintf(`ROOK_CSI_ENABLE_NFS: "%t"`, s.TestNFSCSI)) + manifest = strings.ReplaceAll(manifest, + `# ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS: "maxObjects,maxSize" # default allowed configs`, + `ROOK_OBC_ALLOW_ADDITIONAL_CONFIG_FIELDS: "maxObjects,maxSize,bucketMaxObjects,bucketMaxSize,bucketPolicy,bucketLifecycle,bucketOwner"`) return manifest }