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

Auth failure listener page with basic get, delete dummy create #2086

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export enum ResourceType {
tenantsConfigureTab = 'tenantsConfigureTab',
auth = 'auth',
auditLogging = 'auditLogging',
authFailureListeners = 'authFailureListeners',
}

/**
Expand Down
12 changes: 12 additions & 0 deletions public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import { buildHashUrl, buildUrl } from './utils/url-builder';
import { CrossPageToast } from './cross-page-toast';
import { getDataSourceFromUrl, LocalCluster } from '../../utils/datasource-utils';
import { AuthFailureListeners } from './panels/auth-failure-listeners';

const LANDING_PAGE_URL = '/getstarted';

Expand Down Expand Up @@ -77,6 +78,10 @@
name: 'Audit logs',
href: buildUrl(ResourceType.auditLogging),
},
[ResourceType.authFailureListeners]: {
name: 'Rate limiting',
href: buildUrl(ResourceType.authFailureListeners),
},
};

const getRouteList = (multitenancyEnabled: boolean) => {
Expand Down Expand Up @@ -262,6 +267,13 @@
return <GetStarted {...props} />;
}}
/>
<Route
path={ROUTE_MAP.authFailureListeners.href}
render={() => {
setGlobalBreadcrumbs();
return <AuthFailureListeners {...props} />;

Check warning on line 274 in public/apps/configuration/app-router.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/app-router.tsx#L272-L274

Added lines #L272 - L274 were not covered by tests
}}
/>
{multitenancyEnabled && (
<Route
path={ROUTE_MAP.tenants.href}
Expand Down
1 change: 1 addition & 0 deletions public/apps/configuration/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const API_ENDPOINT = API_PREFIX + '/configuration';
export const API_ENDPOINT_ROLES = API_ENDPOINT + '/roles';
export const API_ENDPOINT_ROLESMAPPING = API_ENDPOINT + '/rolesmapping';
export const API_ENDPOINT_ACTIONGROUPS = API_ENDPOINT + '/actiongroups';
export const API_ENDPOINT_AUTHFAILURELISTENERS = API_ENDPOINT + '/authfailurelisteners';
export const API_ENDPOINT_TENANTS = API_ENDPOINT + '/tenants';
export const API_ENDPOINT_MULTITENANCY = API_PREFIX + '/multitenancy/tenant';
export const API_ENDPOINT_TENANCY_CONFIGS = API_ENDPOINT + '/tenancy/config';
Expand Down
125 changes: 125 additions & 0 deletions public/apps/configuration/panels/auth-failure-listeners.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import { EuiButton, EuiInMemoryTable, EuiIcon } from '@elastic/eui';
import React, { useContext, useState } from 'react';
import { AppDependencies } from '../../types';
import { API_ENDPOINT_AUTHFAILURELISTENERS } from '../constants';
import { createRequestContextWithDataSourceId } from '../utils/request-utils';
import { SecurityPluginTopNavMenu } from '../top-nav-menu';
import { DataSourceContext } from '../app-router';
import { getResourceUrl } from '../utils/resource-utils';

export function AuthFailureListeners(props: AppDependencies) {
const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled;
const { dataSource, setDataSource } = useContext(DataSourceContext)!;

Check warning on line 27 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L25-L27

Added lines #L25 - L27 were not covered by tests

const [listeners, setListeners] = useState([]);

Check warning on line 29 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L29

Added line #L29 was not covered by tests

const fetchData = async () => {
const data = await createRequestContextWithDataSourceId(dataSource.id).httpGet<any>({

Check warning on line 32 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L31-L32

Added lines #L31 - L32 were not covered by tests
http: props.coreStart.http,
url: API_ENDPOINT_AUTHFAILURELISTENERS,
});
setListeners(data.data);

Check warning on line 36 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L36

Added line #L36 was not covered by tests
};

const handleDelete = async (name: string) => {
await createRequestContextWithDataSourceId(dataSource.id).httpDelete<any>({

Check warning on line 40 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L39-L40

Added lines #L39 - L40 were not covered by tests
http: props.coreStart.http,
url: getResourceUrl(API_ENDPOINT_AUTHFAILURELISTENERS, name),
});
};

const createDummyAuthFailureListener = async () => {
await createRequestContextWithDataSourceId(dataSource.id).httpPost<any>({

Check warning on line 47 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L46-L47

Added lines #L46 - L47 were not covered by tests
http: props.coreStart.http,
url: getResourceUrl(API_ENDPOINT_AUTHFAILURELISTENERS, 'test'),
body: {
type: 'ip',
authentication_backend: 'test',
allowed_tries: 10,
time_window_seconds: 3600,
block_expiry_seconds: 600,
max_blocked_clients: 100000,
max_tracked_clients: 100000,
},
});
};

const columns = [

Check warning on line 62 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L62

Added line #L62 was not covered by tests
{
field: 'name',
name: 'Name',
},
{
field: 'type',
name: 'Type',
},
{
field: 'authentication_backend',
name: 'Authentication backend',
},
{
field: 'allowed_tries',
name: 'Allowed tries',
},
{
field: 'time_window_seconds',
name: 'Time window (sec)',
},
{
field: 'block_expiry_seconds',
name: 'Block expiry (sec)',
},
{
field: 'max_blocked_clients',
name: 'Max blocked clients',
},
{
field: 'max_tracked_clients',
name: 'Max tracked clients',
},
{
field: 'name',
name: 'Actions',
render: (name) => <EuiIcon type="trash" onClick={() => handleDelete(name)} />,

Check warning on line 98 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L98

Added line #L98 was not covered by tests
},
];

return (

Check warning on line 102 in public/apps/configuration/panels/auth-failure-listeners.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/configuration/panels/auth-failure-listeners.tsx#L102

Added line #L102 was not covered by tests
<>
<div className="panel-restrict-width">
<SecurityPluginTopNavMenu
{...props}
dataSourcePickerReadOnly={false}
setDataSource={setDataSource}
selectedDataSource={dataSource}
/>
</div>
<EuiButton onClick={fetchData}>GET</EuiButton>
<EuiInMemoryTable
tableLayout={'auto'}
columns={columns}
items={listeners}
itemId={'domain_name'}
pagination={true}
sorting={true}
/>

<EuiButton onClick={createDummyAuthFailureListener}>CREATE</EuiButton>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ exports[`SecurityPluginTopNavMenu renders DataSourceMenu when dataSource is enab
path="/getstarted"
render={[Function]}
/>
<Route
path="/authFailureListeners"
render={[Function]}
/>
<Route
path="/tenants"
render={[Function]}
Expand Down
10 changes: 10 additions & 0 deletions server/backend/opensearch_security_configuration_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,14 @@ export default function (Client: any, config: any, components: any) {
fmt: '/_plugins/_security/api/audit/config',
},
});

/**
* Gets auth failure listeners.
*/
Client.prototype.opensearch_security.prototype.getAuthFailureListeners = ca({
method: 'GET',
url: {
fmt: '/_plugins/_security/api/authfailurelisteners',
},
});
}
57 changes: 57 additions & 0 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,24 @@ export function defineRoutes(router: IRouter, dataSourceEnabled: boolean) {
current_password: schema.string(),
});

