tba-router-wpt-verification 0.4.0.dev2__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.
- tba_router_wpt_verification-0.4.0.dev2/PKG-INFO +90 -0
- tba_router_wpt_verification-0.4.0.dev2/README.md +70 -0
- tba_router_wpt_verification-0.4.0.dev2/pyproject.toml +20 -0
- tba_router_wpt_verification-0.4.0.dev2/src/tba_router_wpt_verification/__init__.py +9 -0
- tba_router_wpt_verification-0.4.0.dev2/src/tba_router_wpt_verification/binding.py +83 -0
- tba_router_wpt_verification-0.4.0.dev2/src/tba_router_wpt_verification/py.typed +1 -0
- tba_router_wpt_verification-0.4.0.dev2/src/tba_router_wpt_verification/schemas.py +26 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tba-router-wpt-verification
|
|
3
|
+
Version: 0.4.0.dev2
|
|
4
|
+
Summary: Authenticated remote WIT/WPT verification for a configured recipient.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10,<3.16
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
14
|
+
Requires-Dist: pydantic (>=2,<3)
|
|
15
|
+
Requires-Dist: tba-concrete-jwt (==0.4.0.dev2)
|
|
16
|
+
Requires-Dist: tba-profile-workload-proof-wimse-wpt (==0.4.0.dev4)
|
|
17
|
+
Requires-Dist: tigrbl (==0.4.5.dev8)
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# tba-router-wpt-verification
|
|
21
|
+
|
|
22
|
+
<!-- BEGIN TBA README HEADER -->
|
|
23
|
+
<p align="center">
|
|
24
|
+
<a href="https://github.com/tigrbl/tigrbl_auth#readme"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="240"></a>
|
|
25
|
+
</p>
|
|
26
|
+
<p align="center">
|
|
27
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/80-routers/tba-router-wpt-verification/pyproject.toml"><img alt="Checkout: 0.4.0.dev2" src="https://img.shields.io/badge/Checkout-0.4.0.dev2-1f6feb"></a>
|
|
28
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/80-routers/tba-router-wpt-verification/pyproject.toml"><img alt="Python: >=3.10,<3.16" src="https://img.shields.io/badge/Python-%3E%3D3.10%2C%3C3.16-3776ab"></a>
|
|
29
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/80-routers/tba-router-wpt-verification/pyproject.toml"><img alt="License: Apache-2.0" src="https://img.shields.io/badge/License-Apache--2.0-525252"></a>
|
|
30
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/80-routers"><img alt="Layer: 80 routers" src="https://img.shields.io/badge/Layer-80%20routers-0a7f5a"></a>
|
|
31
|
+
<a href="https://pypi.org/project/tba-router-wpt-verification/"><img alt="PyPI version for tba-router-wpt-verification" src="https://img.shields.io/pypi/v/tba-router-wpt-verification?label=tba-router-wpt-verification%20PyPI"></a>
|
|
32
|
+
</p>
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://pepy.tech/project/tba-router-wpt-verification"><img alt="Monthly PyPI downloads for tba-router-wpt-verification" src="https://static.pepy.tech/badge/tba-router-wpt-verification/month"></a>
|
|
35
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/80-routers/tba-router-wpt-verification/README.md#verification"><img alt="Evidence: verification" src="https://img.shields.io/badge/Evidence-verification-8250df"></a>
|
|
36
|
+
</p>
|
|
37
|
+
<!-- END TBA README HEADER -->
|
|
38
|
+
|
|
39
|
+
Authenticated remote WIT/WPT verification for a configured recipient.
|
|
40
|
+
|
|
41
|
+
## Quick start
|
|
42
|
+
|
|
43
|
+
Mount `build_wpt_verification_router(verifier=..., audience=...,
|
|
44
|
+
authenticate=..., authorize_verification=...)` on a `TigrblApp`.
|
|
45
|
+
`authenticate` identifies the calling recipient service; the separate
|
|
46
|
+
`authorize_verification` callback must explicitly allow that service to delegate
|
|
47
|
+
verification for the configured audience. These checks precede proof validation.
|
|
48
|
+
|
|
49
|
+
`POST /wpt/verify` accepts:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"workload_identity_token": "<original WIT>",
|
|
54
|
+
"workload_proof_token": "<original WPT, without the WPT scheme prefix>",
|
|
55
|
+
"token_headers": [{"name": "Txn-Token", "value": "<original token>"}]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`token_headers` is a list so duplicate original headers remain observable and
|
|
60
|
+
are rejected when used as bindings. Do not collapse duplicates before forwarding.
|
|
61
|
+
Caller authentication belongs in this API request's headers, separately from
|
|
62
|
+
the submitted workload proof. Submitted audiences and trust configuration are rejected.
|
|
63
|
+
The audience and `required_token_headers` are selected when mounting. Required
|
|
64
|
+
headers must be present and cryptographically bound; clients cannot disable this
|
|
65
|
+
policy by omitting a header. This strict presence policy is separate from the
|
|
66
|
+
profile's optional `bound_token_headers` binding selector.
|
|
67
|
+
|
|
68
|
+
A successful response contains `valid`, `subject`, `audience`, `proof_id`, and
|
|
69
|
+
`expires_at`. Missing/denied caller credentials return 401/403, malformed requests
|
|
70
|
+
return 400, and invalid or replayed workload proofs return 401. Responses disable
|
|
71
|
+
caching and do not echo tokens. An infrastructure exception fails the request;
|
|
72
|
+
it never returns a successful verification decision.
|
|
73
|
+
|
|
74
|
+
Verification **consumes replay state**. Use the result once for the original
|
|
75
|
+
request; do not preflight it and then verify the same proof again. The result
|
|
76
|
+
authenticates the workload; the recipient still applies resource authorization.
|
|
77
|
+
Transport this delegation over the deployment's authenticated confidential channel.
|
|
78
|
+
|
|
79
|
+
Build from the repository root:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uv build --wheel pkgs/80-routers/tba-router-wpt-verification
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Verification
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
uv run --extra test pytest pkgs/120-tests/tba-tests-workload-composition/tests/test_wit_wpt_services.py
|
|
89
|
+
```
|
|
90
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# tba-router-wpt-verification
|
|
2
|
+
|
|
3
|
+
<!-- BEGIN TBA README HEADER -->
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://github.com/tigrbl/tigrbl_auth#readme"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="240"></a>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/80-routers/tba-router-wpt-verification/pyproject.toml"><img alt="Checkout: 0.4.0.dev2" src="https://img.shields.io/badge/Checkout-0.4.0.dev2-1f6feb"></a>
|
|
9
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/80-routers/tba-router-wpt-verification/pyproject.toml"><img alt="Python: >=3.10,<3.16" src="https://img.shields.io/badge/Python-%3E%3D3.10%2C%3C3.16-3776ab"></a>
|
|
10
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/80-routers/tba-router-wpt-verification/pyproject.toml"><img alt="License: Apache-2.0" src="https://img.shields.io/badge/License-Apache--2.0-525252"></a>
|
|
11
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/80-routers"><img alt="Layer: 80 routers" src="https://img.shields.io/badge/Layer-80%20routers-0a7f5a"></a>
|
|
12
|
+
<a href="https://pypi.org/project/tba-router-wpt-verification/"><img alt="PyPI version for tba-router-wpt-verification" src="https://img.shields.io/pypi/v/tba-router-wpt-verification?label=tba-router-wpt-verification%20PyPI"></a>
|
|
13
|
+
</p>
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://pepy.tech/project/tba-router-wpt-verification"><img alt="Monthly PyPI downloads for tba-router-wpt-verification" src="https://static.pepy.tech/badge/tba-router-wpt-verification/month"></a>
|
|
16
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/80-routers/tba-router-wpt-verification/README.md#verification"><img alt="Evidence: verification" src="https://img.shields.io/badge/Evidence-verification-8250df"></a>
|
|
17
|
+
</p>
|
|
18
|
+
<!-- END TBA README HEADER -->
|
|
19
|
+
|
|
20
|
+
Authenticated remote WIT/WPT verification for a configured recipient.
|
|
21
|
+
|
|
22
|
+
## Quick start
|
|
23
|
+
|
|
24
|
+
Mount `build_wpt_verification_router(verifier=..., audience=...,
|
|
25
|
+
authenticate=..., authorize_verification=...)` on a `TigrblApp`.
|
|
26
|
+
`authenticate` identifies the calling recipient service; the separate
|
|
27
|
+
`authorize_verification` callback must explicitly allow that service to delegate
|
|
28
|
+
verification for the configured audience. These checks precede proof validation.
|
|
29
|
+
|
|
30
|
+
`POST /wpt/verify` accepts:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"workload_identity_token": "<original WIT>",
|
|
35
|
+
"workload_proof_token": "<original WPT, without the WPT scheme prefix>",
|
|
36
|
+
"token_headers": [{"name": "Txn-Token", "value": "<original token>"}]
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`token_headers` is a list so duplicate original headers remain observable and
|
|
41
|
+
are rejected when used as bindings. Do not collapse duplicates before forwarding.
|
|
42
|
+
Caller authentication belongs in this API request's headers, separately from
|
|
43
|
+
the submitted workload proof. Submitted audiences and trust configuration are rejected.
|
|
44
|
+
The audience and `required_token_headers` are selected when mounting. Required
|
|
45
|
+
headers must be present and cryptographically bound; clients cannot disable this
|
|
46
|
+
policy by omitting a header. This strict presence policy is separate from the
|
|
47
|
+
profile's optional `bound_token_headers` binding selector.
|
|
48
|
+
|
|
49
|
+
A successful response contains `valid`, `subject`, `audience`, `proof_id`, and
|
|
50
|
+
`expires_at`. Missing/denied caller credentials return 401/403, malformed requests
|
|
51
|
+
return 400, and invalid or replayed workload proofs return 401. Responses disable
|
|
52
|
+
caching and do not echo tokens. An infrastructure exception fails the request;
|
|
53
|
+
it never returns a successful verification decision.
|
|
54
|
+
|
|
55
|
+
Verification **consumes replay state**. Use the result once for the original
|
|
56
|
+
request; do not preflight it and then verify the same proof again. The result
|
|
57
|
+
authenticates the workload; the recipient still applies resource authorization.
|
|
58
|
+
Transport this delegation over the deployment's authenticated confidential channel.
|
|
59
|
+
|
|
60
|
+
Build from the repository root:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
uv build --wheel pkgs/80-routers/tba-router-wpt-verification
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Verification
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
uv run --extra test pytest pkgs/120-tests/tba-tests-workload-composition/tests/test_wit_wpt_services.py
|
|
70
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tba-router-wpt-verification"
|
|
3
|
+
version = "0.4.0.dev2"
|
|
4
|
+
description = "Authenticated remote WIT/WPT verification for a configured recipient."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10,<3.16"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"tigrbl==0.4.5.dev8",
|
|
10
|
+
"pydantic>=2,<3",
|
|
11
|
+
"tba-concrete-jwt==0.4.0.dev2",
|
|
12
|
+
"tba-profile-workload-proof-wimse-wpt==0.4.0.dev4",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
requires = ["poetry-core>=1.0.0"]
|
|
17
|
+
build-backend = "poetry.core.masonry.api"
|
|
18
|
+
|
|
19
|
+
[tool.poetry]
|
|
20
|
+
packages = [{ include = "tba_router_wpt_verification", from = "src" }]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Delegate WIT/WPT authentication for one deployment-configured recipient."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Awaitable, Callable
|
|
4
|
+
|
|
5
|
+
from tigrbl import JSONResponse, Request, TigrblRouter
|
|
6
|
+
from tba_concrete_jwt import decode_jwt_unverified
|
|
7
|
+
from tba_profile_workload_proof_wimse_wpt import (
|
|
8
|
+
WptProofVerifier,
|
|
9
|
+
normalize_wpt_audience,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from .schemas import WptVerificationRequest, WptVerificationResponse
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def build_wpt_verification_router(
|
|
16
|
+
*,
|
|
17
|
+
verifier: WptProofVerifier,
|
|
18
|
+
audience: str,
|
|
19
|
+
authenticate: Callable[[Request], Awaitable[str | None]],
|
|
20
|
+
authorize_verification: Callable[[str], Awaitable[bool]],
|
|
21
|
+
required_token_headers: tuple[str, ...] = (),
|
|
22
|
+
) -> TigrblRouter:
|
|
23
|
+
"""Authenticate the delegating service before consuming any proof replay state.
|
|
24
|
+
|
|
25
|
+
The caller must forward the original request's WIT, WPT and token headers,
|
|
26
|
+
including duplicates. It uses the returned identity for that request once;
|
|
27
|
+
this is not a non-consuming token-inspection endpoint.
|
|
28
|
+
"""
|
|
29
|
+
recipient = normalize_wpt_audience(audience)
|
|
30
|
+
required = tuple(name.lower() for name in required_token_headers)
|
|
31
|
+
if any(name in {"authorization", "workload-identity-token"} for name in required):
|
|
32
|
+
raise ValueError("credential headers cannot be additional token bindings")
|
|
33
|
+
router = TigrblRouter()
|
|
34
|
+
|
|
35
|
+
def reject(status: int, detail: str):
|
|
36
|
+
return JSONResponse(
|
|
37
|
+
{"detail": detail},
|
|
38
|
+
status_code=status,
|
|
39
|
+
headers={"Cache-Control": "no-store"},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
@router.route(
|
|
43
|
+
"/wpt/verify", methods=["POST"], response_model=WptVerificationResponse
|
|
44
|
+
)
|
|
45
|
+
async def verify(request: Request):
|
|
46
|
+
principal = await authenticate(request)
|
|
47
|
+
if not principal:
|
|
48
|
+
return reject(401, "verification caller authentication required")
|
|
49
|
+
if await authorize_verification(principal) is not True:
|
|
50
|
+
return reject(403, "verification caller is not authorized")
|
|
51
|
+
try:
|
|
52
|
+
body = WptVerificationRequest.model_validate(await request.json())
|
|
53
|
+
if any(
|
|
54
|
+
header.name.lower() in {"authorization", "workload-identity-token"}
|
|
55
|
+
for header in body.token_headers
|
|
56
|
+
):
|
|
57
|
+
raise ValueError("credential header in token headers")
|
|
58
|
+
except (ValueError, TypeError):
|
|
59
|
+
return reject(400, "invalid proof verification request")
|
|
60
|
+
headers = [
|
|
61
|
+
("Workload-Identity-Token", body.workload_identity_token),
|
|
62
|
+
("Authorization", f"WPT {body.workload_proof_token}"),
|
|
63
|
+
*((header.name, header.value) for header in body.token_headers),
|
|
64
|
+
]
|
|
65
|
+
try:
|
|
66
|
+
wit = verifier.authenticate_request(
|
|
67
|
+
headers, audience=recipient, required_token_headers=required
|
|
68
|
+
)
|
|
69
|
+
except (ValueError, TypeError, KeyError, UnicodeError):
|
|
70
|
+
return reject(401, "workload proof verification failed")
|
|
71
|
+
# authenticate_request has verified this proof and reserved its replay
|
|
72
|
+
# identifier. Decoding the same token here does not verify it a second time.
|
|
73
|
+
claims = decode_jwt_unverified(body.workload_proof_token).claims
|
|
74
|
+
payload = WptVerificationResponse(
|
|
75
|
+
valid=True,
|
|
76
|
+
subject=wit.claims["sub"],
|
|
77
|
+
audience=recipient,
|
|
78
|
+
proof_id=claims["jti"],
|
|
79
|
+
expires_at=claims["exp"],
|
|
80
|
+
)
|
|
81
|
+
return JSONResponse(payload.model_dump(), headers={"Cache-Control": "no-store"})
|
|
82
|
+
|
|
83
|
+
return router
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Bounded request values for an authenticated verification delegation."""
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TokenHeader(BaseModel):
|
|
7
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
8
|
+
|
|
9
|
+
name: str = Field(min_length=1, max_length=128, pattern=r"^[A-Za-z][A-Za-z0-9-]*$")
|
|
10
|
+
value: str = Field(min_length=1, max_length=16384, pattern=r"^[\x21-\x7e]+$")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class WptVerificationRequest(BaseModel):
|
|
14
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
15
|
+
|
|
16
|
+
workload_identity_token: str = Field(min_length=1, max_length=16384)
|
|
17
|
+
workload_proof_token: str = Field(min_length=1, max_length=16384)
|
|
18
|
+
token_headers: list[TokenHeader] = Field(default_factory=list, max_length=32)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class WptVerificationResponse(BaseModel):
|
|
22
|
+
valid: bool
|
|
23
|
+
subject: str
|
|
24
|
+
audience: str
|
|
25
|
+
proof_id: str
|
|
26
|
+
expires_at: float
|