dex-python-sdk 1.35.0__tar.gz → 1.38.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.
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/PKG-INFO +99 -3
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/README.md +98 -2
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/__init__.py +6 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_async_value_hydrator.py +36 -12
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_credential_transport.py +51 -4
- dex_python_sdk-1.38.0/dex/_flow_service_tls.py +172 -0
- dex_python_sdk-1.38.0/dex/_message_size.py +88 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_pull_worker.py +23 -4
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_value_hydrator.py +36 -12
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_worker_dispatcher.py +2 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/async_client.py +47 -9
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/async_worker.py +24 -2
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/attribute.py +35 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/attribute_values.py +2 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/channel.py +11 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/client.py +69 -9
- dex_python_sdk-1.38.0/dex/client_options.py +49 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/codec.py +4 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/context.py +41 -4
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/credential.py +2 -1
- dex_python_sdk-1.38.0/dex/dexpb/dex_pb2.py +443 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/dexpb/dex_pb2.pyi +4 -2
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/flow.py +7 -0
- dex_python_sdk-1.38.0/dex/flow_config.py +96 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/flow_options.py +27 -5
- dex_python_sdk-1.38.0/dex/flow_service_tls_options.py +81 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/runtime_errors.py +71 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/step.py +129 -7
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/stream.py +23 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/subflow.py +36 -1
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/timer.py +8 -1
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/worker.py +24 -2
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/worker_options.py +35 -3
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/pyproject.toml +1 -1
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/Cargo.lock +332 -5
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/Cargo.toml +1 -1
- dex_python_sdk-1.35.0/dex/client_options.py +0 -31
- dex_python_sdk-1.35.0/dex/dexpb/dex_pb2.py +0 -443
- dex_python_sdk-1.35.0/dex/flow_config.py +0 -56
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/LEGACY_NOTICES.md +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/LICENSE +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_async_worker_dispatcher.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_attribute_reads.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_grpc_errors.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_invocation_context.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_native.pyi +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_server_protocol.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_utils.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/_value_mapper.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/attribute_match.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/blob_cache.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/condition.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/dexpb/__init__.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/dexpb/dex_pb2_grpc.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/flow_info.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/flow_result.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/pull_registration.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/py.typed +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/rpc_invoke_options.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/step_execution.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/wait.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/dex/wait_options.py +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/README.md +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/tests/blob_cache_integration.rs +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache-python/README.md +0 -0
- {dex_python_sdk-1.35.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache-python/src/lib.rs +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dex-python-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.38.0
|
|
4
4
|
Requires-Dist: grpcio>=1.83.0
|
|
5
5
|
Requires-Dist: grpcio-status>=1.83.0
|
|
6
6
|
Requires-Dist: protobuf>=7.35.1
|
|
@@ -92,8 +92,104 @@ coroutine runs on the event loop. A loop-bound Future from another loop raises
|
|
|
92
92
|
TypeError; use `async def` to create it on the right loop. A blocked token keeps
|
|
93
93
|
one executor thread busy until it returns, and an unclosed Client or Worker may
|
|
94
94
|
retain up to four idle credential threads. Sync token lookup must return
|
|
95
|
-
promptly. By default, no authorization metadata is sent.
|
|
96
|
-
gRPC
|
|
95
|
+
promptly. By default, no authorization metadata is sent. The connection uses
|
|
96
|
+
plaintext gRPC unless `flow_service_tls` is set; protect the network path that
|
|
97
|
+
carries the token.
|
|
98
|
+
|
|
99
|
+
## TLS
|
|
100
|
+
|
|
101
|
+
Set `ClientOptions.flow_service_tls` and `WorkerOptions.flow_service_tls`
|
|
102
|
+
independently for a TLS endpoint, such as a TLS gateway in front of Dex.
|
|
103
|
+
Omitting the option keeps plaintext gRPC for local `dexcli dev` servers.
|
|
104
|
+
`FlowServiceTlsOptions()` enables TLS 1.2 or newer, verifies the certificate
|
|
105
|
+
and hostname, and requires HTTP/2 ALPN `h2`. Workers apply it to startup,
|
|
106
|
+
blob hydration, and pull task streams. The same settings work with `AsyncClient`
|
|
107
|
+
and `AsyncWorker`. File, API key, and custom bearer credentials compose with TLS
|
|
108
|
+
as call metadata.
|
|
109
|
+
|
|
110
|
+
With an application's registered `flow`, `registry`, and open `cache`:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
114
|
+
from datetime import timedelta
|
|
115
|
+
from pathlib import Path
|
|
116
|
+
from uuid import uuid4
|
|
117
|
+
|
|
118
|
+
from dex import (
|
|
119
|
+
Client, ClientOptions, FileCredential, FlowServiceTlsOptions,
|
|
120
|
+
Worker, WorkerOptions,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
flow_service_tls = FlowServiceTlsOptions(
|
|
124
|
+
additional_root_cas_pem=Path("/etc/dex/root-ca.pem").read_bytes(),
|
|
125
|
+
)
|
|
126
|
+
credential = FileCredential("/var/run/secrets/dex/token")
|
|
127
|
+
server_address = "dex.example.com:443"
|
|
128
|
+
with Worker(registry, cache, WorkerOptions(
|
|
129
|
+
server_address=server_address,
|
|
130
|
+
flow_service_tls=flow_service_tls,
|
|
131
|
+
credential=credential,
|
|
132
|
+
)) as worker, Client(registry, cache, ClientOptions(
|
|
133
|
+
server_address=server_address,
|
|
134
|
+
flow_service_tls=flow_service_tls,
|
|
135
|
+
credential=credential,
|
|
136
|
+
)) as client, ThreadPoolExecutor(max_workers=1) as executor:
|
|
137
|
+
started = executor.submit(worker.start)
|
|
138
|
+
try:
|
|
139
|
+
worker.wait_pull_registered(timeout=30)
|
|
140
|
+
flow_id = f"tls-{uuid4()}"
|
|
141
|
+
client.start_flow(flow, flow_id, input_value)
|
|
142
|
+
result = client.wait_for_flow(flow_id, timedelta(seconds=30))
|
|
143
|
+
finally:
|
|
144
|
+
worker.stop()
|
|
145
|
+
started.result(timeout=10)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
- `additional_root_cas_pem` accepts PEM bytes or text. Omit it, or use an empty
|
|
149
|
+
value, for gRPC's default trust. A nonempty bundle must contain at least one
|
|
150
|
+
parsable certificate; malformed and non-certificate blocks are skipped when
|
|
151
|
+
another certificate parses. The trust is the gRPC default roots (grpcio's
|
|
152
|
+
bundled roots, or `GRPC_DEFAULT_SSL_ROOTS_FILE_PATH` when set) plus the added
|
|
153
|
+
roots. A configured gRPC root file replaces the bundled roots and takes
|
|
154
|
+
precedence over system roots. Adding roots fails when
|
|
155
|
+
`GRPC_USE_SYSTEM_ROOTS_OVER_LANGUAGE_CALLBACK` is true, unless a root file is
|
|
156
|
+
configured, regardless of `GRPC_NOT_USE_SYSTEM_SSL_ROOTS`.
|
|
157
|
+
True values are `true`, `t`, `yes`, `y`, and `1`, ignoring case. This guard
|
|
158
|
+
also applies to system roots selected with `GRPC_SYSTEM_SSL_ROOTS_DIR`.
|
|
159
|
+
To add roots in that configuration, disable
|
|
160
|
+
`GRPC_USE_SYSTEM_ROOTS_OVER_LANGUAGE_CALLBACK` and pass the full PEM bundle
|
|
161
|
+
as `additional_root_cas_pem`, or set `GRPC_DEFAULT_SSL_ROOTS_FILE_PATH` to the
|
|
162
|
+
full bundle. `SSL_CERT_FILE` and `SSL_CERT_DIR` do not affect this trust.
|
|
163
|
+
These sources are read at construction. An unreadable bundled root file, or an
|
|
164
|
+
unreadable or invalid configured gRPC root file, fails construction when adding
|
|
165
|
+
roots. Errors for configured files include the file path. To trust OS or
|
|
166
|
+
corporate CAs, pass their PEM bundle explicitly:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
tls = FlowServiceTlsOptions(
|
|
170
|
+
additional_root_cas_pem=Path("/etc/ssl/certs/ca-certificates.crt").read_bytes(),
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Use the CA bundle path supplied by your OS or organization.
|
|
175
|
+
- `server_name` defaults to `None`, which verifies the address host and preserves
|
|
176
|
+
the host and port as HTTP/2 authority. Set a DNS name or IP without a port only
|
|
177
|
+
when the certificate name differs. It controls verification, SNI, and HTTP/2
|
|
178
|
+
authority; gateways must accept that authority without a port. Empty strings
|
|
179
|
+
are invalid. IP addresses require matching IP SANs and send no SNI. Prefer
|
|
180
|
+
a DNS name for IPv6 overrides because strict HTTP/2 servers reject an
|
|
181
|
+
unbracketed IPv6 authority.
|
|
182
|
+
- TLS targets accept `host:port`, `dns:///host:port`, and
|
|
183
|
+
`dns://authority/host:port`, including bracketed IPv6 hosts. Ports must be
|
|
184
|
+
unsigned decimal values from 1 through 65535. The DNS resolver authority
|
|
185
|
+
never becomes the certificate name. Other resolver schemes remain available
|
|
186
|
+
with plaintext only.
|
|
187
|
+
- Constructors raise `ValueError` for invalid addresses, server names, or PEM
|
|
188
|
+
bundles. Connections open on demand; certificate and handshake failures
|
|
189
|
+
surface on the first Client call as `UNAVAILABLE` or during Worker startup.
|
|
190
|
+
Servers offering only `http/1.1`, or no ALPN protocol, are rejected.
|
|
191
|
+
- This option does not configure the `ApiKeyCredential` token endpoint, which
|
|
192
|
+
uses HTTPS except on loopback.
|
|
97
193
|
|
|
98
194
|
## Workers
|
|
99
195
|
|
|
@@ -76,8 +76,104 @@ coroutine runs on the event loop. A loop-bound Future from another loop raises
|
|
|
76
76
|
TypeError; use `async def` to create it on the right loop. A blocked token keeps
|
|
77
77
|
one executor thread busy until it returns, and an unclosed Client or Worker may
|
|
78
78
|
retain up to four idle credential threads. Sync token lookup must return
|
|
79
|
-
promptly. By default, no authorization metadata is sent.
|
|
80
|
-
gRPC
|
|
79
|
+
promptly. By default, no authorization metadata is sent. The connection uses
|
|
80
|
+
plaintext gRPC unless `flow_service_tls` is set; protect the network path that
|
|
81
|
+
carries the token.
|
|
82
|
+
|
|
83
|
+
## TLS
|
|
84
|
+
|
|
85
|
+
Set `ClientOptions.flow_service_tls` and `WorkerOptions.flow_service_tls`
|
|
86
|
+
independently for a TLS endpoint, such as a TLS gateway in front of Dex.
|
|
87
|
+
Omitting the option keeps plaintext gRPC for local `dexcli dev` servers.
|
|
88
|
+
`FlowServiceTlsOptions()` enables TLS 1.2 or newer, verifies the certificate
|
|
89
|
+
and hostname, and requires HTTP/2 ALPN `h2`. Workers apply it to startup,
|
|
90
|
+
blob hydration, and pull task streams. The same settings work with `AsyncClient`
|
|
91
|
+
and `AsyncWorker`. File, API key, and custom bearer credentials compose with TLS
|
|
92
|
+
as call metadata.
|
|
93
|
+
|
|
94
|
+
With an application's registered `flow`, `registry`, and open `cache`:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
98
|
+
from datetime import timedelta
|
|
99
|
+
from pathlib import Path
|
|
100
|
+
from uuid import uuid4
|
|
101
|
+
|
|
102
|
+
from dex import (
|
|
103
|
+
Client, ClientOptions, FileCredential, FlowServiceTlsOptions,
|
|
104
|
+
Worker, WorkerOptions,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
flow_service_tls = FlowServiceTlsOptions(
|
|
108
|
+
additional_root_cas_pem=Path("/etc/dex/root-ca.pem").read_bytes(),
|
|
109
|
+
)
|
|
110
|
+
credential = FileCredential("/var/run/secrets/dex/token")
|
|
111
|
+
server_address = "dex.example.com:443"
|
|
112
|
+
with Worker(registry, cache, WorkerOptions(
|
|
113
|
+
server_address=server_address,
|
|
114
|
+
flow_service_tls=flow_service_tls,
|
|
115
|
+
credential=credential,
|
|
116
|
+
)) as worker, Client(registry, cache, ClientOptions(
|
|
117
|
+
server_address=server_address,
|
|
118
|
+
flow_service_tls=flow_service_tls,
|
|
119
|
+
credential=credential,
|
|
120
|
+
)) as client, ThreadPoolExecutor(max_workers=1) as executor:
|
|
121
|
+
started = executor.submit(worker.start)
|
|
122
|
+
try:
|
|
123
|
+
worker.wait_pull_registered(timeout=30)
|
|
124
|
+
flow_id = f"tls-{uuid4()}"
|
|
125
|
+
client.start_flow(flow, flow_id, input_value)
|
|
126
|
+
result = client.wait_for_flow(flow_id, timedelta(seconds=30))
|
|
127
|
+
finally:
|
|
128
|
+
worker.stop()
|
|
129
|
+
started.result(timeout=10)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- `additional_root_cas_pem` accepts PEM bytes or text. Omit it, or use an empty
|
|
133
|
+
value, for gRPC's default trust. A nonempty bundle must contain at least one
|
|
134
|
+
parsable certificate; malformed and non-certificate blocks are skipped when
|
|
135
|
+
another certificate parses. The trust is the gRPC default roots (grpcio's
|
|
136
|
+
bundled roots, or `GRPC_DEFAULT_SSL_ROOTS_FILE_PATH` when set) plus the added
|
|
137
|
+
roots. A configured gRPC root file replaces the bundled roots and takes
|
|
138
|
+
precedence over system roots. Adding roots fails when
|
|
139
|
+
`GRPC_USE_SYSTEM_ROOTS_OVER_LANGUAGE_CALLBACK` is true, unless a root file is
|
|
140
|
+
configured, regardless of `GRPC_NOT_USE_SYSTEM_SSL_ROOTS`.
|
|
141
|
+
True values are `true`, `t`, `yes`, `y`, and `1`, ignoring case. This guard
|
|
142
|
+
also applies to system roots selected with `GRPC_SYSTEM_SSL_ROOTS_DIR`.
|
|
143
|
+
To add roots in that configuration, disable
|
|
144
|
+
`GRPC_USE_SYSTEM_ROOTS_OVER_LANGUAGE_CALLBACK` and pass the full PEM bundle
|
|
145
|
+
as `additional_root_cas_pem`, or set `GRPC_DEFAULT_SSL_ROOTS_FILE_PATH` to the
|
|
146
|
+
full bundle. `SSL_CERT_FILE` and `SSL_CERT_DIR` do not affect this trust.
|
|
147
|
+
These sources are read at construction. An unreadable bundled root file, or an
|
|
148
|
+
unreadable or invalid configured gRPC root file, fails construction when adding
|
|
149
|
+
roots. Errors for configured files include the file path. To trust OS or
|
|
150
|
+
corporate CAs, pass their PEM bundle explicitly:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
tls = FlowServiceTlsOptions(
|
|
154
|
+
additional_root_cas_pem=Path("/etc/ssl/certs/ca-certificates.crt").read_bytes(),
|
|
155
|
+
)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Use the CA bundle path supplied by your OS or organization.
|
|
159
|
+
- `server_name` defaults to `None`, which verifies the address host and preserves
|
|
160
|
+
the host and port as HTTP/2 authority. Set a DNS name or IP without a port only
|
|
161
|
+
when the certificate name differs. It controls verification, SNI, and HTTP/2
|
|
162
|
+
authority; gateways must accept that authority without a port. Empty strings
|
|
163
|
+
are invalid. IP addresses require matching IP SANs and send no SNI. Prefer
|
|
164
|
+
a DNS name for IPv6 overrides because strict HTTP/2 servers reject an
|
|
165
|
+
unbracketed IPv6 authority.
|
|
166
|
+
- TLS targets accept `host:port`, `dns:///host:port`, and
|
|
167
|
+
`dns://authority/host:port`, including bracketed IPv6 hosts. Ports must be
|
|
168
|
+
unsigned decimal values from 1 through 65535. The DNS resolver authority
|
|
169
|
+
never becomes the certificate name. Other resolver schemes remain available
|
|
170
|
+
with plaintext only.
|
|
171
|
+
- Constructors raise `ValueError` for invalid addresses, server names, or PEM
|
|
172
|
+
bundles. Connections open on demand; certificate and handshake failures
|
|
173
|
+
surface on the first Client call as `UNAVAILABLE` or during Worker startup.
|
|
174
|
+
Servers offering only `http/1.1`, or no ALPN protocol, are rejected.
|
|
175
|
+
- This option does not configure the `ApiKeyCredential` token endpoint, which
|
|
176
|
+
uses HTTPS except on loopback.
|
|
81
177
|
|
|
82
178
|
## Workers
|
|
83
179
|
|
|
@@ -22,6 +22,7 @@ from dex.attribute import (
|
|
|
22
22
|
)
|
|
23
23
|
from dex.attribute_match import AttributeMatch
|
|
24
24
|
from dex.attribute_values import AttributeValues
|
|
25
|
+
from dex._message_size import DEFAULT_GRPC_MAX_MESSAGE_BYTES
|
|
25
26
|
from dex.blob_cache import BlobCache, BlobCacheConfig, open_blob_cache
|
|
26
27
|
from dex.channel import Channel, ChannelMap, ChannelMapLoad, ChannelMessage
|
|
27
28
|
from dex.client import Client
|
|
@@ -68,6 +69,7 @@ from dex.flow_options import (
|
|
|
68
69
|
TimeTravelStepMethod,
|
|
69
70
|
TimeTravelType,
|
|
70
71
|
)
|
|
72
|
+
from dex.flow_service_tls_options import FlowServiceTlsOptions
|
|
71
73
|
from dex.flow_result import FlowResult, StepCompletion
|
|
72
74
|
from dex.pull_registration import (
|
|
73
75
|
PullQueueRegistrationState,
|
|
@@ -79,6 +81,7 @@ from dex.runtime_errors import (
|
|
|
79
81
|
AttributeMapNotLoadedError,
|
|
80
82
|
ChannelMessageNotFoundError,
|
|
81
83
|
ChannelMessagesNotLoadedError,
|
|
84
|
+
BlobMessageTooLargeError,
|
|
82
85
|
DexServiceError,
|
|
83
86
|
ErrorSubStatus,
|
|
84
87
|
FlowAlreadyStartedError,
|
|
@@ -168,6 +171,8 @@ __all__ = [
|
|
|
168
171
|
"CodecRegistry",
|
|
169
172
|
"ConditionCombination",
|
|
170
173
|
"Context",
|
|
174
|
+
"BlobMessageTooLargeError",
|
|
175
|
+
"DEFAULT_GRPC_MAX_MESSAGE_BYTES",
|
|
171
176
|
"DexServiceError",
|
|
172
177
|
"ErrorSubStatus",
|
|
173
178
|
"Flow",
|
|
@@ -179,6 +184,7 @@ __all__ = [
|
|
|
179
184
|
"FlowErrorType",
|
|
180
185
|
"FlowInfo",
|
|
181
186
|
"FlowResult",
|
|
187
|
+
"FlowServiceTlsOptions",
|
|
182
188
|
"FlowNotActiveOrNotFoundError",
|
|
183
189
|
"FlowNotFoundError",
|
|
184
190
|
"FlowStatus",
|
|
@@ -10,10 +10,15 @@ from __future__ import annotations
|
|
|
10
10
|
|
|
11
11
|
import logging
|
|
12
12
|
from dataclasses import dataclass, field
|
|
13
|
+
from typing import cast
|
|
13
14
|
|
|
15
|
+
import grpc
|
|
16
|
+
|
|
17
|
+
from dex._message_size import is_grpc_message_size_error
|
|
14
18
|
from dex.blob_cache import BlobCache
|
|
15
19
|
from dex.dexpb import dex_pb2 as pb
|
|
16
20
|
from dex.dexpb import dex_pb2_grpc
|
|
21
|
+
from dex.runtime_errors import BlobMessageTooLargeError
|
|
17
22
|
|
|
18
23
|
_LOGGER = logging.getLogger(__name__)
|
|
19
24
|
|
|
@@ -212,25 +217,44 @@ class AsyncValueHydrator:
|
|
|
212
217
|
async def _load_misses(self, misses: list[_PendingBlob]) -> None:
|
|
213
218
|
if not misses:
|
|
214
219
|
return
|
|
215
|
-
|
|
216
|
-
pb.LoadBlobsRequest(
|
|
217
|
-
entries=[
|
|
218
|
-
pb.LoadBlobRequestEntry(
|
|
219
|
-
flow_id=miss.flow_id,
|
|
220
|
-
blob_value=miss.request,
|
|
221
|
-
)
|
|
222
|
-
for miss in misses
|
|
223
|
-
]
|
|
224
|
-
)
|
|
225
|
-
)
|
|
220
|
+
values = await self._load_blob_values(misses)
|
|
226
221
|
for miss in misses:
|
|
227
|
-
concrete =
|
|
222
|
+
concrete = values.get(miss.blob_id)
|
|
228
223
|
if concrete is None:
|
|
229
224
|
raise RuntimeError(f"LoadBlobs omitted blob {miss.blob_id}")
|
|
230
225
|
self._validate_hydrated(miss, concrete)
|
|
231
226
|
miss.hydrated = concrete
|
|
232
227
|
self._write_cache(miss, concrete)
|
|
233
228
|
|
|
229
|
+
async def _load_blob_values(self, misses: list[_PendingBlob]) -> dict[str, pb.Value]:
|
|
230
|
+
"""Load blobs, halving a batch whose response exceeds a gRPC size limit."""
|
|
231
|
+
try:
|
|
232
|
+
response = await self._service.LoadBlobs(
|
|
233
|
+
pb.LoadBlobsRequest(
|
|
234
|
+
entries=[
|
|
235
|
+
pb.LoadBlobRequestEntry(
|
|
236
|
+
flow_id=miss.flow_id,
|
|
237
|
+
blob_value=miss.request,
|
|
238
|
+
)
|
|
239
|
+
for miss in misses
|
|
240
|
+
]
|
|
241
|
+
)
|
|
242
|
+
)
|
|
243
|
+
except grpc.RpcError as error:
|
|
244
|
+
if not is_grpc_message_size_error(error):
|
|
245
|
+
raise
|
|
246
|
+
if len(misses) == 1:
|
|
247
|
+
raise BlobMessageTooLargeError(
|
|
248
|
+
misses[0].flow_id,
|
|
249
|
+
misses[0].blob_id,
|
|
250
|
+
cast(grpc.Call, error).details() or str(error),
|
|
251
|
+
) from error
|
|
252
|
+
half = len(misses) // 2
|
|
253
|
+
values = await self._load_blob_values(misses[:half])
|
|
254
|
+
values.update(await self._load_blob_values(misses[half:]))
|
|
255
|
+
return values
|
|
256
|
+
return dict(response.values)
|
|
257
|
+
|
|
234
258
|
def _read_cache(self, blob: _PendingBlob) -> pb.Value | None:
|
|
235
259
|
try:
|
|
236
260
|
payload = self._cache.get(self._cache_key(blob))
|
|
@@ -23,7 +23,10 @@ from typing import Any, NamedTuple, cast
|
|
|
23
23
|
|
|
24
24
|
import grpc
|
|
25
25
|
|
|
26
|
+
from dex._message_size import grpc_message_size_channel_options
|
|
27
|
+
from dex._flow_service_tls import FlowServiceTransport, flow_service_transport
|
|
26
28
|
from dex.credential import Credential
|
|
29
|
+
from dex.flow_service_tls_options import FlowServiceTlsOptions
|
|
27
30
|
|
|
28
31
|
_TOKEN_WORKERS = 4
|
|
29
32
|
|
|
@@ -318,20 +321,64 @@ class _AsyncCredentialInterceptor(grpc.aio.UnaryUnaryClientInterceptor):
|
|
|
318
321
|
return call
|
|
319
322
|
|
|
320
323
|
|
|
321
|
-
def sync_channel(
|
|
322
|
-
|
|
324
|
+
def sync_channel(
|
|
325
|
+
server_address: str,
|
|
326
|
+
credential: Credential | None,
|
|
327
|
+
flow_service_tls: FlowServiceTlsOptions | None = None,
|
|
328
|
+
*,
|
|
329
|
+
transport: FlowServiceTransport | None = None,
|
|
330
|
+
grpc_max_message_bytes: int = 0,
|
|
331
|
+
) -> grpc.Channel:
|
|
332
|
+
if transport is None:
|
|
333
|
+
transport = flow_service_transport(server_address, flow_service_tls)
|
|
334
|
+
message_size_options = grpc_message_size_channel_options(grpc_max_message_bytes)
|
|
335
|
+
channel = (
|
|
336
|
+
grpc.insecure_channel(server_address, options=message_size_options)
|
|
337
|
+
if transport.credentials is None
|
|
338
|
+
else grpc.secure_channel(
|
|
339
|
+
transport.target,
|
|
340
|
+
transport.credentials,
|
|
341
|
+
options=message_size_options + transport.channel_options,
|
|
342
|
+
)
|
|
343
|
+
)
|
|
323
344
|
if credential is None:
|
|
324
345
|
return channel
|
|
325
346
|
return grpc.intercept_channel(channel, _SyncCredentialInterceptor(credential))
|
|
326
347
|
|
|
327
348
|
|
|
328
349
|
def async_channel(
|
|
329
|
-
server_address: str,
|
|
350
|
+
server_address: str,
|
|
351
|
+
credential_runner: AsyncCredentialRunner | None,
|
|
352
|
+
flow_service_tls: FlowServiceTlsOptions | None = None,
|
|
353
|
+
*,
|
|
354
|
+
transport: FlowServiceTransport | None = None,
|
|
355
|
+
grpc_max_message_bytes: int = 0,
|
|
330
356
|
) -> grpc.aio.Channel:
|
|
357
|
+
if transport is None:
|
|
358
|
+
transport = flow_service_transport(server_address, flow_service_tls)
|
|
359
|
+
message_size_options = grpc_message_size_channel_options(grpc_max_message_bytes)
|
|
360
|
+
if transport.credentials is not None:
|
|
361
|
+
interceptors = (
|
|
362
|
+
[
|
|
363
|
+
cast(
|
|
364
|
+
grpc.aio.ClientInterceptor,
|
|
365
|
+
_AsyncCredentialInterceptor(credential_runner),
|
|
366
|
+
)
|
|
367
|
+
]
|
|
368
|
+
if credential_runner is not None
|
|
369
|
+
else None
|
|
370
|
+
)
|
|
371
|
+
return grpc.aio.secure_channel(
|
|
372
|
+
transport.target,
|
|
373
|
+
transport.credentials,
|
|
374
|
+
options=message_size_options + transport.channel_options,
|
|
375
|
+
interceptors=interceptors,
|
|
376
|
+
)
|
|
331
377
|
if credential_runner is None:
|
|
332
|
-
return grpc.aio.insecure_channel(server_address)
|
|
378
|
+
return grpc.aio.insecure_channel(server_address, options=message_size_options)
|
|
333
379
|
return grpc.aio.insecure_channel(
|
|
334
380
|
server_address,
|
|
381
|
+
options=message_size_options,
|
|
335
382
|
interceptors=[
|
|
336
383
|
cast(
|
|
337
384
|
grpc.aio.ClientInterceptor,
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
# You may not use this file except in compliance with the License.
|
|
5
|
+
# See the LICENSE file in the repository root.
|
|
6
|
+
#
|
|
7
|
+
# SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import ipaddress
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import ssl
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from importlib.resources import files
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
import grpc
|
|
20
|
+
|
|
21
|
+
from dex.flow_service_tls_options import FlowServiceTlsOptions
|
|
22
|
+
|
|
23
|
+
_RESOLVER_SCHEMES = {"dns", "ipv4", "ipv6", "passthrough", "unix", "unix-abstract"}
|
|
24
|
+
_PEM_CERTIFICATE = re.compile(
|
|
25
|
+
rb"-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----", re.DOTALL
|
|
26
|
+
)
|
|
27
|
+
_TRUE_ENVIRONMENT_VALUES = {"true", "t", "yes", "y", "1"}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class FlowServiceTransport:
|
|
32
|
+
target: str
|
|
33
|
+
credentials: grpc.ChannelCredentials | None
|
|
34
|
+
channel_options: tuple[tuple[str, str], ...] = ()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def flow_service_transport(
|
|
38
|
+
server_address: str, options: FlowServiceTlsOptions | None
|
|
39
|
+
) -> FlowServiceTransport:
|
|
40
|
+
if options is None:
|
|
41
|
+
return FlowServiceTransport(server_address, None)
|
|
42
|
+
target = _flow_service_tls_target(server_address)
|
|
43
|
+
channel_options: tuple[tuple[str, str], ...] = ()
|
|
44
|
+
if options.server_name is not None:
|
|
45
|
+
if not _is_valid_server_name(options.server_name):
|
|
46
|
+
raise ValueError(
|
|
47
|
+
"flow_service_tls.server_name must be a nonempty DNS name or IP address without a port; "
|
|
48
|
+
f"got {options.server_name!r}"
|
|
49
|
+
)
|
|
50
|
+
channel_options = (
|
|
51
|
+
("grpc.ssl_target_name_override", options.server_name),
|
|
52
|
+
("grpc.default_authority", options.server_name),
|
|
53
|
+
)
|
|
54
|
+
root_certificates = None
|
|
55
|
+
if options.additional_root_cas_pem:
|
|
56
|
+
certificates = _additional_root_certificates(options.additional_root_cas_pem)
|
|
57
|
+
root_certificates = _default_root_certificates() + b"\n" + certificates
|
|
58
|
+
return FlowServiceTransport(
|
|
59
|
+
target, grpc.ssl_channel_credentials(root_certificates), channel_options
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _flow_service_tls_target(server_address: str) -> str:
|
|
64
|
+
target = endpoint = server_address
|
|
65
|
+
scheme, separator, dns_target = server_address.partition("://")
|
|
66
|
+
if separator and scheme.lower() == "dns":
|
|
67
|
+
authority, separator, endpoint = dns_target.partition("/")
|
|
68
|
+
if (
|
|
69
|
+
not separator
|
|
70
|
+
or re.search(r"[ \t\r\n?#@]", authority)
|
|
71
|
+
or re.search(r"[/?#]", endpoint)
|
|
72
|
+
):
|
|
73
|
+
raise _unsupported_address(server_address)
|
|
74
|
+
target = f"dns://{dns_target}"
|
|
75
|
+
elif (
|
|
76
|
+
re.search(r"[/?#]", server_address)
|
|
77
|
+
or server_address.partition(":")[0].lower() in _RESOLVER_SCHEMES
|
|
78
|
+
):
|
|
79
|
+
raise _unsupported_address(server_address)
|
|
80
|
+
host, separator, port = endpoint.rpartition(":")
|
|
81
|
+
if not separator:
|
|
82
|
+
raise _unsupported_address(server_address)
|
|
83
|
+
if host.startswith("[") and host.endswith("]"):
|
|
84
|
+
host = host[1:-1]
|
|
85
|
+
if not _is_ipv6(host):
|
|
86
|
+
raise _unsupported_address(server_address)
|
|
87
|
+
elif ":" in host:
|
|
88
|
+
raise _unsupported_address(server_address)
|
|
89
|
+
if "[" in host or "]" in host or not _is_valid_server_name(host):
|
|
90
|
+
raise _unsupported_address(server_address)
|
|
91
|
+
significant_port = port.lstrip("0")
|
|
92
|
+
if (
|
|
93
|
+
not re.fullmatch(r"[0-9]+", port)
|
|
94
|
+
or len(significant_port) > 5
|
|
95
|
+
or not 1 <= int(significant_port or "0") <= 65535
|
|
96
|
+
):
|
|
97
|
+
raise ValueError(
|
|
98
|
+
f"flow_service_tls requires server_address port 1-65535; got {server_address!r}"
|
|
99
|
+
)
|
|
100
|
+
return target
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _unsupported_address(server_address: str) -> ValueError:
|
|
104
|
+
return ValueError(
|
|
105
|
+
"flow_service_tls requires server_address as host:port, dns:///host:port, or dns://authority/host:port; "
|
|
106
|
+
f"got {server_address!r}"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _is_valid_server_name(name: str) -> bool:
|
|
111
|
+
return (
|
|
112
|
+
bool(name)
|
|
113
|
+
and not re.search(r"[\s/#?@]", name)
|
|
114
|
+
and (":" not in name or _is_ipv6(name))
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _is_ipv6(name: str) -> bool:
|
|
119
|
+
try:
|
|
120
|
+
return (
|
|
121
|
+
isinstance(ipaddress.ip_address(name), ipaddress.IPv6Address)
|
|
122
|
+
and "%" not in name
|
|
123
|
+
)
|
|
124
|
+
except ValueError:
|
|
125
|
+
return False
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _additional_root_certificates(bundle: bytes | str) -> bytes:
|
|
129
|
+
encoded_bundle = bundle.encode("utf-8") if isinstance(bundle, str) else bundle
|
|
130
|
+
certificates = []
|
|
131
|
+
for certificate in _PEM_CERTIFICATE.findall(encoded_bundle):
|
|
132
|
+
try:
|
|
133
|
+
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
134
|
+
context.load_verify_locations(cadata=certificate.decode("ascii"))
|
|
135
|
+
except (ValueError, ssl.SSLError, UnicodeError):
|
|
136
|
+
continue
|
|
137
|
+
certificates.append(certificate)
|
|
138
|
+
if not certificates:
|
|
139
|
+
raise ValueError(
|
|
140
|
+
"flow_service_tls.additional_root_cas_pem contains no PEM certificate"
|
|
141
|
+
)
|
|
142
|
+
return b"\n".join(certificates)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _default_root_certificates() -> bytes:
|
|
146
|
+
configured_file = os.environ.get("GRPC_DEFAULT_SSL_ROOTS_FILE_PATH")
|
|
147
|
+
# gRPC tries preferred system roots even when GRPC_NOT_USE_SYSTEM_SSL_ROOTS is true.
|
|
148
|
+
# https://github.com/grpc/grpc/blob/v1.83.0/src/core/credentials/transport/tls/ssl_utils.cc#L559-L606
|
|
149
|
+
if not configured_file and _is_environment_flag_true(
|
|
150
|
+
"GRPC_USE_SYSTEM_ROOTS_OVER_LANGUAGE_CALLBACK"
|
|
151
|
+
):
|
|
152
|
+
raise ValueError(
|
|
153
|
+
"flow_service_tls: added roots cannot be combined with gRPC system roots; "
|
|
154
|
+
"disable GRPC_USE_SYSTEM_ROOTS_OVER_LANGUAGE_CALLBACK and pass the full "
|
|
155
|
+
"bundle via additional_root_cas_pem, or set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH "
|
|
156
|
+
"to the full bundle"
|
|
157
|
+
)
|
|
158
|
+
try:
|
|
159
|
+
if configured_file:
|
|
160
|
+
return _additional_root_certificates(Path(configured_file).read_bytes())
|
|
161
|
+
return (
|
|
162
|
+
files("grpc").joinpath("_cython", "_credentials", "roots.pem").read_bytes()
|
|
163
|
+
)
|
|
164
|
+
except (OSError, ValueError, ssl.SSLError) as failure:
|
|
165
|
+
source = f" from {configured_file!r}" if configured_file else ""
|
|
166
|
+
raise ValueError(
|
|
167
|
+
f"flow_service_tls: cannot load default root CAs{source}"
|
|
168
|
+
) from failure
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _is_environment_flag_true(name: str) -> bool:
|
|
172
|
+
return os.environ.get(name, "").lower() in _TRUE_ENVIRONMENT_VALUES
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
# You may not use this file except in compliance with the License.
|
|
5
|
+
# See the LICENSE file in the repository root.
|
|
6
|
+
#
|
|
7
|
+
# SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import cast
|
|
12
|
+
|
|
13
|
+
import grpc
|
|
14
|
+
from grpc_status import rpc_status
|
|
15
|
+
|
|
16
|
+
#: The gRPC receive limit of a Client or Worker whose ``grpc_max_message_bytes`` is zero.
|
|
17
|
+
#:
|
|
18
|
+
#: The limit applies to every message the SDK receives: Client responses such as RPC
|
|
19
|
+
#: results and state reads, responses to the Worker's FlowService calls such as LoadBlobs,
|
|
20
|
+
#: and the Step and RPC invocations that Dex sends to a Worker. The default is 32 MiB,
|
|
21
|
+
#: which matches the Dex server's default ``api.grpcMaxMessageBytes``. With the default,
|
|
22
|
+
#: the SDK keeps gRPC's unlimited send limit, so the Dex server's receive limit bounds what
|
|
23
|
+
#: the SDK sends. A positive ``grpc_max_message_bytes`` limits both directions.
|
|
24
|
+
#:
|
|
25
|
+
#: A message carries one or more application values plus an envelope of metadata. Keep the
|
|
26
|
+
#: limit above the largest application value by an explicit margin. The default leaves
|
|
27
|
+
#: 16 MiB of headroom for values up to 16 MiB. When an application needs larger values,
|
|
28
|
+
#: raise both ``grpc_max_message_bytes`` and the server's ``api.grpcMaxMessageBytes``,
|
|
29
|
+
#: because each hop applies the smaller limit of its ends.
|
|
30
|
+
#:
|
|
31
|
+
#: Example:
|
|
32
|
+
#: >>> options = ClientOptions(grpc_max_message_bytes=2 * DEFAULT_GRPC_MAX_MESSAGE_BYTES)
|
|
33
|
+
#:
|
|
34
|
+
#: .. versionadded:: 1.38.0
|
|
35
|
+
DEFAULT_GRPC_MAX_MESSAGE_BYTES = 32 << 20
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def validate_grpc_max_message_bytes(configured: int) -> None:
|
|
39
|
+
if configured < 0:
|
|
40
|
+
raise ValueError(
|
|
41
|
+
f"grpc_max_message_bytes must not be negative, got {configured}"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def grpc_message_size_channel_options(configured: int) -> tuple[tuple[str, int], ...]:
|
|
46
|
+
if configured == 0:
|
|
47
|
+
return (("grpc.max_receive_message_length", DEFAULT_GRPC_MAX_MESSAGE_BYTES),)
|
|
48
|
+
return (
|
|
49
|
+
("grpc.max_receive_message_length", configured),
|
|
50
|
+
("grpc.max_send_message_length", configured),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
_GRPC_SIZE_STATUS_CODES = frozenset(
|
|
55
|
+
(grpc.StatusCode.RESOURCE_EXHAUSTED, grpc.StatusCode.OUT_OF_RANGE)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Lowercase diagnostics of gRPC message size limits; transports reuse the codes otherwise.
|
|
59
|
+
_GRPC_SIZE_DIAGNOSTICS = (
|
|
60
|
+
"message larger than max",
|
|
61
|
+
"message after decompression larger than max",
|
|
62
|
+
"message too large",
|
|
63
|
+
"message with a size larger than",
|
|
64
|
+
"decompresses to a size larger than",
|
|
65
|
+
"message length too large",
|
|
66
|
+
"exceeded while decompressing message",
|
|
67
|
+
"cannot return body with more than 4gb of data",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def is_grpc_message_size_error(error: grpc.RpcError) -> bool:
|
|
72
|
+
"""Report a gRPC size rejection, which carries no Dex service error details.
|
|
73
|
+
|
|
74
|
+
The receiver's limit yields RESOURCE_EXHAUSTED, and a tonic server's send limit
|
|
75
|
+
yields OUT_OF_RANGE. The message must also name a size limit, because HTTP/2 flow
|
|
76
|
+
control failures reuse RESOURCE_EXHAUSTED without details.
|
|
77
|
+
"""
|
|
78
|
+
call = cast(grpc.Call, error)
|
|
79
|
+
if call.code() not in _GRPC_SIZE_STATUS_CODES:
|
|
80
|
+
return False
|
|
81
|
+
message = (call.details() or "").lower()
|
|
82
|
+
if not any(diagnostic in message for diagnostic in _GRPC_SIZE_DIAGNOSTICS):
|
|
83
|
+
return False
|
|
84
|
+
try:
|
|
85
|
+
status = rpc_status.from_call(call)
|
|
86
|
+
except ValueError:
|
|
87
|
+
return False
|
|
88
|
+
return status is None or not status.details
|