Skip to content

Commit 4eaac59

Browse files
Jacek Kolezynskikibanamachine
authored andcommitted
[Security Solution] Enforce sending the request to API even if offline, for air-gapped environment. (elastic#220510)
**Resolves: elastic#181808** ## Summary I am fixing the issue of the Rules and Alerts tabs in Security, as well as the Fleet tab in Management, that gets stalled in air-gapped environment. I am doing so by enforcing the request to be sent to the API even when offline. ### Historical context: During investigation of the original issue elastic#181808 I proved that Kibana doesn't try to reach to EPR in the air-gapped environment (that is, with the `xpack.fleet.isAirGapped: true` flag, and WIFI being turned ON). I commented this [here](elastic#181808 (comment)) and we closed the issue. However, @111andre111 reached out to us saying that this wasn't enough, as the real issue remains, that is, Kibana doesn't behave properly when: - `xpack.fleet.isAirGapped` flag is set to `true` - there is no Internet connection (WIFI off or cable physically disconnected) That's why we reopened the ticket and I restarted the investigation. My first observation was that when I turn off the WIFI, I cannot see requests to the API being sent in the Network tab in Dev Tools, most importantly to the `_bootstrap` endpoint at the first entrance to the Solution app, and other endpoints later. I searched that the browser discovers being offline and suppresses such calls. When WIFI is back ON, then the browser sends these requests. That was exactly what I saw in the Network tab. I searched and found an option to force browser to always send the request, regardless of what it thinks about connectivity. Such option, `networkMode: 'always'`, can be added to TanStackQuery client. I started working on adding this option to occurences of `useQuery` and `useMutation`, and immediately sounded success, as the behavior was correct. However, @xcrzx rigthfully pointed out, that it would be much better to only add it to one place, that is the configuration of the QueryClient. I did it, and to my surprise, the problem returned. I noticed that adding this option to the QueryClient in Fleet solved the problem in the Fleet tab immediately, but adding this option to the `SecuritySolutionQueryClient` does nothing, like it was completely ignored. I searched different options and spent two more days debugging the problem, but then, when paired up again with Dmitrii, he found that the `SecuritySolutionQueryClient` is overshadowed by some other QueryClient present in the stack of components much below, the `CasesContext`. That discovery enabled me to add this new setting to the other QueryClient, and this fixes the issue. However, we think that it will be worth investigating why we need this second context, as the situation when one QueryClient overshadows another one, smells badly and may be a source of other issues as well (I will reach out to the team responsible for the CasesContext and ask if we can unify this somehow). ## BEFORE https://github.com/user-attachments/assets/662dab73-b1bd-4d6b-9d15-c35efab679c6 ## AFTER https://github.com/user-attachments/assets/b905bde0-150d-478d-9734-9003fb5bcf66 ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] [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 - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 996462a commit 4eaac59

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

x-pack/platform/plugins/shared/cases/public/components/cases_context/query_client.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,13 @@
77

88
import { QueryClient } from '@tanstack/react-query';
99

10-
export const casesQueryClient = new QueryClient();
10+
export const casesQueryClient = new QueryClient({
11+
defaultOptions: {
12+
queries: {
13+
networkMode: 'always',
14+
},
15+
mutations: {
16+
networkMode: 'always',
17+
},
18+
},
19+
});

x-pack/platform/plugins/shared/fleet/public/applications/fleet/app.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ import { DebugPage } from './sections/debug';
6565

6666
const FEEDBACK_URL = 'https://ela.st/fleet-feedback';
6767

68-
const queryClient = new QueryClient();
68+
const queryClient = new QueryClient({
69+
defaultOptions: {
70+
queries: {
71+
networkMode: 'always',
72+
},
73+
mutations: {
74+
networkMode: 'always',
75+
},
76+
},
77+
});
6978

7079
export const WithPermissionsAndSetup = memo<{ children?: React.ReactNode }>(({ children }) => {
7180
useBreadcrumbs('base');

x-pack/platform/plugins/shared/fleet/public/applications/integrations/app.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ import { IntegrationsHeader } from './components/header';
4747
import { AgentEnrollmentFlyout } from './components';
4848
import { ReadOnlyContextProvider } from './hooks/use_read_only_context';
4949

50-
const queryClient = new QueryClient();
50+
const queryClient = new QueryClient({
51+
defaultOptions: {
52+
queries: {
53+
networkMode: 'always',
54+
},
55+
mutations: {
56+
networkMode: 'always',
57+
},
58+
},
59+
});
5160

5261
const EmptyContext = () => <></>;
5362

x-pack/solutions/security/plugins/security_solution/public/common/containers/query_client/query_client_provider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export class SecuritySolutionQueryClient extends QueryClient {
2525
refetchOnWindowFocus: false,
2626
refetchOnMount: true,
2727
keepPreviousData: true,
28-
...(options?.defaultOptions?.queries ?? {}),
28+
...(options?.defaultOptions?.queries ?? { networkMode: 'always' }),
29+
},
30+
mutations: {
31+
networkMode: 'always',
32+
...(options?.defaultOptions?.mutations ?? { networkMode: 'always' }),
2933
},
3034
},
3135
};

0 commit comments

Comments
 (0)