leblob 0.4.0.dev1__tar.gz → 0.6.0__tar.gz
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.
- {leblob-0.4.0.dev1 → leblob-0.6.0}/PKG-INFO +21 -15
- {leblob-0.4.0.dev1 → leblob-0.6.0}/README.md +17 -11
- {leblob-0.4.0.dev1 → leblob-0.6.0}/pyproject.toml +39 -6
- {leblob-0.4.0.dev1 → leblob-0.6.0}/pyproject.toml.orig +40 -6
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/asgi.py +59 -16
- leblob-0.6.0/src/leblob/blobstore.py +1010 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/cli.py +189 -58
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/handlers.py +468 -172
- leblob-0.6.0/src/leblob/maintenance.py +653 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/meta.py +988 -233
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/metrics.py +1 -1
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/model.py +181 -15
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/access.py +15 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/conditions.py +20 -3
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/errors.py +39 -3
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/listing.py +27 -4
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/multipart.py +49 -15
- leblob-0.6.0/src/leblob/s3/object_lock.py +128 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/payload.py +5 -5
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/post_form.py +6 -6
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/routing.py +118 -20
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/sigv4.py +81 -42
- leblob-0.6.0/src/leblob/s3/sse.py +404 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/tagging.py +13 -7
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/xml.py +160 -38
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/xml_base.py +1 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/xml_config.py +205 -28
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/streams.py +112 -35
- leblob-0.6.0/src/leblob/testing/__init__.py +0 -0
- leblob-0.6.0/src/leblob/testing/locations.py +40 -0
- leblob-0.6.0/src/leblob/testing/volume_contract.py +230 -0
- leblob-0.6.0/src/leblob/volumes.py +129 -0
- leblob-0.4.0.dev1/src/leblob/blobstore.py +0 -594
- leblob-0.4.0.dev1/src/leblob/maintenance.py +0 -444
- leblob-0.4.0.dev1/src/leblob/s3/sse.py +0 -229
- {leblob-0.4.0.dev1 → leblob-0.6.0}/LICENSE +0 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/__init__.py +0 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/__init__.py +0 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/chunked.py +0 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/cors.py +0 -0
- {leblob-0.4.0.dev1 → leblob-0.6.0}/src/leblob/s3/lifecycle.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: leblob
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: An S3-compatible object store
|
|
5
5
|
Author: Stefane Fermigier
|
|
6
6
|
Author-email: Stefane Fermigier <sf@abilian.com>
|
|
@@ -24,24 +24,26 @@ Requires-Dist: httptools>=0.6.4
|
|
|
24
24
|
Requires-Dist: uvicorn>=0.54.0
|
|
25
25
|
Requires-Dist: uvloop>=0.21.0
|
|
26
26
|
Requires-Python: >=3.12
|
|
27
|
-
Project-URL: Repository, https://git.sr.ht/~sfermigier/
|
|
28
|
-
Project-URL: Changelog, https://git.sr.ht/~sfermigier/
|
|
29
|
-
Project-URL: CI, https://builds.sr.ht/~sfermigier/
|
|
27
|
+
Project-URL: Repository, https://git.sr.ht/~sfermigier/leblob
|
|
28
|
+
Project-URL: Changelog, https://git.sr.ht/~sfermigier/leblob/tree/main/item/CHANGES.md
|
|
29
|
+
Project-URL: CI, https://builds.sr.ht/~sfermigier/leblob
|
|
30
30
|
Description-Content-Type: text/markdown
|
|
31
31
|
|
|
32
32
|
# leBLOB
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
leBLOB is an S3-compatible object store written in Python. It starts as one command on one machine, and is designed to grow into a redundant cluster.
|
|
35
35
|
|
|
36
|
-
It is meant to replace self-hosted MinIO
|
|
36
|
+
It is meant to replace self-hosted MinIO. Single-server installs work today; clusters come later.
|
|
37
37
|
|
|
38
38
|
## Quick start
|
|
39
39
|
|
|
40
40
|
```sh
|
|
41
|
-
uv
|
|
42
|
-
|
|
41
|
+
uv tool install leblob
|
|
42
|
+
leblob serve --data-dir ./data
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
From a checkout, `uv sync` installs it, and `uv run leblob` runs it.
|
|
46
|
+
|
|
45
47
|
The first start creates an access key and prints it once. Use it with any S3 client:
|
|
46
48
|
|
|
47
49
|
```python
|
|
@@ -64,14 +66,14 @@ Presigned URLs need SigV4. boto3 presigns with SigV2 by default, which leBLOB re
|
|
|
64
66
|
|
|
65
67
|
## Moving from MinIO or Garage
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
Set up an [rclone](https://rclone.org) remote for each store (`provider = Other`, `force_path_style = true`), create the bucket on leBLOB, then run:
|
|
68
70
|
|
|
69
71
|
```sh
|
|
70
72
|
rclone sync --metadata old:my-bucket leblob:my-bucket
|
|
71
73
|
rclone check old:my-bucket leblob:my-bucket
|
|
72
74
|
```
|
|
73
75
|
|
|
74
|
-
`tests/bench/run_migration.py` checks this from both: the bytes, `Content-Type`, `Cache-Control` and `x-amz-meta-*` arrive, including multipart objects and unusual keys.
|
|
76
|
+
`tests/bench/run_migration.py` checks this from both: the bytes, `Content-Type`, `Cache-Control` and `x-amz-meta-*` arrive, including multipart objects and unusual keys. Object tags, ACLs, lifecycle rules, CORS, keys, and any version but the current one need setting again. rclone also adds `mtime` and `btime` to the metadata. An object's time on leBLOB is when it was copied.
|
|
75
77
|
|
|
76
78
|
## In a container
|
|
77
79
|
|
|
@@ -81,25 +83,29 @@ docker run -d --name leblob -p 9000:9000 -v leblob-data:/data leblob
|
|
|
81
83
|
docker logs leblob # the first start prints an access key once
|
|
82
84
|
```
|
|
83
85
|
|
|
84
|
-
Set `--workers` after the image name if the default, one per CPU, uses more memory than you want. The data format is upgraded when a newer version starts: back up first, with `leblob backup`. A store written by an earlier release is tested to open in this one, from samples in `tests/upgrade/stores/`.
|
|
86
|
+
Set `--workers` after the image name if the default, one per CPU up to 4, uses more memory than you want. The data format is upgraded when a newer version starts: back up first, with `leblob backup`. A store written by an earlier release is tested to open in this one, from samples in `tests/upgrade/stores/`.
|
|
85
87
|
|
|
86
88
|
## Access keys
|
|
87
89
|
|
|
88
90
|
A key has full access unless it is created as scoped. A scoped key has no rights until it is granted some, per bucket, at one of three levels: `read`, `write` (which includes read) or `admin` (which also allows deleting the bucket).
|
|
89
91
|
|
|
90
92
|
```sh
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
leblob key create --scoped --data-dir ./data
|
|
94
|
+
leblob key grant ACCESS_KEY my-bucket read --data-dir ./data
|
|
95
|
+
leblob key revoke ACCESS_KEY my-bucket --data-dir ./data
|
|
94
96
|
```
|
|
95
97
|
|
|
96
98
|
A grant or a revocation applies from the next request. A scoped key cannot create buckets, sees only its own buckets when listing, and cannot tell a bucket it has no grant on from one that does not exist. Grants disappear with their bucket, so a bucket deleted and created again starts with none.
|
|
97
99
|
|
|
100
|
+
## Documentation
|
|
101
|
+
|
|
102
|
+
The documentation site is in `docs/`: `make -C docs serve` to read it locally. See `docs/README.md`.
|
|
103
|
+
|
|
98
104
|
## Development
|
|
99
105
|
|
|
100
106
|
```sh
|
|
101
107
|
make test # the whole test pyramid
|
|
102
|
-
make lint # ruff, ty, pyrefly,
|
|
108
|
+
make lint # ruff, ty, pyrefly, zuban
|
|
103
109
|
```
|
|
104
110
|
|
|
105
111
|
Tests are in `tests/`: `a_unit` for pure logic, `b_integration` for real SQLite and files, `c_e2e` for real S3 clients (boto3, AWS CLI, rclone, s5cmd) against a real server over HTTP and HTTPS. The rclone, s5cmd and AWS CLI v2 tests are skipped if those tools are not installed.
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# leBLOB
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
leBLOB is an S3-compatible object store written in Python. It starts as one command on one machine, and is designed to grow into a redundant cluster.
|
|
4
4
|
|
|
5
|
-
It is meant to replace self-hosted MinIO
|
|
5
|
+
It is meant to replace self-hosted MinIO. Single-server installs work today; clusters come later.
|
|
6
6
|
|
|
7
7
|
## Quick start
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
uv
|
|
11
|
-
|
|
10
|
+
uv tool install leblob
|
|
11
|
+
leblob serve --data-dir ./data
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
From a checkout, `uv sync` installs it, and `uv run leblob` runs it.
|
|
15
|
+
|
|
14
16
|
The first start creates an access key and prints it once. Use it with any S3 client:
|
|
15
17
|
|
|
16
18
|
```python
|
|
@@ -33,14 +35,14 @@ Presigned URLs need SigV4. boto3 presigns with SigV2 by default, which leBLOB re
|
|
|
33
35
|
|
|
34
36
|
## Moving from MinIO or Garage
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
Set up an [rclone](https://rclone.org) remote for each store (`provider = Other`, `force_path_style = true`), create the bucket on leBLOB, then run:
|
|
37
39
|
|
|
38
40
|
```sh
|
|
39
41
|
rclone sync --metadata old:my-bucket leblob:my-bucket
|
|
40
42
|
rclone check old:my-bucket leblob:my-bucket
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
`tests/bench/run_migration.py` checks this from both: the bytes, `Content-Type`, `Cache-Control` and `x-amz-meta-*` arrive, including multipart objects and unusual keys.
|
|
45
|
+
`tests/bench/run_migration.py` checks this from both: the bytes, `Content-Type`, `Cache-Control` and `x-amz-meta-*` arrive, including multipart objects and unusual keys. Object tags, ACLs, lifecycle rules, CORS, keys, and any version but the current one need setting again. rclone also adds `mtime` and `btime` to the metadata. An object's time on leBLOB is when it was copied.
|
|
44
46
|
|
|
45
47
|
## In a container
|
|
46
48
|
|
|
@@ -50,25 +52,29 @@ docker run -d --name leblob -p 9000:9000 -v leblob-data:/data leblob
|
|
|
50
52
|
docker logs leblob # the first start prints an access key once
|
|
51
53
|
```
|
|
52
54
|
|
|
53
|
-
Set `--workers` after the image name if the default, one per CPU, uses more memory than you want. The data format is upgraded when a newer version starts: back up first, with `leblob backup`. A store written by an earlier release is tested to open in this one, from samples in `tests/upgrade/stores/`.
|
|
55
|
+
Set `--workers` after the image name if the default, one per CPU up to 4, uses more memory than you want. The data format is upgraded when a newer version starts: back up first, with `leblob backup`. A store written by an earlier release is tested to open in this one, from samples in `tests/upgrade/stores/`.
|
|
54
56
|
|
|
55
57
|
## Access keys
|
|
56
58
|
|
|
57
59
|
A key has full access unless it is created as scoped. A scoped key has no rights until it is granted some, per bucket, at one of three levels: `read`, `write` (which includes read) or `admin` (which also allows deleting the bucket).
|
|
58
60
|
|
|
59
61
|
```sh
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
leblob key create --scoped --data-dir ./data
|
|
63
|
+
leblob key grant ACCESS_KEY my-bucket read --data-dir ./data
|
|
64
|
+
leblob key revoke ACCESS_KEY my-bucket --data-dir ./data
|
|
63
65
|
```
|
|
64
66
|
|
|
65
67
|
A grant or a revocation applies from the next request. A scoped key cannot create buckets, sees only its own buckets when listing, and cannot tell a bucket it has no grant on from one that does not exist. Grants disappear with their bucket, so a bucket deleted and created again starts with none.
|
|
66
68
|
|
|
69
|
+
## Documentation
|
|
70
|
+
|
|
71
|
+
The documentation site is in `docs/`: `make -C docs serve` to read it locally. See `docs/README.md`.
|
|
72
|
+
|
|
67
73
|
## Development
|
|
68
74
|
|
|
69
75
|
```sh
|
|
70
76
|
make test # the whole test pyramid
|
|
71
|
-
make lint # ruff, ty, pyrefly,
|
|
77
|
+
make lint # ruff, ty, pyrefly, zuban
|
|
72
78
|
```
|
|
73
79
|
|
|
74
80
|
Tests are in `tests/`: `a_unit` for pure logic, `b_integration` for real SQLite and files, `c_e2e` for real S3 clients (boto3, AWS CLI, rclone, s5cmd) against a real server over HTTP and HTTPS. The rclone, s5cmd and AWS CLI v2 tests are skipped if those tools are not installed.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "leblob"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.0"
|
|
4
4
|
description = "An S3-compatible object store"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -33,9 +33,9 @@ name = "Stefane Fermigier"
|
|
|
33
33
|
email = "sf@abilian.com"
|
|
34
34
|
|
|
35
35
|
[project.urls]
|
|
36
|
-
Repository = "https://git.sr.ht/~sfermigier/
|
|
37
|
-
Changelog = "https://git.sr.ht/~sfermigier/
|
|
38
|
-
CI = "https://builds.sr.ht/~sfermigier/
|
|
36
|
+
Repository = "https://git.sr.ht/~sfermigier/leblob"
|
|
37
|
+
Changelog = "https://git.sr.ht/~sfermigier/leblob/tree/main/item/CHANGES.md"
|
|
38
|
+
CI = "https://builds.sr.ht/~sfermigier/leblob"
|
|
39
39
|
|
|
40
40
|
[project.scripts]
|
|
41
41
|
leblob = "leblob.cli:app"
|
|
@@ -61,8 +61,13 @@ dev = [
|
|
|
61
61
|
"ruff>=0.17.3",
|
|
62
62
|
"ty>=0.0.97",
|
|
63
63
|
"types-defusedxml>=0.7.0.20260504",
|
|
64
|
+
"zensical>=0.1.0",
|
|
65
|
+
"zuban>=0.9.2",
|
|
64
66
|
]
|
|
65
67
|
|
|
68
|
+
[tool.uv.workspace]
|
|
69
|
+
members = ["plugins/neo"]
|
|
70
|
+
|
|
66
71
|
[tool.pytest.ini_options]
|
|
67
72
|
testpaths = ["tests"]
|
|
68
73
|
timeout = 120
|
|
@@ -79,6 +84,34 @@ mypy_path = "stubs"
|
|
|
79
84
|
|
|
80
85
|
[tool.pyrefly]
|
|
81
86
|
project-includes = [
|
|
82
|
-
"
|
|
83
|
-
"
|
|
87
|
+
"src/**/*.py*",
|
|
88
|
+
"tests/**/*.py*",
|
|
89
|
+
]
|
|
90
|
+
min-severity = "warn"
|
|
91
|
+
search-path = [
|
|
92
|
+
"src",
|
|
93
|
+
".",
|
|
94
|
+
]
|
|
95
|
+
python-platform = "all"
|
|
96
|
+
ignore-missing-imports = ["s3tests.*"]
|
|
97
|
+
|
|
98
|
+
[tool.ty.src]
|
|
99
|
+
include = [
|
|
100
|
+
"src",
|
|
101
|
+
"tests",
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
[tool.ty.environment]
|
|
105
|
+
python-platform = "all"
|
|
106
|
+
|
|
107
|
+
[tool.ty.analysis]
|
|
108
|
+
allowed-unresolved-imports = ["s3tests.**"]
|
|
109
|
+
|
|
110
|
+
[tool.bruce]
|
|
111
|
+
source = ["src"]
|
|
112
|
+
context = [
|
|
113
|
+
"notes/02-architecture.md",
|
|
114
|
+
"docs/src/guides/access-keys.md",
|
|
115
|
+
"docs/src/guides/production.md",
|
|
116
|
+
"docs/src/guides/sse-c.md",
|
|
84
117
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "leblob"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.0"
|
|
4
4
|
description = "An S3-compatible object store"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -32,9 +32,9 @@ dependencies = [
|
|
|
32
32
|
]
|
|
33
33
|
|
|
34
34
|
[project.urls]
|
|
35
|
-
Repository = "https://git.sr.ht/~sfermigier/
|
|
36
|
-
Changelog = "https://git.sr.ht/~sfermigier/
|
|
37
|
-
CI = "https://builds.sr.ht/~sfermigier/
|
|
35
|
+
Repository = "https://git.sr.ht/~sfermigier/leblob"
|
|
36
|
+
Changelog = "https://git.sr.ht/~sfermigier/leblob/tree/main/item/CHANGES.md"
|
|
37
|
+
CI = "https://builds.sr.ht/~sfermigier/leblob"
|
|
38
38
|
|
|
39
39
|
[project.scripts]
|
|
40
40
|
leblob = "leblob.cli:app"
|
|
@@ -60,8 +60,15 @@ dev = [
|
|
|
60
60
|
"ruff>=0.17.3",
|
|
61
61
|
"ty>=0.0.97",
|
|
62
62
|
"types-defusedxml>=0.7.0.20260504",
|
|
63
|
+
"zensical>=0.1.0",
|
|
64
|
+
"zuban>=0.9.2",
|
|
63
65
|
]
|
|
64
66
|
|
|
67
|
+
[tool.uv.workspace]
|
|
68
|
+
# Plugins under licences of their own. `uv sync` here installs none of them: each is
|
|
69
|
+
# installed with `uv sync --package NAME`, and tested on Linux, as their backends need.
|
|
70
|
+
members = ["plugins/neo"]
|
|
71
|
+
|
|
65
72
|
[tool.pytest.ini_options]
|
|
66
73
|
testpaths = ["tests"]
|
|
67
74
|
timeout = 120
|
|
@@ -80,6 +87,33 @@ mypy_path = "stubs"
|
|
|
80
87
|
|
|
81
88
|
[tool.pyrefly]
|
|
82
89
|
project-includes = [
|
|
83
|
-
"
|
|
84
|
-
"
|
|
90
|
+
"src/**/*.py*",
|
|
91
|
+
"tests/**/*.py*",
|
|
92
|
+
]
|
|
93
|
+
min-severity= "warn"
|
|
94
|
+
# The tests import each other as `tests.*`, from the project's root.
|
|
95
|
+
search-path = ["src", "."]
|
|
96
|
+
# As for ty, below.
|
|
97
|
+
python-platform = "all"
|
|
98
|
+
ignore-missing-imports = ["s3tests.*"]
|
|
99
|
+
|
|
100
|
+
[tool.ty.src]
|
|
101
|
+
# As for pyrefly. A plugin is checked in its own environment, where its backend is.
|
|
102
|
+
include = ["src", "tests"]
|
|
103
|
+
|
|
104
|
+
[tool.ty.environment]
|
|
105
|
+
# The server runs on Linux and macOS, and the power and disk tests on Linux alone.
|
|
106
|
+
python-platform = "all"
|
|
107
|
+
|
|
108
|
+
[tool.ty.analysis]
|
|
109
|
+
# Present only in the environment `make compat` builds for the suite.
|
|
110
|
+
allowed-unresolved-imports = ["s3tests.**"]
|
|
111
|
+
|
|
112
|
+
[tool.bruce]
|
|
113
|
+
source = ["src"]
|
|
114
|
+
context = [
|
|
115
|
+
"notes/02-architecture.md",
|
|
116
|
+
"docs/src/guides/access-keys.md",
|
|
117
|
+
"docs/src/guides/production.md",
|
|
118
|
+
"docs/src/guides/sse-c.md",
|
|
85
119
|
]
|
|
@@ -14,14 +14,15 @@ from pathlib import Path
|
|
|
14
14
|
from typing import TYPE_CHECKING
|
|
15
15
|
|
|
16
16
|
from leblob import handlers, maintenance, meta, metrics
|
|
17
|
-
from leblob.blobstore import BlobStore,
|
|
17
|
+
from leblob.blobstore import BlobStore, load_volume_plugins, open_store
|
|
18
18
|
from leblob.handlers import Context, Request, Response
|
|
19
19
|
from leblob.meta import Database
|
|
20
20
|
from leblob.model import HttpRequest
|
|
21
|
-
from leblob.s3 import access, errors, routing, sigv4, xml
|
|
21
|
+
from leblob.s3 import access, errors, routing, sigv4, sse, xml
|
|
22
22
|
from leblob.s3.errors import S3Error
|
|
23
23
|
from leblob.s3.routing import BucketRoute, ObjectRoute, Operation, ServiceRoute
|
|
24
24
|
from leblob.streams import ClientDisconnectedError
|
|
25
|
+
from leblob.volumes import VolumeError
|
|
25
26
|
|
|
26
27
|
if TYPE_CHECKING:
|
|
27
28
|
from collections.abc import AsyncGenerator, Awaitable, Callable, Mapping
|
|
@@ -37,6 +38,8 @@ ENV_DATA_DIR = "LEBLOB_DATA_DIR"
|
|
|
37
38
|
ENV_BASE_DOMAIN = "LEBLOB_BASE_DOMAIN"
|
|
38
39
|
ENV_LIFECYCLE_DAY_SECONDS = "LEBLOB_LIFECYCLE_DAY_SECONDS"
|
|
39
40
|
ENV_SSE_OVER_HTTP = "LEBLOB_ALLOW_SSE_C_OVER_HTTP"
|
|
41
|
+
# The path, never the keys: they stay out of the environment, which leaks more easily.
|
|
42
|
+
ENV_MASTER_KEY_FILE = "LEBLOB_MASTER_KEY_FILE"
|
|
40
43
|
META_FILE = "meta.db"
|
|
41
44
|
|
|
42
45
|
_CONNECTION_CLOSE = ("connection", "close")
|
|
@@ -53,6 +56,7 @@ def create_app_from_env() -> App:
|
|
|
53
56
|
"""Build the application in a worker process, from what `serve` set up."""
|
|
54
57
|
# Here and not in `serve`: each worker is its own process, with its own logging.
|
|
55
58
|
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
|
59
|
+
load_volume_plugins()
|
|
56
60
|
data_dir = Path(os.environ[ENV_DATA_DIR])
|
|
57
61
|
database = data_dir / META_FILE
|
|
58
62
|
context = Context(
|
|
@@ -61,10 +65,41 @@ def create_app_from_env() -> App:
|
|
|
61
65
|
data_dir,
|
|
62
66
|
int(os.environ[ENV_LIFECYCLE_DAY_SECONDS]) * 1000,
|
|
63
67
|
ENV_SSE_OVER_HTTP in os.environ,
|
|
68
|
+
_master_keys_for_worker(os.environ.get(ENV_MASTER_KEY_FILE)),
|
|
64
69
|
)
|
|
65
70
|
return create_app(context, os.environ.get(ENV_BASE_DOMAIN))
|
|
66
71
|
|
|
67
72
|
|
|
73
|
+
_OTHERS_MAY_ACCESS = 0o007
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def read_master_keys(path: Path) -> sse.MasterKeys:
|
|
77
|
+
"""Read the server's keys, from a file no other user may read.
|
|
78
|
+
|
|
79
|
+
Raises ValueError, or OSError, with a message to show as it is.
|
|
80
|
+
"""
|
|
81
|
+
with path.open(encoding="ascii") as file:
|
|
82
|
+
if os.fstat(file.fileno()).st_mode & _OTHERS_MAY_ACCESS:
|
|
83
|
+
message = "other users may read it: make it readable by the server alone"
|
|
84
|
+
raise ValueError(message)
|
|
85
|
+
return sse.parse_master_keys(file.read())
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _master_keys_for_worker(path: str | None) -> sse.MasterKeys | None:
|
|
89
|
+
"""The keys `serve` checked, or none, for a worker that can't read them now.
|
|
90
|
+
|
|
91
|
+
A worker doesn't refuse to start: with no keys it refuses what needs one, and
|
|
92
|
+
never stores in plain what should have been encrypted.
|
|
93
|
+
"""
|
|
94
|
+
if path is None:
|
|
95
|
+
return None
|
|
96
|
+
try:
|
|
97
|
+
return read_master_keys(Path(path))
|
|
98
|
+
except (OSError, ValueError):
|
|
99
|
+
logger.exception("Can't read the master key file %s.", path)
|
|
100
|
+
return sse.MasterKeys(())
|
|
101
|
+
|
|
102
|
+
|
|
68
103
|
def open_blobs_for_worker(data_dir: Path, database: Path) -> BlobStore:
|
|
69
104
|
"""Open what can be opened, and never refuse to start.
|
|
70
105
|
|
|
@@ -96,7 +131,9 @@ async def _run_lifespan(context: Context, receive: Receive, send: Send) -> None:
|
|
|
96
131
|
tasks = [
|
|
97
132
|
asyncio.create_task(job)
|
|
98
133
|
for job in (
|
|
99
|
-
maintenance.run_forever(
|
|
134
|
+
maintenance.run_forever(
|
|
135
|
+
context.db, context.blobs, context.data_dir, context.master_keys
|
|
136
|
+
),
|
|
100
137
|
maintenance.run_repairs(context.db, context.blobs),
|
|
101
138
|
maintenance.run_scrub(context.db, context.blobs),
|
|
102
139
|
maintenance.run_lifecycle(context.db, context.lifecycle_day_ms),
|
|
@@ -110,6 +147,7 @@ async def _run_lifespan(context: Context, receive: Receive, send: Send) -> None:
|
|
|
110
147
|
for task in tasks:
|
|
111
148
|
with suppress(asyncio.CancelledError):
|
|
112
149
|
await task
|
|
150
|
+
context.blobs.close()
|
|
113
151
|
context.db.close()
|
|
114
152
|
await send({"type": "lifespan.shutdown.complete"})
|
|
115
153
|
|
|
@@ -124,7 +162,7 @@ async def _handle_http(
|
|
|
124
162
|
request_id = secrets.token_hex(8)
|
|
125
163
|
started = time.monotonic()
|
|
126
164
|
http_request = _parse_http(scope)
|
|
127
|
-
|
|
165
|
+
access_log = {
|
|
128
166
|
"request_id": request_id,
|
|
129
167
|
"method": http_request.method,
|
|
130
168
|
"path": http_request.raw_path.decode("latin-1"),
|
|
@@ -132,13 +170,14 @@ async def _handle_http(
|
|
|
132
170
|
}
|
|
133
171
|
route: routing.Route | None = None
|
|
134
172
|
try:
|
|
173
|
+
http_request = routing.with_query_headers(http_request)
|
|
135
174
|
route = routing.route(http_request, base_domain)
|
|
136
|
-
|
|
175
|
+
access_log["operation"] = route.operation.name
|
|
137
176
|
response = await _dispatch(context, http_request, route, receive)
|
|
138
177
|
except S3Error as error:
|
|
139
178
|
response = _error_response(error, http_request.raw_path, request_id)
|
|
140
179
|
except ClientDisconnectedError:
|
|
141
|
-
_log_access(
|
|
180
|
+
_log_access(access_log, _STATUS_CLIENT_GONE, started)
|
|
142
181
|
return
|
|
143
182
|
except Exception:
|
|
144
183
|
logger.exception("Unhandled error in request %s", request_id)
|
|
@@ -155,7 +194,7 @@ async def _handle_http(
|
|
|
155
194
|
await _send_response(response, http_request.method, request_id, receive, send)
|
|
156
195
|
finally:
|
|
157
196
|
# Including a stream that fails midway: its status was already sent.
|
|
158
|
-
_log_access(
|
|
197
|
+
_log_access(access_log, response.status, started)
|
|
159
198
|
|
|
160
199
|
|
|
161
200
|
async def _allow_browser_to_read(
|
|
@@ -213,9 +252,9 @@ async def _dispatch(
|
|
|
213
252
|
await _authorize_anonymous(context, route)
|
|
214
253
|
else:
|
|
215
254
|
claim = sigv4.parse_claim(http_request)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
)
|
|
255
|
+
access_key = claim.credential.access_key
|
|
256
|
+
stored, scope = await meta.get_access_key(context.db, access_key)
|
|
257
|
+
secret = sse.open_secret(context.master_keys, access_key, stored)
|
|
219
258
|
seed = sigv4.verify(http_request, claim, secret, time.time())
|
|
220
259
|
access.authorize(scope, route)
|
|
221
260
|
request = Request(
|
|
@@ -264,6 +303,7 @@ async def _answer_unsigned(
|
|
|
264
303
|
receive,
|
|
265
304
|
None,
|
|
266
305
|
access.ANONYMOUS,
|
|
306
|
+
http_request.secure,
|
|
267
307
|
)
|
|
268
308
|
return await handlers.post_object(context, form, route.bucket)
|
|
269
309
|
return None
|
|
@@ -285,7 +325,7 @@ async def _authorize_anonymous(context: Context, route: routing.Route) -> None:
|
|
|
285
325
|
|
|
286
326
|
async def _metrics_response(context: Context) -> Response:
|
|
287
327
|
"""Answer without a signature, which Prometheus can't make: it names no bucket."""
|
|
288
|
-
gauges = await maintenance.current_gauges(context.db, context.
|
|
328
|
+
gauges = await maintenance.current_gauges(context.db, context.blobs)
|
|
289
329
|
samples = await asyncio.to_thread(metrics.all_workers, context.data_dir)
|
|
290
330
|
return Response(
|
|
291
331
|
body=metrics.render([*samples, *gauges]).encode(),
|
|
@@ -304,7 +344,7 @@ def _error_response(error: S3Error, raw_path: bytes, request_id: str) -> Respons
|
|
|
304
344
|
)
|
|
305
345
|
return Response(
|
|
306
346
|
error.error.status,
|
|
307
|
-
(("content-type",
|
|
347
|
+
(("content-type", handlers.XML_CONTENT_TYPE), *error.headers),
|
|
308
348
|
body,
|
|
309
349
|
)
|
|
310
350
|
|
|
@@ -338,7 +378,10 @@ async def _send_response(
|
|
|
338
378
|
|
|
339
379
|
|
|
340
380
|
async def _stream_body(
|
|
341
|
-
body: AsyncGenerator[bytes
|
|
381
|
+
body: AsyncGenerator[bytes | bytearray],
|
|
382
|
+
request_id: str,
|
|
383
|
+
receive: Receive,
|
|
384
|
+
send: Send,
|
|
342
385
|
) -> None:
|
|
343
386
|
"""Send a blob stream, and stop reading the disk once the client has gone.
|
|
344
387
|
|
|
@@ -370,7 +413,7 @@ async def _wait_for_disconnect(receive: Receive) -> None:
|
|
|
370
413
|
pass
|
|
371
414
|
|
|
372
415
|
|
|
373
|
-
def _log_access(
|
|
416
|
+
def _log_access(access_log: Mapping[str, str], status: int, started: float) -> None:
|
|
374
417
|
seconds = round(time.monotonic() - started, 6)
|
|
375
|
-
metrics.counters.observe_request(
|
|
376
|
-
logger.info("%s", json.dumps({**
|
|
418
|
+
metrics.counters.observe_request(access_log["operation"], status, seconds)
|
|
419
|
+
logger.info("%s", json.dumps({**access_log, "status": status, "seconds": seconds}))
|