-
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
Open
zshuang0316
wants to merge
4
commits into
fluent:master
Choose a base branch
from
zshuang0316:azure-msi-auth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8ce83a7
azure_auth: add common Azure authentication module
zshuang0316 d19d342
out_azure_blob: add OAuth authentication support
zshuang0316 d0497e7
out_azure_kusto: migrate to common Azure authentication
zshuang0316 a4478a1
tests: add unit tests for Azure Blob OAuth authentication
zshuang0316 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* -*- 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 for IMDS (MSI) authentication */ | ||
| #define FLB_AZURE_KUSTO_RESOURCE "https://api.kusto.windows.net" | ||
|
|
||
| /* Azure Kusto scope for MSAL (service principal / workload identity) */ | ||
| #define FLB_AZURE_KUSTO_SCOPE "https://help.kusto.windows.net/.default" | ||
|
|
||
| /* 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 */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For
auth_type managed_identityinazure_blob,flb_azure_auth_build_oauth_url()passes this constant directly as the IMDSresourcequery value, so the token is requested forhttps://storage.azure.cominstead of the Storage data-plane audiencehttps://storage.azure.com/. That audience mismatch causes managed-identity Blob requests to fail authentication even when RBAC is correct; use a separate MSI resource ID with the trailing slash while keeping the current no-slash base for/.defaultscopes.Useful? React with 👍 / 👎.
Uh oh!
There was an error while loading. Please reload this page.
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.
Already have it tested without the slash, and no slash is consistent with azure_kusto, so will not change