Skip to content

Commit

Permalink
parameterized calls into racClient.get() to match solutions, adds mor…
Browse files Browse the repository at this point in the history
…e log statements, added security as a required plugin to rule_registry plugin without which, the rac authorization class was receiving an undefined security client so our calls to shouldCheckAuthorization were failing silently. Added some routes and scripts to test authz functionality. To test please see the README in the rule_registry/scripts.
  • Loading branch information
dhurley14 committed Apr 12, 2021
1 parent 73065a1 commit 5c38595
Show file tree
Hide file tree
Showing 27 changed files with 344 additions and 12 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"requiredPlugins": [
"licensing",
"features",
"ruleRegistry",
"data",
"navigation",
"kibanaLegacy",
Expand Down
36 changes: 35 additions & 1 deletion x-pack/plugins/monitoring/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ export class MonitoringPlugin
logger: this.log,
});
initInfraSource(config, plugins.infra);
router.get({ path: '/monitoring-myfakepath', validate: false }, async (context, req, res) => {
try {
const racClient = await context.ruleRegistry?.getRacClient();
const thing = await racClient?.get({ id: 'hello world', owner: 'observability' });
console.error('THE THING!!!', JSON.stringify(thing.body, null, 2));
return res.ok({ body: { success: true } });
} catch (err) {
console.error('monitoring route threw an error');
console.error(err);
return res.notFound({ body: { message: err.message } });
}
});
}

return {
Expand Down Expand Up @@ -244,8 +256,30 @@ export class MonitoringPlugin
}),
category: DEFAULT_APP_CATEGORIES.management,
app: ['monitoring', 'kibana'],
rac: ['observability'],
catalogue: ['monitoring'],
privileges: null,
privileges: {
all: {
rac: {
all: ['observability'],
},
savedObject: {
all: [],
read: [],
},
ui: ['show', 'save', 'alerting:show', 'alerting:save'],
},
read: {
rac: {
all: ['observability'],
},
savedObject: {
all: [],
read: [],
},
ui: ['show', 'save', 'alerting:show', 'alerting:save'],
},
},
alerting: ALERTS,
reserved: {
description: i18n.translate('xpack.monitoring.feature.reserved.description', {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/monitoring/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
ActionsApiRequestHandlerContext,
} from '../../actions/server';
import type { AlertingApiRequestHandlerContext } from '../../alerting/server';
import { RacApiRequestHandlerContext } from '../../rule_registry/server';
import {
PluginStartContract as AlertingPluginStartContract,
PluginSetupContract as AlertingPluginSetupContract,
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface PluginsSetup {
export interface RequestHandlerContextMonitoringPlugin extends RequestHandlerContext {
actions?: ActionsApiRequestHandlerContext;
alerting?: AlertingApiRequestHandlerContext;
ruleRegistry?: RacApiRequestHandlerContext;
}

export interface PluginsStart {
Expand Down
10 changes: 2 additions & 8 deletions x-pack/plugins/rule_registry/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
"id": "ruleRegistry",
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": [
"xpack",
"ruleRegistry"
],
"requiredPlugins": [
"alerting",
"features"
],
"configPath": ["xpack", "ruleRegistry"],
"requiredPlugins": ["alerting", "features", "security"],
"server": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ export class RacAuthorization {

// Does the owner the client sent up match with the KibanaFeatures structure
const isAvailableOwner = this.featureOwners.has(owner);
console.error('PROVIDED OWNER', owner);
console.error('THIS.FEATUREOWNERS', this.featureOwners);
console.error('IS AVAILABLE OWNER', isAvailableOwner);
console.error('AUTHORIZATION???', authorization);
console.error('THIS.SHOULDCHECKAUTHZ', this.shouldCheckAuthorization());

if (authorization != null && this.shouldCheckAuthorization()) {
const requiredPrivileges = [authorization.actions.rac.get(owner, operation)];
console.error('REQUIRED PRIVILEGES', JSON.stringify(requiredPrivileges, null, 2));
const checkPrivileges = authorization.checkPrivilegesDynamicallyWithRequest(this.request);
const { hasAllRequested, username, privileges } = await checkPrivileges({
kibana: requiredPrivileges,
Expand Down
10 changes: 8 additions & 2 deletions x-pack/plugins/rule_registry/server/rac_client/rac_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ export class RacClient {
this.esClient = esClient;
}

public async get<Params>({ id }: { id: string }): Promise<unknown> {
public async get<Params>({
id,
owner,
}: {
id: string;
owner: 'securitySolution' | 'observability';
}): Promise<unknown> {
// TODO: type alert for the get method
const result = await this.esClient.search({
index: '.siem*',
Expand All @@ -124,7 +130,7 @@ export class RacClient {
await this.authorization.ensureAuthorized(
// TODO: add spaceid here.. I think
// result.body._source?.owner,
'securitySolution',
owner,
ReadOperations.Get
);
} catch (error) {
Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/rule_registry/server/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Users with roles granting them access to monitoring (observability) and siem (security solution) should only be able to access alerts with those roles

```bash
myterminal~$ ./get_security_solution_alert.sh observer
{
"statusCode": 404,
"error": "Not Found",
"message": "Unauthorized to get \"rac:8.0.0:securitySolution/get\" alert\""
}
myterminal~$ ./get_security_solution_alert.sh
{
"success": true
}
myterminal~$ ./get_observability_alert.sh
{
"success": true
}
myterminal~$ ./get_observability_alert.sh hunter
{
"statusCode": 404,
"error": "Not Found",
"message": "Unauthorized to get \"rac:8.0.0:observability/get\" alert\""
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

set -e

USER=${1:-'observer'}

# Example: ./find_rules.sh
curl -s -k \
-u $USER:changeme \
-X GET ${KIBANA_URL}${SPACE_URL}/monitoring-myfakepath | jq .
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

set -e

USER=${1:-'hunter'}

# Example: ./find_rules.sh
curl -s -k \
-u $USER:changeme \
-X GET ${KIBANA_URL}${SPACE_URL}/security-myfakepath | jq .
5 changes: 5 additions & 0 deletions x-pack/plugins/rule_registry/server/scripts/hunter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This user can access the monitoring route at http://localhost:5601/security-myfakepath

| Role | Data Sources | Security Solution ML Jobs/Results | Lists | Rules/Exceptions | Action Connectors | Signals/Alerts |
| :-----------------: | :----------: | :-------------------------------: | :---: | :--------------: | :---------------: | :------------: |
| Hunter / T3 Analyst | read, write | read | read | read, write | read | read, write |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

curl -v -H 'Content-Type: application/json' -H 'kbn-xsrf: 123'\
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
-XDELETE ${ELASTICSEARCH_URL}/_security/user/hunter
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"elasticsearch": {
"cluster": [],
"indices": [
{
"names": [
"apm-*-transaction*",
"auditbeat-*",
"endgame-*",
"filebeat-*",
"logs-*",
"packetbeat-*",
"winlogbeat-*"
],
"privileges": ["read", "write"]
},
{
"names": [".siem-signals-*"],
"privileges": ["read", "write"]
},
{
"names": [".lists*", ".items*"],
"privileges": ["read", "write"]
}
]
},
"kibana": [
{
"feature": {
"ml": ["read"],
"siem": ["all"],
"actions": ["read"],
"builtInAlerts": ["all"]
},
"spaces": ["*"]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"password": "changeme",
"roles": ["hunter"],
"full_name": "Hunter",
"email": "detections-reader@example.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

curl -H 'Content-Type: application/json' -H 'kbn-xsrf: 123'\
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
-XGET ${KIBANA_URL}/api/security/role/hunter | jq -S .
10 changes: 10 additions & 0 deletions x-pack/plugins/rule_registry/server/scripts/hunter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as hunterUser from './detections_user.json';
import * as hunterRole from './detections_role.json';
export { hunterUser, hunterRole };
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

ROLE=(${@:-./detections_role.json})

curl -H 'Content-Type: application/json' -H 'kbn-xsrf: 123'\
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
-XPUT ${KIBANA_URL}/api/security/role/hunter \
-d @${ROLE}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

USER=(${@:-./detections_user.json})

curl -H 'Content-Type: application/json' -H 'kbn-xsrf: 123'\
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
${ELASTICSEARCH_URL}/_security/user/hunter \
-d @${USER}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This user can access the monitoring route at http://localhost:5601/monitoring-myfakepath

| Role | Data Sources | Security Solution ML Jobs/Results | Lists | Rules/Exceptions | Action Connectors | Signals/Alerts |
| :------: | :----------: | :-------------------------------: | :---: | :--------------: | :---------------: | :------------: |
| observer | read, write | read | read | read, write | read | read, write |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

curl -v -H 'Content-Type: application/json' -H 'kbn-xsrf: 123'\
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
-XDELETE ${ELASTICSEARCH_URL}/_security/user/observer
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"elasticsearch": {
"cluster": [],
"indices": [
{
"names": [
"apm-*-transaction*",
"auditbeat-*",
"endgame-*",
"filebeat-*",
"logs-*",
"packetbeat-*",
"winlogbeat-*"
],
"privileges": ["read", "write"]
},
{
"names": [".siem-signals-*"],
"privileges": ["read", "write"]
},
{
"names": [".lists*", ".items*"],
"privileges": ["read", "write"]
}
]
},
"kibana": [
{
"feature": {
"ml": ["read"],
"monitoring": ["all"],
"actions": ["read"],
"builtInAlerts": ["all"]
},
"spaces": ["*"]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"password": "changeme",
"roles": ["observer"],
"full_name": "Observer",
"email": "monitoring-observer@example.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

curl -H 'Content-Type: application/json' -H 'kbn-xsrf: 123'\
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
-XGET ${KIBANA_URL}/api/security/role/hunter | jq -S .
10 changes: 10 additions & 0 deletions x-pack/plugins/rule_registry/server/scripts/observer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as observerUser from './detections_user.json';
import * as observerRole from './detections_role.json';
export { observerUser, observerRole };
Loading

0 comments on commit 5c38595

Please sign in to comment.