Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMT-248: add post action request handler and resources #60581

Conversation

nnamdifrankie
Copy link
Contributor

@nnamdifrankie nnamdifrankie commented Mar 18, 2020

Summary

https://github.com/elastic/endpoint-app-team/issues/248

The change creates a new resource for posting new actions for agents.

/api/ingest_manager/fleet/agents/{agent}/actions

Request: - PostNewAgentActionRequest

{
  "body": {
       "action": {
          "type": "CONFIG_CHANGE",
          "data": "data",
          "sent_at": "2020-03-14T19:45:02.620Z"
       }
  }
}

Response - PostNewAgentActionResponse

{
  "success": true,
  "item": {}
}

Checklist

Delete any items that are not applicable to this PR.

@nnamdifrankie nnamdifrankie requested a review from a team March 18, 2020 23:45
@nnamdifrankie nnamdifrankie added release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Mar 18, 2020
@nnamdifrankie
Copy link
Contributor Author

@elasticmachine merge upstream

@nnamdifrankie nnamdifrankie added the Feature:EPM Fleet team's Elastic Package Manager (aka Integrations) project label Mar 19, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ingest-management (Feature:EPM)

@nnamdifrankie nnamdifrankie added the Feature:Fleet Fleet team's agent central management project label Mar 19, 2020
return async (context, request, response) => {
const soClient = actionsService.getSavedObjectsClientContract(request);

const res = APIKeyService.parseApiKey(request.headers);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler is not going to be consumed by the agent, but by kibana UI, we should not validate API key but rely on kibana authentication and use the builtin saved object client. (like the other crud actions we have in ingest manager)

{
path: AGENT_API_ROUTES.ACTIONS_PATTERN,
validate: PostNewAgentActionRequestSchema,
options: { tags: [] },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
options: { tags: [] },
options: { tags: [`access:${PLUGIN_ID}-all`] },

@paul-tavares
Copy link
Contributor

@nnamdifrankie LGTM. One small question: Would there be a need for this API to accept an array of actions instead of just one?

@nnamdifrankie
Copy link
Contributor Author

@paul-tavares perhaps no. Speaking with @nich07as I think we want one action at a time for now.


Object.assign(agentAction, ...keys(newAgentAction).map(key => ({ [key]: newAgentAction[key] })));

return agentAction as AgentAction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the name/purpose of this function, I think it's important we don't lose the TS typing here.

I think we can keep it by doing something like

function createAgentAction(
  createdAt: Date,
  newAgentAction: NewAgentAction
): AgentAction {
  const agentAction = { id: "uuid value", created_at: createdAt.toISOString() };
  return Object.assign(agentAction, newAgentAction);
}

@@ -22,6 +22,8 @@ export interface AgentAction extends SavedObjectAttributes {
sent_at?: string;
}

export type NewAgentAction = Pick<AgentAction, 'type' | 'data' | 'sent_at'>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should follow the pattern used by AgentBase/Agent in this file and do something like

export interface NewAgentAction {
  type: 'CONFIG_CHANGE' | 'DATA_DUMP' | 'RESUME' | 'PAUSE';
  data?: string;
  sent_at?: string;
}

export interface AgentAction extends NewAgentAction {
  id: string;
  created_at: string;
}

Copy link
Contributor Author

@nnamdifrankie nnamdifrankie Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay will make this change, was limiting the changes to existing structures.

return agentAction as AgentAction;
}

function keys<O extends object>(obj: O): Array<keyof O> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can drop this if we alter the way createAgentAction uses Object.assign

},
postNewAgentActionHandlerBuilder({
getAgent: AgentService.getAgent,
getSavedObjectsClientContract: getInternalUserSOClient,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we want to use the SOClient that comme from the request directly
like this here const soClient = context.core.savedObjects.client; and not the internal user one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay will make the change.

created_at: createdAt.toISOString(),
};

return Object.assign(agentAction, newAgentAction);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized that this order will have the passed values will overwrite the agentAction values

Is agentConfig the default values or final values?

Object.assign({}, newAgentConfig, agentAction) will use agentConfig as final values

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@nnamdifrankie nnamdifrankie merged commit d1aaa44 into elastic:master Mar 19, 2020
@nnamdifrankie nnamdifrankie deleted the EMT-248_add_post_action_request_handler branch March 19, 2020 22:16
nnamdifrankie added a commit that referenced this pull request Mar 20, 2020
… (#60705)

[Ingest]EMT-248: add resource to allow to post new agent action.
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 20, 2020
* master: (52 commits)
  [SIEM] Fix types in rules tests (elastic#60736)
  [Alerting] prevent flickering when fields are updated in an alert (elastic#60666)
  License checks for actions plugin (elastic#59070)
  Implemented ability to clear and properly validate alert interval (elastic#60571)
  WebElementWrapper: add findByTestSubject/findAllByTestSubject to search with data-test-subj (elastic#60568)
  [Maps] Update layer dependencies to NP (elastic#59585)
  [Discover] Remove StateManagementConfigProvider (elastic#60221)
  [ML] Listing all categorization wizard checks (elastic#60502)
  [Upgrade Assistant] First iteration of batch reindex docs (elastic#59887)
  [SIEM] Export timeline (elastic#58368)
  [SIEM] Add support for actions and throttle in Rules (elastic#59641)
  Fix ace a11y listener (elastic#60639)
  Add addInfo toast to core notifications service (elastic#60574)
  fix test description (elastic#60638)
  [SIEM] Cypress screenshots upload to google cloud (elastic#60556)
  [canvas/shareable_runtime] sync sass loaders with kbn/optimizer (elastic#60653)
  [SIEM] Fixes Modification of ML Rules (elastic#60662)
  [SIEM] [Case] Bulk status update, add comment avatar, id => title in breadcrumbs (elastic#60410)
  [Alerting] add functional tests for index threshold alertType (elastic#60597)
  [Ingest]EMT-248: add post action request handler and resources (elastic#60581)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Mar 20, 2020
…o alerting/tls-warning

* 'alerting/tls-warning' of github.com:gmmorris/kibana: (32 commits)
  [ML] Listing all categorization wizard checks (elastic#60502)
  [Upgrade Assistant] First iteration of batch reindex docs (elastic#59887)
  [SIEM] Export timeline (elastic#58368)
  [SIEM] Add support for actions and throttle in Rules (elastic#59641)
  Fix ace a11y listener (elastic#60639)
  Add addInfo toast to core notifications service (elastic#60574)
  fix test description (elastic#60638)
  [SIEM] Cypress screenshots upload to google cloud (elastic#60556)
  [canvas/shareable_runtime] sync sass loaders with kbn/optimizer (elastic#60653)
  [SIEM] Fixes Modification of ML Rules (elastic#60662)
  [SIEM] [Case] Bulk status update, add comment avatar, id => title in breadcrumbs (elastic#60410)
  [Alerting] add functional tests for index threshold alertType (elastic#60597)
  [Ingest]EMT-248: add post action request handler and resources (elastic#60581)
  Return incident's url (elastic#60617)
  [Endpoint] TEST: GET alert details - boundary test for first alert retrieval (elastic#60320)
  [ML] Transforms: Fix pivot preview table mapping. (elastic#60609)
  [Endpoint] Log random seed for sample data CLI to console (elastic#60646)
  Use common event model for determining if event is v0 or v1 (elastic#60667)
  Disables PR Project Assigner workflow
  [Reporting] Allow reports to be deleted in Management > Kibana > Reporting (elastic#60077)
  ...
@jen-huang jen-huang added the Team:Fleet Team label for Observability Data Collection Fleet team label Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:EPM Fleet team's Elastic Package Manager (aka Integrations) project Feature:Fleet Fleet team's agent central management project release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants