-
Notifications
You must be signed in to change notification settings - Fork 1.9k
output_azure: OAuth authentication support for Azure output plugins #11571
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
base: master
Are you sure you want to change the base?
Changes from all commits
555bd8c
e665cd4
091d869
710e330
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| /* Fluent Bit | ||
| * ========== | ||
| * Copyright (C) 2015-2026 The Fluent Bit Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #ifndef FLB_AZURE_AUTH_H | ||
| #define FLB_AZURE_AUTH_H | ||
|
|
||
| #include <fluent-bit/flb_info.h> | ||
| #include <fluent-bit/flb_oauth2.h> | ||
| #include <fluent-bit/flb_sds.h> | ||
|
|
||
| /* Authentication types for Azure services */ | ||
| typedef enum { | ||
| FLB_AZURE_AUTH_KEY = 0, /* Shared Access Key (blob-specific) */ | ||
| FLB_AZURE_AUTH_SAS, /* Shared Access Signature (blob-specific) */ | ||
| FLB_AZURE_AUTH_SERVICE_PRINCIPAL, /* Service Principal (Client ID + Secret) */ | ||
| FLB_AZURE_AUTH_MANAGED_IDENTITY_SYSTEM, /* System-assigned Managed Identity */ | ||
| FLB_AZURE_AUTH_MANAGED_IDENTITY_USER, /* User-assigned Managed Identity */ | ||
| FLB_AZURE_AUTH_WORKLOAD_IDENTITY /* Workload Identity (Federated Token) */ | ||
| } flb_azure_auth_type; | ||
|
|
||
| /* Azure Instance Metadata Service (IMDS) endpoint for Managed Identity */ | ||
| #define FLB_AZURE_IMDS_HOST "169.254.169.254" | ||
| #define FLB_AZURE_IMDS_PORT "80" | ||
|
|
||
| /* Managed Identity authentication URL template */ | ||
| #define FLB_AZURE_MSI_AUTH_URL_TEMPLATE \ | ||
| "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2021-02-01%s%s&resource=%s" | ||
|
|
||
| /* Microsoft Authentication Library (MSAL) authorization URL template */ | ||
| #define FLB_AZURE_MSAL_AUTH_URL_TEMPLATE \ | ||
| "https://login.microsoftonline.com/%s/oauth2/v2.0/token" | ||
|
|
||
| /* Azure Blob Storage resource identifier */ | ||
| #define FLB_AZURE_BLOB_RESOURCE "https://storage.azure.com" | ||
|
|
||
| /* Azure Kusto resource identifier */ | ||
| #define FLB_AZURE_KUSTO_RESOURCE "https://help.kusto.windows.net" | ||
|
|
||
| /* Default Workload Identity token file path */ | ||
| #define FLB_AZURE_WORKLOAD_IDENTITY_TOKEN_FILE \ | ||
| "/var/run/secrets/azure/tokens/azure-identity-token" | ||
|
|
||
| /** | ||
| * Get an OAuth2 access token using Azure Managed Identity (MSI) | ||
| * | ||
| * This function retrieves an access token from the Azure Instance Metadata Service (IMDS) | ||
| * for use with Azure services. Supports both system-assigned and user-assigned managed identities. | ||
| * | ||
| * @param ctx OAuth2 context containing connection and token information | ||
| * @return Access token string on success, NULL on failure | ||
| */ | ||
| char *flb_azure_msi_token_get(struct flb_oauth2 *ctx); | ||
|
|
||
| /** | ||
| * Get an OAuth2 access token using Azure Workload Identity | ||
| * | ||
| * This function exchanges a federated token (JWT) for an Azure AD access token | ||
| * using the OAuth2 client credentials flow with client assertion. | ||
| * | ||
| * @param ctx OAuth2 context for token management | ||
| * @param token_file Path to the file containing the federated token | ||
| * @param client_id Client ID of the Azure AD application | ||
| * @param tenant_id Tenant ID of the Azure AD directory | ||
| * @param resource Resource scope for the token (e.g., "https://storage.azure.com/") | ||
| * @return 0 on success, -1 on failure | ||
| */ | ||
| int flb_azure_workload_identity_token_get(struct flb_oauth2 *ctx, | ||
| const char *token_file, | ||
| const char *client_id, | ||
| const char *tenant_id, | ||
| const char *resource); | ||
|
|
||
| /** | ||
| * Build OAuth URL for Azure authentication | ||
| * | ||
| * Creates the appropriate OAuth2 endpoint URL based on the authentication type. | ||
| * For Managed Identity, uses IMDS endpoint. For Service Principal and Workload Identity, | ||
| * uses Azure AD OAuth2 endpoint. | ||
| * | ||
| * @param auth_type Type of authentication to use | ||
| * @param tenant_id Azure AD tenant ID (required for Service Principal and Workload Identity) | ||
| * @param client_id Client ID (optional, used for user-assigned managed identity) | ||
| * @param resource Resource scope for the token (e.g., storage.azure.com) | ||
| * @return Allocated SDS string with OAuth URL, or NULL on failure | ||
| */ | ||
| flb_sds_t flb_azure_auth_build_oauth_url(flb_azure_auth_type auth_type, | ||
| const char *tenant_id, | ||
| const char *client_id, | ||
| const char *resource); | ||
|
|
||
| #endif /* FLB_AZURE_AUTH_H */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,10 @@ | |
| #include <fluent-bit/flb_upstream.h> | ||
| #include <fluent-bit/flb_sds.h> | ||
| #include <fluent-bit/flb_sqldb.h> | ||
| #include <fluent-bit/flb_azure_auth.h> | ||
| #ifdef FLB_HAVE_TLS | ||
| #include <fluent-bit/flb_oauth2.h> | ||
| #endif | ||
|
|
||
| /* Content-Type */ | ||
| #define AZURE_BLOB_CT "Content-Type" | ||
|
|
@@ -48,9 +52,6 @@ | |
| #define AZURE_BLOB_APPENDBLOB 0 | ||
| #define AZURE_BLOB_BLOCKBLOB 1 | ||
|
|
||
| #define AZURE_BLOB_AUTH_KEY 0 | ||
| #define AZURE_BLOB_AUTH_SAS 1 | ||
|
|
||
| struct flb_azure_blob { | ||
| int auto_create_container; | ||
| int emulator_mode; | ||
|
|
@@ -65,6 +66,13 @@ struct flb_azure_blob { | |
| flb_sds_t date_key; | ||
| flb_sds_t auth_type; | ||
| flb_sds_t sas_token; | ||
|
|
||
| /* OAuth authentication fields */ | ||
| flb_sds_t tenant_id; | ||
| flb_sds_t client_id; | ||
| flb_sds_t client_secret; | ||
| flb_sds_t workload_identity_token_file; | ||
|
|
||
| flb_sds_t database_file; | ||
| size_t part_size; | ||
| time_t upload_parts_timeout; | ||
|
|
@@ -112,7 +120,7 @@ struct flb_azure_blob { | |
| * Internal use | ||
| */ | ||
| int btype; /* blob type */ | ||
| int atype; /* auth type */ | ||
| flb_azure_auth_type atype; /* auth type (uses flb_azure_auth_type enum from flb_azure_auth.h) */ | ||
| flb_sds_t real_endpoint; | ||
| flb_sds_t base_uri; | ||
| flb_sds_t shared_key_prefix; | ||
|
|
@@ -121,6 +129,13 @@ struct flb_azure_blob { | |
| unsigned char *decoded_sk; /* decoded shared key */ | ||
| size_t decoded_sk_size; /* size of decoded shared key */ | ||
|
|
||
| #ifdef FLB_HAVE_TLS | ||
| /* OAuth2 authentication */ | ||
| flb_sds_t oauth_url; | ||
| struct flb_oauth2 *o; | ||
| pthread_mutex_t token_mutex; | ||
|
Comment on lines
+133
to
+136
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check mutex initialization and destruction for azure_blob
echo "=== Checking token_mutex initialization ==="
rg -n "pthread_mutex_init.*token_mutex|token_mutex.*pthread_mutex_init" plugins/out_azure_blob/
echo ""
echo "=== Checking token_mutex destruction ==="
rg -n "pthread_mutex_destroy.*token_mutex|token_mutex.*pthread_mutex_destroy" plugins/out_azure_blob/
echo ""
echo "=== Check azure_blob_conf.c for mutex handling ==="
rg -n -B2 -A2 "token_mutex" plugins/out_azure_blob/azure_blob_conf.cRepository: fluent/fluent-bit Length of output: 779 🏁 Script executed: # Check the function context for mutex init and destroy operations
echo "=== Context around mutex initialization (line 800) ==="
sed -n '770,810p' plugins/out_azure_blob/azure_blob_conf.c
echo ""
echo "=== Context around mutex destruction (line 941) ==="
sed -n '920,960p' plugins/out_azure_blob/azure_blob_conf.c
echo ""
echo "=== Overall structure of azure_blob_conf.c to understand lifecycle ==="
rg -n "^[a-zA-Z_].*\(.*\).*\{" plugins/out_azure_blob/azure_blob_conf.c | head -20Repository: fluent/fluent-bit Length of output: 2497 🏁 Script executed: # Get function names and full context
echo "=== Function containing initialization (around line 800) ==="
sed -n '650,810p' plugins/out_azure_blob/azure_blob_conf.c | grep -B 150 "Initialize token mutex" | head -20
echo ""
echo "=== Function containing destruction (around line 941) ==="
sed -n '850,960p' plugins/out_azure_blob/azure_blob_conf.c | grep -B 100 "pthread_mutex_destroy" | head -20
echo ""
echo "=== Check mutex usage in the codebase ==="
rg -n "token_mutex" plugins/out_azure_blob/ -B1 -A1Repository: fluent/fluent-bit Length of output: 3949 🏁 Script executed: # Get the function signatures
echo "=== Function containing initialization ==="
awk '/^[a-zA-Z_].*\{/,/pthread_mutex_init.*token_mutex/ {print NR": "$0}' plugins/out_azure_blob/azure_blob_conf.c | tail -100 | head -50
echo ""
echo "=== Function containing destruction ==="
awk '/^[a-zA-Z_].*\{/,/pthread_mutex_destroy.*token_mutex/ {print NR": "$0}' plugins/out_azure_blob/azure_blob_conf.c | tail -100 | head -50
echo ""
echo "=== Check error handling for pthread_mutex_init ==="
rg -n -B5 -A5 "pthread_mutex_init.*token_mutex" plugins/out_azure_blob/
echo ""
echo "=== Verify these are plugin init and exit functions ==="
grep -n "^static.*flb_output_plugin\|^static.*plugin_exit\|^static.*plugin_init\|^static.*config_destroy\|^flb_output_plugin_" plugins/out_azure_blob/azure_blob_conf.c | head -20Repository: fluent/fluent-bit Length of output: 1055 🏁 Script executed: # Try to find the function definitions more directly
echo "=== Find function declarations in azure_blob_conf.c ==="
rg -n "^[a-zA-Z_][a-zA-Z0-9_*\s]+\(" plugins/out_azure_blob/azure_blob_conf.c | head -30
echo ""
echo "=== Search for specific function patterns ==="
grep -n "^static.*\*" plugins/out_azure_blob/azure_blob_conf.c | head -20
echo ""
echo "=== Look for function at line 800 context ==="
sed -n '700,820p' plugins/out_azure_blob/azure_blob_conf.c | head -50
echo ""
echo "=== Look for function at line 941 context ==="
sed -n '850,960p' plugins/out_azure_blob/azure_blob_conf.c | tail -100Repository: fluent/fluent-bit Length of output: 5595 Add error handling for mutex initialization. The 🤖 Prompt for AI Agents |
||
| #endif | ||
|
|
||
| #ifdef FLB_HAVE_SQLDB | ||
| /* | ||
| * SQLite by default is not built with multi-threading enabled, and | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.