dex-python-sdk 1.35.0__tar.gz → 1.37.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.
Files changed (73) hide show
  1. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/PKG-INFO +99 -3
  2. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/README.md +98 -2
  3. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/__init__.py +2 -0
  4. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_credential_transport.py +42 -3
  5. dex_python_sdk-1.37.0/dex/_flow_service_tls.py +172 -0
  6. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_pull_worker.py +15 -2
  7. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/async_client.py +41 -9
  8. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/async_worker.py +22 -2
  9. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/attribute.py +35 -0
  10. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/attribute_values.py +2 -0
  11. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/channel.py +11 -0
  12. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/client.py +63 -9
  13. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/client_options.py +8 -3
  14. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/codec.py +4 -0
  15. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/context.py +41 -4
  16. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/credential.py +2 -1
  17. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/flow.py +7 -0
  18. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/flow_options.py +27 -5
  19. dex_python_sdk-1.37.0/dex/flow_service_tls_options.py +81 -0
  20. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/runtime_errors.py +23 -0
  21. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/step.py +129 -7
  22. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/stream.py +23 -0
  23. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/subflow.py +36 -1
  24. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/timer.py +8 -1
  25. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/worker.py +22 -2
  26. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/worker_options.py +25 -3
  27. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/pyproject.toml +1 -1
  28. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/Cargo.lock +332 -5
  29. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/Cargo.toml +1 -1
  30. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/LEGACY_NOTICES.md +0 -0
  31. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/LICENSE +0 -0
  32. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_async_value_hydrator.py +0 -0
  33. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_async_worker_dispatcher.py +0 -0
  34. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_attribute_reads.py +0 -0
  35. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_grpc_errors.py +0 -0
  36. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_invocation_context.py +0 -0
  37. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_native.pyi +0 -0
  38. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_server_protocol.py +0 -0
  39. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_utils.py +0 -0
  40. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_value_hydrator.py +0 -0
  41. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_value_mapper.py +0 -0
  42. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/_worker_dispatcher.py +0 -0
  43. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/attribute_match.py +0 -0
  44. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/blob_cache.py +0 -0
  45. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/condition.py +0 -0
  46. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/dexpb/__init__.py +0 -0
  47. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/dexpb/dex_pb2.py +0 -0
  48. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/dexpb/dex_pb2.pyi +0 -0
  49. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/dexpb/dex_pb2_grpc.py +0 -0
  50. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/flow_config.py +0 -0
  51. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/flow_info.py +0 -0
  52. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/flow_result.py +0 -0
  53. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/pull_registration.py +0 -0
  54. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/py.typed +0 -0
  55. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/rpc_invoke_options.py +0 -0
  56. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/step_execution.py +0 -0
  57. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/wait.py +0 -0
  58. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/dex/wait_options.py +0 -0
  59. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
  60. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
  61. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/README.md +0 -0
  62. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
  63. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
  64. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
  65. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
  66. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
  67. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
  68. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
  69. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache/tests/blob_cache_integration.rs +0 -0
  70. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
  71. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
  72. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.0}/sdk-rust/crates/dex-blob-cache-python/README.md +0 -0
  73. {dex_python_sdk-1.35.0 → dex_python_sdk-1.37.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.35.0
3
+ Version: 1.37.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. Dex uses plaintext
96
- gRPC, so protect the network path that carries the token.
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. Dex uses plaintext
80
- gRPC, so protect the network path that carries the token.
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
 
@@ -68,6 +68,7 @@ from dex.flow_options import (
68
68
  TimeTravelStepMethod,
69
69
  TimeTravelType,
70
70
  )
71
+ from dex.flow_service_tls_options import FlowServiceTlsOptions
71
72
  from dex.flow_result import FlowResult, StepCompletion
72
73
  from dex.pull_registration import (
73
74
  PullQueueRegistrationState,
@@ -179,6 +180,7 @@ __all__ = [
179
180
  "FlowErrorType",
180
181
  "FlowInfo",
181
182
  "FlowResult",
183
+ "FlowServiceTlsOptions",
182
184
  "FlowNotActiveOrNotFoundError",
183
185
  "FlowNotFoundError",
184
186
  "FlowStatus",
@@ -23,7 +23,9 @@ from typing import Any, NamedTuple, cast
23
23
 
24
24
  import grpc
25
25
 
26
+ from dex._flow_service_tls import FlowServiceTransport, flow_service_transport
26
27
  from dex.credential import Credential
28
+ from dex.flow_service_tls_options import FlowServiceTlsOptions
27
29
 
28
30
  _TOKEN_WORKERS = 4
29
31
 
@@ -318,16 +320,53 @@ class _AsyncCredentialInterceptor(grpc.aio.UnaryUnaryClientInterceptor):
318
320
  return call
319
321
 
320
322
 
321
- def sync_channel(server_address: str, credential: Credential | None) -> grpc.Channel:
322
- channel = grpc.insecure_channel(server_address)
323
+ def sync_channel(
324
+ server_address: str,
325
+ credential: Credential | None,
326
+ flow_service_tls: FlowServiceTlsOptions | None = None,
327
+ *,
328
+ transport: FlowServiceTransport | None = None,
329
+ ) -> grpc.Channel:
330
+ if transport is None:
331
+ transport = flow_service_transport(server_address, flow_service_tls)
332
+ channel = (
333
+ grpc.insecure_channel(server_address)
334
+ if transport.credentials is None
335
+ else grpc.secure_channel(
336
+ transport.target, transport.credentials, options=transport.channel_options
337
+ )
338
+ )
323
339
  if credential is None:
324
340
  return channel
325
341
  return grpc.intercept_channel(channel, _SyncCredentialInterceptor(credential))
326
342
 
327
343
 
328
344
  def async_channel(
329
- server_address: str, credential_runner: AsyncCredentialRunner | None
345
+ server_address: str,
346
+ credential_runner: AsyncCredentialRunner | None,
347
+ flow_service_tls: FlowServiceTlsOptions | None = None,
348
+ *,
349
+ transport: FlowServiceTransport | None = None,
330
350
  ) -> grpc.aio.Channel:
351
+ if transport is None:
352
+ transport = flow_service_transport(server_address, flow_service_tls)
353
+ if transport.credentials is not None:
354
+ interceptors = (
355
+ [
356
+ cast(
357
+ grpc.aio.ClientInterceptor,
358
+ _AsyncCredentialInterceptor(credential_runner),
359
+ )
360
+ ]
361
+ if credential_runner is not None
362
+ else None
363
+ )
364
+ return grpc.aio.secure_channel(
365
+ transport.target,
366
+ transport.credentials,
367
+ options=transport.channel_options,
368
+ interceptors=interceptors,
369
+ )
331
370
  if credential_runner is None:
332
371
  return grpc.aio.insecure_channel(server_address)
333
372
  return grpc.aio.insecure_channel(
@@ -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
@@ -27,6 +27,7 @@ from dex._credential_transport import (
27
27
  _reject_credential_token,
28
28
  async_credential_metadata,
29
29
  )
30
+ from dex._flow_service_tls import FlowServiceTransport
30
31
  from dex._grpc_errors import _worker_error_status
31
32
  from dex._server_protocol import sdk_version
32
33
  from dex.dexpb import dex_pb2 as pb
@@ -74,7 +75,15 @@ _IDENTITY_COMPRESSION_ONLY_OPTIONS = (
74
75
  )
75
76
 
76
77
 
77
- def outbound_worker_task_channel(server_address: str) -> grpc.aio.Channel:
78
+ def outbound_worker_task_channel(
79
+ server_address: str, transport: FlowServiceTransport | None = None
80
+ ) -> grpc.aio.Channel:
81
+ if transport is not None and transport.credentials is not None:
82
+ return grpc.aio.secure_channel(
83
+ transport.target,
84
+ transport.credentials,
85
+ options=_IDENTITY_COMPRESSION_ONLY_OPTIONS + transport.channel_options,
86
+ )
78
87
  return grpc.aio.insecure_channel(
79
88
  server_address, options=_IDENTITY_COMPRESSION_ONLY_OPTIONS
80
89
  )
@@ -97,7 +106,9 @@ class PullWorkerRuntime:
97
106
  executor: ThreadPoolExecutor | None,
98
107
  app_worker_id: str | None = None,
99
108
  credential_runner: AsyncCredentialRunner | None = None,
109
+ transport: FlowServiceTransport | None = None,
100
110
  ) -> None:
111
+ self._transport = transport
101
112
  self._registry = registry
102
113
  self.app_worker_id = app_worker_id or resolve_app_worker_id(registry, options)
103
114
  self.flow_types = sorted(registry._registered_flows)
@@ -171,7 +182,9 @@ class PullWorkerRuntime:
171
182
  self._started.set()
172
183
  channel: grpc.aio.Channel | None = None
173
184
  try:
174
- channel = outbound_worker_task_channel(self._server_address)
185
+ channel = outbound_worker_task_channel(
186
+ self._server_address, self._transport
187
+ )
175
188
  stub = dex_pb2_grpc.WorkerTaskServiceStub(channel) # type: ignore[no-untyped-call]
176
189
  self._wake.set()
177
190
  while not self._stopping.is_set():
@@ -105,6 +105,10 @@ class AsyncClient:
105
105
  as any other transport failure. Such failures are not cached, so the next
106
106
  call negotiates again. Negotiation counts against a call's request timeout.
107
107
 
108
+ .. versionchanged:: 1.35.0
109
+ Requires Server protocol 4, available in server-zd v0.1.17 and later.
110
+ Compatibility is checked lazily on the first service request.
111
+
108
112
  Attributes:
109
113
  registry: Flow definitions used to validate typed calls.
110
114
  blob_cache: The open cache used to hydrate large values.
@@ -122,13 +126,17 @@ class AsyncClient:
122
126
  blob_cache: BlobCache,
123
127
  options: ClientOptions | None = None,
124
128
  ) -> None:
125
- """Construct an AsyncClient and its lazy plaintext gRPC channel.
129
+ """Construct an AsyncClient and its lazy gRPC channel, plaintext unless TLS is set.
126
130
 
127
131
  Args:
128
132
  registry: The Flow Registry used for validation and codecs.
129
133
  blob_cache: An open cache used for asynchronous hydration.
130
- options: Service address and bearer credential;
134
+ options: Service address, optional TLS, and bearer credential;
131
135
  ``None`` uses defaults and sends no authorization metadata.
136
+
137
+ Raises:
138
+ ValueError: If the configured TLS address, server name, or CA bundle
139
+ is invalid, or default roots cannot be loaded.
132
140
  """
133
141
  self.registry = registry
134
142
  self.blob_cache = blob_cache
@@ -139,7 +147,9 @@ class AsyncClient:
139
147
  else None
140
148
  )
141
149
  self._channel = async_channel(
142
- self.options.server_address, self._credential_runner
150
+ self.options.server_address,
151
+ self._credential_runner,
152
+ self.options.flow_service_tls,
143
153
  )
144
154
  self._service = dex_pb2_grpc.FlowServiceStub( # type: ignore[no-untyped-call]
145
155
  self._channel
@@ -197,6 +207,10 @@ class AsyncClient:
197
207
  Construction performs no network I/O. An incompatible Server fails this
198
208
  and every later request; transient negotiation failures can be retried.
199
209
 
210
+ The current Dex Server rejects a Flow-level retry_policy or positive
211
+ start_delay with INVALID_ARGUMENT through DexServiceError. Retry work with
212
+ StepOptions instead; put a Timer wait in the starting Step to delay work.
213
+
200
214
  Args:
201
215
  flow: The registered Flow instance to start.
202
216
  flow_id: A non-empty application ID stable across runs.
@@ -326,11 +340,18 @@ class AsyncClient:
326
340
 
327
341
  Pass the bound method from the registered Flow instance. RPC timeout and
328
342
  Attribute locks come from ``@rpc`` configuration. A non-transactional RPC
329
- without Attribute locks starts from a backend query. If the handler returns no
330
- durable effects, a retained terminal execution can serve that query. Locks,
343
+ without Attribute locks uses a read-only execution path. If the handler returns no
344
+ durable effects, a retained terminal execution can serve the RPC. Locks,
331
345
  transactional execution, returned effects, or server policy can require an
332
346
  active execution.
333
347
 
348
+ RPC handlers are not automatically retried by this call. A timeout or
349
+ transport error does not prove that external effects or committed writes
350
+ did not happen. Use application idempotency before repeating a write.
351
+ Acquire and load the same exact AttributeMap instance for a dynamic
352
+ read-modify-write operation through RPCInvokeOptions. A lock alone does
353
+ not request the instance's value in the handler snapshot.
354
+
334
355
  Args:
335
356
  rpc_method: A bound method decorated with ``@rpc``.
336
357
  flow_id: The non-empty target Flow ID.
@@ -338,6 +359,8 @@ class AsyncClient:
338
359
  run_id: Optional exact run. With ``""``, the server resolves the current
339
360
  execution.
340
361
  options: Additive runtime AttributeMap locks and exact map-instance loads.
362
+ They cannot change timeout or transactionality. The Client unions,
363
+ sorts, and deduplicates these selections with the registered ones.
341
364
 
342
365
  Returns:
343
366
  The decoded ``RPCResult.output``, or ``None`` for a no-output RPC.
@@ -630,6 +653,9 @@ class AsyncClient:
630
653
  """Request cancellation, termination, or failure of an active Flow.
631
654
 
632
655
  The await completes after Dex accepts the request, not after terminal status.
656
+ Await wait_for_flow afterward to observe closure. Cancellation is cooperative;
657
+ a handler may still be unwinding, and external effects are not undone.
658
+ The synchronous Client examples also apply here with awaited calls.
633
659
 
634
660
  Args:
635
661
  flow_id: The non-empty target Flow ID.
@@ -695,6 +721,8 @@ class AsyncClient:
695
721
  ) -> AttributeValues:
696
722
  """Read committed Attribute values from the current or latest Flow run.
697
723
 
724
+ .. versionadded:: 1.29.0
725
+
698
726
  Use ``get_attributes`` to read Flow state from outside the Flow without
699
727
  defining an RPC. Pass one or more reads. A read is a singleton
700
728
  ``Attribute`` or one AttributeMap instance selected with
@@ -853,19 +881,23 @@ class AsyncClient:
853
881
  )
854
882
 
855
883
  async def time_travel(self, flow_id: str, options: TimeTravelOptions) -> str:
856
- """Create a new run from a selected point in existing Flow history.
884
+ """Re-run a Flow from a selected point in its existing history.
885
+
886
+ Time travel keeps the current run ID. It does not create a new run.
887
+ Re-run Steps can reuse their Step execution IDs. An idempotency key built
888
+ from the Flow ID, run ID, or Step execution ID therefore repeats.
857
889
 
858
890
  Args:
859
- flow_id: The non-empty Flow ID whose history supplies the new run.
891
+ flow_id: The non-empty Flow ID to re-run.
860
892
  options: Time travel selector, reason, and replay controls.
861
893
 
862
894
  Returns:
863
- The new server-assigned run ID; the Flow ID is unchanged.
895
+ The run ID, which time travel leaves unchanged.
864
896
 
865
897
  Raises:
866
898
  FlowNotFoundError: If ``flow_id`` does not exist.
867
899
  ValueError: If time travel selector fields are invalid.
868
- DexServiceError: If FlowService cannot create the new run.
900
+ DexServiceError: If FlowService cannot perform the time travel.
869
901
  RuntimeError: If the Server reports a protocol range without protocol 4.
870
902
  """
871
903
  request = pb.ResetFlowRequest(