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

[Cases] Suggest user profiles with read permission #172047

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 1 addition & 3 deletions x-pack/plugins/cases/server/services/user_profiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ export class UserProfileService {
private static buildRequiredPrivileges(owners: string[], security: SecurityPluginStart) {
const privileges: string[] = [];
for (const owner of owners) {
for (const operation of [Operations.updateCase.name, Operations.getCase.name]) {
privileges.push(security.authz.actions.cases.get(owner, operation));
}
privileges.push(security.authz.actions.cases.get(owner, Operations.getCase.name));
}

return privileges;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import expect from '@kbn/expect';
import { Cookie } from 'tough-cookie';
import { User } from '@kbn/cases-plugin/common/types/domain';
import { UserProfile } from '@kbn/security-plugin/common';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

Expand All @@ -20,7 +19,6 @@ import {
loginUsers,
} from '../../../../common/lib/api';
import { secOnlySpacesAll, superUser } from '../../../../common/lib/authentication/users';
import { getUserInfo } from '../../../../common/lib/authentication';
import { createUsersAndRoles, deleteUsersAndRoles } from '../../../../common/lib/authentication';
import { securitySolutionOnlyAllSpacesRole } from '../../../../common/lib/authentication/roles';

Expand All @@ -31,7 +29,6 @@ export default ({ getService }: FtrProviderContext): void => {
const supertestWithoutAuth = getService('supertestWithoutAuth');

describe('find_cases', () => {
const secOnlyInfo: User = getUserInfo(secOnlySpacesAll);
let cookies: Cookie[];
let suggestedSecUsers: UserProfile[];
let superUserHeaders: { Cookie: string };
Expand Down Expand Up @@ -62,7 +59,7 @@ export default ({ getService }: FtrProviderContext): void => {
suggestedSecUsers = await suggestUserProfiles({
supertest: supertestWithoutAuth,
req: {
name: secOnlyInfo.username!,
name: 'all_spaces',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

securityPluginStart.userProfiles.suggest seems to do a fuzzy match on the name field so sec_user_all_spaces was now returning another security user, sec_user_read. Changing it here guarantees the right profile is returned.

owners: ['securitySolutionFixture'],
size: 1,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ export default function ({ getService }: FtrProviderContext) {
`);
});

it('find a user who only has read privilege for cases', async () => {
const profiles = await suggestUserProfiles({
supertest: supertestWithoutAuth,
req: {
name: 'read',
owners: ['securitySolutionFixture'],
},
auth: { user: superUser, space: 'space1' },
});

expectSnapshot(profiles.map(({ user, data }) => ({ user, data }))).toMatchInline(`
Copy link
Member

Choose a reason for hiding this comment

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

TIL 🚀

Array [
Object {
"data": Object {},
"user": Object {
"email": "[email protected]",
"full_name": "sec only_read",
"username": "sec_only_read",
},
},
]
`);
});

it('does not find a user who does not have access to the default space', async () => {
const profiles = await suggestUserProfiles({
supertest: supertestWithoutAuth,
Expand Down Expand Up @@ -85,6 +109,14 @@ export default function ({ getService }: FtrProviderContext) {
expect(profiles.filter(({ user }) => user.username === obsOnly.username)).to.be.empty();
expectSnapshot(profiles.map(({ user, data }) => ({ user, data }))).toMatchInline(`
Array [
Object {
"data": Object {},
"user": Object {
"email": "[email protected]",
"full_name": "sec only_read",
"username": "sec_only_read",
},
},
Object {
"data": Object {},
"user": Object {
Expand All @@ -105,19 +137,6 @@ export default function ({ getService }: FtrProviderContext) {
`);
});

it('does not find a user who does not have update privileges to cases', async () => {
const profiles = await suggestUserProfiles({
supertest: supertestWithoutAuth,
req: {
name: 'read',
owners: ['securitySolutionFixture'],
},
auth: { user: superUser, space: 'space1' },
});

expect(profiles).to.be.empty();
});

it('fails with a 403 because the user making the request does not have the appropriate api kibana endpoint privileges', async () => {
await suggestUserProfiles({
supertest: supertestWithoutAuth,
Expand Down Expand Up @@ -186,9 +205,9 @@ export default function ({ getService }: FtrProviderContext) {
Object {
"data": Object {},
"user": Object {
"email": "sec_only_no_delete@elastic.co",
"full_name": "sec only_no_delete",
"username": "sec_only_no_delete",
"email": "sec_only_read@elastic.co",
"full_name": "sec only_read",
"username": "sec_only_read",
},
},
]
Expand Down Expand Up @@ -242,7 +261,7 @@ export default function ({ getService }: FtrProviderContext) {
await deleteUsersAndRoles(getService, users, roles);
});

it('finds 3 profiles when searching for the name sec when a user has both security and observability privileges', async () => {
it('finds 4 profiles when searching for the name sec when a user has both security and observability privileges', async () => {
const profiles = await suggestUserProfiles({
supertest: supertestWithoutAuth,
req: {
Expand All @@ -254,6 +273,14 @@ export default function ({ getService }: FtrProviderContext) {

expectSnapshot(profiles.map(({ user, data }) => ({ user, data }))).toMatchInline(`
Array [
Object {
"data": Object {},
"user": Object {
"email": "[email protected]",
"full_name": "sec only_read",
"username": "sec_only_read",
},
},
Object {
"data": Object {},
"user": Object {
Expand Down