Skip to content

Commit 3a359bf

Browse files
authored
fix: remove unsafe webdav option (#1168)
Closes #1167. Remove unsafe option `bearer_token_command` from the WebDAV provider. See also #964.
1 parent 357962b commit 3a359bf

4 files changed

Lines changed: 33 additions & 31 deletions

File tree

components/renku_data_services/storage/rclone.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
from renku_data_services import errors
1515
from renku_data_services.app_config import logging
1616
from renku_data_services.storage.constants import ENVIDAT_V1_PROVIDER
17-
from renku_data_services.storage.rclone_patches import BANNED_SFTP_OPTIONS, BANNED_STORAGE, apply_patches
17+
from renku_data_services.storage.rclone_patches import (
18+
BANNED_OPTIONS,
19+
BANNED_STORAGE,
20+
apply_patches,
21+
)
1822

1923
logger = logging.getLogger(__name__)
2024

@@ -412,9 +416,10 @@ def get_option_for_provider(self, name: str, provider: str | None) -> RCloneOpti
412416

413417
def check_unsafe_option(self, name: str) -> None:
414418
"""Check that the option is safe."""
415-
if self.prefix != "sftp":
419+
banned = BANNED_OPTIONS.get(self.prefix.lower(), None)
420+
if banned is None:
416421
return None
417-
if name in BANNED_SFTP_OPTIONS:
422+
if name in banned:
418423
raise errors.ValidationError(message=f"The {name} option is not allowed.")
419424
return None
420425

components/renku_data_services/storage/rclone_patches.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@
3838
"zoho",
3939
}
4040

41-
BANNED_SFTP_OPTIONS: Final[set[str]] = {
42-
"key_file", # path to a local file
43-
"pubkey_file", # path to a local file
44-
"known_hosts_file", # path to a local file
45-
"ssh", # arbitrary command to be executed
41+
BANNED_OPTIONS: Final[dict[str, set[str]]] = {
42+
"sftp": {
43+
"key_file", # path to a local file
44+
"pubkey_file", # path to a local file
45+
"known_hosts_file", # path to a local file
46+
"ssh", # arbitrary command to be executed
47+
},
48+
"webdav": {
49+
"bearer_token_command", # arbitrary command to be executed
50+
},
4651
}
4752

4853

@@ -252,14 +257,15 @@ def __patch_switchdrive_storage(spec: list[dict[str, Any]]) -> None:
252257
)
253258

254259

255-
def __patch_schema_remove_banned_sftp_options(spec: list[dict[str, Any]]) -> None:
256-
"""Remove unsafe SFTP options."""
257-
sftp = find_storage(spec, "sftp")
258-
options = []
259-
for option in sftp["Options"]:
260-
if option["Name"] not in BANNED_SFTP_OPTIONS:
261-
options.append(option)
262-
sftp["Options"] = options
260+
def __patch_schema_remove_banned_options(spec: list[dict[str, Any]]) -> None:
261+
"""Remove unsafe options."""
262+
for storage_type, banned in BANNED_OPTIONS.items():
263+
storage = find_storage(spec, storage_type)
264+
options = []
265+
for option in storage["Options"]:
266+
if option["Name"] not in banned:
267+
options.append(option)
268+
storage["Options"] = options
263269

264270

265271
def __patch_schema_add_openbis_type(spec: list[dict[str, Any]]) -> None:
@@ -354,7 +360,7 @@ def apply_patches(spec: list[dict[str, Any]]) -> None:
354360
__patch_schema_remove_oauth_propeties,
355361
__patch_polybox_storage,
356362
__patch_switchdrive_storage,
357-
__patch_schema_remove_banned_sftp_options,
363+
__patch_schema_remove_banned_options,
358364
__patch_schema_add_openbis_type,
359365
]
360366

test/bases/renku_data_services/data_api/__snapshots__/test_storage.ambr

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17415,18 +17415,6 @@
1741517415
'sensitive': True,
1741617416
'type': 'string',
1741717417
}),
17418-
dict({
17419-
'advanced': True,
17420-
'default': '',
17421-
'default_str': '',
17422-
'exclusive': False,
17423-
'help': 'Command to run to get a bearer token.',
17424-
'ispassword': False,
17425-
'name': 'bearer_token_command',
17426-
'required': False,
17427-
'sensitive': False,
17428-
'type': 'string',
17429-
}),
1743017418
dict({
1743117419
'advanced': True,
1743217420
'default': '',

test/bases/renku_data_services/data_api/test_storage.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from renku_data_services.data_api.dependencies import DependencyManager
1313
from renku_data_services.migrations.core import run_migrations_for_app
1414
from renku_data_services.storage.rclone import RCloneValidator
15-
from renku_data_services.storage.rclone_patches import BANNED_SFTP_OPTIONS, BANNED_STORAGE, OAUTH_PROVIDERS
15+
from renku_data_services.storage.rclone_patches import BANNED_OPTIONS, BANNED_STORAGE, OAUTH_PROVIDERS
1616
from renku_data_services.utils.core import get_openbis_session_token
1717
from test.utils import SanicReusableASGITestClient
1818

@@ -725,7 +725,10 @@ async def test_storage_schema_patches(storage_test_client, snapshot) -> None:
725725
# check that unsafe SFTP options are removed
726726
sftp = next((e for e in schema if e["prefix"] == "sftp"), None)
727727
assert sftp
728-
assert all(o["name"] not in BANNED_SFTP_OPTIONS for o in sftp["options"])
728+
assert all(o["name"] not in BANNED_OPTIONS["sftp"] for o in sftp["options"])
729+
webdav = next((e for e in schema if e["prefix"] == "webdav"), None)
730+
assert webdav
731+
assert all(o["name"] not in BANNED_OPTIONS["webdav"] for o in webdav["options"])
729732

730733
# snapshot the schema
731734
assert schema == snapshot

0 commit comments

Comments
 (0)