[PR #6791] [MERGED] [proxy] Bedrock cost-allocation metadata + per-provider metadata_disabled #29897

Closed
opened 2026-08-05 08:09:21 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6791
Author: @mlsmaycon
Created: 7/15/2026
Status: Merged
Merged: 7/20/2026
Merged by: @braginini

Base: mainHead: feature/agentnet-provider-metadata


📝 Commits (2)

  • d6ab06e [proxy] forward Bedrock cost-allocation metadata + per-provider metadata_disabled
  • b04962a Merge branch 'main' into feature/agentnet-provider-metadata

📊 Changes

10 files changed (+256 additions, -5 deletions)

View changed files

📝 management/internals/modules/agentnetwork/catalog/catalog.go (+18 -0)
📝 management/internals/modules/agentnetwork/synthesizer.go (+7 -3)
📝 management/internals/modules/agentnetwork/synthesizer_test.go (+88 -0)
📝 management/internals/modules/agentnetwork/types/provider.go (+10 -0)
📝 management/internals/modules/agentnetwork/types/provider_test.go (+35 -0)
📝 proxy/internal/middleware/builtin/llm_identity_inject/factory.go (+5 -0)
📝 proxy/internal/middleware/builtin/llm_identity_inject/middleware.go (+38 -2)
📝 proxy/internal/middleware/builtin/llm_identity_inject/middleware_test.go (+40 -0)
📝 shared/management/http/api/openapi.yml (+9 -0)
📝 shared/management/http/api/types.gen.go (+6 -0)

📄 Description

Describe your changes

Two related Agent Network provider-metadata features.

A. AWS Bedrock cost-allocation metadata (netbirdio/netbird#6765). The proxy now stamps the caller's user and authorizing group onto Bedrock requests via the X-Amzn-Bedrock-Request-Metadata header, so spend can be attributed in AWS Cost Management via cost-allocation tags. This reuses the existing llm_identity_inject JSONMetadata shape — the bedrock_api catalog entry now declares IdentityInjection.JSONMetadata{Header: "X-Amzn-Bedrock-Request-Metadata", UserKey: "user", GroupsKey: "group"}. Because Bedrock restricts the metadata value character set (letters/digits/space + + - = . _ : / @), a new Sanitize option on the JSONMetadata shape replaces out-of-set characters (notably the groups-CSV comma and arbitrary characters in group display names) with _, so requests aren't rejected with 400. The group value is the authorizing group(s) — the same value already sent to every other gateway — for consistent tracking.

B. Per-provider metadata_disabled flag (default false). Identity metadata (user + authorizing group) is injected by default; setting metadata_disabled on a provider suppresses the identity shape in the synthesizer while leaving catalog routing ExtraHeaders (e.g. x-portkey-config) intact. Plumbed exactly like skip_tls_verification: OpenAPI → generated types → management provider type (FromAPIRequest/ToAPIResponse, gorm column via AutoMigrate) → synthesizer gate.

Out of scope (per the discussion): X-Amzn-Bedrock-Service-Tier, and the additional metadata fields (policy/guardrails) deferred to a later "metadata customization for all providers" change.

https://github.com/netbirdio/netbird/discussions/6765

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

This adds an optional provider setting and a new upstream header for Bedrock; discussed in netbirdio/netbird#6765.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Narrative docs added in netbirdio/docs (Bedrock cost-allocation section + provider "disable metadata" setting); the API reference picks up the new metadata_disabled field automatically from OpenAPI.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/857

Tests

  • llm_identity_inject: sanitization path emits the Bedrock header with commas/# replaced and @/. preserved.
  • synthesizer: Bedrock provider yields the X-Amzn-Bedrock-Request-Metadata JSONMetadata rule (Sanitize on); metadata_disabled drops the provider's identity-inject entry.
  • provider type: metadata_disabled request→provider→response round-trip (nil preserves, explicit false clears).

Note: a full through-tunnel e2e assertion of the header is a follow-up — the agent-network e2e currently depends on the in-flight DNS warm-up + Bedrock-routing PRs to get past the proxy-peer gate.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features

    • Added a provider setting to disable identity metadata injection on upstream requests.
    • Added support for sanitized identity metadata values, replacing unsupported characters before transmission.
    • Added Bedrock integration for forwarding user and group metadata through the reserved request-metadata header.
    • Exposed the new setting through the provider API, including update and response support.
  • Bug Fixes

    • Prevented identity metadata from being added when metadata injection is disabled.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/6791 **Author:** [@mlsmaycon](https://github.com/mlsmaycon) **Created:** 7/15/2026 **Status:** ✅ Merged **Merged:** 7/20/2026 **Merged by:** [@braginini](https://github.com/braginini) **Base:** `main` ← **Head:** `feature/agentnet-provider-metadata` --- ### 📝 Commits (2) - [`d6ab06e`](https://github.com/netbirdio/netbird/commit/d6ab06e59fe633280c0d3c3ee23f8619fd6be1ea) [proxy] forward Bedrock cost-allocation metadata + per-provider metadata_disabled - [`b04962a`](https://github.com/netbirdio/netbird/commit/b04962afab1f61af37506a0789e2633899066275) Merge branch 'main' into feature/agentnet-provider-metadata ### 📊 Changes **10 files changed** (+256 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `management/internals/modules/agentnetwork/catalog/catalog.go` (+18 -0) 📝 `management/internals/modules/agentnetwork/synthesizer.go` (+7 -3) 📝 `management/internals/modules/agentnetwork/synthesizer_test.go` (+88 -0) 📝 `management/internals/modules/agentnetwork/types/provider.go` (+10 -0) 📝 `management/internals/modules/agentnetwork/types/provider_test.go` (+35 -0) 📝 `proxy/internal/middleware/builtin/llm_identity_inject/factory.go` (+5 -0) 📝 `proxy/internal/middleware/builtin/llm_identity_inject/middleware.go` (+38 -2) 📝 `proxy/internal/middleware/builtin/llm_identity_inject/middleware_test.go` (+40 -0) 📝 `shared/management/http/api/openapi.yml` (+9 -0) 📝 `shared/management/http/api/types.gen.go` (+6 -0) </details> ### 📄 Description ## Describe your changes Two related Agent Network provider-metadata features. **A. AWS Bedrock cost-allocation metadata** (netbirdio/netbird#6765). The proxy now stamps the caller's `user` and authorizing `group` onto Bedrock requests via the `X-Amzn-Bedrock-Request-Metadata` header, so spend can be attributed in AWS Cost Management via cost-allocation tags. This reuses the existing `llm_identity_inject` **JSONMetadata** shape — the `bedrock_api` catalog entry now declares `IdentityInjection.JSONMetadata{Header: "X-Amzn-Bedrock-Request-Metadata", UserKey: "user", GroupsKey: "group"}`. Because Bedrock restricts the metadata value character set (letters/digits/space + `+ - = . _ : / @`), a new `Sanitize` option on the JSONMetadata shape replaces out-of-set characters (notably the groups-CSV comma and arbitrary characters in group display names) with `_`, so requests aren't rejected with 400. The group value is the authorizing group(s) — the same value already sent to every other gateway — for consistent tracking. **B. Per-provider `metadata_disabled` flag** (default false). Identity metadata (user + authorizing group) is injected by default; setting `metadata_disabled` on a provider suppresses the identity shape in the synthesizer while leaving catalog routing `ExtraHeaders` (e.g. `x-portkey-config`) intact. Plumbed exactly like `skip_tls_verification`: OpenAPI → generated types → management provider type (`FromAPIRequest`/`ToAPIResponse`, gorm column via AutoMigrate) → synthesizer gate. Out of scope (per the discussion): `X-Amzn-Bedrock-Service-Tier`, and the additional metadata fields (policy/guardrails) deferred to a later "metadata customization for all providers" change. ## Issue ticket number and link https://github.com/netbirdio/netbird/discussions/6765 ## Stack <!-- branch-stack --> ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) - [ ] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — **OR** I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#discuss-changes-with-the-netbird-team-first). > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). This adds an optional provider setting and a new upstream header for Bedrock; discussed in netbirdio/netbird#6765. ## Documentation Select exactly one: - [x] I added/updated documentation for this change - [ ] Documentation is **not needed** for this change (explain why) Narrative docs added in netbirdio/docs (Bedrock cost-allocation section + provider "disable metadata" setting); the API reference picks up the new `metadata_disabled` field automatically from OpenAPI. ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/857 ## Tests - `llm_identity_inject`: sanitization path emits the Bedrock header with commas/`#` replaced and `@`/`.` preserved. - synthesizer: Bedrock provider yields the `X-Amzn-Bedrock-Request-Metadata` JSONMetadata rule (Sanitize on); `metadata_disabled` drops the provider's identity-inject entry. - provider type: `metadata_disabled` request→provider→response round-trip (nil preserves, explicit false clears). Note: a full through-tunnel e2e assertion of the header is a follow-up — the agent-network e2e currently depends on the in-flight DNS warm-up + Bedrock-routing PRs to get past the proxy-peer gate. <!-- codesmith:footer --> --- <a href="https://app.blacksmith.sh/netbirdio/codesmith/netbird/pr/6791"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-light-v2.svg"><img alt="View with Codesmith" src="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"></picture></a> <a href="https://backend.blacksmith.sh/track/enable-autofix?expires=1786749463&installation_id=146802194&pr_number=6791&repository=netbirdio%2Fnetbird&return_to=https%3A%2F%2Fgithub.com%2Fnetbirdio%2Fnetbird%2Fpull%2F6791&signature=02924c8b3129a9be14bd2cb74f5f1f455af94153ed895a9d3bb0939316761f90"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img alt="Autofix with Codesmith" src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"></picture></a> <sup>Need help on this PR? Tag <code>/codesmith</code> with what you need. Autofix is disabled.</sup> <!-- codesmith:autofix:disabled --> <!-- /codesmith:footer --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a provider setting to disable identity metadata injection on upstream requests. - Added support for sanitized identity metadata values, replacing unsupported characters before transmission. - Added Bedrock integration for forwarding user and group metadata through the reserved request-metadata header. - Exposed the new setting through the provider API, including update and response support. - **Bug Fixes** - Prevented identity metadata from being added when metadata injection is disabled. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 08:09:21 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#29897