-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathmodels.py
More file actions
191 lines (176 loc) · 5.32 KB
/
Copy pathmodels.py
File metadata and controls
191 lines (176 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""Models for BedrockAgentCore runtime.
Contains data models and enums used throughout the runtime system.
"""
from enum import Enum
class PingStatus(str, Enum):
"""Ping status enum for health check responses."""
HEALTHY = "Healthy"
HEALTHY_BUSY = "HealthyBusy"
# Header constants
SESSION_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id"
REQUEST_ID_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Request-Id"
ACCESS_TOKEN_HEADER = "WorkloadAccessToken" # nosec
OAUTH2_CALLBACK_URL_HEADER = "OAuth2CallbackUrl"
AUTHORIZATION_HEADER = "Authorization"
CUSTOM_HEADER_PREFIX = "X-Amzn-Bedrock-AgentCore-Runtime-Custom-"
AGENTCORE_RUNTIME_URL_ENV = "AGENTCORE_RUNTIME_URL"
# Headers that cannot be forwarded to agent code.
# Source: https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-header-allowlist.html
RESTRICTED_HEADERS: frozenset[str] = frozenset(
h.lower()
for h in [
# Authentication & Authorization
"Proxy-Authorization",
"WWW-Authenticate",
# Content Negotiation
"Accept",
"Accept-Charset",
"Accept-Encoding",
"Accept-Language",
"Content-Type",
"Content-Length",
"Content-Encoding",
"Content-Language",
"Content-Location",
"Content-Range",
# Caching
"Cache-Control",
"ETag",
"Expires",
"If-Match",
"If-Modified-Since",
"If-None-Match",
"If-Range",
"If-Unmodified-Since",
"Last-Modified",
"Pragma",
"Vary",
# Connection Management
"Connection",
"Keep-Alive",
"Proxy-Connection",
"Upgrade",
# Request Context
"Host",
"User-Agent",
"Referer",
"From",
# Range / Transfer
"Range",
"Accept-Ranges",
"Transfer-Encoding",
"TE",
"Trailer",
# Server Information
"Server",
"Date",
"Location",
"Retry-After",
# Cookies
"Set-Cookie",
"Cookie",
# Security
"Content-Security-Policy",
"Content-Security-Policy-Report-Only",
"Strict-Transport-Security",
"X-Content-Type-Options",
"X-Frame-Options",
"X-XSS-Protection",
"Referrer-Policy",
"Permissions-Policy",
"Cross-Origin-Embedder-Policy",
"Cross-Origin-Opener-Policy",
"Cross-Origin-Resource-Policy",
# CORS
"Access-Control-Allow-Origin",
"Access-Control-Allow-Methods",
"Access-Control-Allow-Headers",
"Access-Control-Allow-Credentials",
"Access-Control-Expose-Headers",
"Access-Control-Max-Age",
"Access-Control-Request-Method",
"Access-Control-Request-Headers",
"Origin",
# Client Hints
"Accept-CH",
"Accept-CH-Lifetime",
"DPR",
"Width",
"Viewport-Width",
"Downlink",
"ECT",
"RTT",
"Save-Data",
# Experimental / Proposed
"Clear-Site-Data",
"Feature-Policy",
"Expect-CT",
"Public-Key-Pins",
"Public-Key-Pins-Report-Only",
# Proxy
"Via",
"Forwarded",
"X-Forwarded-For",
"X-Forwarded-Host",
"X-Forwarded-Proto",
"X-Real-IP",
"X-Requested-With",
"X-CSRF-Token",
# IP Spoofing / URL Manipulation
"True-Client-IP",
"X-Client-IP",
"X-Cluster-Client-IP",
"X-Originating-IP",
"X-Source-IP",
"X-Original-URL",
"X-Original-Host",
"X-Rewrite-URL",
# CDN / Proxy
"CF-Ray",
"CF-Connecting-IP",
"X-Amz-Cf-Id",
"X-Cache",
"X-Served-By",
# HTTP/2 Pseudo Headers
":method",
":path",
":scheme",
":authority",
":status",
# Server Push
"Link",
# WebSocket
"Sec-WebSocket-Key",
"Sec-WebSocket-Accept",
"Sec-WebSocket-Version",
"Sec-WebSocket-Protocol",
"Sec-WebSocket-Extensions",
]
)
# Baggage keys for routing experiment span attributes
BAGGAGE_KEY_EXPERIMENT_ARN = "aws.agentcore.gateway.routing_experiment_arn"
BAGGAGE_KEY_EXPERIMENT_VARIANT = "aws.agentcore.gateway.routing_experiment_variant_name"
# Task action constants
TASK_ACTION_PING_STATUS = "ping_status"
TASK_ACTION_JOB_STATUS = "job_status"
TASK_ACTION_FORCE_HEALTHY = "force_healthy"
TASK_ACTION_FORCE_BUSY = "force_busy"
TASK_ACTION_CLEAR_FORCED_STATUS = "clear_forced_status"
_CUSTOM_HEADER_PREFIX_LOWER = CUSTOM_HEADER_PREFIX.lower()
_AUTHORIZATION_HEADER_LOWER = AUTHORIZATION_HEADER.lower()
def is_forwardable_header(header_name: str) -> bool:
"""Return True if the header may be forwarded to agent code.
Rules (from the AgentCore runtime header allowlist docs):
- Not in the restricted headers list
- Does not start with ``x-amz-`` (reserved for AWS SigV4 signing)
- Does not start with ``x-amzn-`` unless it starts with the legacy
``X-Amzn-Bedrock-AgentCore-Runtime-Custom-`` prefix
"""
lower = header_name.lower()
if lower in RESTRICTED_HEADERS:
return False
if lower.startswith("x-amz-"):
return False
if lower.startswith("x-amzn-") and not lower.startswith(_CUSTOM_HEADER_PREFIX_LOWER):
return False
return True