Skip to content

Conversation

danish9039
Copy link
Contributor

@danish9039 danish9039 commented Jul 30, 2025

Which problem is this PR solving?

part of

Description of the changes

  • Adds API key authentication support to Elasticsearch storage backend alongside existing basic and bearer token authentication.
  • It is part of the planned work to add support for API authentication, as discussed in Elasticsearch support for API Keys #7230 (comment)

Changes

  • Added new authentication method - APIKeyAuthentication struct to support API key-based auth alongside existing basic/bearer token methods

  • Dual source support - API keys can be loaded from files OR extracted from request context

  • Hot reloading - File-based API keys automatically reload at configurable intervals (default 10s, 0 disables)

  • New command flags - Added --es.api-key-file, --es.api-key-allow-from-context, --es.api-key-reload-interval

  • New context module - Created apikey-context.go withGetAPIKey()and ContextWithAPIKey() functions

  • Conditional logic - Health check disabled when AllowFromContext=true AND FilePath="" for both bearer tokens and API keys

How was this change tested?

  • make test-ci
  • make lint

Checklist

@danish9039 danish9039 requested a review from a team as a code owner July 30, 2025 14:04
@danish9039 danish9039 requested a review from albertteoh July 30, 2025 14:04
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.47%. Comparing base (c20bd92) to head (e8a3f26).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7402      +/-   ##
==========================================
+ Coverage   96.46%   96.47%   +0.01%     
==========================================
  Files         375      376       +1     
  Lines       22958    23025      +67     
==========================================
+ Hits        22147    22214      +67     
  Misses        613      613              
  Partials      198      198              
Flag Coverage Δ
badger_v1 9.00% <0.00%> (-0.06%) ⬇️
badger_v2 1.70% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v1-manual 11.69% <0.00%> (-0.07%) ⬇️
cassandra-4.x-v2-auto 1.69% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v2-manual 1.69% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v1-manual 11.69% <0.00%> (-0.07%) ⬇️
cassandra-5.x-v2-auto 1.69% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v2-manual 1.69% <0.00%> (-0.01%) ⬇️
elasticsearch-6.x-v1 16.60% <1.05%> (-0.11%) ⬇️
elasticsearch-7.x-v1 16.64% <1.05%> (-0.11%) ⬇️
elasticsearch-8.x-v1 16.79% <1.05%> (-0.11%) ⬇️
elasticsearch-8.x-v2 1.70% <0.00%> (-0.01%) ⬇️
elasticsearch-9.x-v2 1.70% <0.00%> (-0.01%) ⬇️
grpc_v1 10.22% <0.00%> (-0.07%) ⬇️
grpc_v2 1.70% <0.00%> (-0.01%) ⬇️
kafka-3.x-v1 9.69% <0.00%> (-0.06%) ⬇️
kafka-3.x-v2 1.70% <0.00%> (-0.01%) ⬇️
memory_v2 1.70% <0.00%> (-0.01%) ⬇️
opensearch-1.x-v1 16.69% <1.05%> (-0.11%) ⬇️
opensearch-2.x-v1 16.69% <1.05%> (-0.11%) ⬇️
opensearch-2.x-v2 1.70% <0.00%> (-0.01%) ⬇️
opensearch-3.x-v2 1.70% <0.00%> (-0.01%) ⬇️
query 1.70% <0.00%> (-0.01%) ⬇️
tailsampling-processor 0.47% <0.00%> (-0.01%) ⬇️
unittests 95.46% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danish9039
Copy link
Contributor Author

@yurishkuro can you please review this ,This PR finalizes our effort to add API authentication support for the Elasticsearch storage backend. #7230 (comment)

@@ -227,6 +228,17 @@ type BearerTokenAuthentication struct {
ReloadInterval time.Duration `mapstructure:"reload_interval"`
}

// APIKeyAuthentication contains the configuration for attaching API keys
type APIKeyAuthentication struct {
Copy link
Member

Choose a reason for hiding this comment

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

this struct is identical to the previous one. Please merge into one, e.g. TokenAuthentication. And consolidate init functions, there's no need to repeat so much boiler plate and tests

Copy link
Contributor Author

@danish9039 danish9039 Jul 31, 2025

Choose a reason for hiding this comment

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

@yurishkuro We can definitely merge BearerAuthAuthentication and APIKeyAuthentication structs, but doing so would remove the ability to use both bearer token and API key simultaneously , authentication framework was refactored to support multiple authentication methods together, allowing both API key and bearer token authentication to be used concurrently.
#7230 (comment)

If we're okay with limiting the system to use either bearer token or API key at a time (but not both), then we can go ahead with merging the two structs .

Let me know your take on this .

Copy link
Member

@yurishkuro yurishkuro Jul 31, 2025

Choose a reason for hiding this comment

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

You can still have two fields in the auth config for bearer and api tokens, but they can reuse the same struct type to represent their data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can still have two fields in the auth config for bearer and api tokens, but they can reuse the same struct type to represent their data

got it !

Signed-off-by: danish9039 <[email protected]>
@@ -193,9 +193,21 @@ type BulkProcessing struct {
Workers int `mapstructure:"workers"`
}

// TokenAuthBase contains the common fields shared by all token-based authentication methods
type TokenAuthBase struct {
Copy link
Member

Choose a reason for hiding this comment

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

you don't need the other two types, I would just get rid of them, keep the code simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified as per your suggestion.

func initBearerAuth(tokenAuth *TokenAuthentication, logger *zap.Logger) (*auth.Method, error) {
if tokenAuth == nil {
return nil, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There's an extra tab character at the end of this line that should be removed for consistent formatting.

Suggested change
}
}

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed .

Signed-off-by: danish9039 <[email protected]>
@yurishkuro yurishkuro added this pull request to the merge queue Aug 1, 2025
Merged via the queue into jaegertracing:main with commit e5542b3 Aug 1, 2025
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants