Skip to content

Commit e5213f7

Browse files
authored
Merge branch 'fluent:master' into feature/rdkafka-sasl-mechanism-aws-msk-iam
2 parents 2ced392 + 10ebd3a commit e5213f7

File tree

2 files changed

+137
-13
lines changed

2 files changed

+137
-13
lines changed

plugins/in_kubernetes_events/kubernetes_events_conf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ static int network_init(struct k8s_events *ctx, struct flb_config *config)
128128
return -1;
129129
}
130130

131+
if (flb_input_upstream_set(ctx->upstream, ctx->ins) != 0) {
132+
flb_plg_error(ctx->ins, "network upstream setup failed");
133+
flb_upstream_destroy(ctx->upstream);
134+
ctx->upstream = NULL;
135+
return -1;
136+
}
137+
131138
return 0;
132139
}
133140

src/tls/openssl.c

Lines changed: 130 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,104 @@ int tls_context_alpn_set(void *ctx_backend, const char *alpn)
302302
}
303303

304304
#ifdef _MSC_VER
305+
/* Parse certstore_name prefix like
306+
*
307+
* "My" -> no prefix, leave location untouched
308+
* "CurrentUser\\My" -> CERT_SYSTEM_STORE_CURRENT_USER, "My"
309+
* "HKCU\\My" -> CERT_SYSTEM_STORE_CURRENT_USER, "My"
310+
* "LocalMachine\\My" -> CERT_SYSTEM_STORE_LOCAL_MACHINE, "My"
311+
* "HKLM\\My" -> CERT_SYSTEM_STORE_LOCAL_MACHINE, "My"
312+
* "LocalMachineEnterprise\\My"-> CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, "My"
313+
* "HKLME\\My" -> CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE, "My"
314+
*
315+
* Also accepts '/' as separator.
316+
*
317+
* If no known prefix is found, *store_name_out is left as-is and *location_flags
318+
* is not modified (so legacy behavior is preserved).
319+
*/
320+
static int windows_resolve_certstore_location(const char *configured_name,
321+
DWORD *location_flags,
322+
const char **store_name_out)
323+
{
324+
const char *name;
325+
const char *sep;
326+
size_t prefix_len;
327+
char prefix_buf[32];
328+
size_t i;
329+
size_t len = 0;
330+
char c;
331+
332+
if (!configured_name || !*configured_name) {
333+
return FLB_FALSE;
334+
}
335+
336+
name = configured_name;
337+
len = strlen(name);
338+
339+
/* Optional "Cert:\" prefix (PowerShell style) */
340+
if (len >= 6 &&
341+
strncasecmp(name, "cert:", 5) == 0 &&
342+
(name[5] == '\\' || name[5] == '/')) {
343+
name += 6;
344+
}
345+
346+
/* Find first '\' or '/' separator */
347+
sep = name;
348+
while (*sep != '\0' && *sep != '\\' && *sep != '/') {
349+
sep++;
350+
}
351+
352+
if (*sep == '\0') {
353+
/* No prefix, only store name (e.g. "My" or "Root")
354+
* -> keep legacy behavior (location_flags unchanged).
355+
*/
356+
*store_name_out = name;
357+
358+
return FLB_FALSE;
359+
}
360+
361+
/* Copy and lowercase prefix into buffer */
362+
prefix_len = (size_t)(sep - name);
363+
if (prefix_len >= sizeof(prefix_buf)) {
364+
prefix_len = sizeof(prefix_buf) - 1;
365+
}
366+
367+
for (i = 0; i < prefix_len; i++) {
368+
c = (char) name[i];
369+
370+
if (c >= 'A' && c <= 'Z') {
371+
c = (char) (c - 'A' + 'a');
372+
}
373+
prefix_buf[i] = c;
374+
}
375+
prefix_buf[prefix_len] = '\0';
376+
377+
/* Default: keep *location_flags as-is */
378+
if (strcmp(prefix_buf, "currentuser") == 0 ||
379+
strcmp(prefix_buf, "hkcu") == 0) {
380+
*location_flags = CERT_SYSTEM_STORE_CURRENT_USER;
381+
}
382+
else if (strcmp(prefix_buf, "localmachine") == 0 ||
383+
strcmp(prefix_buf, "hklm") == 0) {
384+
*location_flags = CERT_SYSTEM_STORE_LOCAL_MACHINE;
385+
}
386+
else if (strcmp(prefix_buf, "localmachineenterprise") == 0 ||
387+
strcmp(prefix_buf, "hklme") == 0) {
388+
*location_flags = CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE;
389+
}
390+
else {
391+
/* Unknown prefix -> treat entire string as store name */
392+
*store_name_out = configured_name;
393+
394+
return FLB_FALSE;
395+
}
396+
397+
/* Store name part after the separator "\" or "/" */
398+
*store_name_out = sep + 1;
399+
400+
return FLB_TRUE;
401+
}
402+
305403
static int windows_load_system_certificates(struct tls_context *ctx)
306404
{
307405
int ret;
@@ -311,7 +409,10 @@ static int windows_load_system_certificates(struct tls_context *ctx)
311409
const unsigned char *win_cert_data;
312410
X509_STORE *ossl_store = SSL_CTX_get_cert_store(ctx->ctx);
313411
X509 *ossl_cert;
314-
char *certstore_name = "Root";
412+
char *configured_name = "Root";
413+
const char *store_name = "Root";
414+
DWORD store_location = CERT_SYSTEM_STORE_CURRENT_USER;
415+
int has_location_prefix = FLB_FALSE;
315416

316417
/* Check if OpenSSL certificate store is available */
317418
if (!ossl_store) {
@@ -320,20 +421,36 @@ static int windows_load_system_certificates(struct tls_context *ctx)
320421
}
321422

322423
if (ctx->certstore_name) {
323-
certstore_name = ctx->certstore_name;
424+
configured_name = ctx->certstore_name;
425+
store_name = ctx->certstore_name;
426+
}
427+
428+
/* First, resolve explicit prefix if present */
429+
has_location_prefix = windows_resolve_certstore_location(configured_name,
430+
&store_location,
431+
&store_name);
432+
433+
/* Backward compatibility:
434+
* If no prefix was given (store_name == configured_name) and
435+
* use_enterprise_store is set, override location accordingly.
436+
*/
437+
if (has_location_prefix == FLB_FALSE && ctx->use_enterprise_store) {
438+
store_location = CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE;
324439
}
325440

326-
if (ctx->use_enterprise_store) {
327-
/* Open the Windows system enterprise certificate store */
441+
/* Open the Windows certificate store for the resolved location */
442+
if (store_location == CERT_SYSTEM_STORE_CURRENT_USER) {
443+
/* Keep using CertOpenSystemStoreA for current user to avoid
444+
* changing existing behavior.
445+
*/
446+
win_store = CertOpenSystemStoreA(0, store_name);
447+
}
448+
else {
328449
win_store = CertOpenStore(CERT_STORE_PROV_SYSTEM,
329450
0,
330451
0,
331-
CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE,
332-
certstore_name);
333-
}
334-
else {
335-
/* Open the Windows system certificate store */
336-
win_store = CertOpenSystemStoreA(0, certstore_name);
452+
store_location,
453+
store_name);
337454
}
338455

339456
if (win_store == NULL) {
@@ -389,10 +506,10 @@ static int windows_load_system_certificates(struct tls_context *ctx)
389506
}
390507

391508
if (loaded == 0) {
392-
flb_warn("[tls] no certificates loaded by thumbprint from '%s'.", certstore_name);
509+
flb_warn("[tls] no certificates loaded by thumbprint from '%s'.", configured_name);
393510
}
394511
else {
395-
flb_debug("[tls] loaded %zu certificate(s) by thumbprint from '%s'.", loaded, certstore_name);
512+
flb_debug("[tls] loaded %zu certificate(s) by thumbprint from '%s'.", loaded, configured_name);
396513
}
397514
return 0;
398515
}
@@ -445,7 +562,7 @@ static int windows_load_system_certificates(struct tls_context *ctx)
445562
}
446563

447564
flb_debug("[tls] successfully loaded certificates from windows system %s store.",
448-
certstore_name);
565+
configured_name);
449566
return 0;
450567
}
451568
#endif

0 commit comments

Comments
 (0)