[Cloud Security] Added 'x-elastic-internal-origin' to agentless axios request headers for Kibana 9.0 (#203188)

This commit is contained in:
seanrathier 2024-12-06 14:21:42 -05:00 committed by GitHub
parent 1d3bf85d19
commit e08d7126eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 730 additions and 663 deletions

View file

@ -113,16 +113,7 @@ class AgentlessAgentService {
labels,
},
method: 'POST',
headers: {
'Content-type': 'application/json',
'X-Request-ID': traceId,
},
httpsAgent: new https.Agent({
rejectUnauthorized: tlsConfig.rejectUnauthorized,
cert: tlsConfig.certificate,
key: tlsConfig.key,
ca: tlsConfig.certificateAuthorities,
}),
...this.getHeaders(tlsConfig, traceId),
};
const cloudSetup = appContextService.getCloud();
@ -157,6 +148,7 @@ class AgentlessAgentService {
public async deleteAgentlessAgent(agentlessPolicyId: string) {
const logger = appContextService.getLogger();
const traceId = apm.currentTransaction?.traceparent;
const agentlessConfig = appContextService.getConfig()?.agentless;
const tlsConfig = this.createTlsConfig(agentlessConfig);
const requestConfig = {
@ -165,17 +157,9 @@ class AgentlessAgentService {
`/deployments/${agentlessPolicyId}`
),
method: 'DELETE',
headers: {
'Content-type': 'application/json',
},
httpsAgent: new https.Agent({
rejectUnauthorized: tlsConfig.rejectUnauthorized,
cert: tlsConfig.certificate,
key: tlsConfig.key,
ca: tlsConfig.certificateAuthorities,
}),
...this.getHeaders(tlsConfig, traceId),
};
const traceId = apm.currentTransaction?.traceparent;
const errorMetadata: LogMeta = {
trace: {
id: traceId,
@ -220,6 +204,22 @@ class AgentlessAgentService {
return response;
}
private getHeaders(tlsConfig: SslConfig, traceId: string | undefined) {
return {
headers: {
'Content-type': 'application/json',
'X-Request-ID': traceId,
'x-elastic-internal-origin': 'Kibana',
},
httpsAgent: new https.Agent({
rejectUnauthorized: tlsConfig.rejectUnauthorized,
cert: tlsConfig.certificate,
key: tlsConfig.key,
ca: tlsConfig.certificateAuthorities,
}),
};
}
private getAgentlessTags(agentlessAgentPolicy: AgentPolicy) {
if (!agentlessAgentPolicy.global_data_tags) {
return undefined;