Skip to content

Commit 15578d7

Browse files
committed
Merge branch 'master' of https://github.com/elastic/kibana into np_ready_final
2 parents a811f21 + e3442b1 commit 15578d7

File tree

15 files changed

+182
-50
lines changed

15 files changed

+182
-50
lines changed

packages/kbn-optimizer/src/worker/webpack.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {
289289

290290
resolve: {
291291
extensions: ['.js', '.ts', '.tsx', '.json'],
292+
mainFields: ['browser', 'main'],
292293
alias: {
293294
tinymath: require.resolve('tinymath/lib/tinymath.es5.js'),
294295
},

x-pack/plugins/ingest_manager/common/constants/output.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ export const DEFAULT_OUTPUT = {
1212
is_default: true,
1313
type: OutputType.Elasticsearch,
1414
hosts: [''],
15-
api_key: '',
1615
};

x-pack/plugins/ingest_manager/common/types/models/agent.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ export interface NewAgentAction {
2020
sent_at?: string;
2121
}
2222

23-
export type AgentAction = NewAgentAction & {
23+
export interface AgentAction extends NewAgentAction {
2424
id: string;
2525
agent_id: string;
2626
created_at: string;
27-
} & SavedObjectAttributes;
27+
}
2828

29-
export interface AgentActionSOAttributes extends NewAgentAction, SavedObjectAttributes {
29+
export interface AgentActionSOAttributes extends SavedObjectAttributes {
30+
type: 'CONFIG_CHANGE' | 'DATA_DUMP' | 'RESUME' | 'PAUSE';
31+
sent_at?: string;
3032
created_at: string;
3133
agent_id: string;
34+
data?: string;
3235
}
3336

3437
export interface AgentEvent {
@@ -64,6 +67,7 @@ interface AgentBase {
6467
shared_id?: string;
6568
access_api_key_id?: string;
6669
default_api_key?: string;
70+
default_api_key_id?: string;
6771
config_id?: string;
6872
config_revision?: number | null;
6973
config_newest_revision?: number;

x-pack/plugins/ingest_manager/server/plugin.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
SavedObjectsServiceStart,
1414
} from 'kibana/server';
1515
import { LicensingPluginSetup } from '../../licensing/server';
16-
import { EncryptedSavedObjectsPluginStart } from '../../encrypted_saved_objects/server';
16+
import {
17+
EncryptedSavedObjectsPluginStart,
18+
EncryptedSavedObjectsPluginSetup,
19+
} from '../../encrypted_saved_objects/server';
1720
import { SecurityPluginSetup } from '../../security/server';
1821
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';
1922
import {
@@ -26,7 +29,7 @@ import {
2629
AGENT_EVENT_SAVED_OBJECT_TYPE,
2730
ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
2831
} from './constants';
29-
32+
import { registerEncryptedSavedObjects } from './saved_objects';
3033
import {
3134
registerEPMRoutes,
3235
registerDatasourceRoutes,
@@ -46,6 +49,7 @@ export interface IngestManagerSetupDeps {
4649
licensing: LicensingPluginSetup;
4750
security?: SecurityPluginSetup;
4851
features?: FeaturesPluginSetup;
52+
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup;
4953
}
5054

5155
export type IngestManagerStartDeps = object;
@@ -97,6 +101,8 @@ export class IngestManagerPlugin
97101
this.security = deps.security;
98102
}
99103

104+
registerEncryptedSavedObjects(deps.encryptedSavedObjects);
105+
100106
// Register feature
101107
// TODO: Flesh out privileges
102108
if (deps.features) {

x-pack/plugins/ingest_manager/server/saved_objects.ts

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
AGENT_ACTION_SAVED_OBJECT_TYPE,
1414
ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
1515
} from './constants';
16+
import { EncryptedSavedObjectsPluginSetup } from '../../encrypted_saved_objects/server';
1617

1718
/*
1819
* Saved object mappings
@@ -35,7 +36,7 @@ export const savedObjectMappings = {
3536
last_checkin: { type: 'date' },
3637
config_revision: { type: 'integer' },
3738
config_newest_revision: { type: 'integer' },
38-
// FIXME_INGEST https://github.com/elastic/kibana/issues/56554
39+
default_api_key_id: { type: 'keyword' },
3940
default_api_key: { type: 'keyword' },
4041
updated_at: { type: 'date' },
4142
current_error_events: { type: 'text' },
@@ -45,8 +46,7 @@ export const savedObjectMappings = {
4546
properties: {
4647
agent_id: { type: 'keyword' },
4748
type: { type: 'keyword' },
48-
// FIXME_INGEST https://github.com/elastic/kibana/issues/56554
49-
data: { type: 'flattened' },
49+
data: { type: 'binary' },
5050
sent_at: { type: 'date' },
5151
created_at: { type: 'date' },
5252
},
@@ -83,7 +83,6 @@ export const savedObjectMappings = {
8383
properties: {
8484
name: { type: 'keyword' },
8585
type: { type: 'keyword' },
86-
// FIXME_INGEST https://github.com/elastic/kibana/issues/56554
8786
api_key: { type: 'binary' },
8887
api_key_id: { type: 'keyword' },
8988
config_id: { type: 'keyword' },
@@ -100,8 +99,6 @@ export const savedObjectMappings = {
10099
is_default: { type: 'boolean' },
101100
hosts: { type: 'keyword' },
102101
ca_sha256: { type: 'keyword' },
103-
// FIXME_INGEST https://github.com/elastic/kibana/issues/56554
104-
api_key: { type: 'keyword' },
105102
fleet_enroll_username: { type: 'binary' },
106103
fleet_enroll_password: { type: 'binary' },
107104
config: { type: 'flattened' },
@@ -165,3 +162,61 @@ export const savedObjectMappings = {
165162
},
166163
},
167164
};
165+
166+
export function registerEncryptedSavedObjects(
167+
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup
168+
) {
169+
// Encrypted saved objects
170+
encryptedSavedObjects.registerType({
171+
type: ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
172+
attributesToEncrypt: new Set(['api_key']),
173+
attributesToExcludeFromAAD: new Set([
174+
'name',
175+
'type',
176+
'api_key_id',
177+
'config_id',
178+
'created_at',
179+
'updated_at',
180+
'expire_at',
181+
'active',
182+
]),
183+
});
184+
encryptedSavedObjects.registerType({
185+
type: OUTPUT_SAVED_OBJECT_TYPE,
186+
attributesToEncrypt: new Set(['fleet_enroll_username', 'fleet_enroll_password']),
187+
attributesToExcludeFromAAD: new Set([
188+
'name',
189+
'type',
190+
'is_default',
191+
'hosts',
192+
'ca_sha256',
193+
'config',
194+
]),
195+
});
196+
encryptedSavedObjects.registerType({
197+
type: AGENT_SAVED_OBJECT_TYPE,
198+
attributesToEncrypt: new Set(['default_api_key']),
199+
attributesToExcludeFromAAD: new Set([
200+
'shared_id',
201+
'type',
202+
'active',
203+
'enrolled_at',
204+
'access_api_key_id',
205+
'version',
206+
'user_provided_metadata',
207+
'local_metadata',
208+
'config_id',
209+
'last_updated',
210+
'last_checkin',
211+
'config_revision',
212+
'config_newest_revision',
213+
'updated_at',
214+
'current_error_events',
215+
]),
216+
});
217+
encryptedSavedObjects.registerType({
218+
type: AGENT_ACTION_SAVED_OBJECT_TYPE,
219+
attributesToEncrypt: new Set(['data']),
220+
attributesToExcludeFromAAD: new Set(['agent_id', 'type', 'sent_at', 'created_at']),
221+
});
222+
}

x-pack/plugins/ingest_manager/server/services/agents/acks.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import Boom from 'boom';
77
import { SavedObjectsBulkResponse } from 'kibana/server';
88
import { savedObjectsClientMock } from '../../../../../../src/core/server/saved_objects/service/saved_objects_client.mock';
9+
import { encryptedSavedObjectsMock } from '../../../../../plugins/encrypted_saved_objects/server/mocks';
10+
911
import {
1012
Agent,
1113
AgentAction,
@@ -14,10 +16,31 @@ import {
1416
} from '../../../common/types/models';
1517
import { AGENT_TYPE_PERMANENT } from '../../../common/constants';
1618
import { acknowledgeAgentActions } from './acks';
19+
import { appContextService } from '../app_context';
20+
import { IngestManagerAppContext } from '../../plugin';
1721

1822
describe('test agent acks services', () => {
1923
it('should succeed on valid and matched actions', async () => {
2024
const mockSavedObjectsClient = savedObjectsClientMock.create();
25+
const mockStartEncryptedSOClient = encryptedSavedObjectsMock.createStart();
26+
appContextService.start(({
27+
encryptedSavedObjects: mockStartEncryptedSOClient,
28+
} as unknown) as IngestManagerAppContext);
29+
30+
mockStartEncryptedSOClient.getDecryptedAsInternalUser.mockReturnValue(
31+
Promise.resolve({
32+
id: 'action1',
33+
references: [],
34+
type: 'agent_actions',
35+
attributes: {
36+
type: 'CONFIG_CHANGE',
37+
agent_id: 'id',
38+
sent_at: '2020-03-14T19:45:02.620Z',
39+
timestamp: '2019-01-04T14:32:03.36764-05:00',
40+
created_at: '2020-03-14T19:45:02.620Z',
41+
},
42+
})
43+
);
2144

2245
mockSavedObjectsClient.bulkGet.mockReturnValue(
2346
Promise.resolve({

x-pack/plugins/ingest_manager/server/services/agents/actions.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
import { createAgentAction } from './actions';
88
import { SavedObject } from 'kibana/server';
9-
import { AgentAction, AgentActionSOAttributes } from '../../../common/types/models';
9+
import { AgentAction } from '../../../common/types/models';
1010
import { savedObjectsClientMock } from '../../../../../../src/core/server/saved_objects/service/saved_objects_client.mock';
1111

1212
describe('test agent actions services', () => {
1313
it('should create a new action', async () => {
1414
const mockSavedObjectsClient = savedObjectsClientMock.create();
1515

16-
const newAgentAction: AgentActionSOAttributes = {
16+
const newAgentAction: Omit<AgentAction, 'id'> = {
1717
agent_id: 'agentid',
1818
type: 'CONFIG_CHANGE',
19-
data: 'data',
19+
data: { content: 'data' },
2020
sent_at: '2020-03-14T19:45:02.620Z',
2121
created_at: '2020-03-14T19:45:02.620Z',
2222
};
@@ -31,7 +31,7 @@ describe('test agent actions services', () => {
3131
.calls[0][1] as unknown) as AgentAction;
3232
expect(createdAction).toBeDefined();
3333
expect(createdAction?.type).toEqual(newAgentAction.type);
34-
expect(createdAction?.data).toEqual(newAgentAction.data);
34+
expect(createdAction?.data).toEqual(JSON.stringify(newAgentAction.data));
3535
expect(createdAction?.sent_at).toEqual(newAgentAction.sent_at);
3636
});
3737
});

x-pack/plugins/ingest_manager/server/services/agents/actions.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ import { SavedObjectsClientContract } from 'kibana/server';
88
import { Agent, AgentAction, AgentActionSOAttributes } from '../../../common/types/models';
99
import { AGENT_ACTION_SAVED_OBJECT_TYPE } from '../../../common/constants';
1010
import { savedObjectToAgentAction } from './saved_objects';
11+
import { appContextService } from '../app_context';
1112

1213
export async function createAgentAction(
1314
soClient: SavedObjectsClientContract,
14-
newAgentAction: AgentActionSOAttributes
15+
newAgentAction: Omit<AgentAction, 'id'>
1516
): Promise<AgentAction> {
1617
const so = await soClient.create<AgentActionSOAttributes>(AGENT_ACTION_SAVED_OBJECT_TYPE, {
1718
...newAgentAction,
19+
data: newAgentAction.data ? JSON.stringify(newAgentAction.data) : undefined,
1820
});
1921

20-
return savedObjectToAgentAction(so);
22+
const agentAction = savedObjectToAgentAction(so);
23+
agentAction.data = newAgentAction.data;
24+
25+
return agentAction;
2126
}
2227

2328
export async function getAgentActionsForCheckin(
@@ -29,21 +34,47 @@ export async function getAgentActionsForCheckin(
2934
filter: `not ${AGENT_ACTION_SAVED_OBJECT_TYPE}.attributes.sent_at: * and ${AGENT_ACTION_SAVED_OBJECT_TYPE}.attributes.agent_id:${agentId}`,
3035
});
3136

32-
return res.saved_objects.map(savedObjectToAgentAction);
37+
return Promise.all(
38+
res.saved_objects.map(async so => {
39+
// Get decrypted actions
40+
return savedObjectToAgentAction(
41+
await appContextService
42+
.getEncryptedSavedObjects()
43+
.getDecryptedAsInternalUser<AgentActionSOAttributes>(
44+
AGENT_ACTION_SAVED_OBJECT_TYPE,
45+
so.id
46+
)
47+
);
48+
})
49+
);
3350
}
3451

3552
export async function getAgentActionByIds(
3653
soClient: SavedObjectsClientContract,
3754
actionIds: string[]
3855
) {
39-
const res = await soClient.bulkGet<AgentActionSOAttributes>(
40-
actionIds.map(actionId => ({
41-
id: actionId,
42-
type: AGENT_ACTION_SAVED_OBJECT_TYPE,
43-
}))
44-
);
56+
const actions = (
57+
await soClient.bulkGet<AgentActionSOAttributes>(
58+
actionIds.map(actionId => ({
59+
id: actionId,
60+
type: AGENT_ACTION_SAVED_OBJECT_TYPE,
61+
}))
62+
)
63+
).saved_objects.map(savedObjectToAgentAction);
4564

46-
return res.saved_objects.map(savedObjectToAgentAction);
65+
return Promise.all(
66+
actions.map(async action => {
67+
// Get decrypted actions
68+
return savedObjectToAgentAction(
69+
await appContextService
70+
.getEncryptedSavedObjects()
71+
.getDecryptedAsInternalUser<AgentActionSOAttributes>(
72+
AGENT_ACTION_SAVED_OBJECT_TYPE,
73+
action.id
74+
)
75+
);
76+
})
77+
);
4778
}
4879

4980
export interface ActionsService {

x-pack/plugins/ingest_manager/server/services/agents/checkin.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ describe('Agent checkin service', () => {
5353
agent_id: 'agent1',
5454
type: 'CONFIG_CHANGE',
5555
created_at: new Date().toISOString(),
56-
data: JSON.stringify({
56+
data: {
5757
config: {
5858
id: 'config1',
5959
revision: 2,
6060
},
61-
}),
61+
},
6262
},
6363
]
6464
);
@@ -80,24 +80,24 @@ describe('Agent checkin service', () => {
8080
agent_id: 'agent1',
8181
type: 'CONFIG_CHANGE',
8282
created_at: new Date().toISOString(),
83-
data: JSON.stringify({
83+
data: {
8484
config: {
8585
id: 'config2',
8686
revision: 2,
8787
},
88-
}),
88+
},
8989
},
9090
{
9191
id: 'action1',
9292
agent_id: 'agent1',
9393
type: 'CONFIG_CHANGE',
9494
created_at: new Date().toISOString(),
95-
data: JSON.stringify({
95+
data: {
9696
config: {
9797
id: 'config1',
9898
revision: 1,
9999
},
100-
}),
100+
},
101101
},
102102
]
103103
);

0 commit comments

Comments
 (0)