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

Permissions required for stateful agentless integrations #118644

Merged
merged 14 commits into from
Jan 10, 2025

Conversation

orestisfl
Copy link
Contributor

@orestisfl orestisfl commented Dec 13, 2024

Closes https://github.com/elastic/security-team/issues/11102
Closes https://github.com/elastic/security-team/issues/11104

This allows agentless integrations (via elastic/beats#41446, elastic/kibana#203810) to write to agentless-* indices. Each index is created on-demand by the filebeat client and kibana conditionally extends the API key permissions to allow writing to the index.

@elasticsearchmachine elasticsearchmachine added v9.0.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Dec 13, 2024
@elasticsearchmachine
Copy link
Collaborator

@orestisfl please enable the option "Allow edits and access to secrets by maintainers" on your PR. For more information, see the documentation.

@orestisfl orestisfl self-assigned this Dec 13, 2024
@orestisfl orestisfl requested a review from jedrazb December 13, 2024 15:10
@orestisfl orestisfl added the auto-backport Automatically create backport pull requests when merged label Dec 13, 2024
@orestisfl orestisfl changed the title WIP: permissions required for stateful agentless integrations Permissions required for stateful agentless integrations Dec 13, 2024
@orestisfl orestisfl marked this pull request as ready for review December 30, 2024 09:23
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Dec 30, 2024
@astefan astefan added :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC and removed needs:triage Requires assignment of a team area label labels Dec 30, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Security Meta label for security team label Dec 30, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

orestisfl added a commit to elastic/kibana that referenced this pull request Jan 7, 2025
## Summary

Adds necessary permissions to write to the `agentless-*` index. See:
- Elasticsearch PR: elastic/elasticsearch#118644
- Context: elastic/security-team#11104

As part of elastic/security-team#11104, we
need to write integration data that needs to be persistent. The
implementation we are working on, uses Elasticsearch as the storage
mechanism for this data.

Normally, integrations write to data streams instead of normal ES
indices. However, data streams cannot provide a generic implementation
for our use case and thus we need a normal ES index.

This PR grants permissions from the fleet service account to the
agentless integrations to write to `agentless-*` ES indices.

In
`x-pack/plugins/fleet/server/services/agent_policies/package_policies_to_agent_permissions.ts`
there are other examples of other integrations that need ES index
permissions so there is prior art in doing this. The difference with
this PR however, is that we need to conditionally merge the extra
`agentless-*` permissions with any potential existing data stream
permissions since we are dealing with arbitrary agentless integrations.
Copy link
Contributor

@jakelandis jakelandis left a comment

Choose a reason for hiding this comment

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

It looks like the CI failure is related and will need update https://github.com/elastic/elasticsearch/blob/main/docs/reference/rest-api/security/get-service-accounts.asciidoc to account for the new privilege in response. Should be able to test and reproduce locally with ./gradlew ":docs:yamlRestTest" --tests "org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT.test {yaml=reference/rest-api/security/get-service-accounts/line_57}" (not tested)

Also, ideally these indindes would be hidden, which requires an index template or explicit creation ; but that is orthogonal to the privileges being introduced here.

kowalczyk-krzysztof pushed a commit to kowalczyk-krzysztof/kibana that referenced this pull request Jan 7, 2025
## Summary

Adds necessary permissions to write to the `agentless-*` index. See:
- Elasticsearch PR: elastic/elasticsearch#118644
- Context: elastic/security-team#11104

As part of elastic/security-team#11104, we
need to write integration data that needs to be persistent. The
implementation we are working on, uses Elasticsearch as the storage
mechanism for this data.

Normally, integrations write to data streams instead of normal ES
indices. However, data streams cannot provide a generic implementation
for our use case and thus we need a normal ES index.

This PR grants permissions from the fleet service account to the
agentless integrations to write to `agentless-*` ES indices.

In
`x-pack/plugins/fleet/server/services/agent_policies/package_policies_to_agent_permissions.ts`
there are other examples of other integrations that need ES index
permissions so there is prior art in doing this. The difference with
this PR however, is that we need to conditionally merge the extra
`agentless-*` permissions with any potential existing data stream
permissions since we are dealing with arbitrary agentless integrations.
@orestisfl orestisfl force-pushed the agentless-storage-permissions branch from 3667d0a to c4eb0fa Compare January 8, 2025 16:28
@orestisfl orestisfl force-pushed the agentless-storage-permissions branch from c4eb0fa to db8f1f6 Compare January 8, 2025 16:36
@orestisfl orestisfl requested a review from jakelandis January 9, 2025 19:18
@orestisfl
Copy link
Contributor Author

@jakelandis managed to fix the tests and introduced the index templates, could you please take another look?

Copy link
Contributor

@jakelandis jakelandis left a comment

Choose a reason for hiding this comment

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

LGTM

"index": {
"hidden": true,
"number_of_shards": 1,
"number_of_replicas": 1
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I would suggest to omit these (shard/replica) as they are the defaults.

@orestisfl orestisfl enabled auto-merge (squash) January 10, 2025 15:26
@orestisfl orestisfl merged commit 3c184b9 into main Jan 10, 2025
22 checks passed
@orestisfl orestisfl deleted the agentless-storage-permissions branch January 10, 2025 16:30
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 118644

@orestisfl
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

orestisfl added a commit to orestisfl/elasticsearch that referenced this pull request Jan 10, 2025
)

Closes elastic/security-team#11102
Closes elastic/security-team#11104

This allows agentless integrations (via elastic/beats#41446, elastic/kibana#203810) to write to agentless-* indices. Each index is created on-demand by the filebeat client and kibana conditionally extends the API key permissions to allow writing to the index.

(cherry picked from commit 3c184b9)

# Conflicts:
#	docs/reference/rest-api/security/get-service-accounts.asciidoc
#	x-pack/plugin/security/qa/service-account/src/javaRestTest/java/org/elasticsearch/xpack/security/authc/service/ServiceAccountIT.java
#	x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/service/ElasticServiceAccounts.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged backport pending external-contributor Pull request authored by a developer outside the Elasticsearch team >non-issue :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Security Meta label for security team v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants