Skip to content

Commit

Permalink
[Observability Onboarding] Fix EDOT collector permissions (#197248)
Browse files Browse the repository at this point in the history
## Summary

Fix EDOT collector permissions.

## Details

Adds `traces-*-*` index privilege and removed unnecessary `apm`
application privileges:

```json
{
  "standalone_agent": {
    "cluster": [
      "monitor"
    ],
    "indices": [
      {
        "names": [
          "logs-*-*",
          "metrics-*-*",
          "traces-*-*"
        ],
        "privileges": [
          "auto_configure",
          "create_doc"
        ],
        "allow_restricted_indices": false
      }
    ],
    "applications": []
  }
}
```

(cherry picked from commit e1c4a60)
  • Loading branch information
thomheymann committed Oct 22, 2024
1 parent 0b47f78 commit 3524fcc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
*/

import { ElasticsearchClient } from '@kbn/core/server';
import { MONITOR_CLUSTER, INDEX_LOGS_AND_METRICS, WRITE_APM_EVENTS } from './privileges';
import {
MONITOR_CLUSTER,
INDEX_LOGS_AND_METRICS,
INDEX_LOGS_METRICS_AND_TRACES,
} from './privileges';

export function createShipperApiKey(esClient: ElasticsearchClient, name: string, withAPM = false) {
// Based on https://www.elastic.co/guide/en/fleet/master/grant-access-to-elasticsearch.html#create-api-key-standalone-agent
Expand All @@ -20,8 +24,7 @@ export function createShipperApiKey(esClient: ElasticsearchClient, name: string,
role_descriptors: {
standalone_agent: {
cluster: [MONITOR_CLUSTER],
indices: [INDEX_LOGS_AND_METRICS],
applications: withAPM ? [WRITE_APM_EVENTS] : undefined,
indices: [withAPM ? INDEX_LOGS_METRICS_AND_TRACES : INDEX_LOGS_AND_METRICS],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
*/

import { ElasticsearchClient } from '@kbn/core/server';
import { MONITOR_CLUSTER, INDEX_LOGS_AND_METRICS, WRITE_APM_EVENTS } from './privileges';
import {
MONITOR_CLUSTER,
INDEX_LOGS_AND_METRICS,
INDEX_LOGS_METRICS_AND_TRACES,
} from './privileges';

export async function hasLogMonitoringPrivileges(esClient: ElasticsearchClient, withAPM = false) {
const res = await esClient.security.hasPrivileges({
body: {
cluster: [MONITOR_CLUSTER, 'manage_own_api_key'],
index: [INDEX_LOGS_AND_METRICS],
application: withAPM ? [WRITE_APM_EVENTS] : undefined,
index: [withAPM ? INDEX_LOGS_METRICS_AND_TRACES : INDEX_LOGS_AND_METRICS],
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export const INDEX_LOGS_AND_METRICS: estypes.SecurityIndicesPrivileges = {
privileges: ['auto_configure', 'create_doc'],
};

// https://www.elastic.co/guide/en/observability/master/apm-api-key.html#apm-create-api-key-workflow-es
export const WRITE_APM_EVENTS: estypes.SecurityApplicationPrivileges = {
application: 'apm',
privileges: ['event:write', 'config_agent:read'],
resources: ['*'],
// https://www.elastic.co/guide/en/fleet/master/grant-access-to-elasticsearch.html#create-api-key-standalone-agent
export const INDEX_LOGS_METRICS_AND_TRACES: estypes.SecurityIndicesPrivileges = {
names: ['logs-*-*', 'metrics-*-*', 'traces-*-*'],
privileges: ['auto_configure', 'create_doc'],
};

0 comments on commit 3524fcc

Please sign in to comment.