-
Notifications
You must be signed in to change notification settings - Fork 1.9k
filter_kubernetes: use service account issuer to detect EKS env (compiler fix) #11146
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
Conversation
More reliable AWS EKS detection by inspecting service account token issuer Signed-off-by: Hyunsoo Kim <hsookim@amazon.com>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
WalkthroughA macro for AWS auth ConfigMap detection was removed and the Kubernetes platform detection logic was replaced. The change shifts from inspecting the aws-auth ConfigMap to analyzing the serviceaccount JWT token issuer field, incorporating JWT extraction, base64url decoding, and JSON payload parsing to identify EKS OIDC issuer patterns. Changes
Sequence Diagram(s)sequenceDiagram
participant Old as Old Flow
participant New as New Flow
participant FileSystem
participant JWT as JWT Parser
participant OIDC as Pattern Matcher
rect rgb(240, 248, 255)
Note over Old: Legacy Approach
Old->>Old: Query aws-auth ConfigMap
Old-->>Old: Check ConfigMap presence
end
rect rgb(230, 245, 230)
Note over New: New Approach
New->>FileSystem: Read serviceaccount token
FileSystem-->>New: Token content
New->>JWT: Extract & decode JWT
JWT-->>New: Payload with "iss" claim
New->>OIDC: Match oidc.eks.* pattern
OIDC-->>New: EKS issuer detected (1) or not (-1)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
plugins/filter_kubernetes/kube_conf.h(1 hunks)plugins/filter_kubernetes/kubernetes_aws.c(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/filter_kubernetes/kubernetes_aws.c (4)
src/flb_record_accessor.c (1)
flb_ra_create(271-358)src/flb_hash_table.c (1)
flb_hash_table_add(401-494)src/flb_utils.c (1)
flb_utils_read_file(1937-1940)include/fluent-bit/flb_mem.h (1)
flb_free(126-128)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (31)
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
- GitHub Check: pr-compile-without-cxx (3.31.6)
- GitHub Check: pr-compile-centos-7
- GitHub Check: PR - fuzzing test
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_COMPILER_STRICT_POINTER_TYPES=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
| ret = flb_utils_read_file(FLB_KUBE_TOKEN, &token_buf, &token_size); | ||
| if (ret != 0 || !token_buf) { | ||
| return -1; | ||
| } | ||
|
|
||
| /* JWT tokens have 3 parts separated by dots: header.payload.signature */ | ||
| first_dot = strchr(token_buf, '.'); | ||
| if (!first_dot) { | ||
| flb_free(token_buf); | ||
| return -1; | ||
| } | ||
|
|
||
| second_dot = strchr(first_dot + 1, '.'); | ||
| if (!second_dot) { | ||
| flb_free(token_buf); | ||
| return -1; | ||
| } | ||
|
|
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.
Respect configured token file path in determine_platform()
The new logic hardcodes FLB_KUBE_TOKEN when reading the serviceaccount JWT. Deployments that set Kube_Token_File (populating ctx->token_file) will now fail to read their token, causing determine_platform() to return -1 and misclassify EKS clusters. Please honor the configured path and fall back to the default only when the configuration is unset.
Apply this diff to restore compatibility:
- ret = flb_utils_read_file(FLB_KUBE_TOKEN, &token_buf, &token_size);
+ const char *token_path = ctx->token_file ? ctx->token_file : FLB_KUBE_TOKEN;
+
+ ret = flb_utils_read_file((char *) token_path, &token_buf, &token_size);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ret = flb_utils_read_file(FLB_KUBE_TOKEN, &token_buf, &token_size); | |
| if (ret != 0 || !token_buf) { | |
| return -1; | |
| } | |
| /* JWT tokens have 3 parts separated by dots: header.payload.signature */ | |
| first_dot = strchr(token_buf, '.'); | |
| if (!first_dot) { | |
| flb_free(token_buf); | |
| return -1; | |
| } | |
| second_dot = strchr(first_dot + 1, '.'); | |
| if (!second_dot) { | |
| flb_free(token_buf); | |
| return -1; | |
| } | |
| const char *token_path = ctx->token_file ? ctx->token_file : FLB_KUBE_TOKEN; | |
| ret = flb_utils_read_file((char *) token_path, &token_buf, &token_size); | |
| if (ret != 0 || !token_buf) { | |
| return -1; | |
| } | |
| /* JWT tokens have 3 parts separated by dots: header.payload.signature */ | |
| first_dot = strchr(token_buf, '.'); | |
| if (!first_dot) { | |
| flb_free(token_buf); | |
| return -1; | |
| } | |
| second_dot = strchr(first_dot + 1, '.'); | |
| if (!second_dot) { | |
| flb_free(token_buf); | |
| return -1; | |
| } |
Background
Explored Related introduced
filter_kubernetesto add Kubernetes metadata to logs and metrics. The filter historically relied on the presence of theaws-authConfigMap to determine if the cluster is running on Amazon EKS. However, with the launch of EKS access entries, theaws-authConfigMap is no longer guaranteed to be present in EKS clusters.Problem
With the launch of EKS access entries,
aws-authConfigMap is no longer guaranteed to be present in EKS clusters. Missing ConfigMap causes two issues:aws-authConfigMap doesn't existAPI) are falsely tagged asGenericorK8splatform instead ofAWS::EKSfor "Explore Related" functionalityFluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.
Summary by CodeRabbit
Release Notes