dserver-signed-url-plugin 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dserver_signed_url_plugin/__init__.py +779 -0
- dserver_signed_url_plugin/config.py +33 -0
- dserver_signed_url_plugin/schemas.py +92 -0
- dserver_signed_url_plugin/sql_models.py +47 -0
- dserver_signed_url_plugin/version.py +24 -0
- dserver_signed_url_plugin-0.1.0.dist-info/METADATA +595 -0
- dserver_signed_url_plugin-0.1.0.dist-info/RECORD +10 -0
- dserver_signed_url_plugin-0.1.0.dist-info/WHEEL +4 -0
- dserver_signed_url_plugin-0.1.0.dist-info/entry_points.txt +2 -0
- dserver_signed_url_plugin-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dserver-signed-url-plugin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: dserver plugin for generating signed URLs for dataset access
|
|
5
|
+
Project-URL: Repository, https://github.com/jic-dtool/dserver-signed-url-plugin
|
|
6
|
+
Author-email: Lars Pastewka <lars.pastewka@imtek.uni-freiburg.de>
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: dservercore>0.18.0
|
|
11
|
+
Requires-Dist: dtool-s3>=0.15.0
|
|
12
|
+
Requires-Dist: dtoolcore>=3.20.0
|
|
13
|
+
Requires-Dist: flask-smorest
|
|
14
|
+
Requires-Dist: marshmallow
|
|
15
|
+
Provides-Extra: azure
|
|
16
|
+
Requires-Dist: dtool-azure; extra == 'azure'
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: dservercore; extra == 'test'
|
|
19
|
+
Requires-Dist: pytest; extra == 'test'
|
|
20
|
+
Requires-Dist: pytest-cov; extra == 'test'
|
|
21
|
+
Description-Content-Type: text/x-rst
|
|
22
|
+
|
|
23
|
+
dserver-signed-url-plugin
|
|
24
|
+
=========================
|
|
25
|
+
|
|
26
|
+
A dserver extension plugin that enables dserver to act as a storage access
|
|
27
|
+
delegate by generating time-limited signed URLs for S3, Azure, and other
|
|
28
|
+
storage backends.
|
|
29
|
+
|
|
30
|
+
Overview
|
|
31
|
+
--------
|
|
32
|
+
|
|
33
|
+
This plugin solves a key access control challenge: traditionally, users need
|
|
34
|
+
direct credentials (AWS keys, Azure tokens) to access datasets stored in cloud
|
|
35
|
+
backends. This plugin allows dserver to act as an intermediary, generating
|
|
36
|
+
signed URLs on behalf of authenticated users based on their dserver permissions.
|
|
37
|
+
|
|
38
|
+
Architecture
|
|
39
|
+
------------
|
|
40
|
+
|
|
41
|
+
The plugin follows a backend-agnostic design::
|
|
42
|
+
|
|
43
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
44
|
+
│ Data Flow │
|
|
45
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
46
|
+
│ │
|
|
47
|
+
│ User (no backend credentials) │
|
|
48
|
+
│ │ │
|
|
49
|
+
│ │ 1. Authenticate with dserver (JWT) │
|
|
50
|
+
│ ▼ │
|
|
51
|
+
│ dserver-signed-url-plugin │
|
|
52
|
+
│ │ │
|
|
53
|
+
│ │ 2. Check permissions (may_search / may_register) │
|
|
54
|
+
│ │ 3. Load storage broker for backend │
|
|
55
|
+
│ │ 4. Generate signed URLs │
|
|
56
|
+
│ ▼ │
|
|
57
|
+
│ Storage Broker (dtool-s3 / dtool-azure) │
|
|
58
|
+
│ │ │
|
|
59
|
+
│ │ 5. Create presigned URLs / SAS tokens │
|
|
60
|
+
│ ▼ │
|
|
61
|
+
│ Cloud Backend (S3 / Azure / etc.) │
|
|
62
|
+
│ │ │
|
|
63
|
+
│ │ 6. User downloads/uploads directly │
|
|
64
|
+
│ ▼ │
|
|
65
|
+
│ User receives data │
|
|
66
|
+
│ │
|
|
67
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
68
|
+
|
|
69
|
+
Key benefits:
|
|
70
|
+
|
|
71
|
+
- **No credential sharing**: Users never see backend credentials
|
|
72
|
+
- **Centralized access control**: dserver's permission system controls all access
|
|
73
|
+
- **Time-limited access**: Signed URLs expire automatically
|
|
74
|
+
- **Backend agnostic**: Works with any storage broker that implements signing
|
|
75
|
+
- **Audit trail**: All access requests go through dserver
|
|
76
|
+
|
|
77
|
+
Installation
|
|
78
|
+
------------
|
|
79
|
+
|
|
80
|
+
.. code-block:: bash
|
|
81
|
+
|
|
82
|
+
pip install dserver-signed-url-plugin
|
|
83
|
+
|
|
84
|
+
The plugin requires storage brokers with signing support:
|
|
85
|
+
|
|
86
|
+
.. code-block:: bash
|
|
87
|
+
|
|
88
|
+
# For S3/MinIO backends
|
|
89
|
+
pip install dtool-s3>=0.15.0
|
|
90
|
+
|
|
91
|
+
# For Azure backends
|
|
92
|
+
pip install dtool-azure>=0.8.0
|
|
93
|
+
|
|
94
|
+
Configuration
|
|
95
|
+
-------------
|
|
96
|
+
|
|
97
|
+
Environment variables:
|
|
98
|
+
|
|
99
|
+
``SIGNED_URL_READ_EXPIRY_SECONDS``
|
|
100
|
+
Expiry time for read URLs in seconds. Default: 3600 (1 hour)
|
|
101
|
+
|
|
102
|
+
``SIGNED_URL_WRITE_EXPIRY_SECONDS``
|
|
103
|
+
Expiry time for write/upload URLs in seconds. Default: 14400 (4 hours)
|
|
104
|
+
|
|
105
|
+
``DTOOL_CONFIG_PATH``
|
|
106
|
+
Optional path to dtool configuration file
|
|
107
|
+
|
|
108
|
+
The plugin uses existing dtool storage broker configuration for backend
|
|
109
|
+
credentials. For S3, ensure these are set::
|
|
110
|
+
|
|
111
|
+
DTOOL_S3_ENDPOINT_<bucket>=<endpoint_url>
|
|
112
|
+
DTOOL_S3_ACCESS_KEY_ID_<bucket>=<access_key>
|
|
113
|
+
DTOOL_S3_SECRET_ACCESS_KEY_<bucket>=<secret_key>
|
|
114
|
+
|
|
115
|
+
For Azure::
|
|
116
|
+
|
|
117
|
+
DTOOL_AZURE_ACCOUNT_KEY_<account>=<account_key>
|
|
118
|
+
|
|
119
|
+
API Reference
|
|
120
|
+
-------------
|
|
121
|
+
|
|
122
|
+
All endpoints require JWT authentication via the ``Authorization: Bearer <token>``
|
|
123
|
+
header.
|
|
124
|
+
|
|
125
|
+
GET /signed-urls/dataset/<uri>
|
|
126
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
127
|
+
|
|
128
|
+
Get signed URLs for reading an entire dataset.
|
|
129
|
+
|
|
130
|
+
**URL Parameters:**
|
|
131
|
+
|
|
132
|
+
- ``uri``: URL-encoded dataset URI (e.g., ``s3%3A%2F%2Fbucket%2Fuuid``)
|
|
133
|
+
|
|
134
|
+
**Authorization:**
|
|
135
|
+
|
|
136
|
+
- User must have ``search`` permission on the dataset's base URI
|
|
137
|
+
|
|
138
|
+
**Response (200 OK):**
|
|
139
|
+
|
|
140
|
+
.. code-block:: json
|
|
141
|
+
|
|
142
|
+
{
|
|
143
|
+
"uri": "s3://bucket/uuid",
|
|
144
|
+
"expiry_seconds": 3600,
|
|
145
|
+
"expiry_timestamp": "2024-01-15T14:30:00.000000Z",
|
|
146
|
+
"admin_metadata_url": "https://...",
|
|
147
|
+
"manifest_url": "https://...",
|
|
148
|
+
"readme_url": "https://...",
|
|
149
|
+
"item_urls": {
|
|
150
|
+
"abc123...": "https://...",
|
|
151
|
+
"def456...": "https://..."
|
|
152
|
+
},
|
|
153
|
+
"overlay_urls": {
|
|
154
|
+
"file_size": "https://..."
|
|
155
|
+
},
|
|
156
|
+
"annotation_urls": {
|
|
157
|
+
"author": "https://..."
|
|
158
|
+
},
|
|
159
|
+
"tags": ["project-x", "2024"]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
**Error Responses:**
|
|
163
|
+
|
|
164
|
+
- ``403 Forbidden``: User lacks search permission on base URI
|
|
165
|
+
- ``404 Not Found``: Dataset not found in dserver
|
|
166
|
+
- ``501 Not Implemented``: Storage backend doesn't support signed URLs
|
|
167
|
+
|
|
168
|
+
GET /signed-urls/item/<uri>/<identifier>
|
|
169
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
170
|
+
|
|
171
|
+
Get a signed URL for a single dataset item. More efficient than fetching
|
|
172
|
+
URLs for the entire dataset when only one item is needed.
|
|
173
|
+
|
|
174
|
+
**URL Parameters:**
|
|
175
|
+
|
|
176
|
+
- ``uri``: URL-encoded dataset URI
|
|
177
|
+
- ``identifier``: Item identifier (SHA-1 hash of relpath)
|
|
178
|
+
|
|
179
|
+
**Authorization:**
|
|
180
|
+
|
|
181
|
+
- User must have ``search`` permission on the dataset's base URI
|
|
182
|
+
|
|
183
|
+
**Response (200 OK):**
|
|
184
|
+
|
|
185
|
+
.. code-block:: json
|
|
186
|
+
|
|
187
|
+
{
|
|
188
|
+
"uri": "s3://bucket/uuid",
|
|
189
|
+
"identifier": "abc123...",
|
|
190
|
+
"expiry_seconds": 3600,
|
|
191
|
+
"expiry_timestamp": "2024-01-15T14:30:00.000000Z",
|
|
192
|
+
"url": "https://..."
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
POST /signed-urls/upload/<base_uri>
|
|
196
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
197
|
+
|
|
198
|
+
Get signed URLs for uploading a new dataset.
|
|
199
|
+
|
|
200
|
+
**URL Parameters:**
|
|
201
|
+
|
|
202
|
+
- ``base_uri``: URL-encoded base URI (e.g., ``s3%3A%2F%2Fbucket``)
|
|
203
|
+
|
|
204
|
+
**Request Body:**
|
|
205
|
+
|
|
206
|
+
.. code-block:: json
|
|
207
|
+
|
|
208
|
+
{
|
|
209
|
+
"uuid": "550e8400-e29b-41d4-a716-446655440000",
|
|
210
|
+
"name": "my-dataset",
|
|
211
|
+
"items": [
|
|
212
|
+
{"relpath": "data/file1.txt"},
|
|
213
|
+
{"relpath": "data/file2.csv"}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
**Authorization:**
|
|
218
|
+
|
|
219
|
+
- User must have ``register`` permission on the base URI
|
|
220
|
+
|
|
221
|
+
**Response (200 OK):**
|
|
222
|
+
|
|
223
|
+
.. code-block:: json
|
|
224
|
+
|
|
225
|
+
{
|
|
226
|
+
"uuid": "550e8400-e29b-41d4-a716-446655440000",
|
|
227
|
+
"uri": "s3://bucket/550e8400-e29b-41d4-a716-446655440000",
|
|
228
|
+
"base_uri": "s3://bucket",
|
|
229
|
+
"expiry_seconds": 14400,
|
|
230
|
+
"expiry_timestamp": "2024-01-15T18:30:00.000000Z",
|
|
231
|
+
"upload_urls": {
|
|
232
|
+
"admin_metadata": "https://...",
|
|
233
|
+
"readme": "https://...",
|
|
234
|
+
"manifest": "https://...",
|
|
235
|
+
"structure": "https://...",
|
|
236
|
+
"items": {
|
|
237
|
+
"abc123...": {
|
|
238
|
+
"url": "https://...",
|
|
239
|
+
"relpath": "data/file1.txt"
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
**Error Responses:**
|
|
246
|
+
|
|
247
|
+
- ``403 Forbidden``: User lacks register permission on base URI
|
|
248
|
+
- ``409 Conflict``: Dataset with this UUID already exists
|
|
249
|
+
|
|
250
|
+
POST /signed-urls/upload-complete
|
|
251
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
252
|
+
|
|
253
|
+
Signal that a dataset upload is complete. This triggers dataset validation
|
|
254
|
+
and registration in dserver.
|
|
255
|
+
|
|
256
|
+
**Request Body:**
|
|
257
|
+
|
|
258
|
+
.. code-block:: json
|
|
259
|
+
|
|
260
|
+
{
|
|
261
|
+
"uri": "s3://bucket/550e8400-e29b-41d4-a716-446655440000"
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
**Authorization:**
|
|
265
|
+
|
|
266
|
+
- User must have ``register`` permission on the base URI
|
|
267
|
+
|
|
268
|
+
**Response (200 OK):**
|
|
269
|
+
|
|
270
|
+
.. code-block:: json
|
|
271
|
+
|
|
272
|
+
{
|
|
273
|
+
"uri": "s3://bucket/550e8400-e29b-41d4-a716-446655440000",
|
|
274
|
+
"status": "registered",
|
|
275
|
+
"name": "my-dataset",
|
|
276
|
+
"uuid": "550e8400-e29b-41d4-a716-446655440000"
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
**Error Responses:**
|
|
280
|
+
|
|
281
|
+
- ``400 Bad Request``: Dataset is incomplete or invalid
|
|
282
|
+
- ``403 Forbidden``: User lacks register permission
|
|
283
|
+
|
|
284
|
+
Usage Examples
|
|
285
|
+
--------------
|
|
286
|
+
|
|
287
|
+
Reading a Dataset (Python)
|
|
288
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
289
|
+
|
|
290
|
+
.. code-block:: python
|
|
291
|
+
|
|
292
|
+
import requests
|
|
293
|
+
|
|
294
|
+
# Authenticate
|
|
295
|
+
token = "your-jwt-token"
|
|
296
|
+
headers = {"Authorization": f"Bearer {token}"}
|
|
297
|
+
|
|
298
|
+
# Get signed URLs for dataset
|
|
299
|
+
uri = "s3://my-bucket/dataset-uuid"
|
|
300
|
+
encoded_uri = requests.utils.quote(uri, safe="")
|
|
301
|
+
|
|
302
|
+
response = requests.get(
|
|
303
|
+
f"http://dserver:5000/signed-urls/dataset/{encoded_uri}",
|
|
304
|
+
headers=headers
|
|
305
|
+
)
|
|
306
|
+
urls = response.json()
|
|
307
|
+
|
|
308
|
+
# Download an item using the signed URL
|
|
309
|
+
item_id = list(urls["item_urls"].keys())[0]
|
|
310
|
+
item_response = requests.get(urls["item_urls"][item_id])
|
|
311
|
+
with open("downloaded_file", "wb") as f:
|
|
312
|
+
f.write(item_response.content)
|
|
313
|
+
|
|
314
|
+
Uploading a Dataset (Python)
|
|
315
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
316
|
+
|
|
317
|
+
.. code-block:: python
|
|
318
|
+
|
|
319
|
+
import requests
|
|
320
|
+
import uuid
|
|
321
|
+
import json
|
|
322
|
+
import hashlib
|
|
323
|
+
|
|
324
|
+
token = "your-jwt-token"
|
|
325
|
+
headers = {"Authorization": f"Bearer {token}"}
|
|
326
|
+
|
|
327
|
+
# Generate dataset UUID
|
|
328
|
+
dataset_uuid = str(uuid.uuid4())
|
|
329
|
+
|
|
330
|
+
# Prepare items
|
|
331
|
+
items = [
|
|
332
|
+
{"relpath": "data/file1.txt"},
|
|
333
|
+
{"relpath": "data/file2.txt"}
|
|
334
|
+
]
|
|
335
|
+
|
|
336
|
+
# Get upload URLs
|
|
337
|
+
base_uri = "s3://my-bucket"
|
|
338
|
+
encoded_base_uri = requests.utils.quote(base_uri, safe="")
|
|
339
|
+
|
|
340
|
+
response = requests.post(
|
|
341
|
+
f"http://dserver:5000/signed-urls/upload/{encoded_base_uri}",
|
|
342
|
+
headers=headers,
|
|
343
|
+
json={
|
|
344
|
+
"uuid": dataset_uuid,
|
|
345
|
+
"name": "my-new-dataset",
|
|
346
|
+
"items": items
|
|
347
|
+
}
|
|
348
|
+
)
|
|
349
|
+
upload_info = response.json()
|
|
350
|
+
|
|
351
|
+
# Upload admin metadata
|
|
352
|
+
admin_metadata = {
|
|
353
|
+
"uuid": dataset_uuid,
|
|
354
|
+
"name": "my-new-dataset",
|
|
355
|
+
"type": "dataset",
|
|
356
|
+
"creator_username": "user",
|
|
357
|
+
"frozen_at": 1705312200.0
|
|
358
|
+
}
|
|
359
|
+
requests.put(
|
|
360
|
+
upload_info["upload_urls"]["admin_metadata"],
|
|
361
|
+
data=json.dumps(admin_metadata),
|
|
362
|
+
headers={"Content-Type": "application/json"}
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
# Upload README
|
|
366
|
+
readme = "---\ndescription: My dataset\n"
|
|
367
|
+
requests.put(
|
|
368
|
+
upload_info["upload_urls"]["readme"],
|
|
369
|
+
data=readme,
|
|
370
|
+
headers={"Content-Type": "text/plain"}
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
# Upload items
|
|
374
|
+
for relpath, content in [("data/file1.txt", b"content1"), ...]:
|
|
375
|
+
identifier = hashlib.sha1(relpath.encode()).hexdigest()
|
|
376
|
+
item_url = upload_info["upload_urls"]["items"][identifier]["url"]
|
|
377
|
+
requests.put(item_url, data=content)
|
|
378
|
+
|
|
379
|
+
# Upload manifest
|
|
380
|
+
manifest = {"items": {...}} # Build manifest
|
|
381
|
+
requests.put(
|
|
382
|
+
upload_info["upload_urls"]["manifest"],
|
|
383
|
+
data=json.dumps(manifest),
|
|
384
|
+
headers={"Content-Type": "application/json"}
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
# Signal upload complete
|
|
388
|
+
response = requests.post(
|
|
389
|
+
"http://dserver:5000/signed-urls/upload-complete",
|
|
390
|
+
headers=headers,
|
|
391
|
+
json={"uri": upload_info["uri"]}
|
|
392
|
+
)
|
|
393
|
+
print(f"Dataset registered: {response.json()}")
|
|
394
|
+
|
|
395
|
+
Integration with dtool-dserver
|
|
396
|
+
------------------------------
|
|
397
|
+
|
|
398
|
+
For command-line access, use the ``dtool-dserver`` storage broker which
|
|
399
|
+
provides a standard dtool interface backed by this plugin::
|
|
400
|
+
|
|
401
|
+
# Set authentication
|
|
402
|
+
export DSERVER_TOKEN="your-jwt-token"
|
|
403
|
+
|
|
404
|
+
# List datasets through dserver
|
|
405
|
+
dtool ls dserver://localhost:5000/s3/my-bucket/
|
|
406
|
+
|
|
407
|
+
# Copy a dataset to local storage
|
|
408
|
+
dtool cp dserver://localhost:5000/s3/my-bucket/uuid /local/path/
|
|
409
|
+
|
|
410
|
+
# Create a new dataset through dserver
|
|
411
|
+
dtool create dserver://localhost:5000/s3/my-bucket/my-dataset
|
|
412
|
+
|
|
413
|
+
Pending Upload Management
|
|
414
|
+
-------------------------
|
|
415
|
+
|
|
416
|
+
When a client initiates a dataset upload, a proto-dataset is created in storage
|
|
417
|
+
and a record is stored in the database to track the pending upload. This allows
|
|
418
|
+
the server to:
|
|
419
|
+
|
|
420
|
+
1. Detect incomplete/abandoned uploads
|
|
421
|
+
2. Persist upload state across server restarts
|
|
422
|
+
3. Clean up stale uploads
|
|
423
|
+
|
|
424
|
+
Database Model
|
|
425
|
+
~~~~~~~~~~~~~~
|
|
426
|
+
|
|
427
|
+
The plugin adds a ``pending_upload`` table to the dserver database with the
|
|
428
|
+
following fields:
|
|
429
|
+
|
|
430
|
+
- ``uuid``: Dataset UUID (unique)
|
|
431
|
+
- ``uri``: Full dataset URI
|
|
432
|
+
- ``base_uri``: Base URI for the dataset
|
|
433
|
+
- ``name``: Dataset name
|
|
434
|
+
- ``creator_username``: Who initiated the upload
|
|
435
|
+
- ``created_at``: When the upload was initiated
|
|
436
|
+
- ``frozen_at``: Timestamp to use when freezing
|
|
437
|
+
- ``manifest_json``: JSON-serialized manifest data
|
|
438
|
+
|
|
439
|
+
After deploying this plugin, run database migrations to create the table::
|
|
440
|
+
|
|
441
|
+
flask db migrate -m "Add pending_upload table"
|
|
442
|
+
flask db upgrade
|
|
443
|
+
|
|
444
|
+
CLI Commands
|
|
445
|
+
~~~~~~~~~~~~
|
|
446
|
+
|
|
447
|
+
The plugin provides Flask CLI commands for managing pending uploads:
|
|
448
|
+
|
|
449
|
+
**List pending uploads**::
|
|
450
|
+
|
|
451
|
+
# List all pending uploads
|
|
452
|
+
flask pending_upload list
|
|
453
|
+
|
|
454
|
+
# List uploads older than 24 hours
|
|
455
|
+
flask pending_upload list --older-than 24
|
|
456
|
+
|
|
457
|
+
Output example::
|
|
458
|
+
|
|
459
|
+
Found 2 pending upload(s):
|
|
460
|
+
|
|
461
|
+
UUID: 550e8400-e29b-41d4-a716-446655440000
|
|
462
|
+
Name: my-dataset
|
|
463
|
+
URI: s3://bucket/550e8400-e29b-41d4-a716-446655440000
|
|
464
|
+
Creator: admin
|
|
465
|
+
Created: 2024-01-15T10:30:00 (26.5 hours ago)
|
|
466
|
+
Items: 5
|
|
467
|
+
|
|
468
|
+
UUID: 660e8400-e29b-41d4-a716-446655440001
|
|
469
|
+
Name: another-dataset
|
|
470
|
+
URI: s3://bucket/660e8400-e29b-41d4-a716-446655440001
|
|
471
|
+
Creator: user1
|
|
472
|
+
Created: 2024-01-15T12:00:00 (25.0 hours ago)
|
|
473
|
+
Items: 3
|
|
474
|
+
|
|
475
|
+
**Clean up stale uploads**::
|
|
476
|
+
|
|
477
|
+
# Preview what would be deleted (dry run)
|
|
478
|
+
flask pending_upload cleanup --older-than 48 --dry-run
|
|
479
|
+
|
|
480
|
+
# Actually delete uploads older than 48 hours
|
|
481
|
+
flask pending_upload cleanup --older-than 48
|
|
482
|
+
|
|
483
|
+
# Also attempt to delete proto-datasets from storage
|
|
484
|
+
flask pending_upload cleanup --older-than 48 --delete-storage
|
|
485
|
+
|
|
486
|
+
**Delete a specific pending upload**::
|
|
487
|
+
|
|
488
|
+
# Delete by UUID
|
|
489
|
+
flask pending_upload delete 550e8400-e29b-41d4-a716-446655440000
|
|
490
|
+
|
|
491
|
+
# Also attempt to delete from storage
|
|
492
|
+
flask pending_upload delete 550e8400-e29b-41d4-a716-446655440000 --delete-storage
|
|
493
|
+
|
|
494
|
+
Docker Compose Usage
|
|
495
|
+
~~~~~~~~~~~~~~~~~~~~
|
|
496
|
+
|
|
497
|
+
When running dserver in Docker Compose::
|
|
498
|
+
|
|
499
|
+
# List pending uploads
|
|
500
|
+
docker compose exec dserver flask pending_upload list
|
|
501
|
+
|
|
502
|
+
# Clean up uploads older than 24 hours
|
|
503
|
+
docker compose exec dserver flask pending_upload cleanup --older-than 24
|
|
504
|
+
|
|
505
|
+
Automated Cleanup
|
|
506
|
+
~~~~~~~~~~~~~~~~~
|
|
507
|
+
|
|
508
|
+
For production deployments, consider setting up a cron job or scheduled task
|
|
509
|
+
to periodically clean up stale pending uploads::
|
|
510
|
+
|
|
511
|
+
# Run daily at 2 AM to clean up uploads older than 48 hours
|
|
512
|
+
0 2 * * * docker compose exec -T dserver flask pending_upload cleanup --older-than 48
|
|
513
|
+
|
|
514
|
+
Upload Workflow
|
|
515
|
+
~~~~~~~~~~~~~~~
|
|
516
|
+
|
|
517
|
+
The upload process works as follows:
|
|
518
|
+
|
|
519
|
+
1. **Upload initiation** (``POST /signed-urls/upload/<base_uri>``):
|
|
520
|
+
|
|
521
|
+
- Creates a proto-dataset in storage (type: ``protodataset``)
|
|
522
|
+
- Stores manifest and metadata in ``pending_upload`` table
|
|
523
|
+
- Returns signed URLs for README and item uploads
|
|
524
|
+
|
|
525
|
+
2. **Data upload** (client-side):
|
|
526
|
+
|
|
527
|
+
- Client uploads README and items using signed URLs
|
|
528
|
+
- Client computes hashes during upload
|
|
529
|
+
|
|
530
|
+
3. **Upload completion** (``POST /signed-urls/upload-complete``):
|
|
531
|
+
|
|
532
|
+
- Retrieves pending upload record from database
|
|
533
|
+
- Freezes proto-dataset with stored manifest (type: ``dataset``)
|
|
534
|
+
- Registers dataset in dserver
|
|
535
|
+
- Deletes pending upload record
|
|
536
|
+
|
|
537
|
+
This architecture provides clear visibility into upload state:
|
|
538
|
+
|
|
539
|
+
- **Proto-datasets** (``type: protodataset``) indicate incomplete uploads
|
|
540
|
+
- **Datasets** (``type: dataset``) indicate completed, frozen datasets
|
|
541
|
+
- **Pending upload records** track uploads in progress
|
|
542
|
+
|
|
543
|
+
Security Considerations
|
|
544
|
+
-----------------------
|
|
545
|
+
|
|
546
|
+
1. **URL Expiry**: Signed URLs are time-limited. Choose appropriate expiry
|
|
547
|
+
times based on your use case. Shorter times are more secure but may
|
|
548
|
+
cause issues with large file uploads.
|
|
549
|
+
|
|
550
|
+
2. **Backend Credentials**: Backend credentials (AWS keys, Azure tokens)
|
|
551
|
+
are only held by dserver, never exposed to users.
|
|
552
|
+
|
|
553
|
+
3. **Permission Inheritance**: Access is controlled by dserver's permission
|
|
554
|
+
system. Users can only generate signed URLs for datasets/base URIs they
|
|
555
|
+
have permission to access.
|
|
556
|
+
|
|
557
|
+
4. **HTTPS**: In production, always use HTTPS for dserver to protect JWT
|
|
558
|
+
tokens in transit.
|
|
559
|
+
|
|
560
|
+
5. **Token Security**: JWT tokens grant access to generate signed URLs.
|
|
561
|
+
Treat them as sensitive credentials.
|
|
562
|
+
|
|
563
|
+
Storage Broker Requirements
|
|
564
|
+
---------------------------
|
|
565
|
+
|
|
566
|
+
For a storage broker to work with this plugin, it must implement:
|
|
567
|
+
|
|
568
|
+
.. code-block:: python
|
|
569
|
+
|
|
570
|
+
class MyStorageBroker:
|
|
571
|
+
def generate_signed_read_url(self, key, expiry_seconds=3600):
|
|
572
|
+
"""Generate a time-limited URL for reading an object."""
|
|
573
|
+
...
|
|
574
|
+
|
|
575
|
+
def generate_signed_write_url(self, key, expiry_seconds=3600):
|
|
576
|
+
"""Generate a time-limited URL for writing an object."""
|
|
577
|
+
...
|
|
578
|
+
|
|
579
|
+
def generate_dataset_signed_urls(self, expiry_seconds=3600):
|
|
580
|
+
"""Generate all signed URLs for a dataset."""
|
|
581
|
+
...
|
|
582
|
+
|
|
583
|
+
def supports_signing(self):
|
|
584
|
+
"""Return True if this broker supports signing."""
|
|
585
|
+
return True
|
|
586
|
+
|
|
587
|
+
Currently supported brokers:
|
|
588
|
+
|
|
589
|
+
- ``dtool-s3`` >= 0.15.0 (S3, MinIO, and S3-compatible)
|
|
590
|
+
- ``dtool-azure`` >= 0.8.0 (Azure Blob Storage)
|
|
591
|
+
|
|
592
|
+
License
|
|
593
|
+
-------
|
|
594
|
+
|
|
595
|
+
MIT License
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
dserver_signed_url_plugin/__init__.py,sha256=0GeJd7KgniK-FlSpfMyav88hUwM5kxbsnXmrbB29670,28923
|
|
2
|
+
dserver_signed_url_plugin/config.py,sha256=8Dt7O-8h1lFcb_XefLtit0iOqKmNdHZNj4zODzcn2BM,1084
|
|
3
|
+
dserver_signed_url_plugin/schemas.py,sha256=8aAIamxkIqe-jhBV10fMP1YaXdUnORfB9N92uczVfhI,5774
|
|
4
|
+
dserver_signed_url_plugin/sql_models.py,sha256=iR_XhD3Yk39H8ftzH8fDmiSlhdMwmCzWGzUCsGGyGI0,1867
|
|
5
|
+
dserver_signed_url_plugin/version.py,sha256=n_5vdJsPNu7wZ57LGuRL585uvll-hiuvZUBWzdG0RQU,520
|
|
6
|
+
dserver_signed_url_plugin-0.1.0.dist-info/METADATA,sha256=oYBYf3ni87rmDDypwl0jgu3QOYWffJ5oaDPWJCWS114,18108
|
|
7
|
+
dserver_signed_url_plugin-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
8
|
+
dserver_signed_url_plugin-0.1.0.dist-info/entry_points.txt,sha256=AGAmBOyfhspDayS7aGXjBet0JweVi7XuNgJUzohpdUA,90
|
|
9
|
+
dserver_signed_url_plugin-0.1.0.dist-info/licenses/LICENSE,sha256=iPc61c-gQAdPU2dqhL9Pz5NB-5TIUjzbKZCRVIswmWI,1070
|
|
10
|
+
dserver_signed_url_plugin-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Lars Pastewka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|