const authFailureListenersSchema = schema.object({
allowed_tries: schema.number(),
authentication_backend: schema.string(),
block_expiry_seconds: schema.number(),
max_blocked_clients: schema.number(),
max_tracked_clients: schema.number(),
time_window_seconds: schema.number(),
type: schema.string(),
});

const schemaMap: any = {
internalusers: internalUserSchema,
actiongroups: actionGroupSchema,
rolesmapping: roleMappingSchema,
roles: roleSchema,
tenants: tenantSchema,
account: accountSchema,
authfailurelisteners: authFailureListenersSchema,
};

function validateRequestBody(resourceName: string, requestBody: any): any {
Expand Down Expand Up @@ -694,6 +705,52 @@ export function defineRoutes(router: IRouter, dataSourceEnabled: boolean) {
}
);

/**
* Gets auth failure listeners。
*
* Sample payload:
* [
* { ??? }
*
* ]
*/
router.get(
{
path: `${API_PREFIX}/configuration/authfailurelisteners`,
validate: {
query: schema.object({
dataSourceId: schema.maybe(schema.string()),
}),
},
},
async (
context,
request,
response
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => {
try {
const esResp = await wrapRouteWithDataSource(
dataSourceEnabled,
context,
request,
'opensearch_security.getAuthFailureListeners'
);

return response.ok({
body: {
total: Object.keys(esResp).length,
data: esResp,
},
});
} catch (error) {
return response.custom({
statusCode: error.statusCode,
body: parseEsErrorResponse(error),
});
}
}
);

/**
* Update audit log configuration。
*
Expand Down
Loading