Skip to content

chore(confinement): create UnconfinedTemplate and ConfinedTemplate abstractions - #25938

Merged
thomasqueirozb merged 31 commits into
masterfrom
chore/confined-template-pattern
Jul 27, 2026
Merged

chore(confinement): create UnconfinedTemplate and ConfinedTemplate abstractions#25938
thomasqueirozb merged 31 commits into
masterfrom
chore/confined-template-pattern

Conversation

@thomasqueirozb

@thomasqueirozb thomasqueirozb commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

Introduces template path-confinement as a first-class, type-enforced security control for sinks, so that a log producer that controls an event field used in a templated destination (file path, URL, Kafka topic, Redis key, tenant ID, …) cannot steer a sink to write outside an operator-authored boundary.

The type model

Three template types make the confinement contract impossible to bypass:

  • new Template — the type sink config structs store. It is serde-able and renders as a plain string in generated schemas, but exposes no render method. The only thing a sink can do with it is call `.confine()``.
  • new ConfinedTemplate (= Confined<UnconfinedTemplate>) — the render-capable type, obtainable only via .confine(). It is deliberately not deserializable and its fields are module-private, so it can never be constructed (or deserialized) without going through confinement. There is no way to render a configured template without first confining it. The chain is always Template -> confine() -> ConfinedTemplate -> render().
  • renamed: previously called Template UnconfinedTemplate — deserializable and renderable, for transforms/sources and the few sinks that intentionally render without a confinement boundary (they render arbitrary attribute values, not routing/destination values).

How did you test this PR?

Unit tests cover prefix/URI confinement, traversal and injection bypass attempts, startup rejection, and the opt-out path. make fmt, make check-clippy, and make test all pass (3262 tests passed, 13 skipped).

Change Type

  • Bug fix
  • New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

NA

@thomasqueirozb thomasqueirozb added the no-changelog Changes in this PR do not need user-facing explanations in the release changelog label Jul 23, 2026
@github-actions github-actions Bot added domain: transforms Anything related to Vector's transform components domain: sinks Anything related to the Vector's sinks labels Jul 23, 2026
@ghost

ghost commented Jul 24, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 17f43c9 | Docs | Datadog PR Page | Give us feedback!

Comment thread src/sinks/clickhouse/config.rs Outdated
Comment thread src/sinks/clickhouse/config.rs Outdated
Comment thread src/sinks/elasticsearch/config.rs Outdated
Comment thread src/sinks/elasticsearch/tests.rs Outdated
Comment thread src/sinks/util/http.rs Outdated
Comment thread src/sinks/splunk_hec/metrics/config.rs Outdated

@pront pront left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea here: first submit a PR including just the the renaming of Template to UnconfinedTemplate. It should make this one easier to review later.

@thomasqueirozb

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce16c183d0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/template.rs Outdated
@thomasqueirozb thomasqueirozb changed the title chore(confinement): create UnconfinedTemplate and Confined<> abstractions chore(confinement): create UnconfinedTemplate and ConfinedTemplate abstractions Jul 24, 2026
Comment thread src/sinks/file/mod.rs
docs::warnings = "Rendered paths are confined to `base_dir` (derived from the literal prefix of `path` when unset). See the `base_dir` option."
))]
pub path: Template,
pub path: UnconfinedTemplate,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be addressed in a followup, but we should have a file-specific type similar to Template so that grabbing the resolved path is not possible unless confinement is applied

@thomasqueirozb
thomasqueirozb marked this pull request as ready for review July 24, 2026 20:46
@thomasqueirozb
thomasqueirozb requested a review from a team as a code owner July 24, 2026 20:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 821f491158

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/sinks/gcp_chronicle/chronicle_unstructured.rs
Comment thread src/template.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a063bab69

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/template.rs

@pront pront left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, mostly left nits about comments. I will come back for round 2 after these are addressed.

Comment thread src/template.rs Outdated
Comment thread src/template.rs Outdated
Comment thread src/template.rs Outdated
Comment thread src/template.rs Outdated
Comment thread src/template.rs
Comment thread src/template.rs Outdated
@thomasqueirozb
thomasqueirozb requested a review from pront July 27, 2026 14:51
Comment thread src/template.rs Outdated
Comment thread src/template.rs Outdated
Comment thread src/template.rs
Comment thread src/template.rs Outdated

@pront pront left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good refactoring.

@thomasqueirozb

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 17f43c9cfe

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@thomasqueirozb
thomasqueirozb enabled auto-merge July 27, 2026 17:31
@thomasqueirozb
thomasqueirozb added this pull request to the merge queue Jul 27, 2026
Merged via the queue into master with commit d460506 Jul 27, 2026
61 checks passed
@thomasqueirozb
thomasqueirozb deleted the chore/confined-template-pattern branch July 27, 2026 18:15
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

domain: sinks Anything related to the Vector's sinks domain: transforms Anything related to Vector's transform components no-changelog Changes in this PR do not need user-facing explanations in the release changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants