Skip to content

(Connectors) MongoDB connector - #279607

Open
tara-elastic wants to merge 61 commits into
elastic:mainfrom
tara-elastic:mongodb-connector-standalone
Open

tara-elastic wants to merge 61 commits into
elastic:mainfrom
tara-elastic:mongodb-connector-standalone

Conversation

@tara-elastic

@tara-elastic tara-elastic commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a spec-based MongoDB connector to @kbn/connector-specs, built on the client-registry
framework (#280445, which closed kibana#275613).
Talks to MongoDB over the native driver (binary wire protocol, not HTTP) using a connection URI
plus basic auth (username/password stored as encrypted secrets).

The mongodb client type (lib/clients/mongodb_client_type.ts) is the first client type
registered in ClientRegistry/clientTypes — it owns connecting, host-allowlist enforcement, and
credential decoding via a pooled, leased client (ctx.getClient('mongodb')). The connector's
action handlers (specs/mongodb/mongodb.ts) just lease the client and run queries. Credentials are
decoded from the same CredentialAccessor.getAuthHeaders() HTTP-based connectors use, via a new
shared helper (lib/clients/parse_basic_auth_header.ts) that recovers username/password from the
Authorization: Basic header for non-HTTP client types.

Actions:

  • Agent-facing (read-only, isTool: true): find, aggregate, count, listCollections
  • Workflow-only (isTool: false, never exposed to agents): insertOne, updateOne, deleteOne

aggregate recursively rejects write/code-execution stages ($out, $merge, $function,
$accumulator), including inside $facet, $lookup, and $unionWith sub-pipelines, so the
read-only tool surface can't be used to mutate data.

Also touches x-pack/platform/plugins/shared/actions: adds resolveSrvHosts(name, serviceName?)
and getTlsOptions(logger, verificationMode, sslOverrides) to the ConnectorNetworkSettings
interface (client_type_spec.ts) and implements both in create_connector_network_settings.ts,
using node:dns/promises and @kbn/actions-utils's getNodeSSLOptions respectively. Both have to
live in the actions plugin rather than @kbn/connector-specs because that package is isomorphic
(shared-common) and can't import Node builtins or @kbn/actions-utils's Node-only proxy-agent
code, even dynamically:

  • mongodb+srv:// connection strings carry only a single DNS seed name — the real target hosts
    are resolved via SRV records — so the client type has to resolve and allowlist-check those
    targets too, not just the seed.
  • getTlsOptions lets the client type apply xpack.actions.ssl/customHostSettings the same way
    the Axios connector path does, without pulling getCustomAgents's https-proxy-agent dependency
    chain into the isomorphic package.

Docs added at docs/reference/connectors-kibana/mongodb-action-type.md, wired into the TOC and
the third-party connectors snippet list.

Release note

Adds a MongoDB connector with find, aggregate, count, and listCollections available as Agent Builder tools.

Third-party dependencies

Per the automated dependency review bot, addressing each point below for the 2 new dependencies:

mongodb (6.21.0) — official MongoDB Node.js driver

  • Purpose: Connects to and queries MongoDB deployments (Atlas, self-hosted replica sets,
    standalone) over the native binary wire protocol, from the connector's server-side action handlers.
  • Justification: MongoDB's wire protocol is binary, not HTTP, so Kibana's existing
    connector infra (the injected Axios client) can't reach it. The official driver is the
    standard, actively-maintained way to speak MongoDB CRUD/aggregation without reimplementing
    wire-protocol, auth negotiation, and TLS handling in-house.
  • Alternatives explored: None viable. There's no HTTP/REST façade for MongoDB that works
    uniformly across Atlas and self-hosted deployments; hand-rolling the wire protocol was ruled
    out as out of scope and a correctness/security risk.
  • Existing dependencies: Kibana has no existing MongoDB client — this is a net-new
    capability, not a duplicate of something already vendored.

mongodb-connection-string-url (3.0.2) — MongoDB connection URI parser

  • Purpose: Parses the configured mongodb:// / mongodb+srv:// connection URI to extract
    the default database name (from the URI path) and detect an existing authSource query
    param, so the connector can support "database in the URI" as a fallback to the explicit
    database action input and avoid overriding a user-specified authSource.
  • Justification: It's already a transitive dependency of mongodb itself (the driver uses
    it internally for identical parsing), so declaring it directly reuses the same vetted parser
    the driver ships with rather than hand-rolling URI parsing.
  • Alternatives explored: Parsing with the built-in URL class was considered and rejected —
    mongodb+srv:// is not a spec-compliant URL scheme that URL handles correctly (it involves
    SRV record lookups and comma-separated host lists), so it would silently mishandle valid Atlas
    connection strings.
  • Existing dependencies: None. It was already present as an indirect dependency via
    mongodb; this change adds an explicit direct dependency since connector code imports it too.

Both packages are excluded from browser bundles via webpack.config.ts/externals.ts
(commonjs externals) and are only ever loaded server-side through dynamic import() inside
action handlers — see the "New native dependency" risk note below.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

Identify risks

Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.

  • See some risk examples
  • SSRF — resolved: Every host is validated against xpack.actions.allowedHosts via ctx.networkSettings.ensureHostnameAllowed(). For mongodb+srv:// URIs, the connector resolves the DNS SRV records itself and validates every resolved target host, not just the seed name in the URI (mongodb_client_type.ts, create_connector_network_settings.ts). Covered by tests in mongodb_client_type.test.ts and create_connector_network_settings.test.ts.
  • New native dependency (low): Adds the mongodb npm driver (and its mongodb-connection-string-url dependency) to the workspace. Both are excluded from the browser bundle via webpack.config.ts/externals.ts (commonjs externals) and only loaded server-side via dynamic import(). See the "Third-party dependencies" section above for purpose/justification detail.
  • Data loss via write actions (low): insertOne/updateOne/deleteOne can mutate/delete data, but are isTool: false and therefore never callable by agents. They also aren't reachable from anywhere yet: metadata.supportedFeatureIds is ['agentBuilder'] only for this introducing PR (new connector types can't declare user-facing features like 'workflows' until registered in every Production-NonCanary version, per the two-step release policy — see create-connector/SKILL.md). A follow-up PR adding 'workflows' to supportedFeatureIds is required before these actions become reachable from a workflow.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

🔍 Preview links for changed docs

@github-actions

Copy link
Copy Markdown
Contributor

Elastic Docs Style Checker (Vale)

Summary: 2 suggestions found

💡 Suggestions (2): Optional style improvements. Apply when helpful.
File Line Rule Message
docs/reference/connectors-kibana/mongodb-action-type.md 23 Elastic.Semicolons Use semicolons judiciously.
docs/reference/connectors-kibana/mongodb-action-type.md 113 Elastic.Semicolons Use semicolons judiciously.

The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale.

# Conflicts:
#	src/platform/packages/shared/kbn-connector-specs/src/all_specs.ts
#	src/platform/packages/shared/kbn-connector-specs/src/connector_icons_map.ts
@tara-elastic tara-elastic changed the title Mongodb connector standalone MongoDB connector (standalone) Jul 29, 2026
@tara-elastic
tara-elastic requested a review from a team July 29, 2026 14:00
# Conflicts:
#	docs/reference/connectors-kibana/_snippets/data-context-sources-connectors-list.md
#	docs/reference/toc.yml
#	src/platform/packages/shared/kbn-connector-specs/src/connector_icons_map.ts
@tara-elastic
tara-elastic marked this pull request as ready for review July 29, 2026 16:10
@tara-elastic
tara-elastic requested review from a team as code owners July 29, 2026 16:10
@kibanamachine

kibanamachine commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Dependency Review Bot Analysis 🔍

Found 2 new third-party dependencies:

Package Version Vulnerabilities Health Score
mongodb-connection-string-url 3.0.2 🔴 C: 0, 🟠 H: 0, 🟡 M: 0, 🟢 L: 0 mongodb-connection-string-url
mongodb 6.21.0 🔴 C: 0, 🟠 H: 0, 🟡 M: 0, 🟢 L: 0 mongodb

Self Checklist

To help with the review, please update the PR description to address the following points for each new third-party dependency listed above:

  • Purpose: What is this dependency used for? Briefly explain its role in your changes.
  • Justification: Why is adding this dependency the best approach?
  • Alternatives explored: Were other options considered (e.g., using existing internal libraries/utilities, implementing the functionality directly)? If so, why was this dependency chosen over them?
  • Existing dependencies: Does Kibana have a dependency providing similar functionality? If so, why is the new one preferred?

Thank you for providing this information!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the MongoDB connector spec. Two security findings on the read-only enforcement — both are cases where the agent-facing (isTool: true) surface can trigger server-side JavaScript execution despite the intended read-only guarantee. Details in the inline comments. The rest (bundle externals, docs, auth-source handling, per-call client lifecycle, disclosed SSRF gap) looks consistent with the PR's stated scope.

Generated by Claude Reviewer for #279607 · 26.1 AIC · ⌖ 1.12 AIC

Comment thread src/platform/packages/shared/kbn-connector-specs/src/specs/mongodb/mongodb.ts Outdated
Comment thread src/platform/packages/shared/kbn-connector-specs/src/specs/mongodb/mongodb.ts Outdated
…ally, or add an exception to src/dev/yarn_deduplicate/index.ts and then commit the changes and push to your branch

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the MongoDB connector. The earlier security findings (JS-execution operators, unescaped nameFilter, $facet limit bypass, unbounded pipeline, embedded-URI credentials, server-only static import) all look addressed in the current revision, and the SRV allowlist/TOCTOU handling and test coverage are thorough. Two remaining concrete concerns on agent-facing inputs, noted inline.

Generated by Claude Reviewer for #279607 · opus · 226.3 AIC · ⌖ 14.3 AIC · ⊞ 5.1K

skip: z
.number()
.int()
.min(0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

skip is an agent-facing (isTool: true via find) numeric input with no upper bound, unlike its sibling limit (bounded 1–1000). A large skip (e.g. 1e9) forces MongoDB to walk and discard that many documents server-side before returning results — the classic large-skip performance cliff — giving an LLM-supplied value a cheap server-side DoS vector. This is the same unbounded-agent-input class the repo guideline calls out (and that was applied to the pipeline array's .max(100)).

Suggested change
.min(0)
.min(0)
.max(100_000)

(bound value illustrative — pick whatever ceiling still supports realistic pagination.)

return { ...stage, $facet: clampedFacet };
}
if ('$lookup' in stage) {
const lookup = stage.$lookup as Record<string, unknown>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The volume clamp bounds $lookup only in its pipeline form; the equality-join form (localField/foreignField, no pipeline) short-circuits here untouched. That form produces an unbounded as array per outer document, and the outer $limit only bounds the outer document count — so up to maxLimit documents can each carry an arbitrarily large joined array. This is the same nested data-volume gap the $facet/pipeline-form $lookup clamping was built to close, and it leaves the docs' claim ("none of them can be used to return more than the limit's worth of documents") not fully true for equality-form $lookup on an agent-facing read tool. Bounding it requires rewriting the equality form into pipeline form with an injected $limit, or documenting the residual gap.

* — the same accessor HTTP-based connectors use — and must recover the raw username/password
* from the header to hand to their driver's binary protocol.
*/
export const parseBasicAuthHeader = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have seen this a bunch of times now... we should probably extract it next time (it is also in my MySql PR)

@erikcurrin-elastic erikcurrin-elastic Sep 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you change the MySQL client type to use this now?

Comment thread docs/reference/connectors-kibana/mongodb-action-type.md

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the MongoDB connector. The read-only enforcement (assertReadOnly recursion, clampPipelineLimit), URI/credential handling, and SRV allowlist pinning are solid and well-tested. One inline note about a residual allowlist-bypass path via the driver's replica-set/sharded-cluster topology discovery.

Generated by Claude Reviewer for #279607 · claude · opus · 220.8 AIC · ⌖ 22.9 AIC · ⊞ 5.5K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the MongoDB connector. The security surface is thorough and well-tested (host-allowlist enforcement including SRV resolution, DNS-rebinding pinning, recursive read-only operator rejection, and nested $limit clamping). One inline comment on a credential-leak inconsistency in the URI-parse path used by read handlers.

Generated by Claude Reviewer for #279607 · claude · opus · 173.8 AIC · ⌖ 23.4 AIC · ⊞ 5.5K

# Conflicts:
#	src/platform/packages/shared/kbn-connector-specs/src/lib/clients/client_type_spec.ts
@tara-elastic

Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

# Conflicts:
#	.github/CODEOWNERS
#	docs/reference/connectors-kibana/_snippets/data-context-sources-connectors-list.md
#	docs/reference/toc.yml
#	packages/kbn-optimizer/src/worker/webpack.config.ts
#	packages/kbn-rspack-optimizer/src/config/externals.test.ts
#	packages/kbn-rspack-optimizer/src/config/externals.ts
#	src/platform/packages/shared/kbn-connector-specs/src/lib/clients/index.ts
@kibanamachine

kibanamachine commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

💔 Build Failed

Failed CI Steps

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
shared-packages 4.6MB 4.6MB +14.2KB
Unknown metric groups

shared chunk count

id before after diff
all 202 203 +1

shared chunks total size

id before after diff
all 7.0MB 7.0MB +1.1KB

total optimizer output size

id before after diff
all 64.0MB 64.0MB +15.2KB

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting connectors-v2 Feature:Actions/ConnectorTypes Issues related to specific Connector Types on the Actions Framework release_note:feature Makes this part of the condensed release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants