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 <blaine.gardner@ibm.com>
This commit is contained in:
Blaine Gardner committed 2025-02-12 14:18:01 -07:00
1 parent 1cf0a83ead
commit 0e33536539
12 files changed
+164 -6

No files matched your search

@@ -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))
}
})
}
}