Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
46710bc
Let users update API Keys
kc13greiner Nov 18, 2022
e1478f0
Adding tests and readonly
kc13greiner Nov 23, 2022
d946bfe
Removing debugging logs
kc13greiner Nov 23, 2022
96fd016
Fixing message formatting
kc13greiner Nov 28, 2022
61a22e7
Adding braces around sub value
kc13greiner Nov 28, 2022
4658de1
Fixing translations
kc13greiner Nov 28, 2022
1d493ce
plugin test fix
kc13greiner Nov 28, 2022
1187d80
Changing other message IDs
kc13greiner Nov 28, 2022
912f5dd
Merge branch 'main' into feature/api_keys_update
kc13greiner Nov 28, 2022
38245c7
Merge branch 'main' into feature/api_keys_update
kc13greiner Nov 28, 2022
227d11d
Updating API Key docs
kc13greiner Nov 28, 2022
0e27f9e
Fixing error message title and adding API test
kc13greiner Nov 28, 2022
c3d819d
Fixing for ES validations
kc13greiner Nov 29, 2022
6626a74
Fixing values sent and username when updating/viewing
kc13greiner Nov 29, 2022
9da296b
Merge branch 'main' into feature/api_keys_update
kc13greiner Nov 29, 2022
6084e4d
Fixing API test
kc13greiner Nov 30, 2022
d317cd4
Removing unused services
kc13greiner Nov 30, 2022
7b27465
PR Review feedback
kc13greiner Dec 8, 2022
f1b81f2
Update docs/user/security/api-keys/index.asciidoc
kc13greiner Dec 8, 2022
cb41247
Update docs/user/security/api-keys/index.asciidoc
kc13greiner Dec 8, 2022
337988e
Adding docs update about readonly mode
kc13greiner Dec 8, 2022
f23230a
Merge branch 'main' into feature/api_keys_update
kc13greiner Dec 8, 2022
1a8c8f7
Changes for PR feedback
kc13greiner Dec 13, 2022
200e57e
Merge branch 'main' into feature/api_keys_update
kc13greiner Dec 13, 2022
1a10fc8
Fixing test
kc13greiner Dec 13, 2022
92079c8
Merge branch 'main' into feature/api_keys_update
kc13greiner Dec 13, 2022
9ecb176
Merge branch 'main' into feature/api_keys_update
kibanamachine Dec 13, 2022
5eacf4a
Merge branch 'main' into feature/api_keys_update
kc13greiner Dec 13, 2022
cb5cc5a
Merge branch 'main' into feature/api_keys_update
kc13greiner Dec 13, 2022
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
14 changes: 10 additions & 4 deletions docs/user/security/api-keys/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ image:images/api-keys.png["API Keys UI"]
=== Security privileges

You must have the `manage_security`, `manage_api_key`, or the `manage_own_api_key`
cluster privileges to use API keys in {kib}. To manage roles, open the main menu, then click
cluster privileges to use API keys in {kib}. API keys can also be seen in a readonly view with access to the page and the `read_security` cluster privilege. To manage roles, open the main menu, then click
*Stack Management > Roles*, or use the <<role-management-api, {kib} Role Management API>>.


Expand All @@ -45,11 +45,20 @@ curl --location --request GET 'http://localhost:5601/api/security/role' \
--header 'kbn-xsrf: true' \
--header 'Authorization: ApiKey aVZlLUMzSUJuYndxdDJvN0k1bU46aGxlYUpNS2lTa2FKeVZua1FnY1VEdw==' \


[IMPORTANT]
============================================================================
API keys are intended for programmatic access to {kib} and {es}. Do not use API keys to authenticate access via a web browser.
============================================================================

[float]
[[udpate-api-key]]
=== Update an API key

To update an API key, open the main menu, click *Stack Management > API Keys*, and then click on the name of the key.

You can only update the `Restrict privileges` and `metadata` fields.

