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

[Fleet] Add permissions checks #48143

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 24 additions & 0 deletions x-pack/legacy/plugins/fleet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ export function fleet(kibana: any) {
attributesToEncrypt: new Set(['token']),
attributesToExcludeFromAAD: new Set(['enrollment_rules']),
});
server.plugins.xpack_main.registerFeature({
id: 'fleet',
name: 'Fleet',
app: ['fleet', 'kibana'],
excludeFromBasePrivileges: true,
privileges: {
all: {
savedObject: {
all: ['agents', 'events', 'tokens'],
read: [],
},
ui: ['read', 'write'],
api: ['fleet-read', 'fleet-all'],
},
read: {
savedObject: {
all: [],
read: ['agents', 'events', 'tokens'],
},
ui: ['read'],
api: ['fleet-read'],
},
},
});
initServerWithKibana(server);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface FrameworkAdapter {
// Instance vars
info: FrameworkInfo;
version: string;
capabilities: { read: boolean; write: boolean };
currentUser: FrameworkUser;
// Methods
waitUntilFrameworkReady(): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isLeft } from 'fp-ts/lib/Either';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { UIRoutes } from 'ui/routes';
import { capabilities } from 'ui/capabilities';
import { BufferedKibanaServiceCall, KibanaAdapterServiceRefs, KibanaUIConfig } from '../../types';
import {
FrameworkAdapter,
Expand All @@ -36,6 +37,10 @@ export class KibanaFrameworkAdapter implements FrameworkAdapter {
public get currentUser() {
return this.shieldUser!;
}
public get capabilities(): Readonly<{ read: boolean; write: boolean }> {
return capabilities.get().fleet as { read: boolean; write: boolean };
}

private xpackInfo: FrameworkInfo | null = null;
private adapterService: KibanaAdapterServiceProvider;
private shieldUser: FrameworkUser | null = null;
Expand Down
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/fleet/public/lib/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class FrameworkLib {
return this.adapter.currentUser;
}

public get capabilities(): { read: boolean; write: boolean } {
return this.adapter.capabilities;
}

public get info() {
return this.adapter.info;
}
Expand Down
34 changes: 20 additions & 14 deletions x-pack/legacy/plugins/fleet/public/pages/agent_list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,16 @@ export const AgentListPage: React.SFC<RouterProps> = ({ libs }) => {
</h2>
}
actions={
<EuiButton fill iconType="plusInCircle">
<FormattedMessage
id="xpack.fleet.agentList.addButton"
defaultMessage="Install new agent"
/>
</EuiButton>
libs.framework.capabilities.write ? (
<EuiButton fill iconType="plusInCircle">
<FormattedMessage
id="xpack.fleet.agentList.addButton"
defaultMessage="Install new agent"
/>
</EuiButton>
) : (
null
)
}
/>
);
Expand Down Expand Up @@ -184,14 +188,16 @@ export const AgentListPage: React.SFC<RouterProps> = ({ libs }) => {
<EuiFlexItem grow={4}>
<SearchBar libs={libs} value={search} onChange={setSearch} fieldPrefix="agents" />
</EuiFlexItem>
<EuiFlexItem>
<EuiButton fill iconType="plusInCircle">
<FormattedMessage
id="xpack.fleet.agentList.addButton"
defaultMessage="Install new agent"
/>
</EuiButton>
</EuiFlexItem>
{libs.framework.capabilities.write && (
<EuiFlexItem>
<EuiButton fill iconType="plusInCircle">
<FormattedMessage
id="xpack.fleet.agentList.addButton"
defaultMessage="Install new agent"
/>
</EuiButton>
</EuiFlexItem>
)}
</EuiFlexGroup>

<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const NoAccessPage = injectI18n(({ intl }) => (
<FormattedMessage
id="xpack.fleet.noAccess.accessDeniedDescription"
defaultMessage="You are not authorized to access Elastic Fleet. To use Elastic Fleet,
you need the privileges granted by the {elasticFleetRole} role."
you need a user role that contains read or all permissions for this application."
values={{ elasticFleetRole: '`elastic_admin`' }}
/>
</p>
Expand Down
10 changes: 10 additions & 0 deletions x-pack/legacy/plugins/fleet/public/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ export class AppRoutes extends Component<RouterProps, RouterState> {
/>
)}

{!this.props.libs.framework.capabilities.read && (
<Route
render={props =>
!props.location.pathname.includes('/error') ? (
<Redirect to="/error/no_access" />
) : null
}
/>
)}

{/* Ensure security is eanabled for elastic and kibana */}
{/* TODO: Disabled for now as we don't have this info set up on backend yet */}
{/* {!get(this.props.libs.framework.info, 'security.enabled', true) && (
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/fleet/server/routes/agents/enroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const createEnrollAgentsRoute = (libs: FleetServerLib) => ({
path: '/api/fleet/agents/enroll',
config: {
auth: false,
tags: ['access:fleet-all'],
validate: {
headers: Joi.object({
'kbn-fleet-enrollment-token': Joi.string().required(),
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/fleet/server/routes/agents/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const createGETAgentEventsRoute = (libs: FleetServerLib) => ({
method: 'GET',
path: '/api/fleet/agents/{agentId}/events',
config: {
tags: ['access:fleet-read'],
validate: {
query: Joi.object({
kuery: Joi.string()
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/fleet/server/routes/agents/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const createGETAgentsRoute = (libs: FleetServerLib) => ({
method: 'GET',
path: '/api/fleet/agents/{agentId}',
config: {
tags: ['access:fleet-read'],
validate: {},
},
handler: async (
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/fleet/server/routes/agents/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const createListAgentsRoute = (libs: FleetServerLib) => ({
method: 'GET',
path: '/api/fleet/agents',
config: {
tags: ['access:fleet-read'],
validate: {
query: {
page: Joi.number().default(1),
Expand Down