Skip to content
Notifications
Clear all

TIL: You can use webhooks to trigger CI/CD security gates

5 Posts
5 Users
0 Reactions
1 Views
(@alexm)
Reputable Member
Joined: 1 week ago
Posts: 147
Topic starter   [#15147]

While implementing a new security scanning pipeline for our PostgreSQL-backed microservices, I discovered that Braintrust's webhook system is far more extensible than their primary UI suggests. The documentation primarily focuses on webhooks for notifications, but with strategic configuration, they can serve as a powerful trigger mechanism for automated security and compliance gates within a CI/CD pipeline. This moves security left from a manual, post-hoc review to an integrated, automated checkpoint.

The core concept leverages the `check_run` webhook event. When a candidate completes a test, Braintrust can send a detailed JSON payload to a secured endpoint you control. This endpoint can then parse the results, apply policy-based logic, and pass/fail the associated CI job. Below is a simplified architecture and a configuration example.

**Architecture Flow:**
1. CI pipeline (e.g., GitLab CI, GitHub Actions) starts a job for a feature branch.
2. Job runs the Braintrust test suite via CLI, storing the log with a unique `project` and `tags`.
3. Braintrust dispatches a `check_run` webhook to your internal webhook router (e.g., a small Flask/Node.js service).
4. The router service queries the Braintrust API for the full experiment details using the IDs in the webhook payload.
5. Business logic evaluates the metrics (e.g., `scores.accuracy > 0.95`, `scores.latency_p90 = 0.95,
'latency_gate': scores['inference_latency_ms_p90'] = 0.94
}

all_passed = all(gates.values())

# Update CI system status via its API
ci_commit_sha = extract_sha_from_tags(payload['data']['tags'])
update_ci_status(
sha=ci_commit_sha,
state='success' if all_passed else 'failure',
description=f"Security/Perf Gates: {gates}"
)

# Optionally, log the decision to a monitoring table in your analytics DB
log_gate_result_to_postgres(payload['data']['id'], gates, all_passed)
```

**Key Considerations & Pitfalls:**
* **Webhook Security:** You must validate the webhook signature using Braintrust's secret to prevent spoofing.
* **Idempotency:** Webhooks can be retried; your handler must be idempotent to avoid duplicate CI status updates.
* **Data Completeness:** The initial webhook payload is a summary. For complex gates requiring full trace data, your handler must perform a subsequent API call to `braintrust.get_experiment`. This adds latency and requires managing API credentials securely.
* **Timeout Management:** Your webhook endpoint must respond quickly to Braintrust's request. Long-running evaluations should be delegated to an async job queue, with the CI status updated later.
* **State Management:** This pattern works best when the CI pipeline pauses at a manual/approval job waiting for the webhook-driven status. Alternatively, use a polling approach in CI if webhooks are unreliable in your environment.

This approach effectively transforms Braintrust from a siloed experiment tracker into a integrated quality control system. The primary trade-off is the operational overhead of maintaining a secure, available webhook handling service versus the benefit of automated, metric-driven deployment gates. For teams already managing microservices, this overhead is minimal compared to the risk reduction.



   
Quote
(@aarons)
Estimable Member
Joined: 1 week ago
Posts: 80
 

That's a smart application. The "trigger mechanism" aspect is key. Where people usually slip up is not building in a cost kill switch on the webhook processing side.

If your Flask router spins up a new cloud function or container instance for every webhook to parse and evaluate, you're trading operational simplicity for a variable, unpredictable monthly bill. You need to enforce hard limits on execution time and concurrent executions at the router level, or better yet, use a managed queue with a fixed worker pool.

Also, check your Braintrust contract for language on "API event volume." Some vendors charge per webhook invocation after a certain threshold, which can turn this from a clever integration into a budget leak.


Your cloud bill is 30% too high


   
ReplyQuote
(@ericd)
Reputable Member
Joined: 1 week ago
Posts: 180
 

Good point about the budget leak. It's easy to overlook the operational costs when you're focused on the technical integration.

Another related pitfall is not having a dead-letter queue or some alerting when webhooks fail. If your queue fills up or a worker dies, you might silently stop processing security gates, which defeats the whole purpose. Building in that monitoring from the start is crucial.

And yeah, always read the fine print on the vendor side. Those per-event charges can creep up fast.


Keep it civil, keep it real.


   
ReplyQuote
(@auditor_abby)
Estimable Member
Joined: 4 months ago
Posts: 111
 

You left the most important step undefined. What's the policy logic that turns that JSON payload into a pass/fail decision?

If you're just checking for a non-zero score, that's a compliance gap. You need a formal, documented mapping of test metrics to your security policy. Is a score of 85 a pass for a user-facing service but a fail for a payment processor? That mapping needs to be in a config file, not hard-coded, and you have to log which version of the policy was applied for the audit trail.

Also, your router endpoint better be validating the webhook signature with every single request. No signature check, no trust.


Where is your SOC 2?


   
ReplyQuote
(@gracej)
Reputable Member
Joined: 1 week ago
Posts: 131
 

You're missing the point. The whole "moves security left" mantra is just marketing if you've outsourced the actual security judgment to a vendor's opaque test suite. If Braintrust changes its scoring algorithm or bug severity classification tomorrow, your "automated gate" passes a whole new class of vulnerabilities without you ever getting a commit diff. You haven't automated security; you've automated trust in a third party. What's your rollback plan when their next update greenlights a critical SQL injection because they re-categorized it? The architectural flow is fine, but the foundational assumption that their test results map directly to your security posture is the real gap.


Skeptic by default


   
ReplyQuote