[float]
[[view-api-keys]]
=== View and delete API keys
Expand All @@ -62,6 +71,3 @@ created by which user in which realm.
If you have only the `manage_own_api_key` permission, you see only a list of your own keys.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to also be true if you have the 'read_sec' permission and access to the API key's screen (via kibana admin or viewer role)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch! I've added a line in the docs to reference the readonly view. @gchaps Would you mind reviewing the new sentence I added?


You can delete API keys individually or in bulk.

You cannot modify an API key. If you need additional privileges,
you must create a new key with the desired configuration and invalidate the old key.
1 change: 1 addition & 0 deletions x-pack/plugins/security/common/model/api_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ApiKey {
expiration: number;
invalidated: boolean;
metadata: Record<string, any>;
role_descriptors?: Record<string, any>;
}

export interface ApiKeyToInvalidate {
Expand Down
28 changes: 16 additions & 12 deletions x-pack/plugins/security/public/components/form_flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface FormFlyoutProps extends Omit<EuiFlyoutProps, 'onClose'> {
submitButtonColor?: EuiButtonProps['color'];
isLoading?: EuiButtonProps['isLoading'];
isDisabled?: EuiButtonProps['isDisabled'];
isSubmitButtonHidden?: boolean;
}

export const FormFlyout: FunctionComponent<FormFlyoutProps> = ({
Expand All @@ -44,6 +45,7 @@ export const FormFlyout: FunctionComponent<FormFlyoutProps> = ({
onSubmit,
isLoading,
isDisabled,
isSubmitButtonHidden,
children,
initialFocus,
...rest
Expand Down Expand Up @@ -80,18 +82,20 @@ export const FormFlyout: FunctionComponent<FormFlyoutProps> = ({
/>
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="formFlyoutSubmitButton"
isLoading={isLoading}
isDisabled={isDisabled}
color={submitButtonColor}
fill
onClick={onSubmit}
>
{submitButtonText}
</EuiButton>
</EuiFlexItem>
{!isSubmitButtonHidden && (
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="formFlyoutSubmitButton"
isLoading={isLoading}
isDisabled={isDisabled}
color={submitButtonColor}
fill
onClick={onSubmit}
>
{submitButtonText}
</EuiButton>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlyoutFooter>
</EuiFlyout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export const apiKeysAPIClientMock = {
getApiKeys: jest.fn(),
invalidateApiKeys: jest.fn(),
createApiKey: jest.fn(),
updateApiKey: jest.fn(),
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,20 @@ describe('APIKeysAPIClient', () => {
body: JSON.stringify(mockAPIKeys),
});
});

it('updateApiKey() queries correct endpoint', async () => {
const httpMock = httpServiceMock.createStartContract();

const mockResponse = Symbol('mockResponse');
httpMock.put.mockResolvedValue(mockResponse);

const apiClient = new APIKeysAPIClient(httpMock);
const mockApiKeyUpdate = { id: 'test_id', metadata: {}, roles_descriptor: {} };

await expect(apiClient.updateApiKey(mockApiKeyUpdate)).resolves.toBe(mockResponse);
expect(httpMock.put).toHaveBeenCalledTimes(1);
expect(httpMock.put).toHaveBeenCalledWith('/internal/security/api_key', {
body: JSON.stringify(mockApiKeyUpdate),
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export interface CreateApiKeyResponse {
api_key: string;
}

export interface UpdateApiKeyRequest {
id: string;
role_descriptors?: ApiKeyRoleDescriptors;
metadata?: Record<string, any>;
}

export interface UpdateApiKeyResponse {
updated: boolean;
}

const apiKeysUrl = '/internal/security/api_key';

export class APIKeysAPIClient {
Expand All @@ -62,4 +72,10 @@ export class APIKeysAPIClient {
body: JSON.stringify(apiKey),
});
}

public async updateApiKey(apiKey: UpdateApiKeyRequest) {
return await this.http.put<UpdateApiKeyResponse>(apiKeysUrl, {
body: JSON.stringify(apiKey),
});
}
}
Loading