Skip to content

Commit ae083f9

Browse files
cwperksabhivka7
andauthored
[Backport 2.8] Fixing dynamic tenancy changes for issues 1412 (#1457)
* Fixing dynamic tenancy changes for issues 1412 (#1419) * Fixing dynamic tenancy changes for opensearchdasbhoard.yaml Signed-off-by: Abhi Kalra <[email protected]> Co-authored-by: Abhi Kalra <[email protected]> Co-authored-by: Stephen Crawford <[email protected]> (cherry picked from commit c4e6c37) * Update versions in new workflow Signed-off-by: Craig Perkins <[email protected]> --------- Signed-off-by: Craig Perkins <[email protected]> Co-authored-by: Abhi Kalra <[email protected]>
1 parent 920e6eb commit ae083f9

File tree

8 files changed

+95
-21
lines changed

8 files changed

+95
-21
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Cypress Tests Multitenancy Disabled
2+
3+
on: [ push, pull_request ]
4+
5+
env:
6+
TEST_BROWSER_HEADLESS: 1
7+
CI: 1
8+
FTR_PATH: 'ftr'
9+
START_CMD: 'node ../scripts/opensearch_dashboards --dev --no-base-path --no-watch --opensearch_security.multitenancy.enable_aggregation_view=true'
10+
OPENSEARCH_SNAPSHOT_CMD: 'node ../scripts/opensearch snapshot'
11+
SPEC: 'cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js,'
12+
OPENSEARCH_VERSION: 2.8.0
13+
PLUGIN_NAME: opensearch-security
14+
PLUGIN_VERSION: 2.8.0.0
15+
16+
jobs:
17+
tests:
18+
name: Run Cypress Tests Multitenancy Disabled
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ ubuntu-latest , windows-latest ]
23+
runs-on: ${{ matrix.os }}
24+
25+
steps:
26+
- name: Set up JDK
27+
uses: actions/setup-java@v1
28+
with:
29+
java-version: 11
30+
31+
- name: Checkout Branch
32+
uses: actions/checkout@v3
33+
34+
- name: Download security plugin and create setup scripts
35+
uses: ./.github/actions/download-plugin
36+
with:
37+
opensearch-version: ${{ env.OPENSEARCH_VERSION }}
38+
plugin-name: ${{ env.PLUGIN_NAME }}
39+
plugin-version: ${{ env.PLUGIN_VERSION }}
40+
41+
- name: Run Opensearch with A Single Plugin
42+
uses: opensearch-project/security/.github/actions/start-opensearch-with-one-plugin@main
43+
with:
44+
opensearch-version: ${{ env.OPENSEARCH_VERSION }}
45+
plugin-name: ${{ env.PLUGIN_NAME }}
46+
setup-script-name: setup
47+
48+
- name: Run Dashboard with Security Dashboards Plugin
49+
uses: ./.github/actions/install-dashboards
50+
with:
51+
plugin_name: security-dashboards-plugin
52+
53+
- name: Configure and Run OpenSearch Dashboards with Cypress Test Cases
54+
run: |
55+
cd ./OpenSearch-Dashboards
56+
echo 'server.host: "0.0.0.0"' >> ./config/opensearch_dashboards.yml
57+
echo 'opensearch.hosts: ["https://localhost:9200"]' >> ./config/opensearch_dashboards.yml
58+
echo 'opensearch.ssl.verificationMode: none' >> ./config/opensearch_dashboards.yml
59+
echo 'opensearch.username: "kibanaserver"' >> ./config/opensearch_dashboards.yml
60+
echo 'opensearch.password: "kibanaserver"' >> ./config/opensearch_dashboards.yml
61+
echo 'opensearch.requestHeadersWhitelist: [ authorization,securitytenant ]' >> ./config/opensearch_dashboards.yml
62+
echo 'opensearch_security.multitenancy.enabled: false' >> ./config/opensearch_dashboards.yml
63+
echo 'opensearch_security.readonly_mode.roles: ["kibana_read_only"]' >> ./config/opensearch_dashboards.yml
64+
echo 'opensearch_security.cookie.secure: false' >> ./config/opensearch_dashboards.yml
65+
nohup yarn start --no-base-path --no-watch &
66+
sleep 500
67+
git clone https://github.com/opensearch-project/opensearch-dashboards-functional-test.git
68+
cd opensearch-dashboards-functional-test
69+
npm install cypress --save-dev
70+
yarn cypress:run-with-security --browser chrome --spec "cypress/integration/plugins/security-dashboards-plugin/inaccessible_tenancy_features.js"

public/apps/account/account-nav-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function AccountNavButton(props: {
8585
}, [props.coreStart.http]);
8686

8787
// Check if the tenant modal should be shown on load
88-
if (isMultiTenancyEnabled && getShouldShowTenantPopup()) {
88+
if (isMultiTenancyEnabled && getShouldShowTenantPopup() && props.config.multitenancy.enabled) {
8989
setShouldShowTenantPopup(false);
9090
showTenantSwitchPanel();
9191
}
@@ -128,7 +128,7 @@ export function AccountNavButton(props: {
128128
>
129129
View roles and identities
130130
</EuiButtonEmpty>
131-
{isMultiTenancyEnabled && (
131+
{isMultiTenancyEnabled && props.config.multitenancy.enabled && (
132132
<>
133133
{horizontalRule}
134134
<EuiButtonEmpty data-test-subj="switch-tenants" size="xs" onClick={showTenantSwitchPanel}>

public/apps/account/test/account-nav-button.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,6 @@ describe('Account navigation button, multitenancy disabled', () => {
171171
currAuthType={'dummy'}
172172
/>
173173
);
174-
expect(setState).toBeCalledTimes(1);
174+
expect(setState).toBeCalledTimes(0);
175175
});
176176
});

public/apps/configuration/panels/tenant-list/manage_tab.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import { showTableStatusMessage } from '../../utils/loading-spinner-utils';
6767
import { useContextMenuState } from '../../utils/context-menu';
6868
import { generateResourceName } from '../../utils/resource-utils';
6969
import { DocLinks } from '../../constants';
70-
import { TenantInstructionView } from './tenant-instruction-view';
7170
import { TenantList } from './tenant-list';
7271
import { getBreadcrumbs, Route_MAP } from '../../app-router';
7372
import { buildUrl } from '../../utils/url-builder';
@@ -92,30 +91,29 @@ export function ManageTab(props: AppDependencies) {
9291
const [isPrivateTenantEnabled, setIsPrivateTenantEnabled] = useState(false);
9392
const [dashboardsDefaultTenant, setDashboardsDefaultTenant] = useState('');
9493

94+
const { http } = props.coreStart;
95+
9596
const fetchData = useCallback(async () => {
9697
try {
9798
setLoading(true);
98-
const rawTenantData = await fetchTenants(props.coreStart.http);
99+
const rawTenantData = await fetchTenants(http);
99100
const processedTenantData = transformTenantData(rawTenantData);
100-
const activeTenant = await fetchCurrentTenant(props.coreStart.http);
101-
const currentUser = await getCurrentUser(props.coreStart.http);
101+
const activeTenant = await fetchCurrentTenant(http);
102+
const currentUser = await getCurrentUser(http);
102103
setCurrentUsername(currentUser);
103104
setCurrentTenant(resolveTenantName(activeTenant, currentUser));
104105
setTenantData(processedTenantData);
105-
setIsMultiTenancyEnabled(
106-
(await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled
107-
);
108-
setIsPrivateTenantEnabled(
109-
(await getDashboardsInfo(props.coreStart.http)).private_tenant_enabled
110-
);
111-
setDashboardsDefaultTenant((await getDashboardsInfo(props.coreStart.http)).default_tenant);
106+
const tenancyConfig = await getDashboardsInfo(http);
107+
setIsMultiTenancyEnabled(tenancyConfig.multitenancy_enabled);
108+
setIsPrivateTenantEnabled(tenancyConfig.private_tenant_enabled);
109+
setDashboardsDefaultTenant(tenancyConfig.default_tenant);
112110
} catch (e) {
113111
console.log(e);
114112
setErrorFlag(true);
115113
} finally {
116114
setLoading(false);
117115
}
118-
}, [props.coreStart.http]);
116+
}, [http]);
119117

120118
React.useEffect(() => {
121119
fetchData();
@@ -479,9 +477,6 @@ export function ManageTab(props: AppDependencies) {
479477
);
480478
};
481479

482-
if (!props.config.multitenancy.enabled) {
483-
return <TenantInstructionView />;
484-
}
485480
/* eslint-disable */
486481
return (
487482
<>

public/apps/configuration/panels/tenant-list/tenant-list.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { ExternalLink } from '../../utils/display-utils';
3131
import { displayBoolean } from '../../utils/display-utils';
3232
import { DocLinks } from '../../constants';
3333
import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils';
34+
import { TenantInstructionView } from './tenant-instruction-view';
3435

3536
interface TenantListProps extends AppDependencies {
3637
tabID: string;
@@ -127,6 +128,10 @@ export function TenantList(props: TenantListProps) {
127128
));
128129
};
129130

131+
if (!props.config.multitenancy.enabled) {
132+
return <TenantInstructionView />;
133+
}
134+
130135
return (
131136
<>
132137
<EuiPageHeader>

public/apps/configuration/panels/tenant-list/test/tenant-list.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('Tenant list', () => {
131131
config={config1 as any}
132132
/>
133133
);
134-
expect(component.find(TenantInstructionView).length).toBe(1);
134+
expect(component.find(TenantInstructionView).length).toBe(0);
135135
});
136136

137137
it('fetch data error', (done) => {

public/plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ export class SecurityPlugin
155155
})
156156
);
157157

158-
if (multitenancyEnabled && config.multitenancy.enable_aggregation_view) {
158+
if (
159+
multitenancyEnabled &&
160+
config.multitenancy.enabled &&
161+
config.multitenancy.enable_aggregation_view
162+
) {
159163
deps.savedObjectsManagement.columns.register(
160164
(tenantColumn as unknown) as SavedObjectsManagementColumn<string>
161165
);

server/multitenancy/tenant_resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { SecurityPluginConfigType } from '..';
1919
import { GLOBAL_TENANT_SYMBOL, PRIVATE_TENANT_SYMBOL, globalTenantName } from '../../common';
2020

2121
export const PRIVATE_TENANTS: string[] = [PRIVATE_TENANT_SYMBOL, 'private'];
22-
export const GLOBAL_TENANTS: string[] = ['global', GLOBAL_TENANT_SYMBOL];
22+
export const GLOBAL_TENANTS: string[] = ['global', GLOBAL_TENANT_SYMBOL, 'Global'];
2323
/**
2424
* Resovles the tenant the user is using.
2525
*

0 commit comments

Comments
 (0)