Skip to content

Commit fa769ce

Browse files
kibanamachineEamonn-OLelasticmachineSiddharthMantri
authored
[9.0] Adding API Key Wildcard Search (#221959) (#237269)
# Backport This will backport the following commits from `main` to `9.0`: - [Adding API Key Wildcard Search (#221959)](#221959) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Eamonn-OL","email":"119305140+Eamonn-OL@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-10-02T11:09:41Z","message":"Adding API Key Wildcard Search (#221959)\n\nAdding ability to do partial matches/searches in the API Key section of\nthe Management Console.\n\n\n\nhttps://github.com/user-attachments/assets/02e9c44f-101f-44e3-b7cb-dc731646d140\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>\nCo-authored-by: Sid <siddharthmantri1@gmail.com>","sha":"7aa44ebe60393c5eba50881cb6646d78ccfb09b0","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Security","Feature:Users/Roles/API Keys","backport:all-open","v9.2.0"],"title":"Adding API Key Wildcard Search","number":221959,"url":"https://github.com/elastic/kibana/pull/221959","mergeCommit":{"message":"Adding API Key Wildcard Search (#221959)\n\nAdding ability to do partial matches/searches in the API Key section of\nthe Management Console.\n\n\n\nhttps://github.com/user-attachments/assets/02e9c44f-101f-44e3-b7cb-dc731646d140\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>\nCo-authored-by: Sid <siddharthmantri1@gmail.com>","sha":"7aa44ebe60393c5eba50881cb6646d78ccfb09b0"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/221959","number":221959,"mergeCommit":{"message":"Adding API Key Wildcard Search (#221959)\n\nAdding ability to do partial matches/searches in the API Key section of\nthe Management Console.\n\n\n\nhttps://github.com/user-attachments/assets/02e9c44f-101f-44e3-b7cb-dc731646d140\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>\nCo-authored-by: Sid <siddharthmantri1@gmail.com>","sha":"7aa44ebe60393c5eba50881cb6646d78ccfb09b0"}}]}] BACKPORT--> Co-authored-by: Eamonn-OL <119305140+Eamonn-OL@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Sid <siddharthmantri1@gmail.com>
1 parent a90e86b commit fa769ce

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

x-pack/platform/plugins/shared/security/public/management/api_keys/api_keys_grid/api_keys_grid_page.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ interface ApiKeysTableState {
4343
filters: QueryFilters;
4444
}
4545

46+
type KueryNode = any;
47+
4648
const DEFAULT_TABLE_STATE = {
4749
query: EuiSearchBar.Query.MATCH_ALL,
4850
sort: {
@@ -54,6 +56,8 @@ const DEFAULT_TABLE_STATE = {
5456
filters: {},
5557
};
5658

59+
const PLUS_SIGN_REGEX = /[+]/g;
60+
5761
export const APIKeysGridPage: FunctionComponent = () => {
5862
const { services } = useKibana<CoreStart>();
5963
const history = useHistory();
@@ -68,6 +72,41 @@ export const APIKeysGridPage: FunctionComponent = () => {
6872
const [state, queryApiKeysAndAggregations] = useAsyncFn((tableStateArgs: ApiKeysTableState) => {
6973
const queryContainer = EuiSearchBar.Query.toESQuery(tableStateArgs.query);
7074

75+
// Enhance the query to support partial matches for name and owner field
76+
if (queryContainer.bool?.must) {
77+
queryContainer.bool.must = queryContainer.bool.must.map((clause: KueryNode) => {
78+
if (clause.simple_query_string) {
79+
// Add wildcard to support partial matches
80+
const rawQuery = String(clause.simple_query_string.query ?? '');
81+
const wildCardQuery = rawQuery.replace(PLUS_SIGN_REGEX, '');
82+
return {
83+
bool: {
84+
should: [
85+
clause,
86+
{
87+
wildcard: {
88+
name: {
89+
value: `*${wildCardQuery}*`,
90+
case_insensitive: true,
91+
},
92+
},
93+
},
94+
{
95+
wildcard: {
96+
username: {
97+
value: `*${wildCardQuery}*`,
98+
case_insensitive: true,
99+
},
100+
},
101+
},
102+
],
103+
},
104+
};
105+
}
106+
return clause;
107+
});
108+
}
109+
71110
const requestBody = {
72111
...tableStateArgs,
73112
query: queryContainer,

x-pack/test/functional/apps/api_keys/home_page.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,17 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
483483
username: 'elastic',
484484
password: 'changeme',
485485
});
486-
487-
await pageObjects.common.navigateToApp('apiKeys');
488486
});
489487

490488
after(async () => {
491489
await security.testUser.restoreDefaults();
492490
await clearAllApiKeys(es, log);
493491
});
494492

493+
beforeEach(async () => {
494+
await pageObjects.common.navigateToApp('apiKeys');
495+
});
496+
495497
it('active/expired filter buttons work as expected', async () => {
496498
await pageObjects.apiKeys.clickExpiryFilters('active');
497499
await ensureApiKeysExist(['my api key', 'Alerting: Managed', 'test_cross_cluster']);
@@ -539,13 +541,16 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
539541
await ensureApiKeysExist(['my api key', 'Alerting: Managed', 'test_cross_cluster']);
540542
});
541543

542-
it.skip('search bar works as expected', async () => {
544+
it('search bar works as expected', async () => {
543545
await pageObjects.apiKeys.setSearchBarValue('test_user_api_key');
544546

545547
await ensureApiKeysExist(['test_user_api_key']);
546548

547549
await pageObjects.apiKeys.setSearchBarValue('"my api key"');
548550
await ensureApiKeysExist(['my api key']);
551+
552+
await pageObjects.apiKeys.setSearchBarValue('"api"');
553+
await ensureApiKeysExist(['my api key']);
549554
});
550555
});
551556
});

0 commit comments

Comments
 (0)