Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Connector APIs] Enforce index prefix for managed connectors #117778

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jedrazb
Copy link
Member

@jedrazb jedrazb commented Nov 29, 2024

Changes

For 9.x, Connectors will be deployed in an agentless environment. This means the Fleet service account will now be responsible for generating API keys, enabling the connector to read/write from connector state indices and interact with the content index (where data is synced by connector from the 3rd party data source).

To maintain granular permissions and avoid granting the Fleet service account access to all indices (e.g., *), it has been decided to restrict content index names to those prefixed with content-*.

This PR introduces restrictions and validations to ensure that Elastic-managed connectors (with isNative: true flag) can only attach to indices with the content- prefix. We validate index name on:

  • connector creation
  • index name update (e.g. native connector cannot have index name changed with illegal prefix)
  • isNative property update (we need to first change the attached index to have content- then update the connector to native connector)

Additionally, the ConnectorIndexServiceTests have been unmuted. These tests have been stable for about a year. A few flaky runs (IMO not related to our test logic) had caused them to be muted earlier, but they now run successfully. We need to keep them active.

BCC approval

Relates to [Search Connectors] introduce "content-*" prefix requirement for Elastic-managed connectors dev issue that got green light from bcc.

Verification

  • Verified API calls manually.
  • YAML end-to-end tests.
  • unit tests

ConnectorStatus status = getConnectorStatusFromSearchResult(connector);

// If connector was connected already, change its status to CONFIGURED as we need to re-connect
if (status == ConnectorStatus.CONNECTED) {
Copy link
Member Author

@jedrazb jedrazb Nov 29, 2024

Choose a reason for hiding this comment

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

I realised we would always set status CONFIGURED once changing the is_native flag - it's likely wrong, we got here because I copied logic from Kibana initially https://github.com/elastic/kibana/pull/175536/files

Copy link
Member

Choose a reason for hiding this comment

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

nice catch.

- match: { results.0.id: "connector-a" }
- match: { results.0.index_name: "search-1-test" }
- match: { results.0.language: "pl" }
- match: { results.0.id: "connector-b" }
Copy link
Member Author

@jedrazb jedrazb Dec 2, 2024

Choose a reason for hiding this comment

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

content- index is first alphabetically so order of list API results changes (we sort by index_name by default)

@jedrazb jedrazb changed the title [Connector APIs] Enforce manage connector index prefix [Connector APIs] Enforce index prefix for managed connectors Dec 2, 2024
@jedrazb jedrazb marked this pull request as ready for review December 2, 2024 11:11
@elasticsearchmachine elasticsearchmachine added the Team:SearchOrg Meta label for the Search Org (Enterprise Search) label Dec 2, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-eng (Team:SearchOrg)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-extract-and-transform (Team:Search - Extract & Transform)

@jedrazb
Copy link
Member Author

jedrazb commented Dec 2, 2024

Rest compatibility failing because it's not a backward compatible change

@seanstory
Copy link
Member

the relevant backwards compatibility change proposal is here: https://github.com/elastic/dev/issues/2932

@jedrazb
Copy link
Member Author

jedrazb commented Dec 11, 2024

This is a workaround for failing bcc changes #118260 (should be merged and backported first)

@jedrazb
Copy link
Member Author

jedrazb commented Dec 13, 2024

@elasticmachine merge upstream

@jedrazb
Copy link
Member Author

jedrazb commented Dec 16, 2024

@elasticmachine merge upstream

@elasticsearchmachine
Copy link
Collaborator

Hi @jedrazb, I've created a changelog YAML for you.

@@ -91,8 +91,6 @@ tests:
- class: org.elasticsearch.search.StressSearchServiceReaperIT
method: testStressReaper
issue: https://github.com/elastic/elasticsearch/issues/115816
- class: org.elasticsearch.xpack.application.connector.ConnectorIndexServiceTests
Copy link
Member Author

Choose a reason for hiding this comment

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

The ConnectorIndexServiceTests has been running fine for almost a year, I saw seemingly unrelated issue in the failed buildkite run that led to muting this

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me. Are there any BWC cases that we should be aware of/test? Also are there any docs updates required?

Comment on lines +826 to +827
// Ensure attached content index is prefixed correctly
if (isNative && indexName != null && isValidManagedConnectorIndexName(indexName) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Ensure attached content index is prefixed correctly
if (isNative && indexName != null && isValidManagedConnectorIndexName(indexName) == false) {
// Ensure attached content index is prefixed correctly
boolean doesNotHaveContentPrefix = indexName != null && isValidManagedConnectorIndexName(indexName) == false
if (isNative && doesNotHaveContentPrefix) {

Rationale: Cognitive load is what matters: complex conditionals

Copy link
Member Author

Choose a reason for hiding this comment

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

Good read! Thank you for linking


// If connector was connected already, change its status to CONFIGURED as we need to re-connect
if (status == ConnectorStatus.CONNECTED) {
status = ConnectorStatus.CONFIGURED;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this transition be guarded/validated through ConnectorStateMachine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature :SearchOrg/Extract&Transform Label for the Search E&T team Team:Search - Extract & Transform Team:SearchOrg Meta label for the Search Org (Enterprise Search) v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants