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

Update api keys to include acl filter index #159840

Merged

Conversation

seanstory
Copy link
Member

Summary

Part of https://github.com/elastic/enterprise-search-team/issues/4304

Ensures that new API keys generated from our application include permissions not only to the document index but also to the .search-acl-filter-* index that corresponds to it.

For maintainers

@seanstory seanstory added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:EnterpriseSearch v8.9.0 labels Jun 15, 2023
@seanstory seanstory requested a review from a team June 15, 2023 19:39
@@ -17,14 +17,22 @@ export const createApiKey = async (
indexName: string,
keyName: string
) => {
let aclIndexName: string;
if (indexName.startsWith('search-')) {
const suffix = indexName.replace('search-', '');
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we have to replace the prefix?

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering the same thing. Seems to me that this could create conflicting index names.

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 index name isn't getting modified, we're just figuring out the suffix.

If the user uses our UI to create an index:

  • they type test
  • the index name is search-test
  • the permissions index name is .search-acl-filter-test

I don't want the permissions index name to be .search-acl-filter-search-test, so I have to strip off the search- from the index name to determine the suffix.

Copy link
Member

Choose a reason for hiding this comment

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

Right, my question is really: why don't we want it to be .search-acl-filter-search-test?

Copy link
Member Author

Choose a reason for hiding this comment

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

because then you have search in the prefix twice and it's redundant

Copy link
Member

Choose a reason for hiding this comment

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

Not really? The second search isn't part of the prefix, it's the actual index name that just happens to start with search. What happens when people want to use their own indices that don't start with search (which we don't really support, but people can easily do)? We may accidentally create conflicting ACL index names (eg: search-test and test would have the same ACL name).

Copy link
Contributor

Choose a reason for hiding this comment

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

++ @sphilipse - I am not too worried about the redundancy, more about consistency in the future where we don't require the search- prefix.

Copy link
Member Author

Choose a reason for hiding this comment

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

🤦 totally missed that I had replies on here when I asked again for an approve and then merged. Sorry both, did not mean to ignore this concern.

I do think that we're in an OK place right now. If we get rid of using search-*, we could switch to using .acl-filter as our prefix anyway.

@@ -17,14 +17,22 @@ export const createApiKey = async (
indexName: string,
keyName: string
) => {
let aclIndexName: string;
if (indexName.startsWith('search-')) {
const suffix = indexName.replace('search-', '');
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering the same thing. Seems to me that this could create conflicting index names.

@@ -17,14 +17,22 @@ export const createApiKey = async (
indexName: string,
keyName: string
) => {
let aclIndexName: string;
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: more idiomatic for our codebase would be

const aclIndexName = indexName.startsWith('search-') ? `.search-acl-filter-${indexName.slice(7)}` : `.search-acl-filter-${indexName}`;

Copy link
Member Author

Choose a reason for hiding this comment

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

I can make that change. I hadn't considered using a substring method so I could inline the suffix extraction with the prefix concatenation.

If I had to have a block of logic, what's the idiomatic way to do this to avoid the let? (I assume that's what you're trying to avoid?)

Choose a reason for hiding this comment

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

maybe the closest thing you can get to a block/scope that returns a value for assignment is an IIFE.

with this code it would look something like this:

const aclIndexName: string = (() => {
  if (indexName.startsWith('search-')) {
    const suffix = indexName.replace('search-', '');
    return `.search-acl-filter-${suffix}`;
  } else {
    return `.search-acl-filter-${indexName}`;
  }
})()

Copy link
Member

Choose a reason for hiding this comment

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

An IIFE is possible but isn't really idiomatic, we're more likely to extract it to a function elsewhere in the file and call it here (or to a shared utility function that's used in multiple places, which might be useful here).

@seanstory
Copy link
Member Author

@elasticmachine merge upstream

Comment on lines 20 to 22
const aclIndexName = indexName.startsWith('search-')
? `.search-acl-filter-${indexName.slice(7)}`
: `.search-acl-filter-${indexName}`;

Choose a reason for hiding this comment

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

okay i know this code has been rewritten for you already but i got a bit nerdsniped and thought "could we do this with a regular expression?

Suggested change
const aclIndexName = indexName.startsWith('search-')
? `.search-acl-filter-${indexName.slice(7)}`
: `.search-acl-filter-${indexName}`;
const aclIndexName = indexName.replace(/^(?:search-)?(.*)$/, '.search-acl-filter-$1')

this regexp matches a string with an optional search- prefix and adds it to the end of the desired .search-acl-filter- without any search- prefix.

image

again, this is so minor, please feel free to disregard.

Copy link
Member Author

Choose a reason for hiding this comment

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

TIL "Nerd Sniping" 😂
I actually like this better, because the slice(7) didn't seem explicitly clear, but this regex isn't too hard to follow.

@seanstory seanstory force-pushed the seanstory/4304-update-api-key-to-include-acl-filter-index branch from c0072a6 to 44fefbc Compare June 20, 2023 16:09
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #39 / endpoint For each artifact list under management "after all" hook in "For each artifact list under management"
  • [job] [logs] FTR Configs #39 / endpoint For each artifact list under management "before all" hook in "For each artifact list under management"

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 13 15 +2
securitySolution 411 415 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 14 16 +2
securitySolution 494 498 +4
total +6

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@seanstory seanstory merged commit 9382687 into main Jun 21, 2023
@seanstory seanstory deleted the seanstory/4304-update-api-key-to-include-acl-filter-index branch June 21, 2023 14:18
seanstory added a commit that referenced this pull request Jun 23, 2023
…unction (#160457)

## Summary
I'd added this logic in #159840
and turns out that was the wrong place to influence connector api keys.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 23, 2023
…unction (elastic#160457)

## Summary
I'd added this logic in elastic#159840
and turns out that was the wrong place to influence connector api keys.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 8251481)
kibanamachine referenced this pull request Jun 23, 2023
…tion function (#160457) (#160465)

# Backport

This will backport the following commits from `main` to `8.9`:
- [move .search-acl-filter-* permissions to the right api key creation
function (#160457)](#160457)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sean
Story","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-06-23T21:35:26Z","message":"move
.search-acl-filter-* permissions to the right api key creation function
(#160457)\n\n## Summary\r\nI'd added this logic in
https://github.com/elastic/kibana/pull/159840\r\nand turns out that was
the wrong place to influence connector api keys.\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"8251481340c8125e450ef1386cbd73209de882ff","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:EnterpriseSearch","v8.9.0","v8.10.0"],"number":160457,"url":"https://github.com/elastic/kibana/pull/160457","mergeCommit":{"message":"move
.search-acl-filter-* permissions to the right api key creation function
(#160457)\n\n## Summary\r\nI'd added this logic in
https://github.com/elastic/kibana/pull/159840\r\nand turns out that was
the wrong place to influence connector api keys.\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"8251481340c8125e450ef1386cbd73209de882ff"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/160457","number":160457,"mergeCommit":{"message":"move
.search-acl-filter-* permissions to the right api key creation function
(#160457)\n\n## Summary\r\nI'd added this logic in
https://github.com/elastic/kibana/pull/159840\r\nand turns out that was
the wrong place to influence connector api keys.\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"8251481340c8125e450ef1386cbd73209de882ff"}}]}]
BACKPORT-->

Co-authored-by: Sean Story <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:EnterpriseSearch v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants