Skip to content

Commit a64f819

Browse files
committed
aws_msk_iam: support VPC endpoint
Signed-off-by: Arbin <arbin.cheng@coins.ph>
1 parent c8ffbf4 commit a64f819

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/aws/flb_aws_msk_iam.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,33 +135,53 @@ static int hmac_sha256_sign(unsigned char out[32],
135135
}
136136

137137
/* Extract region from MSK broker address
138-
* MSK Standard format: b-1.example.c1.kafka.<Region>.amazonaws.com:port
139-
* MSK Serverless format: boot-<ClusterUniqueID>.c<x>.kafka-serverless.<Region>.amazonaws.com:port
138+
* Supported formats:
139+
* - MSK Standard: b-1.example.c1.kafka.<Region>.amazonaws.com:port
140+
* - MSK Serverless: boot-<ClusterUniqueID>.c<x>.kafka-serverless.<Region>.amazonaws.com:port
141+
* - VPC Endpoint: vpce-<ID>.kafka.<Region>.vpce.amazonaws.com:port
140142
*/
141143
static flb_sds_t extract_region_from_broker(const char *broker)
142144
{
143145
const char *p;
144146
const char *start;
145147
const char *end;
148+
const char *port_pos;
146149
size_t len;
147150
flb_sds_t out;
148151

149152
if (!broker || strlen(broker) == 0) {
150153
return NULL;
151154
}
152155

156+
/* Remove port if present (e.g., :9098) */
157+
port_pos = strchr(broker, ':');
158+
if (port_pos) {
159+
len = port_pos - broker;
160+
} else {
161+
len = strlen(broker);
162+
}
163+
153164
/* Find .amazonaws.com */
154165
p = strstr(broker, ".amazonaws.com");
155-
if (!p) {
166+
if (!p || p >= broker + len) {
156167
return NULL;
157168
}
158169

159170
/* Region is between the last dot before .amazonaws.com and .amazonaws.com
160-
* Example: ...kafka.us-east-1.amazonaws.com
161-
* or ...kafka-serverless.us-east-1.amazonaws.com
171+
* Handle VPC endpoints (vpce-xxx.kafka.region.vpce.amazonaws.com)
172+
* Example formats:
173+
* Standard: ...kafka.us-east-1.amazonaws.com
174+
* Serverless: ...kafka-serverless.us-east-1.amazonaws.com
175+
* VPC Endpoint: ...kafka.us-east-1.vpce.amazonaws.com
162176
*/
163177
end = p; /* Points to .amazonaws.com */
164178

179+
/* Check for VPC endpoint format: .vpce.amazonaws.com */
180+
if (p >= broker + 5 && strncmp(p - 5, ".vpce", 5) == 0) {
181+
/* For VPC endpoints, region ends at .vpce */
182+
end = p - 5;
183+
}
184+
165185
/* Find the start of region by going backwards to find the previous dot */
166186
start = end - 1;
167187
while (start > broker && *start != '.') {
@@ -177,7 +197,9 @@ static flb_sds_t extract_region_from_broker(const char *broker)
177197
}
178198

179199
len = end - start;
180-
if (len == 0 || len > 32) { /* Sanity check on region length (AWS regions are typically <= 20 chars) */
200+
201+
/* Sanity check on region length (AWS regions are typically 9-20 chars) */
202+
if (len == 0 || len > 32) {
181203
return NULL;
182204
}
183205

0 commit comments

Comments
 (0)