Skip to content

Commit bd24c82

Browse files
reeceyangConvex, Inc.
authored andcommitted
Add x-webhook-signature header to webhook log stream requests (#43381)
GitOrigin-RevId: 46d4a18b755e059cd51c3cbfb770bd53fb84c47e
1 parent ea63494 commit bd24c82

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/log_streaming/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ testing = [
2222
[dependencies]
2323
anyhow = { workspace = true }
2424
async-trait = { workspace = true }
25+
aws-lc-rs = { workspace = true }
2526
bytes = { workspace = true }
2627
common = { workspace = true }
2728
convex_macro = { workspace = true }
2829
database = { workspace = true }
2930
errors = { workspace = true }
3031
futures = { workspace = true }
32+
hex = { workspace = true }
3133
http = { workspace = true }
3234
keybroker = { workspace = true }
3335
maplit = { workspace = true }

crates/log_streaming/src/sinks/webhook.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ use std::{
33
sync::Arc,
44
};
55

6+
use aws_lc_rs::hmac::{
7+
self,
8+
HMAC_SHA256,
9+
};
610
use bytes::Bytes;
711
use common::{
812
backoff::Backoff,
@@ -23,7 +27,11 @@ use errors::{
2327
ErrorMetadata,
2428
ErrorMetadataAnyhowExt,
2529
};
26-
use http::header::CONTENT_TYPE;
30+
use hex::ToHex;
31+
use http::{
32+
header::CONTENT_TYPE,
33+
HeaderValue,
34+
};
2735
use model::log_sinks::types::webhook::{
2836
WebhookConfig,
2937
WebhookFormat,
@@ -166,9 +174,17 @@ impl<RT: Runtime> WebhookSink<RT> {
166174
};
167175
let payload = Bytes::from(payload);
168176

169-
// Make request in a loop that retries on transient errors
170-
let headers = HeaderMap::from_iter([(CONTENT_TYPE, APPLICATION_JSON_CONTENT_TYPE)]);
177+
// Create HMAC-SHA256 signature
178+
let s_key = hmac::Key::new(HMAC_SHA256, self.config.hmac_secret.as_ref());
179+
let signature: String = hmac::sign(&s_key, &payload).encode_hex();
171180

181+
let mut headers = HeaderMap::from_iter([(CONTENT_TYPE, APPLICATION_JSON_CONTENT_TYPE)]);
182+
headers.append(
183+
"x-webhook-signature",
184+
HeaderValue::from_str(format!("sha256={signature}").as_str())?,
185+
);
186+
187+
// Make request in a loop that retries on transient errors
172188
for _ in 0..consts::WEBHOOK_SINK_MAX_REQUEST_ATTEMPTS {
173189
let response = self
174190
.fetch_client

0 commit comments

Comments
 (0)