Skip to content

Commit

Permalink
remove ability to specify arbitrary config values in agent_features
Browse files Browse the repository at this point in the history
  • Loading branch information
hop-dev committed Feb 7, 2023
1 parent 7a9127d commit 41f2357
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"index-pattern": "48e77ca393c254e93256f11a7cdc0232dd754c08",
"infrastructure-monitoring-log-view": "e2c78c1076bd35e57d7c5fa1b410e5c126d12327",
"infrastructure-ui-source": "7c8dbbc0a608911f1b683a944f4a65383f6153ed",
"ingest-agent-policies": "bb5141304409d3faafd6647494d36727f4dc77ea",
"ingest-agent-policies": "a94bd53b8f81ca883de8a75386db04e27dda973e",
"ingest-download-sources": "1e69dabd6db5e320fe08c5bda8f35f29bafc6b54",
"ingest-outputs": "29181ecfdc7723f544325ecef7266bccbc691a54",
"ingest-package-policies": "0335a28af793ce25b4969d2156cfaf1dae2ef812",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -5812,7 +5812,6 @@
"type": "array",
"items": {
"type": "object",
"additionalProperties": true,
"properties": {
"name": {
"type": "string"
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,6 @@ components:
type: array
items:
type: object
additionalProperties: true
properties:
name:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ allOf:
type: array
items:
type: object
additionalProperties: true
properties:
name:
type: string
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface NewAgentPolicy {
download_source_id?: string | null;
fleet_server_host_id?: string | null;
schema_version?: string;
agent_features?: Array<{ name: string; enabled: boolean; [key: string]: any }>;
agent_features?: Array<{ name: string; enabled: boolean }>;
}

export interface AgentPolicy extends Omit<NewAgentPolicy, 'id'> {
Expand Down Expand Up @@ -113,7 +113,7 @@ export interface FullAgentPolicy {
logs: boolean;
};
download: { sourceURI: string };
features: Record<string, { enabled: boolean; [key: string]: any }>;
features: Record<string, { enabled: boolean }>;
};
}

Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ const getSavedObjectTypes = (
download_source_id: { type: 'keyword' },
fleet_server_host_id: { type: 'keyword' },
agent_features: {
dynamic: false,
properties: {
name: { type: 'keyword' },
enabled: { type: 'boolean' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ describe('getFullAgentPolicy', () => {
revision: 1,
monitoring_enabled: ['metrics'],
agent_features: [
{ name: 'fqdn', enabled: true, config_1: 'something' },
{ name: 'feature2', enabled: true, config_2: 'something' },
{ name: 'fqdn', enabled: true },
{ name: 'feature2', enabled: true },
],
});
const agentPolicy = await getFullAgentPolicy(savedObjectsClientMock.create(), 'agent-policy');
Expand Down Expand Up @@ -425,11 +425,9 @@ describe('getFullAgentPolicy', () => {
features: {
fqdn: {
enabled: true,
config_1: 'something',
},
feature2: {
enabled: true,
config_2: 'something',
},
},
},
Expand Down
11 changes: 4 additions & 7 deletions x-pack/plugins/fleet/server/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ export const AgentPolicyBaseSchema = {
fleet_server_host_id: schema.maybe(schema.nullable(schema.string())),
agent_features: schema.maybe(
schema.arrayOf(
schema.object(
{
name: schema.string(),
enabled: schema.boolean(),
},
{ unknowns: 'allow' }
)
schema.object({
name: schema.string(),
enabled: schema.boolean(),
})
)
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ export default function (providerContext: FtrProviderContext) {
expect(policy2.is_managed).to.equal(false);
});

it('does not allow arbitrary config in agent_features value', async () => {
await supertest
.post(`/api/fleet/agent_policies`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'test-agent-features',
namespace: 'default',
agent_features: [
{
name: 'fqdn',
enabled: true,
config: "I'm not allowed yet",
},
],
})
.expect(400);
});

it('sets given agent_features value', async () => {
const {
body: { item: createdPolicy },
Expand All @@ -110,7 +128,6 @@ export default function (providerContext: FtrProviderContext) {
{
name: 'fqdn',
enabled: true,
config_1: 'config_1',
},
],
})
Expand All @@ -121,7 +138,6 @@ export default function (providerContext: FtrProviderContext) {
{
name: 'fqdn',
enabled: true,
config_1: 'config_1',
},
]);

Expand All @@ -138,7 +154,6 @@ export default function (providerContext: FtrProviderContext) {
expect(policyDocRes?.hits?.hits[0]?._source?.data?.agent?.features).to.eql({
fqdn: {
enabled: true,
config_1: 'config_1',
},
});
});
Expand Down

0 comments on commit 41f2357

Please sign in to comment.