Skip to content

Commit 47b883d

Browse files
committed
aws: add IoT provider support and related credentials definitions
This update introduces the IoT provider creation function and adds necessary environment variable definitions for IoT credentials in the AWS module. Additionally, the CMake configuration is updated to include the new IoT credentials source file. Signed-off-by: SagiROosto <sagi.rosenthal@oosto.com>
1 parent d142e3f commit 47b883d

5 files changed

Lines changed: 1098 additions & 5 deletions

File tree

include/fluent-bit/flb_aws_credentials.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
/* 5 second timeout for credential related http requests */
3535
#define FLB_AWS_CREDENTIAL_NET_TIMEOUT 5
3636

37+
/* IoT Credentials Environment Variables */
38+
#define AWS_IOT_KEY_FILE "AWS_IOT_KEY_FILE"
39+
#define AWS_IOT_CERT_FILE "AWS_IOT_CERT_FILE"
40+
#define AWS_IOT_CA_CERT_FILE "AWS_IOT_CA_CERT_FILE"
41+
#define AWS_IOT_CREDENTIALS_ENDPOINT "AWS_IOT_CREDENTIALS_ENDPOINT"
42+
#define AWS_IOT_THING_NAME "AWS_IOT_THING_NAME"
43+
#define AWS_IOT_ROLE_ALIAS "AWS_IOT_ROLE_ALIAS"
44+
45+
/* Greengrass V2 Config File - fallback source for IoT configuration */
46+
#define AWS_IOT_GREENGRASS_V2_CONFIG "AWS_IOT_GREENGRASS_V2_CONFIG_PATH"
47+
48+
/* Greengrass V2 Component Environment Variable - fallback for CA cert */
49+
#define AWS_GG_ROOT_CA_PATH "AWS_GG_ROOT_CA_PATH"
50+
3751
/*
3852
* A structure that wraps the sensitive data needed to sign an AWS request
3953
*/
@@ -225,6 +239,11 @@ struct flb_aws_provider *flb_eks_provider_create(struct flb_config *config,
225239
flb_aws_client_generator
226240
*generator);
227241

242+
/*
243+
* IoT Provider
244+
*/
245+
struct flb_aws_provider *flb_iot_provider_create(struct flb_config *config,
246+
struct flb_aws_client_generator *generator);
228247

229248
/*
230249
* STS Assume Role Provider.

src/aws/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(src
1616
"flb_aws_credentials_http.c"
1717
"flb_aws_credentials_profile.c"
1818
"flb_aws_aggregation.c"
19+
"flb_aws_credentials_iot.c"
1920
)
2021

2122
message(STATUS "=== AWS Credentials ===")

src/aws/flb_aws_credentials.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ static struct flb_aws_provider *standard_chain_create(struct flb_config
5151
int eks_irsa,
5252
char *profile);
5353

54-
5554
/*
5655
* The standard credential provider chain:
5756
* 1. Environment variables
58-
* 2. Shared credentials file (AWS Profile)
59-
* 3. EKS OIDC
60-
* 4. EC2 IMDS
57+
* 2. IoT credentials endpoint (AWS_IOT_* env vars / Greengrass V2 config)
58+
* 3. Shared credentials file (AWS Profile)
59+
* 4. EKS OIDC
6160
* 5. ECS HTTP credentials endpoint
61+
* 6. EC2 IMDS
6262
*
6363
* This provider will evaluate each provider in order, returning the result
6464
* from the first provider that returns valid credentials.
@@ -566,6 +566,28 @@ static struct flb_aws_provider *standard_chain_create(struct flb_config
566566

567567
mk_list_add(&sub_provider->_head, &implementation->sub_providers);
568568

569+
/*
570+
* IoT Provider - placed after environment provider but before profile provider.
571+
*
572+
* Rationale for this position in the credential chain:
573+
* 1. Standard AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY env vars take precedence
574+
* (handled by env provider above) - explicit credentials always win.
575+
* 2. IoT-specific env vars (AWS_IOT_*) or Greengrass V2 config indicate the user
576+
* explicitly wants IoT credentials on devices like AWS Greengrass.
577+
* 3. IoT provider comes before profile/EKS/ECS/EC2 because when IoT config
578+
* is present, the device is specifically configured for IoT credentials.
579+
*
580+
* Configuration sources (in priority order):
581+
* - AWS_IOT_* environment variables (explicit)
582+
* - AWS_IOT_GREENGRASS_V2_CONFIG_PATH -> config.yaml (Greengrass V2)
583+
* - GG_ROOT_CA_PATH fallback for CA certificate
584+
*/
585+
sub_provider = flb_iot_provider_create(config, generator);
586+
if (sub_provider) {
587+
mk_list_add(&sub_provider->_head, &implementation->sub_providers);
588+
flb_debug("[aws_credentials] Initialized IoT Provider in standard chain");
589+
}
590+
569591
flb_debug("[aws_credentials] creating profile %s provider", profile);
570592
sub_provider = flb_profile_provider_create(profile);
571593
if (sub_provider) {

0 commit comments

Comments
 (0)