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

Add API Keys app to Management > Security. #45740

Merged
merged 20 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
96f97b6
Add API Keys app to Management > Security.
cjcenizal Sep 14, 2019
236d81c
Extract EmptyPrompt, InvalidateProvider, and NotEnabled components. R…
cjcenizal Oct 9, 2019
8afd388
Replace 'revoke' with 'invalidate'.
cjcenizal Oct 9, 2019
0704baa
Add documentationLinks service.
cjcenizal Oct 10, 2019
5988691
Merge branch 'master' into api-key-list
cjcenizal Oct 10, 2019
07d2786
Merge branch 'master' into api-key-list
cjcenizal Oct 11, 2019
e4b3d84
Using the Shield plugin methods instead
kobelb Oct 11, 2019
43698ce
Add time to rendered dates and add Status column so users can identif…
cjcenizal Oct 11, 2019
f0298cd
Merge pull request #20 from kobelb/pr/cjcenizal/45740
cjcenizal Oct 11, 2019
be05d8d
Merge branch 'api-key-list' of github.com:cjcenizal/kibana into api-k…
cjcenizal Oct 11, 2019
14a5839
Address API feedback.
cjcenizal Oct 12, 2019
8d725a4
Update copy.
cjcenizal Oct 12, 2019
3296f33
Rename ApiKeyCore type to ApiKeyToInvalidate. Remove unnecessary lint…
cjcenizal Oct 12, 2019
e58ab8e
Hide app title and description in inactive states.
cjcenizal Oct 12, 2019
56167df
Merge branch 'master' of github.com:elastic/kibana into api-key-list
cjcenizal Oct 14, 2019
27be6e6
Renaming API_BASE_PATH to INTERNAL_API_BASE_PATH
kobelb Oct 14, 2019
86ff3aa
Making isAdmin required
kobelb Oct 14, 2019
5da0a8f
Merge pull request #21 from kobelb/pr/cjcenizal/45740
cjcenizal Oct 14, 2019
4ad8055
Fix TS error.
cjcenizal Oct 14, 2019
8e6b934
Sort on expiration date by default, so users will see expired API key…
cjcenizal Oct 14, 2019
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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.
*/

export { SectionLoading } from './section_loading';
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding this to es_ui_shared 👍

* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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 React from 'react';

import {
EuiEmptyPrompt,
EuiLoadingSpinner,
EuiText,
EuiFlexGroup,
EuiFlexItem,
EuiTextColor,
} from '@elastic/eui';

interface Props {
inline?: boolean;
children: React.ReactNode;
[key: string]: any;
}

export const SectionLoading: React.FunctionComponent<Props> = ({ inline, children, ...rest }) => {
if (inline) {
return (
<EuiFlexGroup justifyContent="flexStart" alignItems="center" gutterSize="s">
<EuiFlexItem grow={false}>
<EuiLoadingSpinner size="m" />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText {...rest}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we really want to allow consumers to set any props for the EuiText? If we do, can we use the following so we don't have to use [key: string]: any?

type InferredProps<T> = T extends (props: infer P & { children?: ReactNode }, context?: any) => ReactElement | null ? P : T;

interface Props extends InferredProps<typeof EuiText> {
  inline?: boolean;
  children: React.ReactNode;
}

FWIW, this is my first time using type inference in conditional types, so I very well might be doing this wrong. Type-checking passes, so 🤷‍♂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not experienced enough with TS to assess this suggestion so I'm going to defer it to later.

<EuiTextColor color="subdued">{children}</EuiTextColor>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
);
}

return (
<EuiEmptyPrompt
title={<EuiLoadingSpinner size="xl" />}
body={<EuiText color="subdued">{children}</EuiText>}
data-test-subj="sectionLoading"
/>
);
};
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/security/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const GLOBAL_RESOURCE = '*';
export const IGNORED_TYPES = ['space'];
export const APPLICATION_PREFIX = 'kibana-';
export const RESERVED_PRIVILEGES_APPLICATION_WILDCARD = 'kibana-*';
export const API_BASE_PATH = '/internal/security';
20 changes: 20 additions & 0 deletions x-pack/legacy/plugins/security/common/model/api_key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export interface ApiKey {
id: string;
name: string;
username: string;
realm: string;
creation: number;
expiration: number;
invalidated: boolean;
}

