Skip to content

Commit e47f785

Browse files
authored
EDM-2540 Perform user permission checks through the Flight Control API exclusively (#376)
* EDM-2540: Move the permission check to be generic through the flightctl API * Fix applications structure to prevent API requests in LoginPage
1 parent 4fa79ec commit e47f785

50 files changed

Lines changed: 436 additions & 311 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONFIGURATION.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ This document describes all environment variables and configuration options avai
2525
| `TLS_CERT` | Path to TLS certificate | _(empty)_ | `/path/to/server.crt` |
2626
| `TLS_KEY` | Path to TLS private key | _(empty)_ | `/path/to/server.key` |
2727
| `API_PORT` | UI proxy server port | `3001` | `8080`, `3000`, etc. |
28-
| `K8S_RBAC_NS` | Kubernetes RBAC namespace | _(empty)_ | `flightctl` |
2928
| `IS_OCP_PLUGIN` | Run as OpenShift Console plugin | `false` | `true`, `false` |
3029
| `IS_RHEM` | Red Hat Enterprise Mode | _(empty)_ | `true`, `false` |
3130

apps/ocp-plugin/src/components/AppContext/AppContext.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
NavLinkFC,
77
PromptFC,
88
} from '@flightctl/ui-components/src/hooks/useAppContext';
9-
import { SystemRestoreProvider } from '@flightctl/ui-components/src/hooks/useSystemRestoreContext';
109
import { ROUTE } from '@flightctl/ui-components/src/hooks/useNavigate';
1110
import {
1211
Link,
@@ -27,18 +26,14 @@ import { useFetch } from '../../hooks/useFetch';
2726
import './AppContext.css';
2827

2928
/**
30-
* OCP Plugin App Context Provider that includes SystemRestoreProvider
29+
* OCP Plugin App Context Provider
3130
* The OCP plugin system calls useValuesAppContext separately and passes the value as a prop
3231
*/
3332
export const OCPPluginAppContext: React.FC<React.PropsWithChildren<{ value: AppContextProps }>> = ({
3433
children,
3534
value,
3635
}) => {
37-
return (
38-
<AppContext.Provider value={value}>
39-
<SystemRestoreProvider>{children}</SystemRestoreProvider>
40-
</AppContext.Provider>
41-
);
36+
return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
4237
};
4338

4439
const appRoutes = {

apps/ocp-plugin/src/components/common/WithPageLayout.tsx

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
import * as React from 'react';
22
import OrganizationGuard from '@flightctl/ui-components/src/components/common/OrganizationGuard';
3-
4-
// Restore WithPageLayoutContent when organizations are enabled for OCP plugin
5-
// The context is still needed since "useOrganizationGuardContext" is used in common components
6-
/*
7-
const WithPageLayoutContent = ({ children }: React.PropsWithChildren) => {
8-
const { isOrganizationSelectionRequired } = useOrganizationGuardContext();
9-
10-
return isOrganizationSelectionRequired ? (
11-
<OrganizationSelector isFirstLogin />
12-
) : (
13-
<>
14-
<PageNavigation />
15-
{children}
16-
</>
17-
);
18-
};
19-
*/
3+
import { SystemRestoreProvider } from '@flightctl/ui-components/src/hooks/useSystemRestoreContext';
4+
import { PermissionsContextProvider } from '@flightctl/ui-components/src/components/common/PermissionsContext';
205

216
const WithPageLayout = ({ children }: React.PropsWithChildren) => {
227
return (
238
<OrganizationGuard>
24-
<>{children}</>
9+
<PermissionsContextProvider>
10+
<SystemRestoreProvider>
11+
<>{children}</>
12+
</SystemRestoreProvider>
13+
</PermissionsContextProvider>
2514
</OrganizationGuard>
2615
);
2716
};
Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
11
import * as React from 'react';
2-
import {
3-
deleteData,
4-
fetchData,
5-
fetchUiProxy,
6-
handleApiJSONResponse,
7-
patchData,
8-
postData,
9-
putData,
10-
uiProxy,
11-
wsEndpoint,
12-
} from '../utils/apiCalls';
2+
import { deleteData, fetchData, fetchUiProxy, patchData, postData, putData, wsEndpoint } from '../utils/apiCalls';
133
import { PatchRequest } from '@flightctl/types';
14-
import { K8sVerb, checkAccess } from '@openshift-console/dynamic-plugin-sdk';
15-
16-
type OcpConfig = {
17-
rbacNs: string;
18-
};
19-
20-
const useOcpConfig = () => {
21-
const [config, setConfig] = React.useState<OcpConfig>();
22-
23-
React.useEffect(() => {
24-
const doItAsync = async () => {
25-
try {
26-
const response = await fetch(`${uiProxy}/api/config`);
27-
const cfg = await handleApiJSONResponse<OcpConfig>(response);
28-
setConfig(cfg);
29-
} catch (error) {
30-
// eslint-disable-next-line
31-
console.error('Error making request:', error);
32-
}
33-
};
34-
doItAsync();
35-
}, []);
36-
37-
return config;
38-
};
394

405
export const useFetch = () => {
416
const get = React.useCallback(
@@ -67,21 +32,6 @@ export const useFetch = () => {
6732

6833
const getWsEndpoint = React.useCallback((deviceId: string) => `${wsEndpoint}/api/terminal/${deviceId}`, []);
6934

70-
const ocpConfig = useOcpConfig();
71-
72-
const checkPermissions = React.useCallback(
73-
async (resource: string, op: string) => {
74-
const ssar = await checkAccess({
75-
group: 'flightctl.io',
76-
resource,
77-
verb: op as K8sVerb,
78-
namespace: ocpConfig?.rbacNs,
79-
});
80-
return !!ssar.status?.allowed;
81-
},
82-
[ocpConfig],
83-
);
84-
8535
const proxyFetch = React.useCallback(async (endpoint: string, requestInit: RequestInit): Promise<Response> => {
8636
return fetchUiProxy(endpoint, requestInit);
8737
}, []);
@@ -93,7 +43,6 @@ export const useFetch = () => {
9343
put,
9444
remove,
9545
patch,
96-
checkPermissions,
9746
proxyFetch,
9847
};
9948
};

apps/standalone/src/app/components/AppLayout/AppLayout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import OrganizationGuard, {
2020
import OrganizationSelector from '@flightctl/ui-components/src/components/common/OrganizationSelector';
2121
import PageNavigation from '@flightctl/ui-components/src/components/common/PageNavigation';
2222
import { useTranslation } from '@flightctl/ui-components/src/hooks/useTranslation';
23+
import { SystemRestoreProvider } from '@flightctl/ui-components/src/hooks/useSystemRestoreContext';
24+
import { PermissionsContextProvider } from '@flightctl/ui-components/src/components/common/PermissionsContext';
2325

2426
import logo from '@fctl-assets/bgimages/flight-control-logo.svg';
2527
import rhemLogo from '@fctl-assets/bgimages/RHEM-logo.svg';
@@ -109,7 +111,11 @@ const AppLayoutContent = () => {
109111
const AppLayout = () => {
110112
return (
111113
<OrganizationGuard>
112-
<AppLayoutContent />
114+
<PermissionsContextProvider>
115+
<SystemRestoreProvider>
116+
<AppLayoutContent />
117+
</SystemRestoreProvider>
118+
</PermissionsContextProvider>
113119
</OrganizationGuard>
114120
);
115121
};

apps/standalone/src/app/hooks/useFetch.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ export const useFetch = () => {
3232

3333
const getWsEndpoint = React.useCallback((deviceId: string) => `${wsEndpoint}/api/terminal/${deviceId}`, []);
3434

35-
const checkPermissions = React.useCallback(() => Promise.resolve(true), []);
36-
3735
const proxyFetch = React.useCallback(async (endpoint: string, requestInit: RequestInit): Promise<Response> => {
3836
return fetchUiProxy(endpoint, requestInit);
3937
}, []);
@@ -45,7 +43,6 @@ export const useFetch = () => {
4543
put,
4644
remove,
4745
patch,
48-
checkPermissions,
4946
proxyFetch,
5047
};
5148
};

apps/standalone/src/app/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { AppContext } from '@flightctl/ui-components/src/hooks/useAppContext';
3-
import { SystemRestoreProvider } from '@flightctl/ui-components/src/hooks/useSystemRestoreContext';
43

54
import { AppRouter } from './routes';
65
import { useStandaloneAppContext } from './hooks/useStandaloneAppContext';
@@ -20,9 +19,7 @@ const App: React.FunctionComponent = () => {
2019
<React.Suspense fallback={<div />}>
2120
<AuthContext.Provider value={authContextValue}>
2221
<AppContext.Provider value={appContextValue}>
23-
<SystemRestoreProvider>
24-
<AppRouter />
25-
</SystemRestoreProvider>
22+
<AppRouter />
2623
</AppContext.Provider>
2724
</AuthContext.Provider>
2825
</React.Suspense>

libs/ansible/src/hooks/useFetch.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ export const useFetch = (getCookie: (name: string) => string | undefined, servic
5252
[serviceUrl],
5353
);
5454

55-
const checkPermissions = React.useCallback(() => Promise.resolve(true), []);
56-
5755
const proxyFetch = React.useCallback(
5856
async (endpoint: string, requestInit: RequestInit): Promise<Response> => {
5957
return fetchUiProxy(endpoint, serviceUrl, applyHeaders, requestInit);
@@ -68,7 +66,6 @@ export const useFetch = (getCookie: (name: string) => string | undefined, servic
6866
put,
6967
remove,
7068
patch,
71-
checkPermissions,
7269
proxyFetch,
7370
};
7471
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './organization';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const defaultOrg = {
2+
apiVersion: 'v1alpha1',
3+
kind: 'Organization',
4+
metadata: {
5+
name: 'default',
6+
},
7+
spec: {
8+
displayName: 'Default Organization',
9+
},
10+
};
11+
12+
export { defaultOrg };

0 commit comments

Comments
 (0)