Commit cf1e783
authored
Add support for Unframing SigV4 signed messages for Servers (#4356)
# SigV4 Event Stream Support for Server SDK
## Problem
Clients wrap event stream messages in SigV4 envelopes with signature
headers (`:chunk-signature`, `:date`), but servers couldn't parse these
signed messages because they expected the raw event shape, not the
envelope.
## Solution
Added server-side SigV4 event stream unsigning support that
automatically extracts inner messages from signed envelopes while
maintaining compatibility with unsigned messages.
## Implementation
### Type System Changes
Event stream types are wrapped to handle both signed and unsigned
messages:
- `Receiver<Events, Error>` → `Receiver<SignedEvent<Events>,
SignedEventError<Error>>`
- `SignedEvent<T>` provides access to both the inner message and
signature information
- `SignedEventError<E>` wraps both extraction errors and underlying
event errors
### Runtime Components
**SigV4Unmarshaller**: Wraps the base event stream unmarshaller to
handle SigV4 extraction:
```rust
impl<T: UnmarshallMessage> UnmarshallMessage for SigV4Unmarshaller<T> {
type Output = SignedEvent<T::Output>;
type Error = SignedEventError<T::Error>;
fn unmarshall(&self, message: &Message) -> Result<...> {
match extract_signed_message(message) {
Ok(Signed { message: inner, signature }) => {
// Process inner message with base unmarshaller
self.inner.unmarshall(&inner).map(|event| SignedEvent {
message: event,
signature: Some(signature),
})
}
Ok(Unsigned) => {
// Process unsigned message directly
self.inner.unmarshall(message).map(|event| SignedEvent {
message: event,
signature: None,
})
}
Err(err) => Ok(SignedEventError::InvalidSignedEvent(err))
}
}
}
```
### Code Generation Integration
**SigV4EventStreamDecorator**:
- Detects services with `@sigv4` trait and event streams
- Wraps event stream types using `SigV4EventStreamSymbolProvider`
- Generates support structures (`SignedEvent`, `SigV4Unmarshaller`,
etc.)
- Injects unmarshaller wrapping via HTTP binding customizations
**HTTP Binding Customization**:
- Added `BeforeCreatingEventStreamReceiver` section to
`HttpBindingGenerator`
- Allows decorators to wrap the unmarshaller before `Receiver` creation
- Generates: `let unmarshaller = SigV4Unmarshaller::new(unmarshaller);`
### Usage
Server handlers receive `SignedEvent<T>` and extract the inner message:
```rust
async fn streaming_operation_handler(input: StreamingOperationInput) -> Result<...> {
let event = input.events.recv().await?;
if let Some(signed_event) = event {
let actual_event = &signed_event.message; // Extract inner message
let signature_info = &signed_event.signature; // Access signature if present
// Process actual_event...
}
}
```
## Testing
- Added `test_sigv4_signed_event_stream` that sends SigV4-wrapped events
- Verifies both signed and unsigned messages work correctly
- All existing event stream tests continue to pass
## Architecture Benefits
- **Backward Compatible**: Unsigned messages work unchanged
- **Type Safe**: Compile-time guarantees about message structure
- **Extensible**: Pattern can be applied to other authentication schemes
- **Minimal Impact**: Only affects services with `@sigv4` trait and
event streams
## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] For changes to the smithy-rs codegen or runtime crates, I have
created a changelog entry Markdown file in the `.changelog` directory,
specifying "client," "server," or both in the `applies_to` key.
- [ ] For changes to the AWS SDK, generated SDK code, or SDK runtime
crates, I have created a changelog entry Markdown file in the
`.changelog` directory, specifying "aws-sdk-rust" in the `applies_to`
key.
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._1 parent 1de7020 commit cf1e783
File tree
21 files changed
+750
-76
lines changed- .changelog
- codegen-core
- common-test-models
- src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy
- generators/http
- codegen-server-test/integration-tests
- eventstreams/tests
- codegen-server
- codegen-server-typescript/src/main/kotlin/software/amazon/smithy/rust/codegen/server/typescript/smithy
- src
- main/kotlin/software/amazon/smithy/rust/codegen/server/smithy
- customizations
- customize
- generators/http
- protocols
- testutil
- test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations
- examples
- pokemon-service-tls/tests/common
- pokemon-service/tests/common
21 files changed
+750
-76
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
51 | 71 | | |
52 | 72 | | |
53 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
87 | 90 | | |
88 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
| |||
Lines changed: 23 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
99 | 105 | | |
100 | 106 | | |
101 | 107 | | |
| |||
272 | 278 | | |
273 | 279 | | |
274 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
275 | 298 | | |
276 | 299 | | |
277 | 300 | | |
278 | 301 | | |
279 | | - | |
280 | 302 | | |
281 | 303 | | |
282 | 304 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 60 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
152 | | - | |
| 154 | + | |
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
| |||
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
177 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
183 | | - | |
| 187 | + | |
184 | 188 | | |
185 | 189 | | |
186 | 190 | | |
| |||
229 | 233 | | |
230 | 234 | | |
231 | 235 | | |
232 | | - | |
| 236 | + | |
233 | 237 | | |
234 | 238 | | |
235 | 239 | | |
| |||
348 | 352 | | |
349 | 353 | | |
350 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
351 | 388 | | |
352 | 389 | | |
353 | 390 | | |
| |||
439 | 476 | | |
440 | 477 | | |
441 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
442 | 497 | | |
443 | 498 | | |
444 | 499 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
Lines changed: 14 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | 127 | | |
138 | | - | |
139 | 128 | | |
140 | 129 | | |
141 | 130 | | |
| |||
146 | 135 | | |
147 | 136 | | |
148 | 137 | | |
149 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| |||
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| 164 | + | |
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
| |||
0 commit comments