Skip to content

Commit

Permalink
[Fleet] Use package policy id in output permission instead of name (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Jun 6, 2022
1 parent dabd348 commit 9431231
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import type {
} from '../../types';
import { agentPolicyService } from '../agent_policy';
import { outputService } from '../output';
import {
storedPackagePoliciesToAgentPermissions,
DEFAULT_CLUSTER_PERMISSIONS,
} from '../package_policies_to_agent_permissions';
import { dataTypes, outputType } from '../../../common';
import type { FullAgentPolicyOutputPermissions } from '../../../common';
import { getSettings } from '../settings';
import { DEFAULT_OUTPUT } from '../../constants';

import { getMonitoringPermissions } from './monitoring_permissions';
import { storedPackagePoliciesToAgentInputs } from '.';
import {
storedPackagePoliciesToAgentPermissions,
DEFAULT_CLUSTER_PERMISSIONS,
} from './package_policies_to_agent_permissions';

export async function getFullAgentPolicy(
soClient: SavedObjectsClientContract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import type { SavedObjectsClientContract } from '@kbn/core/server';

import { getPackageInfo, getInstallation } from '../epm/packages';
import { getDataStreamPrivileges } from '../package_policies_to_agent_permissions';
import {
PACKAGE_POLICY_DEFAULT_INDEX_PRIVILEGES,
AGENT_POLICY_DEFAULT_MONITORING_DATASETS,
Expand All @@ -17,6 +16,8 @@ import type { FullAgentPolicyOutputPermissions } from '../../../common';
import { FLEET_ELASTIC_AGENT_PACKAGE } from '../../../common';
import { dataTypes } from '../../../common';

import { getDataStreamPrivileges } from './package_policies_to_agent_permissions';

function buildDefault(enabled: { logs: boolean; metrics: boolean }, namespace: string) {
let names: string[] = [];
if (enabled.logs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* 2.0.
*/

jest.mock('./epm/packages');
jest.mock('../epm/packages');
import type { SavedObjectsClientContract } from '@kbn/core/server';

import { savedObjectsClientMock } from '@kbn/core/server/mocks';

import type { PackagePolicy, RegistryDataStream } from '../types';
import type { PackagePolicy, RegistryDataStream } from '../../types';
import { getPackageInfo } from '../epm/packages';

import { getPackageInfo } from './epm/packages';
import {
getDataStreamPrivileges,
storedPackagePoliciesToAgentPermissions,
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {

const packagePolicies: PackagePolicy[] = [
{
id: '12345',
id: 'package-policy-uuid-test-123',
name: 'test-policy',
namespace: 'test',
enabled: true,
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {

const permissions = await storedPackagePoliciesToAgentPermissions(soClient, packagePolicies);
expect(permissions).toMatchObject({
'test-policy': {
'package-policy-uuid-test-123': {
indices: [
{
names: ['logs-some-logs-test'],
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {

const packagePolicies: PackagePolicy[] = [
{
id: '12345',
id: 'package-policy-uuid-test-123',
name: 'test-policy',
namespace: 'test',
enabled: true,
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {

const permissions = await storedPackagePoliciesToAgentPermissions(soClient, packagePolicies);
expect(permissions).toMatchObject({
'test-policy': {
'package-policy-uuid-test-123': {
indices: [
{
names: ['logs-compiled-test'],
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {

const packagePolicies: PackagePolicy[] = [
{
id: '12345',
id: 'package-policy-uuid-test-123',
name: 'test-policy',
namespace: 'test',
enabled: true,
Expand Down Expand Up @@ -344,7 +344,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {

const permissions = await storedPackagePoliciesToAgentPermissions(soClient, packagePolicies);
expect(permissions).toMatchObject({
'test-policy': {
'package-policy-uuid-test-123': {
indices: [
{
names: ['logs-compiled-test'],
Expand Down Expand Up @@ -422,7 +422,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {

const packagePolicies: PackagePolicy[] = [
{
id: '12345',
id: 'package-policy-uuid-test-123',
name: 'test-policy',
namespace: 'test',
enabled: true,
Expand Down Expand Up @@ -453,7 +453,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {

const permissions = await storedPackagePoliciesToAgentPermissions(soClient, packagePolicies);
expect(permissions).toMatchObject({
'test-policy': {
'package-policy-uuid-test-123': {
indices: [
{
names: ['logs-osquery_manager.result-test'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
*/
import type { SavedObjectsClientContract } from '@kbn/core/server';

import type { FullAgentPolicyOutputPermissions, RegistryDataStreamPrivileges } from '../../common';
import { PACKAGE_POLICY_DEFAULT_INDEX_PRIVILEGES } from '../constants';
import type {
FullAgentPolicyOutputPermissions,
RegistryDataStreamPrivileges,
} from '../../../common';
import { PACKAGE_POLICY_DEFAULT_INDEX_PRIVILEGES } from '../../constants';

import type { PackagePolicy } from '../types';
import type { PackagePolicy } from '../../types';

import { getPackageInfo } from './epm/packages';
import { getPackageInfo } from '../epm/packages';

export const DEFAULT_CLUSTER_PERMISSIONS = ['monitor'];

Expand Down Expand Up @@ -120,7 +123,7 @@ export async function storedPackagePoliciesToAgentPermissions(
}

return [
packagePolicy.name,
packagePolicy.id,
{
indices: dataStreamsForPermissions.map((ds) =>
getDataStreamPrivileges(ds, packagePolicy.namespace)
Expand Down

0 comments on commit 9431231

Please sign in to comment.