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

Create manage_connector privilege #110128

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

Conversation

jedrazb
Copy link
Member

@jedrazb jedrazb commented Jun 25, 2024

Changes

Define manage_connector and monitor_connector privileges that will be required role by Connector APIs. Migration of existing logic and endpoints to use this privilege will be done in next steps.

I followed pattern from a previous similar PR: #97941 , few notes:

  • The new privilege is not used as of now for any API endpoints. We have a migration strategy to move connectors to system indices and that would require this privilege.
  • Since manage_connector is not used as of now, I didn't add this to public docs in: docs/reference/security/authorization/privileges.asciidoc (issue to do it once we start using this for api auth)
  • Added this privilege to kibanaSystem, to allow for telemetry collection in the future (see reference)

@jedrazb jedrazb added >non-issue :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Security Meta label for security team :SearchOrg/Extract&Transform Label for the Search E&T team Team:Search - Extract & Transform labels Jun 25, 2024
Copy link

Documentation preview:

@jedrazb jedrazb marked this pull request as ready for review June 25, 2024 11:29
@jedrazb jedrazb requested review from a team as code owners June 25, 2024 11:29
@elasticsearchmachine elasticsearchmachine added the Team:SearchOrg Meta label for the Search Org (Enterprise Search) label Jun 25, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

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.

lgtm

@@ -92,6 +92,7 @@ A successful call returns an object with "cluster", "index", and "remote_cluster
"manage_rollup",
"manage_saml",
"manage_search_application",
"manage_search_connector",
Copy link
Member

Choose a reason for hiding this comment

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

FYI this will be in docs.

Copy link
Member Author

@jedrazb jedrazb Jun 25, 2024

Choose a reason for hiding this comment

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

Wouldn't it be required for the docs' tests? I think it makes sense to keep it there, as this console block references an actual privilege API output. Since the privilege is in ES, it will be returned, but I think we can skip documenting the manage_search_connector in the dedicated section.

Comment on lines 15 to 17
# This is fragile - it needs to be updated every time we add a new cluster/index privilege
# I would much prefer we could just check that specific entries are in the array, but we don't have
# an assertion for that
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated to your changes, but I always wondered if this comment is still accurate and why couldn't we just assert the contents of the array

@@ -174,6 +174,7 @@ public class ClusterPrivilegeResolver {
);

private static final Set<String> MANAGE_SEARCH_APPLICATION_PATTERN = Set.of("cluster:admin/xpack/application/search_application/*");
private static final Set<String> MANAGE_SEARCH_CONNECTOR_PATTERN = Set.of("cluster:admin/xpack/connector/*");
Copy link
Contributor

Choose a reason for hiding this comment

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

one side effect is that manage_search_connector will include the read_connector_secret and write_connector_secret, but that is the intention right?

public static final NamedClusterPrivilege READ_CONNECTOR_SECRETS = new ActionClusterPrivilege(
"read_connector_secrets",
Set.of("cluster:admin/xpack/connector/secret/get")
);
public static final NamedClusterPrivilege WRITE_CONNECTOR_SECRETS = new ActionClusterPrivilege(
"write_connector_secrets",
Set.of(
"cluster:admin/xpack/connector/secret/delete",
"cluster:admin/xpack/connector/secret/post",
"cluster:admin/xpack/connector/secret/put"
)
);

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a requirement that the user managing connectors has write_connector_secrets, so that API keys can be stored for the Connector (only relevant if the Connector is native). So that is okay to include.
Regarding read_connector_secrets, I don't think it's a requirement for users to have this. It should only be important for the Connector itself to read the API key.
If a user needs read_connector_secrets for some reason they could manually assign it to whichever role anyway, there is no restriction from doing this.

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 spot! I see that it's possible to define excludePatterns in the ActionClusterPrivilege constructor.

     * Constructor for {@link ActionClusterPrivilege} that defines what cluster actions are accessible for the
     * user with this privilege after excluding the action patterns {@code excludedActionPatterns} from the allowed action patterns
     * {@code allowedActionPatterns}

If I read the javadoc correctly it should allow us to match cluster:admin/xpack/connector/* while it's possible to exclude secrets-related privileges.

@navarone-feekery do you think the best way forward is to exclude all secret-related privileges from manage_search_connector to keep status quo? Right now API key generated used by connector service doesn't have this privilege right?

Copy link
Contributor

@navarone-feekery navarone-feekery Jun 26, 2024

Choose a reason for hiding this comment

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

do you think the best way forward is to exclude all secret-related privileges from manage_search_connector to keep status quo?

I think so. Users don't need read_connector_secrets, and having write_connector_secrets be separate for now is okay. It is already a documented requirement for creating a native connector. It has a slightly different scope and we can always add it later if we expand secrets to do more things (like storing sensitive RCF values).

Right now API key generated used by connector service doesn't have this privilege right?

Yes that's correct. Native connectors use the Enterprise Search system role to fetch the API key from connector secrets, then native connectors use that API key to index documents. The API key that a Connector uses to index docs itself doesn't need access to secrets.

@jfreden
Copy link
Contributor

jfreden commented Jun 25, 2024

My understanding is that the new privilege isn't currently used by anything, but implicitly grants read_connector_secrets and write_connector_secrets that grants actions in the ent-search plugin. The purpose is to switch everything that reads from the connector indices to use new actions in the ent-search plugin and that the new manage_search_connector privilege will grant access to those actions. For example getting telemetry data from the connector index for usage in kibana. Is that correct?

Do you think splitting it into more granular privileges might make sense and is there a use case for that? Such as read_connectors, write_connectors and so on?

manage_search_connectors is a little confusing, are there other type of actions or would manage_connectors be a better name?

Thank you!

@jfreden
Copy link
Contributor

jfreden commented Jun 25, 2024

If you want this new privilege in serverless it needs to be added here.

You will need to merge this PR before adding it and then either add it to the serverless registry or to the tests “ignore” list, otherwise the serveless ci will fail.

@jedrazb
Copy link
Member Author

jedrazb commented Jun 26, 2024

Hey @jfreden thank you for reviewing. Answering your questions:

The purpose is to switch everything that reads from the connector indices to use new actions in the ent-search plugin and that the new manage_search_connector privilege will grant access to those actions.

Yes, you got it right :) The story is that: .connector-* hidden indices are planned to be migrated to system indices so we need to define a new privilege to define access to API endpoints that would interact with new hidden indices.

Do you think splitting it into more granular privileges might make sense and is there a use case for that? Such as read_connectors, write_connectors and so on?

All of our current use-cases require to have read and write permissions at the same time, so to me it makes sense to "package" is as a single manage permission. Note the destination index to which the connector would write (sync) data can have other index-level permissions.

but implicitly grants read_connector_secrets and write_connector_secrets that grants actions in the ent-search plugin.

Actually we might want to exclude some secrets-related patterns from that privilege, do I understand correctly that we can use excludePatterns for that, see my comment above.

manage_search_connectors is a little confusing, are there other type of actions or would manage_connectors be a better name?

You are right that manage_connectors perhaps fits better to existing privilege names such as write_connector_secrets and read_connector_secrets. I was tempted to use _search_ to indicate the search org owning this privilege. But I agree that manage_connectors could fit better.

You will need to merge this PR before adding it and then either add it to the serverless registry or to the tests “ignore” list, otherwise the serveless ci will fail.

I will def reach out to you before merging to clarify exact steps 😅

@jedrazb jedrazb changed the title Create manage_search_connector privilege Create manage_connector privilege Jun 26, 2024
@jedrazb jedrazb requested a review from ioanatia June 26, 2024 12:11
@jfreden
Copy link
Contributor

jfreden commented Jun 26, 2024

Thanks @jedrazb!

All of our current use-cases require to have read and write permissions at the same time, so to me it makes sense to "package" is as a single manage permission. Note the destination index to which the connector would write (sync) data can have other index-level permissions.

Sounds like there is a use case for Kibana where they need only read access, so adding a monitor_connector would make sense. @azasypkin might have some more context if needed.

I was tempted to use search to indicate the search org owning this privilege

In general we should avoid naming privileges based on our internal org structure since it might change and it can confuse users.

Actually we might want to exclude some secrets-related patterns from that privilege, do I understand correctly that we can use excludePatterns for that, see my #110128 (comment).

After thinking more about this I think the expectation on the manage privilege from a user is to include the secret rest actions too.


I brought this PR up in todays Elasticsearch security team meeting and we have some concerns around reading and writing secrets through the API. In general we should not write or read secrets through the API, but instead use the elasticsearch-keystore and store the secrets in secure settings.

I can see that the read and write secrets are used to store api keys needed by the connectors and it might not be possible to build the functionality you're trying to build using the keystore. Is using the keystore something you considered?

CC: @bytebilly

@jedrazb
Copy link
Member Author

jedrazb commented Jun 27, 2024

Hi @jfreden thank you for bringing this topic up in the Elasticsearch security team meeting

Sounds like there is a use case for Kibana where they need only read access, so adding a monitor_connector would make sense.

Sure, we can include monitor_connector privilege alongside manage_connector, to allow for read-only access.

After thinking more about this I think the expectation on the manage privilege from a user is to include the secret rest actions too.

This case is tricky. We don't necessarily expect that a user/service that has manage_connector privilege should have access to reading secrets. The "read secret" privilege is only used by Enterprise Search system account to enable native (running in cloud) connectors writing data to non search- prefixed indices.

How strongly are you feeling that manage_connector should include secret (get) rest actions?

I brought this PR up in todays Elasticsearch security team meeting and we have some concerns around reading and writing secrets through the API. In general we should not write or read secrets through the API, but instead use the elasticsearch-keystore and store the secrets in secure settings.

I don't have the full context about this decision. IIRC we followed the pattern established by Fleet (see read_fleet_secrets and write_fleet_secrets). I can share more context from the implementation doc in Slack. I'm not sure if using elasticsearch-keystore was considered. I could tag some folks with more context if this doesn't answer your question. Let me know!

@jedrazb
Copy link
Member Author

jedrazb commented Jun 28, 2024

Hey @jfreden we introduced monitor_connector privilege with read-only access in af27b4e and Kibana system role will use it for telemetry 9410537.

Let me know if you have any other concerns with this change?

@jfreden
Copy link
Contributor

jfreden commented Jun 28, 2024

Thanks for adding that @jedrazb and thanks for the added context!

Even though this change is not related to the secrets, I feel hesitant to approving it until I better understand this part:

I don't have the full context about this decision. IIRC we followed the pattern established by Fleet (see read_fleet_secrets and write_fleet_secrets). I can share more context from the implementation doc in Slack. I'm not sure if using elasticsearch-keystore was considered. I could tag some folks with more context if this doesn't answer your question. Let me know!

The security team is concerned about how the Fleet secrets index was handled and we don't have any recommendation on how this should ideally be built. I'm going to sync with the rest of the team and get back to you as soon as I can, probably early next week. I understand this is time critical and will try to move as fast as possible.

Since privilege names are often namespaced and used with globs, we want to ensure that if there's a future privilege like `manage_connector_secrets`, that it is not implicitly included in this new privileg's <name>*. By extending the privilege name to include "_state", we better namespace this distinct from any "_secrets" namespace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :SearchOrg/Extract&Transform Label for the Search E&T team :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC Team:Search - Extract & Transform Team:SearchOrg Meta label for the Search Org (Enterprise Search) Team:Security Meta label for security team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants