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

No longer use generated IDs for X-Opaque-ID / requestId #123197

Closed
wants to merge 11 commits into from

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Jan 18, 2022

Summary

Fix #123737

  • rename KibanaRequest.id to opaqueId
  • no longer generate ids for KibanaRequest.opaqueId when the x-opaque-id header is not provided by the client

Checklist

@pgayvallet pgayvallet added v7.17.0 v8.0.0 v8.1.0 release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc bug Fixes for quality problems that affect the customer experience labels Jan 18, 2022
src/core/server/http/http_server.ts Show resolved Hide resolved
@@ -166,7 +166,7 @@ export class AuditService {
session_id: sessionId,
...event.kibana,
},
trace: { id: request.id },
trace: { id: request.opaqueId },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elastic/kibana-security request.id was renamed to request.opaqueId, but is now optional, as we're no longer generating a value when not provided by the client / when the configuration forbid its usage.

Is this change fine, or should we fallback to request.uuid when request.opaqueId is empty?

Copy link
Contributor

@mshustov mshustov Jan 18, 2022

Choose a reason for hiding this comment

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

JFYI: Kibana sets tracing fields starting from #118466 The value from meta override them (sorry, I need to update the test suite name 😅 )

test('format() meta can not override tracing properties', () => {

maybe audit logging should rely on the trace field supplied by the Kibana server and not overwrite them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#118466 was merged on 8.1 only, and not backported though, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it wasn't. because it's not a bug fix

Copy link
Contributor

Choose a reason for hiding this comment

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

@elastic/kibana-security request.id was renamed to request.opaqueId, but is now optional, as we're no longer generating a value when not provided by the client / when the configuration forbid its usage.

Is this change fine, or should we fallback to request.uuid when request.opaqueId is empty?

I responded to the linked issue in #120124 (comment).

I'm not on board with this change in general as it hamstrings auditing functionality. If we have to go through with this though, we at least need the ability to correlate audit records within the Kibana audit log which originate from the same request. In that case it would be better to fall back to request.uuid.

Comment on lines 156 to 160
if (!this.enabled) return;
// requestId may not be present in the case of FakeRequest
// requestId may not be present if unspecified by the client or in the case of FakeRequest
const requestId = this.requestIdStore.getStore()?.requestId ?? 'unknownId';
const executionContext = this.contextStore.getStore()?.toString();
const executionContextStr = executionContext ? `;kibana:${executionContext}` : '';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(This is correlated with the change in src/core/server/elasticsearch/client/cluster_client.ts)

ATM we kinda have an inconsistency between when EC is enabled or not, as when EC is enabled, the x-opaque-id value will be coming from EC.getAsHeader, and when it's not, the value is generated within ClusterClient.getScopedHeaders

ATM (with the PR's current change), the value matrix looks like:

EC enabled request.opaqueId present EC present x-opaque-id sent to ES
true true true '${opaqueId};kibana:${executionContext}'
true true false '${opaqueId}'
true false true 'unknownId;kibana:${executionContext}'
true false false 'unknownId'
false true true N/A
false true false '${opaqueId}'
false false true N/A
false false false undefined

I got a few questions here:

  • is this unknownId default value for opaqueId acceptable?
  • When EC is disabled, the header is populated by ClusterClient.getScopedHeaders. ATM when request.opaqueId is not present, we're not sending any x-opaque-id header to ES. Do we want to change that to send kibana (or any constant value we agreed on from the previous point) instead?
  • (follow-up of next point) Should we decide to have the EC service the single source of truth for the x-opaque-id header and have getAsHeader always return a value even when disabled
    • this would require the requestIdStore to always be populated even when EC is disabled, which could be a performance issue as the whole purpose of allowing to disable the EC was for performances reasons

@mshustov @lukeelmers what do you think about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we fine with this format? Do we just want to use kibana:${executionContext} in that case instead?

Worth noting, ES doesn't parse x-opaque-id value, so we can use any format. I used kibana static value to simplify parsing when an incoming request contains x-opaque-id. If you find it easier to use kibana;${executionContext}, we can change the format.

ATM when request.opaqueId is not present, we're not sending any x-opaque-id header to ES. Do we want to change that to send kibana (or any constant value we agreed on from the previous point) instead?

@pgomulka what is better for the depreciation service of Elasticsearch?

Should we decide to have the EC service the single source of truth for the x-opaque-id header and have getAsHeader always return a value even when disabled

I didn't put this logic in the EC service to have a proper separation of concerns. The fact we put execution_context in x-opaque-id header of outbound requests is an implementation detail. When the buggage header is available, we will use it for context propagation. Having said that, I'd rather keep this logic on the elasticsearch service level. But we can refactor it a bit.

Copy link

@pgomulka pgomulka Jan 18, 2022

Choose a reason for hiding this comment

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

ATM when request.opaqueId is not present, we're not sending any x-opaque-id header to ES. Do we want to change that to send kibana (or any constant value we agreed on from the previous point) instead?

@pgomulka what is better for the depreciation service of Elasticsearch?

either way is good. As long as it is constant (or from a finite set). If Kibana wants to send a constant x-opaque-id-from-kibana it would help identifying its requests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used kibana static value to simplify parsing when an incoming request contains x-opaque-id. If you find it easier to use kibana;${executionContext}, we can change the format.

Let's not overcomplicate the PR for no good reasons. The current format is good enough to address #120124, let's not change it for now. We'll reevaluate when we'll use the baggage header anyway.

src/core/server/http/router/request.ts Outdated Show resolved Hide resolved
Comment on lines 156 to 160
if (!this.enabled) return;
// requestId may not be present in the case of FakeRequest
// requestId may not be present if unspecified by the client or in the case of FakeRequest
const requestId = this.requestIdStore.getStore()?.requestId ?? 'unknownId';
const executionContext = this.contextStore.getStore()?.toString();
const executionContextStr = executionContext ? `;kibana:${executionContext}` : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we fine with this format? Do we just want to use kibana:${executionContext} in that case instead?

Worth noting, ES doesn't parse x-opaque-id value, so we can use any format. I used kibana static value to simplify parsing when an incoming request contains x-opaque-id. If you find it easier to use kibana;${executionContext}, we can change the format.

ATM when request.opaqueId is not present, we're not sending any x-opaque-id header to ES. Do we want to change that to send kibana (or any constant value we agreed on from the previous point) instead?

@pgomulka what is better for the depreciation service of Elasticsearch?

Should we decide to have the EC service the single source of truth for the x-opaque-id header and have getAsHeader always return a value even when disabled

I didn't put this logic in the EC service to have a proper separation of concerns. The fact we put execution_context in x-opaque-id header of outbound requests is an implementation detail. When the buggage header is available, we will use it for context propagation. Having said that, I'd rather keep this logic on the elasticsearch service level. But we can refactor it a bit.

src/core/server/http/http_server.ts Show resolved Hide resolved
@@ -166,7 +166,7 @@ export class AuditService {
session_id: sessionId,
...event.kibana,
},
trace: { id: request.id },
trace: { id: request.opaqueId },
Copy link
Contributor

@mshustov mshustov Jan 18, 2022

Choose a reason for hiding this comment

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

JFYI: Kibana sets tracing fields starting from #118466 The value from meta override them (sorry, I need to update the test suite name 😅 )

test('format() meta can not override tracing properties', () => {

maybe audit logging should rely on the trace field supplied by the Kibana server and not overwrite them?

@pgayvallet pgayvallet added Feature:elasticsearch and removed v8.0.0 v7.17.0 bug Fixes for quality problems that affect the customer experience labels Jan 25, 2022
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Test Failures

  • [job] [logs] Default CI Group #10 / Uptime app with generated data certificates with certs page "before each" hook for "displays certificates"

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/server-http-tools 50 49 -1

History

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

@rudolf
Copy link
Contributor

rudolf commented Jan 24, 2023

Closing as stale PR

@rudolf rudolf closed this Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:elasticsearch release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop Kibana from generating unique X-Opaque-ID values when not received from the client.
6 participants