-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[EDR Workflows][API] Gate Agent Tamper Protection setting on Agent Policy Settings #174400
Merged
szwarckonrad
merged 24 commits into
elastic:main
from
szwarckonrad:gated-agent-tamper-api
Feb 1, 2024
Merged
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
cb3c9b2
upsell on essential
szwarckonrad db8b0e5
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad dd697bd
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad 0c4e21a
upsell on essential
szwarckonrad 65ad15e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine cb5d3c1
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad 63ac984
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad 77666a8
upsell on essential
szwarckonrad 30f54d0
upsell on essential
szwarckonrad 255b23a
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad 03ec056
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad fa11c4b
upsell on essential
szwarckonrad d01cb0a
Merge remote-tracking branch 'origin/gated-agent-tamper-api' into gat…
szwarckonrad 510c3e0
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad b18a7b4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 14c1f7b
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad 63b86df
cr changes
szwarckonrad b3c6937
cr changes
szwarckonrad 557791f
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad f7c342f
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad 06c9bc9
cr changes
szwarckonrad b63e686
cr changes
szwarckonrad 34c9de8
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad 527a332
Merge branch 'main' into gated-agent-tamper-api
szwarckonrad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,9 @@ import type { | |
FullAgentPolicy, | ||
ListWithKuery, | ||
NewPackagePolicy, | ||
ExternalCallbackAgentPolicy, | ||
PostAgentPolicyCreateCallback, | ||
PostAgentPolicyUpdateCallback, | ||
} from '../types'; | ||
import { | ||
getAllowedOutputTypeForPolicy, | ||
|
@@ -234,6 +237,43 @@ class AgentPolicyService { | |
return policyHasSyntheticsIntegration(agentPolicy); | ||
} | ||
|
||
public async runExternalCallbacks( | ||
externalCallbackType: ExternalCallbackAgentPolicy[0], | ||
agentPolicy: NewAgentPolicy | Partial<AgentPolicy> | ||
): Promise<NewAgentPolicy | Partial<AgentPolicy>> { | ||
const logger = appContextService.getLogger(); | ||
logger.debug(`Running external callbacks for ${externalCallbackType}`); | ||
try { | ||
const externalCallbacks = appContextService.getExternalCallbacks(externalCallbackType); | ||
let newAgentPolicy = agentPolicy; | ||
|
||
if (externalCallbacks && externalCallbacks.size > 0) { | ||
let updatedNewAgentPolicy = newAgentPolicy; | ||
for (const callback of externalCallbacks) { | ||
let result; | ||
if (externalCallbackType === 'agentPolicyCreate') { | ||
result = await (callback as PostAgentPolicyCreateCallback)( | ||
newAgentPolicy as NewAgentPolicy | ||
); | ||
updatedNewAgentPolicy = result; | ||
} | ||
if (externalCallbackType === 'agentPolicyUpdate') { | ||
result = await (callback as PostAgentPolicyUpdateCallback)( | ||
newAgentPolicy as Partial<AgentPolicy> | ||
); | ||
updatedNewAgentPolicy = result; | ||
} | ||
} | ||
newAgentPolicy = updatedNewAgentPolicy; | ||
} | ||
return newAgentPolicy; | ||
} catch (error) { | ||
logger.error(`Error running external callbacks for ${externalCallbackType}`); | ||
logger.error(error); | ||
throw error; | ||
} | ||
} | ||
|
||
public async create( | ||
soClient: SavedObjectsClientContract, | ||
esClient: ElasticsearchClient, | ||
|
@@ -254,7 +294,7 @@ class AgentPolicyService { | |
id: options.id, | ||
savedObjectType: AGENT_POLICY_SAVED_OBJECT_TYPE, | ||
}); | ||
|
||
await this.runExternalCallbacks('agentPolicyCreate', agentPolicy); | ||
this.checkTamperProtectionLicense(agentPolicy); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be moved to sec sol side to an external callback |
||
|
||
const logger = appContextService.getLogger(); | ||
|
@@ -520,6 +560,7 @@ class AgentPolicyService { | |
throw new AgentPolicyNotFoundError('Agent policy not found'); | ||
} | ||
|
||
await this.runExternalCallbacks('agentPolicyUpdate', agentPolicy); | ||
this.checkTamperProtectionLicense(agentPolicy); | ||
await this.checkForValidUninstallToken(agentPolicy, id); | ||
Comment on lines
570
to
571
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be moved to sec sol side to an external callback |
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment further below. This union can be avoided by just adding the new types to the existing
ExternalCallback
type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed