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

[SecuritySolution][Detections] Fix "Closing a signal silently fails with reduced privileges" #86908

Merged
merged 5 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add a new hasIndexUpdateDelete flag
  • Loading branch information
banderror committed Jan 5, 2021
commit 9c14fdf7c9185e81d24ca38125de71fe090fdefb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('useUserInfo', () => {
hasEncryptionKey: null,
hasIndexManage: null,
hasIndexWrite: null,
hasIndexUpdateDelete: null,
isAuthenticated: null,
isSignalIndexExists: null,
loading: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface State {
canUserCRUD: boolean | null;
hasIndexManage: boolean | null;
hasIndexWrite: boolean | null;
hasIndexUpdateDelete: boolean | null;
isSignalIndexExists: boolean | null;
isAuthenticated: boolean | null;
hasEncryptionKey: boolean | null;
Expand All @@ -27,6 +28,7 @@ export const initialState: State = {
canUserCRUD: null,
hasIndexManage: null,
hasIndexWrite: null,
hasIndexUpdateDelete: null,
isSignalIndexExists: null,
isAuthenticated: null,
hasEncryptionKey: null,
Expand All @@ -45,6 +47,10 @@ export type Action =
type: 'updateHasIndexWrite';
hasIndexWrite: boolean | null;
}
| {
type: 'updateHasIndexUpdateDelete';
hasIndexUpdateDelete: boolean | null;
}
| {
type: 'updateIsSignalIndexExists';
isSignalIndexExists: boolean | null;
Expand Down Expand Up @@ -90,6 +96,12 @@ export const userInfoReducer = (state: State, action: Action): State => {
hasIndexWrite: action.hasIndexWrite,
};
}
case 'updateHasIndexUpdateDelete': {
return {
...state,
hasIndexUpdateDelete: action.hasIndexUpdateDelete,
};
}
case 'updateIsSignalIndexExists': {
return {
...state,
Expand Down Expand Up @@ -151,6 +163,7 @@ export const useUserInfo = (): State => {
canUserCRUD,
hasIndexManage,
hasIndexWrite,
hasIndexUpdateDelete,
isSignalIndexExists,
isAuthenticated,
hasEncryptionKey,
Expand All @@ -166,6 +179,7 @@ export const useUserInfo = (): State => {
hasEncryptionKey: isApiEncryptionKey,
hasIndexManage: hasApiIndexManage,
hasIndexWrite: hasApiIndexWrite,
hasIndexUpdateDelete: hasApiIndexUpdateDelete,
} = usePrivilegeUser();
const {
loading: indexNameLoading,
Expand Down Expand Up @@ -197,6 +211,19 @@ export const useUserInfo = (): State => {
}
}, [dispatch, loading, hasIndexWrite, hasApiIndexWrite]);

useEffect(() => {
if (
!loading &&
hasIndexUpdateDelete !== hasApiIndexUpdateDelete &&
hasApiIndexUpdateDelete != null
) {
dispatch({
type: 'updateHasIndexUpdateDelete',
hasIndexUpdateDelete: hasApiIndexUpdateDelete,
});
}
}, [dispatch, loading, hasIndexUpdateDelete, hasApiIndexUpdateDelete]);

useEffect(() => {
if (
!loading &&
Expand Down Expand Up @@ -272,6 +299,7 @@ export const useUserInfo = (): State => {
canUserCRUD,
hasIndexManage,
hasIndexWrite,
hasIndexUpdateDelete,
signalIndexName,
signalIndexMappingOutdated,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('usePrivilegeUser', () => {
hasEncryptionKey: null,
hasIndexManage: null,
hasIndexWrite: null,
hasIndexUpdateDelete: null,
isAuthenticated: null,
loading: true,
});
Expand All @@ -38,6 +39,7 @@ describe('usePrivilegeUser', () => {
hasEncryptionKey: true,
hasIndexManage: true,
hasIndexWrite: true,
hasIndexUpdateDelete: true,
isAuthenticated: true,
loading: false,
});
Expand All @@ -59,6 +61,7 @@ describe('usePrivilegeUser', () => {
hasEncryptionKey: false,
hasIndexManage: false,
hasIndexWrite: false,
hasIndexUpdateDelete: false,
isAuthenticated: false,
loading: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@ export interface ReturnPrivilegeUser {
hasEncryptionKey: boolean | null;
hasIndexManage: boolean | null;
hasIndexWrite: boolean | null;
hasIndexUpdateDelete: boolean | null;
}
/**
* Hook to get user privilege from
*
*/
export const usePrivilegeUser = (): ReturnPrivilegeUser => {
const [loading, setLoading] = useState(true);
const [privilegeUser, setPrivilegeUser] = useState<
Pick<
ReturnPrivilegeUser,
'isAuthenticated' | 'hasEncryptionKey' | 'hasIndexManage' | 'hasIndexWrite'
>
>({
const [privilegeUser, setPrivilegeUser] = useState<Omit<ReturnPrivilegeUser, 'loading'>>({
isAuthenticated: null,
hasEncryptionKey: null,
hasIndexManage: null,
hasIndexWrite: null,
hasIndexUpdateDelete: null,
});
const [, dispatchToaster] = useStateToaster();

Expand All @@ -59,6 +56,7 @@ export const usePrivilegeUser = (): ReturnPrivilegeUser => {
privilege.index[indexName].create_doc ||
privilege.index[indexName].index ||
privilege.index[indexName].write,
hasIndexUpdateDelete: privilege.index[indexName].write,
});
}
}
Expand All @@ -69,6 +67,7 @@ export const usePrivilegeUser = (): ReturnPrivilegeUser => {
hasEncryptionKey: false,
hasIndexManage: false,
hasIndexWrite: false,
hasIndexUpdateDelete: false,
});
errorToToaster({ title: i18n.PRIVILEGE_FETCH_FAILURE, error, dispatchToaster });
}
Expand Down