export interface ApiKeyToInvalidate {
id: string;
name: string;
}
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/security/common/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { Role, RoleIndexPrivilege, RoleKibanaPrivilege } from './role';
export { FeaturesPrivileges } from './features_privileges';
export { RawKibanaPrivileges, RawKibanaFeaturePrivileges } from './raw_kibana_privileges';
export { KibanaPrivileges } from './kibana_privileges';
export { ApiKey } from './api_key';
export { User, EditUser, getUserDisplayName } from '../../../../../plugins/security/common/model';
export {
AuthenticatedUser,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/security/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { resolve } from 'path';
import { initAuthenticateApi } from './server/routes/api/v1/authenticate';
import { initUsersApi } from './server/routes/api/v1/users';
import { initApiKeysApi } from './server/routes/api/v1/api_keys';
import { initExternalRolesApi } from './server/routes/api/external/roles';
import { initPrivilegesApi } from './server/routes/api/external/privileges';
import { initIndicesApi } from './server/routes/api/v1/indices';
Expand Down Expand Up @@ -195,6 +196,7 @@ export const security = (kibana) => new kibana.Plugin({
initAPIAuthorization(server, authorization);
initAppAuthorization(server, xpackMainPlugin, authorization);
initUsersApi(securityPlugin, server);
initApiKeysApi(server);
initExternalRolesApi(server);
initIndicesApi(server);
initPrivilegesApi(server);
Expand Down
48 changes: 48 additions & 0 deletions x-pack/legacy/plugins/security/public/lib/api_keys_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { kfetch } from 'ui/kfetch';
import { ApiKey, ApiKeyToInvalidate } from '../../common/model/api_key';
import { API_BASE_PATH } from '../../common/constants';

interface CheckPrivilegesResponse {
areApiKeysEnabled: boolean;
isAdmin: boolean;
}

interface InvalidateApiKeysResponse {
itemsInvalidated: ApiKeyToInvalidate[];
errors: any[];
}

interface GetApiKeysResponse {
apiKeys: ApiKey[];
}

const apiKeysUrl = `${API_BASE_PATH}/api_key`;

export class ApiKeysApi {
public static async checkPrivileges(): Promise<CheckPrivilegesResponse> {
return kfetch({ pathname: `${apiKeysUrl}/privileges` });
}

public static async getApiKeys(isAdmin: boolean = false): Promise<GetApiKeysResponse> {
const query = {
isAdmin,
};

return kfetch({ pathname: apiKeysUrl, query });
}

public static async invalidateApiKeys(
apiKeys: ApiKeyToInvalidate[],
isAdmin: boolean = false
): Promise<InvalidateApiKeysResponse> {
const pathname = `${apiKeysUrl}/invalidate`;
const body = JSON.stringify({ apiKeys, isAdmin });
return kfetch({ pathname, method: 'POST', body });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<kbn-management-app section="security/api_keys">
<div id="apiKeysGridReactRoot" />
</kbn-management-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import routes from 'ui/routes';
import template from './api_keys.html';
import { API_KEYS_PATH } from '../management_urls';
import { getApiKeysBreadcrumbs } from '../breadcrumbs';
import { I18nContext } from 'ui/i18n';
import { ApiKeysGridPage } from './components';

routes.when(API_KEYS_PATH, {
template,
k7Breadcrumbs: getApiKeysBreadcrumbs,
controller($scope) {
$scope.$$postDigest(() => {
const domNode = document.getElementById('apiKeysGridReactRoot');

render(
<I18nContext>
<ApiKeysGridPage />
</I18nContext>, domNode);

// unmount react on controller destroy
$scope.$on('$destroy', () => {
unmountComponentAtNode(domNode);
});
});
},
});
Loading