Skip to content

Commit

Permalink
[Fleet] Update final pipeline based on ECS event.agent_id_status (ela…
Browse files Browse the repository at this point in the history
…stic#102805) (elastic#102832)

This updates the Fleet final pipeline added in elastic#100973 to match the specification of
`event.agent_id_status` field as defined in ECS. The field was added to ECS in
elastic/ecs#1454. Basically the values of the field were simplified
from what was originally proposed and implemented.

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
  • Loading branch information
kibanamachine and andrewkroh committed Jun 22, 2021
1 parent 7f15592 commit 7f7ba0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,26 @@ processors:
}
String verified(def ctx, def params) {
// Agents only use API keys.
if (ctx?._security?.authentication_type == null || ctx._security.authentication_type != 'API_KEY') {
return "no_api_key";
// No agent.id field to validate.
if (ctx?.agent?.id == null) {
return "missing";
}
// Verify the API key owner before trusting any metadata it contains.
if (!is_user_trusted(ctx, params.trusted_users)) {
return "untrusted_user";
}
// API keys created by Fleet include metadata about the agent they were issued to.
if (ctx?._security?.api_key?.metadata?.agent_id == null || ctx?.agent?.id == null) {
return "missing_metadata";
// Check auth metadata from API key.
if (ctx?._security?.authentication_type == null
// Agents only use API keys.
|| ctx._security.authentication_type != 'API_KEY'
// Verify the API key owner before trusting any metadata it contains.
|| !is_user_trusted(ctx, params.trusted_users)
// Verify the API key has metadata indicating the assigned agent ID.
|| ctx?._security?.api_key?.metadata?.agent_id == null) {
return "auth_metadata_missing";
}
// The API key can only be used represent the agent.id it was issued to.
if (ctx._security.api_key.metadata.agent_id != ctx.agent.id) {
// Potential masquerade attempt.
return "agent_id_mismatch";
return "mismatch";
}
return "verified";
Expand Down
8 changes: 4 additions & 4 deletions x-pack/test/fleet_api_integration/apis/epm/final_pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ export default function (providerContext: FtrProviderContext) {
// @ts-expect-error
const event = doc._source.event;

expect(event.agent_id_status).to.be('no_api_key');
expect(event.agent_id_status).to.be('auth_metadata_missing');
expect(event).to.have.property('ingested');
});

const scenarios = [
{
name: 'API key without metadata',
expectedStatus: 'missing_metadata',
expectedStatus: 'auth_metadata_missing',
event: { agent: { id: 'agent1' } },
},
{
Expand All @@ -134,7 +134,7 @@ export default function (providerContext: FtrProviderContext) {
},
{
name: 'API key with agent id metadata and no agent id in event',
expectedStatus: 'missing_metadata',
expectedStatus: 'missing',
apiKey: {
metadata: {
agent_id: 'agent1',
Expand All @@ -143,7 +143,7 @@ export default function (providerContext: FtrProviderContext) {
},
{
name: 'API key with agent id metadata and tampered agent id in event',
expectedStatus: 'agent_id_mismatch',
expectedStatus: 'mismatch',
apiKey: {
metadata: {
agent_id: 'agent2',
Expand Down

0 comments on commit 7f7ba0b

Please sign in to comment.