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

[8.x] [Fleet] Require AgentPolicies:All to add a fleet server (#193014) #193156

Merged
merged 2 commits into from
Sep 26, 2024
Merged
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
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/common/authz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export const calculateAuthz = ({
allSettings: fleet.settings?.all ?? false,
allAgentPolicies: fleet.agentPolicies?.all ?? false,
addAgents: fleet.agents?.all ?? false,
addFleetServers: (fleet.agents?.all && fleet.settings?.all) ?? false,
addFleetServers:
(fleet.agents?.all && fleet.agentPolicies?.all && fleet.settings?.all) ?? false,
// Setup is needed to access the Fleet UI
setup:
hasFleetAll ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const FleetServerHostsSection: React.FunctionComponent<FleetServerHostsSe
fleetServerHosts={fleetServerHosts}
deleteFleetServerHost={deleteFleetServerHost}
/>
{authz.fleet.allSettings && authz.fleet.allAgents ? (
{authz.fleet.addFleetServers ? (
<>
<EuiSpacer size="s" />
<EuiButtonEmpty
Expand Down
53 changes: 53 additions & 0 deletions x-pack/plugins/fleet/server/services/security/security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,57 @@ describe('getAuthzFromRequest', () => {
expect(res.fleet.readAgents).toBe(false);
});
});

describe('Fleet addFleetServer', () => {
beforeEach(() => {
mockSecurity.authz.mode.useRbacForRequest.mockReturnValue(true);
});
it('should authorize user with Fleet:Agents:All Fleet:AgentsPolicies:All Fleet:Settings:All', async () => {
checkPrivileges.mockResolvedValue({
privileges: {
kibana: [
{
resource: 'default',
privilege: 'api:fleet-agents-all',
authorized: true,
},
{
resource: 'default',
privilege: 'api:fleet-agent-policies-all',
authorized: true,
},
{
resource: 'default',
privilege: 'api:fleet-settings-all',
authorized: true,
},
],
elasticsearch: {} as any,
},
hasAllRequested: true,
username: 'test',
});
const res = await getAuthzFromRequest({} as any);
expect(res.fleet.addFleetServers).toBe(true);
});

it('should not authorize user with only Fleet:Agents:All', async () => {
checkPrivileges.mockResolvedValue({
privileges: {
kibana: [
{
resource: 'default',
privilege: 'api:fleet-agents-all',
authorized: true,
},
],
elasticsearch: {} as any,
},
hasAllRequested: true,
username: 'test',
});
const res = await getAuthzFromRequest({} as any);
expect(res.fleet.addFleetServers).toBe(false);
});
});
});
Loading