Skip to content

Commit e5a9dfc

Browse files
committed
feat(aw): improve and organize mtls logs
Ticket: WP-5523
1 parent a9cad8e commit e5a9dfc

File tree

5 files changed

+82
-23
lines changed

5 files changed

+82
-23
lines changed

src/advancedWalletManagerApp.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,29 @@ export function startup(config: AdvancedWalletManagerConfig, baseUri: string): (
2929
return () => {
3030
logger.info('Advanced Wallet Manager starting...');
3131
logger.info(`Base URI: ${baseUri}`);
32-
logger.info(`mTLS Mode: ${config.tlsMode}`);
33-
logger.info(`Allow Self-Signed Certificates: ${config.clientCertAllowSelfSigned}`);
3432
logger.info(`Port: ${config.port}`);
3533
logger.info(`Bind: ${config.bind}`);
3634
logger.info(`KMS URL: ${config.kmsUrl}`);
3735
logger.info(`Recovery Mode: ${config.recoveryMode}`);
36+
37+
// mTLS Configuration Section
38+
logger.info('=== mTLS Configuration ===');
39+
logger.info(`TLS Mode: ${config.tlsMode}`);
40+
if (config.tlsMode === 'mtls') {
41+
logger.info('Server Settings (incoming connections):');
42+
logger.info(` • Allow Self-Signed Client Certificates: ${config.allowSelfSigned}`);
43+
if (config.mtlsAllowedClientFingerprints && config.mtlsAllowedClientFingerprints.length > 0) {
44+
logger.info(
45+
` • Allowed Client Fingerprints: ${config.mtlsAllowedClientFingerprints.join(', ')}`,
46+
);
47+
}
48+
logger.info('Client Settings (outbound to KMS):');
49+
logger.info(
50+
` • Allow Self-Signed KMS Server Certificates: ${config.kmsServerCertAllowSelfSigned}`,
51+
);
52+
}
53+
logger.info('========================');
54+
3855
logger.info('Advanced Wallet Manager started successfully');
3956
};
4057
}

src/api/master/clients/advancedWalletManagerClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class AdvancedWalletManagerClient {
260260
// Build the type-safe API client
261261
this.apiClient = buildApiClient(requestFactory, AdvancedWalletManagerApiSpec);
262262

263-
logger.info('Advanced Wallet Manager initialized with URL: %s', this.baseUrl);
263+
logger.info('✓ AWM Client initialized with URL: %s', this.baseUrl);
264264
}
265265

266266
private createHttpsAgent(): https.Agent {

src/initConfig.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,22 @@ function configureAdvancedWalletManagaerMode(): AdvancedWalletManagerConfig {
161161
const env = advancedWalletManagerEnvConfig();
162162
let config = mergeAkmConfigs(env);
163163

164+
// Certificate Loading Section
165+
logger.info('=== Certificate Loading ===');
166+
164167
// Only load certificates if TLS is enabled
165168
if (config.tlsMode !== TlsMode.DISABLED) {
166169
// Handle file loading for TLS certificates
167170
if (!config.serverTlsKey && config.serverTlsKeyPath) {
168171
try {
169172
config = { ...config, serverTlsKey: fs.readFileSync(config.serverTlsKeyPath, 'utf-8') };
170-
logger.info(`Successfully loaded TLS private key from file: ${config.serverTlsKeyPath}`);
173+
logger.info(`TLS private key loaded from file: ${config.serverTlsKeyPath}`);
171174
} catch (e) {
172175
const err = e instanceof Error ? e : new Error(String(e));
173176
throw new Error(`Failed to read TLS key from serverTlsKeyPath: ${err.message}`);
174177
}
175178
} else if (config.serverTlsKey) {
176-
logger.info('Using TLS private key from environment variable');
179+
logger.info(' TLS private key loaded from environment variable');
177180
}
178181

179182
if (!config.serverTlsCert && config.serverTlsCertPath) {
@@ -182,13 +185,13 @@ function configureAdvancedWalletManagaerMode(): AdvancedWalletManagerConfig {
182185
...config,
183186
serverTlsCert: fs.readFileSync(config.serverTlsCertPath, 'utf-8'),
184187
};
185-
logger.info(`Successfully loaded TLS certificate from file: ${config.serverTlsCertPath}`);
188+
logger.info(`TLS certificate loaded from file: ${config.serverTlsCertPath}`);
186189
} catch (e) {
187190
const err = e instanceof Error ? e : new Error(String(e));
188191
throw new Error(`Failed to read TLS certificate from serverTlsCertPath: ${err.message}`);
189192
}
190193
} else if (config.serverTlsCert) {
191-
logger.info('Using TLS certificate from environment variable');
194+
logger.info(' TLS certificate loaded from environment variable');
192195
}
193196

194197
if (!config.kmsServerCaCertPath) {
@@ -197,9 +200,7 @@ function configureAdvancedWalletManagaerMode(): AdvancedWalletManagerConfig {
197200
if (config.kmsServerCaCertPath) {
198201
try {
199202
config.kmsServerCaCert = fs.readFileSync(config.kmsServerCaCertPath, 'utf-8');
200-
logger.info(
201-
`Successfully loaded KMS TLS certificate from file: ${config.kmsServerCaCertPath}`,
202-
);
203+
logger.info(`✓ KMS server CA certificate loaded from file: ${config.kmsServerCaCertPath}`);
203204
} catch (e) {
204205
const err = e instanceof Error ? e : new Error(String(e));
205206
throw new Error(`Failed to read KMS TLS certificate from kmsTlsCert: ${err.message}`);
@@ -209,7 +210,7 @@ function configureAdvancedWalletManagaerMode(): AdvancedWalletManagerConfig {
209210
if (config.kmsClientTlsKeyPath) {
210211
try {
211212
config.kmsClientTlsKey = fs.readFileSync(config.kmsClientTlsKeyPath, 'utf-8');
212-
logger.info(`Successfully loaded KMS client key from file: ${config.kmsClientTlsKeyPath}`);
213+
logger.info(`KMS client key loaded from file: ${config.kmsClientTlsKeyPath}`);
213214
} catch (e) {
214215
const err = e instanceof Error ? e : new Error(String(e));
215216
throw new Error(`Failed to read KMS client key from kmsClientTlsKeyPath: ${err.message}`);
@@ -219,9 +220,7 @@ function configureAdvancedWalletManagaerMode(): AdvancedWalletManagerConfig {
219220
if (config.kmsClientTlsCertPath) {
220221
try {
221222
config.kmsClientTlsCert = fs.readFileSync(config.kmsClientTlsCertPath, 'utf-8');
222-
logger.info(
223-
`Successfully loaded KMS client cert from file: ${config.kmsClientTlsCertPath}`,
224-
);
223+
logger.info(`✓ KMS client certificate loaded from file: ${config.kmsClientTlsCertPath}`);
225224
} catch (e) {
226225
const err = e instanceof Error ? e : new Error(String(e));
227226
throw new Error(`Failed to read KMS client cert from kmsClientTlsCertPath: ${err.message}`);
@@ -240,6 +239,8 @@ function configureAdvancedWalletManagaerMode(): AdvancedWalletManagerConfig {
240239
validateTlsCertificates(config);
241240
}
242241

242+
logger.info('==========================');
243+
243244
return config;
244245
}
245246

@@ -385,19 +386,22 @@ export function configureMasterExpressMode(): MasterExpressConfig {
385386
}
386387
config = { ...config, ...updates };
387388

389+
// Certificate Loading Section
390+
logger.info('=== Certificate Loading ===');
391+
388392
// Only load certificates if TLS is enabled
389393
if (config.tlsMode !== TlsMode.DISABLED) {
390394
// Handle file loading for TLS certificates
391395
if (!config.serverTlsKey && config.serverTlsKeyPath) {
392396
try {
393397
config = { ...config, serverTlsKey: fs.readFileSync(config.serverTlsKeyPath, 'utf-8') };
394-
logger.info(`Successfully loaded TLS private key from file: ${config.serverTlsKeyPath}`);
398+
logger.info(`TLS private key loaded from file: ${config.serverTlsKeyPath}`);
395399
} catch (e) {
396400
const err = e instanceof Error ? e : new Error(String(e));
397401
throw new Error(`Failed to read TLS key from serverTlsKeyPath: ${err.message}`);
398402
}
399403
} else if (config.serverTlsKey) {
400-
logger.info('Using TLS private key from environment variable');
404+
logger.info(' TLS private key loaded from environment variable');
401405
}
402406

403407
if (!config.serverTlsCert && config.serverTlsCertPath) {
@@ -406,13 +410,13 @@ export function configureMasterExpressMode(): MasterExpressConfig {
406410
...config,
407411
serverTlsCert: fs.readFileSync(config.serverTlsCertPath, 'utf-8'),
408412
};
409-
logger.info(`Successfully loaded TLS certificate from file: ${config.serverTlsCertPath}`);
413+
logger.info(`TLS certificate loaded from file: ${config.serverTlsCertPath}`);
410414
} catch (e) {
411415
const err = e instanceof Error ? e : new Error(String(e));
412416
throw new Error(`Failed to read TLS certificate from serverTlsCertPath: ${err.message}`);
413417
}
414418
} else if (config.serverTlsCert) {
415-
logger.info('Using TLS certificate from environment variable');
419+
logger.info(' TLS certificate loaded from environment variable');
416420
}
417421

418422
// Validate that certificates are properly loaded when TLS is enabled
@@ -428,7 +432,7 @@ export function configureMasterExpressMode(): MasterExpressConfig {
428432
awmServerCaCert: fs.readFileSync(config.awmServerCaCertPath, 'utf-8'),
429433
};
430434
logger.info(
431-
`Successfully loaded Advanced Wallet Manager certificate from file: ${config.awmServerCaCertPath?.substring(
435+
`✓ AWM server CA certificate loaded from file: ${config.awmServerCaCertPath?.substring(
432436
0,
433437
50,
434438
)}...`,
@@ -445,7 +449,7 @@ export function configureMasterExpressMode(): MasterExpressConfig {
445449
if (config.awmClientTlsKeyPath) {
446450
try {
447451
config.awmClientTlsKey = fs.readFileSync(config.awmClientTlsKeyPath, 'utf-8');
448-
logger.info(`Successfully loaded AWM client key from file: ${config.awmClientTlsKeyPath}`);
452+
logger.info(`AWM client key loaded from file: ${config.awmClientTlsKeyPath}`);
449453
} catch (e) {
450454
const err = e instanceof Error ? e : new Error(String(e));
451455
throw new Error(`Failed to read AWM client key from awmClientTlsKeyPath: ${err.message}`);
@@ -455,13 +459,15 @@ export function configureMasterExpressMode(): MasterExpressConfig {
455459
if (config.awmClientTlsCertPath) {
456460
try {
457461
config.awmClientTlsCert = fs.readFileSync(config.awmClientTlsCertPath, 'utf-8');
458-
logger.info(`Successfully loaded AWM client cert from file: ${config.awmClientTlsCertPath}`);
462+
logger.info(`AWM client certificate loaded from file: ${config.awmClientTlsCertPath}`);
459463
} catch (e) {
460464
const err = e instanceof Error ? e : new Error(String(e));
461465
throw new Error(`Failed to read AWM client cert from awmClientTlsCertPath: ${err.message}`);
462466
}
463467
}
464468

469+
logger.info('==========================');
470+
465471
// Fallback to server certs if client certs are not provided
466472
if (!config.awmClientTlsKey) {
467473
config.awmClientTlsKey = config.serverTlsKey;

src/masterBitGoExpressApp.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,29 @@ export function startup(config: MasterExpressConfig, baseUri: string): () => voi
2424
return () => {
2525
logger.info('Master Express server starting...');
2626
logger.info(`Base URI: ${baseUri}`);
27-
logger.info(`TLS Mode: ${config.tlsMode}`);
2827
logger.info(`Port: ${config.port}`);
2928
logger.info(`Bind: ${config.bind}`);
3029
logger.info(`Recovery Mode: ${config.recoveryMode}`);
3130
logger.info(`Advanced Wallet Manager URL: ${config.advancedWalletManagerUrl}`);
31+
32+
// mTLS Configuration Section
33+
logger.info('=== mTLS Configuration ===');
34+
logger.info(`TLS Mode: ${config.tlsMode}`);
35+
if (config.tlsMode === 'mtls') {
36+
logger.info('Server Settings (incoming connections):');
37+
logger.info(` • Allow Self-Signed Client Certificates: ${config.allowSelfSigned}`);
38+
if (config.mtlsAllowedClientFingerprints && config.mtlsAllowedClientFingerprints.length > 0) {
39+
logger.info(
40+
` • Allowed Client Fingerprints: ${config.mtlsAllowedClientFingerprints.join(', ')}`,
41+
);
42+
}
43+
logger.info('Client Settings (outbound to AWM):');
44+
logger.info(
45+
` • Allow Self-Signed AWM Server Certificates: ${config.awmServerCertAllowSelfSigned}`,
46+
);
47+
}
48+
logger.info('========================');
49+
3250
logger.info('Master Express server started successfully');
3351
};
3452
}

src/masterExpressApp.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,28 @@ export function startup(config: MasterExpressConfig, baseUri: string): () => voi
2424
return () => {
2525
logger.info('Master Express server starting...');
2626
logger.info(`Base URI: ${baseUri}`);
27-
logger.info(`TLS Mode: ${config.tlsMode}`);
2827
logger.info(`Port: ${config.port}`);
2928
logger.info(`Bind: ${config.bind}`);
3029
logger.info(`Advanced Wallet Manager URL: ${config.advancedWalletManagerUrl}`);
30+
31+
// mTLS Configuration Section
32+
logger.info('=== mTLS Configuration ===');
33+
logger.info(`TLS Mode: ${config.tlsMode}`);
34+
if (config.tlsMode === 'mtls') {
35+
logger.info('Server Settings (incoming connections):');
36+
logger.info(` • Allow Self-Signed Client Certificates: ${config.allowSelfSigned}`);
37+
if (config.mtlsAllowedClientFingerprints && config.mtlsAllowedClientFingerprints.length > 0) {
38+
logger.info(
39+
` • Allowed Client Fingerprints: ${config.mtlsAllowedClientFingerprints.join(', ')}`,
40+
);
41+
}
42+
logger.info('Client Settings (outbound to AWM):');
43+
logger.info(
44+
` • Allow Self-Signed AWM Server Certificates: ${config.awmServerCertAllowSelfSigned}`,
45+
);
46+
}
47+
logger.info('========================');
48+
3149
logger.info('Master Express server started successfully');
3250
};
3351
}

0 commit comments

Comments
 (0)