@celerispay/hazelcast-client 3.12.5 → 3.12.7-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +111 -87
- package/CHANGES_UNCOMMITTED.md +53 -0
- package/FAILOVER_FIXES.md +148 -230
- package/FAULT_TOLERANCE_IMPROVEMENTS.md +208 -0
- package/HAZELCAST_CLIENT_EVOLUTION.md +402 -0
- package/QUICK_START.md +184 -95
- package/RELEASE_SUMMARY.md +227 -147
- package/lib/HeartbeatService.js +11 -2
- package/lib/PartitionService.d.ts +14 -0
- package/lib/PartitionService.js +32 -9
- package/lib/invocation/ClientConnection.d.ts +14 -0
- package/lib/invocation/ClientConnection.js +95 -1
- package/lib/invocation/ClientConnectionManager.d.ts +99 -0
- package/lib/invocation/ClientConnectionManager.js +394 -10
- package/lib/invocation/ClusterService.d.ts +91 -5
- package/lib/invocation/ClusterService.js +490 -17
- package/lib/invocation/ConnectionAuthenticator.d.ts +11 -0
- package/lib/invocation/ConnectionAuthenticator.js +85 -12
- package/lib/invocation/CredentialPreservationService.d.ts +141 -0
- package/lib/invocation/CredentialPreservationService.js +377 -0
- package/lib/invocation/HazelcastFailoverManager.d.ts +102 -0
- package/lib/invocation/HazelcastFailoverManager.js +285 -0
- package/lib/invocation/InvocationService.js +8 -0
- package/lib/nearcache/StaleReadDetectorImpl.js +31 -4
- package/lib/proxy/ProxyManager.js +25 -4
- package/package.json +20 -28
|
@@ -34,53 +34,126 @@ var ConnectionAuthenticator = /** @class */ (function () {
|
|
|
34
34
|
}
|
|
35
35
|
ConnectionAuthenticator.prototype.authenticate = function (asOwner) {
|
|
36
36
|
var _this = this;
|
|
37
|
+
var addressStr = this.connection.getAddress().toString();
|
|
38
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDD10 Starting authentication for " + addressStr + " (asOwner=" + asOwner + ")");
|
|
37
39
|
var credentials = this.createCredentials(asOwner);
|
|
40
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDCE4 Sending authentication request to " + addressStr + "...");
|
|
38
41
|
return this.client.getInvocationService()
|
|
39
42
|
.invokeOnConnection(this.connection, credentials)
|
|
40
43
|
.then(function (msg) {
|
|
44
|
+
_this.logger.info('ConnectionAuthenticator', "\uD83D\uDCE5 Received authentication response from " + addressStr);
|
|
41
45
|
var authResponse = ClientAuthenticationCodec_1.ClientAuthenticationCodec.decodeResponse(msg);
|
|
46
|
+
_this.logger.info('ConnectionAuthenticator', "\uD83D\uDD0D Authentication response for " + addressStr + ":");
|
|
47
|
+
_this.logger.info('ConnectionAuthenticator', " - Status: " + authResponse.status + " (" + _this.getStatusDescription(authResponse.status) + ")");
|
|
48
|
+
_this.logger.info('ConnectionAuthenticator', " - Server UUID: " + (authResponse.uuid || 'NOT PROVIDED'));
|
|
49
|
+
_this.logger.info('ConnectionAuthenticator', " - Server Owner UUID: " + (authResponse.ownerUuid || 'NOT PROVIDED'));
|
|
50
|
+
_this.logger.info('ConnectionAuthenticator', " - Server Address: " + (authResponse.address ? authResponse.address.toString() : 'NOT PROVIDED'));
|
|
51
|
+
_this.logger.info('ConnectionAuthenticator', " - Server Version: " + (authResponse.serverHazelcastVersion || 'NOT PROVIDED'));
|
|
42
52
|
switch (authResponse.status) {
|
|
43
53
|
case 0 /* AUTHENTICATED */:
|
|
54
|
+
_this.logger.info('ConnectionAuthenticator', "\u2705 Authentication SUCCESSFUL for " + addressStr);
|
|
44
55
|
_this.connection.setAddress(authResponse.address);
|
|
45
56
|
_this.connection.setConnectedServerVersion(authResponse.serverHazelcastVersion);
|
|
46
57
|
if (asOwner) {
|
|
58
|
+
var oldUuid = _this.clusterService.uuid;
|
|
59
|
+
var oldOwnerUuid = _this.clusterService.ownerUuid;
|
|
47
60
|
_this.clusterService.uuid = authResponse.uuid;
|
|
48
61
|
_this.clusterService.ownerUuid = authResponse.ownerUuid;
|
|
62
|
+
_this.logger.info('ConnectionAuthenticator', "\uD83D\uDD04 Updated cluster service for " + addressStr + ":");
|
|
63
|
+
_this.logger.info('ConnectionAuthenticator', " - UUID: " + (oldUuid || 'NOT SET') + " \u2192 " + authResponse.uuid);
|
|
64
|
+
_this.logger.info('ConnectionAuthenticator', " - Owner UUID: " + (oldOwnerUuid || 'NOT SET') + " \u2192 " + authResponse.ownerUuid);
|
|
49
65
|
}
|
|
50
|
-
_this.logger.info('ConnectionAuthenticator',
|
|
51
|
-
_this.connection.getAddress().toString() + ' authenticated');
|
|
66
|
+
_this.logger.info('ConnectionAuthenticator', "\u2705 Connection to " + addressStr + " authenticated successfully");
|
|
52
67
|
break;
|
|
53
68
|
case 1 /* CREDENTIALS_FAILED */:
|
|
54
|
-
_this.logger.error('ConnectionAuthenticator',
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
_this.logger.error('ConnectionAuthenticator', "\u274C Authentication FAILED for " + addressStr + ": Invalid Credentials");
|
|
70
|
+
_this.logger.error('ConnectionAuthenticator', " - Server rejected our credentials");
|
|
71
|
+
_this.logger.error('ConnectionAuthenticator', " - Check if UUIDs and group credentials are correct");
|
|
72
|
+
throw new Error('Invalid Credentials, could not authenticate connection to ' + addressStr);
|
|
57
73
|
case 2 /* SERIALIZATION_VERSION_MISMATCH */:
|
|
58
|
-
_this.logger.error('ConnectionAuthenticator',
|
|
59
|
-
throw new Error('Serialization version mismatch, could not authenticate connection to ' +
|
|
60
|
-
_this.connection.getAddress().toString());
|
|
74
|
+
_this.logger.error('ConnectionAuthenticator', "\u274C Authentication FAILED for " + addressStr + ": Serialization version mismatch");
|
|
75
|
+
throw new Error('Serialization version mismatch, could not authenticate connection to ' + addressStr);
|
|
61
76
|
default:
|
|
62
|
-
_this.logger.error('ConnectionAuthenticator',
|
|
63
|
-
+ authResponse.status);
|
|
77
|
+
_this.logger.error('ConnectionAuthenticator', "\u274C Authentication FAILED for " + addressStr + ": Unknown status " + authResponse.status);
|
|
64
78
|
throw new HazelcastError_1.AuthenticationError('Unknown authentication status: ' + authResponse.status +
|
|
65
|
-
' , could not authenticate connection to ' +
|
|
66
|
-
_this.connection.getAddress().toString());
|
|
79
|
+
' , could not authenticate connection to ' + addressStr);
|
|
67
80
|
}
|
|
81
|
+
})
|
|
82
|
+
.catch(function (error) {
|
|
83
|
+
_this.logger.error('ConnectionAuthenticator', "\uD83D\uDCA5 Authentication ERROR for " + addressStr + ": " + error.message);
|
|
84
|
+
throw error;
|
|
68
85
|
});
|
|
69
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Gets a human-readable description of authentication status
|
|
89
|
+
*/
|
|
90
|
+
ConnectionAuthenticator.prototype.getStatusDescription = function (status) {
|
|
91
|
+
switch (status) {
|
|
92
|
+
case 0 /* AUTHENTICATED */: return 'AUTHENTICATED';
|
|
93
|
+
case 1 /* CREDENTIALS_FAILED */: return 'CREDENTIALS_FAILED';
|
|
94
|
+
case 2 /* SERIALIZATION_VERSION_MISMATCH */: return 'SERIALIZATION_VERSION_MISMATCH';
|
|
95
|
+
default: return "UNKNOWN_STATUS_" + status;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Creates credentials with optional restoration from preservation service
|
|
100
|
+
* @param asOwner Whether this is an owner connection
|
|
101
|
+
* @param preservedCredentials Optional preserved credentials to use
|
|
102
|
+
* @returns The credentials message
|
|
103
|
+
*/
|
|
104
|
+
ConnectionAuthenticator.prototype.createCredentialsWithRestoration = function (asOwner, preservedCredentials) {
|
|
105
|
+
if (preservedCredentials && preservedCredentials.uuid && preservedCredentials.ownerUuid) {
|
|
106
|
+
this.logger.debug('ConnectionAuthenticator', "Using preserved credentials: uuid=" + preservedCredentials.uuid + ", ownerUuid=" + preservedCredentials.ownerUuid);
|
|
107
|
+
// Use preserved credentials instead of current cluster state
|
|
108
|
+
var groupConfig = this.client.getConfig().groupConfig;
|
|
109
|
+
var customCredentials = this.client.getConfig().customCredentials;
|
|
110
|
+
var clientMessage = void 0;
|
|
111
|
+
var clientVersion = BuildInfo_1.BuildInfo.getClientVersion();
|
|
112
|
+
if (customCredentials != null) {
|
|
113
|
+
var credentialsPayload = this.client.getSerializationService().toData(customCredentials);
|
|
114
|
+
clientMessage = ClientAuthenticationCustomCodec_1.ClientAuthenticationCustomCodec.encodeRequest(credentialsPayload, preservedCredentials.uuid, preservedCredentials.ownerUuid, asOwner, 'NJS', 1, clientVersion);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
clientMessage = ClientAuthenticationCodec_1.ClientAuthenticationCodec.encodeRequest(preservedCredentials.groupName, preservedCredentials.groupPassword, preservedCredentials.uuid, preservedCredentials.ownerUuid, asOwner, 'NJS', 1, clientVersion);
|
|
118
|
+
}
|
|
119
|
+
return clientMessage;
|
|
120
|
+
}
|
|
121
|
+
// Fall back to normal credential creation
|
|
122
|
+
return this.createCredentials(asOwner);
|
|
123
|
+
};
|
|
70
124
|
ConnectionAuthenticator.prototype.createCredentials = function (asOwner) {
|
|
71
125
|
var groupConfig = this.client.getConfig().groupConfig;
|
|
72
126
|
var uuid = this.clusterService.uuid;
|
|
73
127
|
var ownerUuid = this.clusterService.ownerUuid;
|
|
74
128
|
var customCredentials = this.client.getConfig().customCredentials;
|
|
129
|
+
// LOG EXACTLY WHAT CREDENTIALS WE'RE SENDING
|
|
130
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDD10 Creating authentication credentials for " + this.connection.getAddress().toString() + ":");
|
|
131
|
+
this.logger.info('ConnectionAuthenticator', " - As Owner: " + asOwner);
|
|
132
|
+
this.logger.info('ConnectionAuthenticator', " - UUID: " + (uuid || 'NOT SET'));
|
|
133
|
+
this.logger.info('ConnectionAuthenticator', " - Owner UUID: " + (ownerUuid || 'NOT SET'));
|
|
134
|
+
this.logger.info('ConnectionAuthenticator', " - Group Name: " + (groupConfig.name || 'NOT SET'));
|
|
135
|
+
this.logger.info('ConnectionAuthenticator', " - Group Password: " + (groupConfig.password ? '***SET***' : 'NOT SET'));
|
|
136
|
+
this.logger.info('ConnectionAuthenticator', " - Custom Credentials: " + (customCredentials ? 'YES' : 'NO'));
|
|
137
|
+
this.logger.info('ConnectionAuthenticator', " - Client Version: " + BuildInfo_1.BuildInfo.getClientVersion());
|
|
75
138
|
var clientMessage;
|
|
76
139
|
var clientVersion = BuildInfo_1.BuildInfo.getClientVersion();
|
|
77
140
|
if (customCredentials != null) {
|
|
78
141
|
var credentialsPayload = this.client.getSerializationService().toData(customCredentials);
|
|
142
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDCE4 Sending CUSTOM authentication request with:");
|
|
143
|
+
this.logger.info('ConnectionAuthenticator', " - Custom Credentials: " + typeof credentialsPayload);
|
|
144
|
+
this.logger.info('ConnectionAuthenticator', " - UUID: " + (uuid || 'NOT SET'));
|
|
145
|
+
this.logger.info('ConnectionAuthenticator', " - Owner UUID: " + (ownerUuid || 'NOT SET'));
|
|
79
146
|
clientMessage = ClientAuthenticationCustomCodec_1.ClientAuthenticationCustomCodec.encodeRequest(credentialsPayload, uuid, ownerUuid, asOwner, 'NJS', 1, clientVersion);
|
|
80
147
|
}
|
|
81
148
|
else {
|
|
149
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDCE4 Sending STANDARD authentication request with:");
|
|
150
|
+
this.logger.info('ConnectionAuthenticator', " - Group Name: " + (groupConfig.name || 'NOT SET'));
|
|
151
|
+
this.logger.info('ConnectionAuthenticator', " - Group Password: " + (groupConfig.password ? '***SET***' : 'NOT SET'));
|
|
152
|
+
this.logger.info('ConnectionAuthenticator', " - UUID: " + (uuid || 'NOT SET'));
|
|
153
|
+
this.logger.info('ConnectionAuthenticator', " - Owner UUID: " + (ownerUuid || 'NOT SET'));
|
|
82
154
|
clientMessage = ClientAuthenticationCodec_1.ClientAuthenticationCodec.encodeRequest(groupConfig.name, groupConfig.password, uuid, ownerUuid, asOwner, 'NJS', 1, clientVersion);
|
|
83
155
|
}
|
|
156
|
+
this.logger.info('ConnectionAuthenticator', "\uD83D\uDCCB Final authentication message created and ready to send");
|
|
84
157
|
return clientMessage;
|
|
85
158
|
};
|
|
86
159
|
return ConnectionAuthenticator;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ILogger } from '../logging/ILogger';
|
|
2
|
+
import Address = require('../Address');
|
|
3
|
+
/**
|
|
4
|
+
* Interface for node credentials
|
|
5
|
+
*/
|
|
6
|
+
export interface NodeCredentials {
|
|
7
|
+
uuid: string;
|
|
8
|
+
ownerUuid: string;
|
|
9
|
+
groupName: string;
|
|
10
|
+
groupPassword: string;
|
|
11
|
+
lastAuthenticated: number;
|
|
12
|
+
isOwner: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Service to preserve and restore authentication credentials across failover cycles
|
|
16
|
+
* This fixes the "Invalid Credentials" issue that occurs when nodes rejoin after failover
|
|
17
|
+
*/
|
|
18
|
+
export declare class CredentialPreservationService {
|
|
19
|
+
private readonly logger;
|
|
20
|
+
/**
|
|
21
|
+
* Stores authentication context for each node
|
|
22
|
+
*/
|
|
23
|
+
private nodeCredentials;
|
|
24
|
+
constructor(logger: ILogger);
|
|
25
|
+
/**
|
|
26
|
+
* Preserves authentication credentials for a node before it gets disconnected
|
|
27
|
+
* @param address The node address
|
|
28
|
+
* @param uuid The node's UUID
|
|
29
|
+
* @param ownerUuid The owner UUID
|
|
30
|
+
* @param groupName The group name
|
|
31
|
+
* @param groupPassword The group password
|
|
32
|
+
* @param isOwner Whether this is an owner connection
|
|
33
|
+
*/
|
|
34
|
+
preserveCredentials(address: Address, uuid: string, ownerUuid: string, groupName: string, groupPassword: string, isOwner: boolean): void;
|
|
35
|
+
/**
|
|
36
|
+
* Restores authentication credentials for a specific node
|
|
37
|
+
* @param address The node address
|
|
38
|
+
* @returns The preserved credentials or null if not found
|
|
39
|
+
*/
|
|
40
|
+
restoreCredentials(address: Address): NodeCredentials | null;
|
|
41
|
+
/**
|
|
42
|
+
* Updates credentials after successful authentication
|
|
43
|
+
* @param address The node address
|
|
44
|
+
* @param uuid The new UUID
|
|
45
|
+
* @param ownerUuid The new owner UUID
|
|
46
|
+
*/
|
|
47
|
+
updateCredentials(address: Address, uuid: string, ownerUuid: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Clears credentials for a specific node
|
|
50
|
+
* @param address The node address
|
|
51
|
+
*/
|
|
52
|
+
clearCredentials(address: Address): void;
|
|
53
|
+
/**
|
|
54
|
+
* Clears all stored credentials - used for cluster reset scenarios
|
|
55
|
+
*/
|
|
56
|
+
clearAllCredentials(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Cleans up stale credentials older than the specified age
|
|
59
|
+
* @param maxAgeMs Maximum age in milliseconds (default: 5 minutes)
|
|
60
|
+
*/
|
|
61
|
+
cleanupStaleCredentials(maxAgeMs?: number): void;
|
|
62
|
+
/**
|
|
63
|
+
* Gets a summary of preserved credentials for debugging
|
|
64
|
+
* @returns A summary string
|
|
65
|
+
*/
|
|
66
|
+
getCredentialsSummary(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Smart credential restoration that handles both scenarios:
|
|
69
|
+
* 1. If member added event occurred -> use new UUID
|
|
70
|
+
* 2. If no member added event -> use old UUID (node probably never changed)
|
|
71
|
+
* @param address The address to restore credentials for
|
|
72
|
+
* @param hasMemberAddedEvent Whether we received a member added event for this address
|
|
73
|
+
* @returns The appropriate credentials to use
|
|
74
|
+
*/
|
|
75
|
+
smartRestoreCredentials(address: Address, hasMemberAddedEvent?: boolean): NodeCredentials | null;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if we have valid credentials for an address
|
|
78
|
+
* @param address The address to check
|
|
79
|
+
* @returns True if we have valid credentials
|
|
80
|
+
*/
|
|
81
|
+
hasValidCredentials(address: Address): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Gets the last known UUID for an address
|
|
84
|
+
* @param address The address to get UUID for
|
|
85
|
+
* @returns The UUID or null if not found
|
|
86
|
+
*/
|
|
87
|
+
getLastKnownUuid(address: Address): string | null;
|
|
88
|
+
/**
|
|
89
|
+
* Updates the owner UUID for ALL preserved credentials
|
|
90
|
+
* This is called when cluster membership changes and we need to sync all credentials
|
|
91
|
+
* @param newOwnerUuid The new owner UUID from the current cluster state
|
|
92
|
+
*/
|
|
93
|
+
updateAllOwnerUuids(newOwnerUuid: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Gets the current owner UUID from preserved credentials
|
|
96
|
+
* @returns The current owner UUID or null if not found
|
|
97
|
+
*/
|
|
98
|
+
getCurrentOwnerUuid(): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Validates that all credentials have consistent owner UUIDs
|
|
101
|
+
* @returns True if all credentials are consistent, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
validateOwnerUuidConsistency(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Invalidates ALL credentials that have a specific owner UUID
|
|
106
|
+
* This is called when cluster membership changes and old owner UUIDs become invalid
|
|
107
|
+
* @param oldOwnerUuid The old owner UUID that is no longer valid
|
|
108
|
+
*/
|
|
109
|
+
invalidateCredentialsWithOwnerUuid(oldOwnerUuid: string): void;
|
|
110
|
+
/**
|
|
111
|
+
* Invalidates ALL credentials that don't match the current cluster owner UUID
|
|
112
|
+
* This ensures complete credential consistency across the entire cluster
|
|
113
|
+
* @param currentClusterOwnerUuid The current cluster owner UUID that should be valid
|
|
114
|
+
*/
|
|
115
|
+
invalidateAllCredentialsExceptCurrentOwner(currentClusterOwnerUuid: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Invalidates only problematic credentials while preserving working ones
|
|
118
|
+
* This prevents breaking working connections (like 192.168.1.108)
|
|
119
|
+
* @param currentClusterOwnerUuid The current cluster owner UUID that should be valid
|
|
120
|
+
*/
|
|
121
|
+
invalidateOnlyProblematicCredentials(currentClusterOwnerUuid: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Checks if an address has had recent authentication issues
|
|
124
|
+
* This helps determine which credentials to invalidate
|
|
125
|
+
* @param addressStr The address to check
|
|
126
|
+
* @returns True if the address has recent auth issues
|
|
127
|
+
*/
|
|
128
|
+
private hasRecentAuthenticationIssues(addressStr);
|
|
129
|
+
/**
|
|
130
|
+
* Clears all credentials for a specific address
|
|
131
|
+
* This is called when we need to force fresh authentication for a node
|
|
132
|
+
* @param address The address to clear credentials for
|
|
133
|
+
*/
|
|
134
|
+
clearCredentialsForAddress(address: Address): void;
|
|
135
|
+
/**
|
|
136
|
+
* Gets all addresses that have credentials with a specific owner UUID
|
|
137
|
+
* @param ownerUuid The owner UUID to search for
|
|
138
|
+
* @returns Array of addresses that have credentials with this owner UUID
|
|
139
|
+
*/
|
|
140
|
+
getAddressesWithOwnerUuid(ownerUuid: string): string[];
|
|
141
|
+
}
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
/**
|
|
19
|
+
* Service to preserve and restore authentication credentials across failover cycles
|
|
20
|
+
* This fixes the "Invalid Credentials" issue that occurs when nodes rejoin after failover
|
|
21
|
+
*/
|
|
22
|
+
var CredentialPreservationService = /** @class */ (function () {
|
|
23
|
+
function CredentialPreservationService(logger) {
|
|
24
|
+
/**
|
|
25
|
+
* Stores authentication context for each node
|
|
26
|
+
*/
|
|
27
|
+
this.nodeCredentials = new Map();
|
|
28
|
+
this.logger = logger;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Preserves authentication credentials for a node before it gets disconnected
|
|
32
|
+
* @param address The node address
|
|
33
|
+
* @param uuid The node's UUID
|
|
34
|
+
* @param ownerUuid The owner UUID
|
|
35
|
+
* @param groupName The group name
|
|
36
|
+
* @param groupPassword The group password
|
|
37
|
+
* @param isOwner Whether this is an owner connection
|
|
38
|
+
*/
|
|
39
|
+
CredentialPreservationService.prototype.preserveCredentials = function (address, uuid, ownerUuid, groupName, groupPassword, isOwner) {
|
|
40
|
+
var addressStr = address.toString();
|
|
41
|
+
this.nodeCredentials.set(addressStr, {
|
|
42
|
+
uuid: uuid,
|
|
43
|
+
ownerUuid: ownerUuid,
|
|
44
|
+
groupName: groupName,
|
|
45
|
+
groupPassword: groupPassword,
|
|
46
|
+
lastAuthenticated: Date.now(),
|
|
47
|
+
isOwner: isOwner
|
|
48
|
+
});
|
|
49
|
+
this.logger.debug('CredentialPreservationService', "Preserved credentials for " + addressStr + ": uuid=" + uuid + ", ownerUuid=" + ownerUuid + ", isOwner=" + isOwner);
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Restores authentication credentials for a specific node
|
|
53
|
+
* @param address The node address
|
|
54
|
+
* @returns The preserved credentials or null if not found
|
|
55
|
+
*/
|
|
56
|
+
CredentialPreservationService.prototype.restoreCredentials = function (address) {
|
|
57
|
+
var _this = this;
|
|
58
|
+
var addressStr = address.toString();
|
|
59
|
+
var credentials = this.nodeCredentials.get(addressStr);
|
|
60
|
+
if (credentials) {
|
|
61
|
+
this.logger.info('CredentialPreservationService', "\u2705 Found preserved credentials for " + addressStr + ": uuid=" + credentials.uuid + ", ownerUuid=" + credentials.ownerUuid);
|
|
62
|
+
return credentials;
|
|
63
|
+
}
|
|
64
|
+
// Log all available credentials for debugging
|
|
65
|
+
this.logger.info('CredentialPreservationService', "\u274C No preserved credentials found for " + addressStr);
|
|
66
|
+
this.logger.info('CredentialPreservationService', "\uD83D\uDCCB Available credentials: " + this.nodeCredentials.size + " entries");
|
|
67
|
+
if (this.nodeCredentials.size > 0) {
|
|
68
|
+
this.nodeCredentials.forEach(function (cred, addr) {
|
|
69
|
+
_this.logger.info('CredentialPreservationService', " - " + addr + ": uuid=" + cred.uuid + ", ownerUuid=" + cred.ownerUuid + ", isOwner=" + cred.isOwner);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Updates credentials after successful authentication
|
|
76
|
+
* @param address The node address
|
|
77
|
+
* @param uuid The new UUID
|
|
78
|
+
* @param ownerUuid The new owner UUID
|
|
79
|
+
*/
|
|
80
|
+
CredentialPreservationService.prototype.updateCredentials = function (address, uuid, ownerUuid) {
|
|
81
|
+
var addressStr = address.toString();
|
|
82
|
+
var credentials = this.nodeCredentials.get(addressStr);
|
|
83
|
+
if (credentials) {
|
|
84
|
+
credentials.uuid = uuid;
|
|
85
|
+
credentials.ownerUuid = ownerUuid;
|
|
86
|
+
credentials.lastAuthenticated = Date.now();
|
|
87
|
+
this.logger.debug('CredentialPreservationService', "Updated credentials for " + addressStr + ": uuid=" + uuid + ", ownerUuid=" + ownerUuid);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Clears credentials for a specific node
|
|
92
|
+
* @param address The node address
|
|
93
|
+
*/
|
|
94
|
+
CredentialPreservationService.prototype.clearCredentials = function (address) {
|
|
95
|
+
var addressStr = address.toString();
|
|
96
|
+
if (this.nodeCredentials.delete(addressStr)) {
|
|
97
|
+
this.logger.debug('CredentialPreservationService', "Cleared credentials for " + addressStr);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Clears all stored credentials - used for cluster reset scenarios
|
|
102
|
+
*/
|
|
103
|
+
CredentialPreservationService.prototype.clearAllCredentials = function () {
|
|
104
|
+
var credentialCount = this.nodeCredentials.size;
|
|
105
|
+
this.nodeCredentials.clear();
|
|
106
|
+
this.logger.info('CredentialPreservationService', "\uD83E\uDDF9 Cleared all " + credentialCount + " stored credentials for cluster reset");
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Cleans up stale credentials older than the specified age
|
|
110
|
+
* @param maxAgeMs Maximum age in milliseconds (default: 5 minutes)
|
|
111
|
+
*/
|
|
112
|
+
CredentialPreservationService.prototype.cleanupStaleCredentials = function (maxAgeMs) {
|
|
113
|
+
var _this = this;
|
|
114
|
+
if (maxAgeMs === void 0) { maxAgeMs = 300000; }
|
|
115
|
+
var now = Date.now();
|
|
116
|
+
var addressesToRemove = [];
|
|
117
|
+
this.nodeCredentials.forEach(function (credentials, addressStr) {
|
|
118
|
+
var age = now - credentials.lastAuthenticated;
|
|
119
|
+
if (age > maxAgeMs) {
|
|
120
|
+
addressesToRemove.push(addressStr);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (addressesToRemove.length > 0) {
|
|
124
|
+
addressesToRemove.forEach(function (addressStr) {
|
|
125
|
+
_this.nodeCredentials.delete(addressStr);
|
|
126
|
+
});
|
|
127
|
+
this.logger.debug('CredentialPreservationService', "Cleaned up " + addressesToRemove.length + " stale credential entries");
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Gets a summary of preserved credentials for debugging
|
|
132
|
+
* @returns A summary string
|
|
133
|
+
*/
|
|
134
|
+
CredentialPreservationService.prototype.getCredentialsSummary = function () {
|
|
135
|
+
var entries = Array.from(this.nodeCredentials.entries());
|
|
136
|
+
if (entries.length === 0) {
|
|
137
|
+
return 'none';
|
|
138
|
+
}
|
|
139
|
+
return entries.map(function (_a) {
|
|
140
|
+
var address = _a[0], creds = _a[1];
|
|
141
|
+
return address + ": uuid=" + (creds.uuid || 'null') + ", ownerUuid=" + (creds.ownerUuid || 'null') + ", isOwner=" + creds.isOwner;
|
|
142
|
+
}).join('; ');
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Smart credential restoration that handles both scenarios:
|
|
146
|
+
* 1. If member added event occurred -> use new UUID
|
|
147
|
+
* 2. If no member added event -> use old UUID (node probably never changed)
|
|
148
|
+
* @param address The address to restore credentials for
|
|
149
|
+
* @param hasMemberAddedEvent Whether we received a member added event for this address
|
|
150
|
+
* @returns The appropriate credentials to use
|
|
151
|
+
*/
|
|
152
|
+
CredentialPreservationService.prototype.smartRestoreCredentials = function (address, hasMemberAddedEvent) {
|
|
153
|
+
if (hasMemberAddedEvent === void 0) { hasMemberAddedEvent = false; }
|
|
154
|
+
var addressStr = address.toString();
|
|
155
|
+
var credentials = this.nodeCredentials.get(addressStr);
|
|
156
|
+
if (!credentials) {
|
|
157
|
+
this.logger.debug('CredentialPreservationService', "No preserved credentials found for " + addressStr);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
if (hasMemberAddedEvent) {
|
|
161
|
+
// Member actually left and rejoined - use the updated credentials
|
|
162
|
+
this.logger.info('CredentialPreservationService', "\uD83D\uDD04 Member added event detected for " + addressStr + ", using updated credentials: uuid=" + credentials.uuid);
|
|
163
|
+
return credentials;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// No member added event - node probably never changed, use original credentials
|
|
167
|
+
this.logger.info('CredentialPreservationService', "\uD83D\uDD04 No member added event for " + addressStr + ", assuming node unchanged, using original credentials: uuid=" + credentials.uuid);
|
|
168
|
+
return credentials;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Checks if we have valid credentials for an address
|
|
173
|
+
* @param address The address to check
|
|
174
|
+
* @returns True if we have valid credentials
|
|
175
|
+
*/
|
|
176
|
+
CredentialPreservationService.prototype.hasValidCredentials = function (address) {
|
|
177
|
+
var addressStr = address.toString();
|
|
178
|
+
var credentials = this.nodeCredentials.get(addressStr);
|
|
179
|
+
return !!(credentials && credentials.uuid && credentials.ownerUuid);
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Gets the last known UUID for an address
|
|
183
|
+
* @param address The address to get UUID for
|
|
184
|
+
* @returns The UUID or null if not found
|
|
185
|
+
*/
|
|
186
|
+
CredentialPreservationService.prototype.getLastKnownUuid = function (address) {
|
|
187
|
+
var addressStr = address.toString();
|
|
188
|
+
var credentials = this.nodeCredentials.get(addressStr);
|
|
189
|
+
return credentials ? credentials.uuid : null;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Updates the owner UUID for ALL preserved credentials
|
|
193
|
+
* This is called when cluster membership changes and we need to sync all credentials
|
|
194
|
+
* @param newOwnerUuid The new owner UUID from the current cluster state
|
|
195
|
+
*/
|
|
196
|
+
CredentialPreservationService.prototype.updateAllOwnerUuids = function (newOwnerUuid) {
|
|
197
|
+
var _this = this;
|
|
198
|
+
this.logger.info('CredentialPreservationService', "\uD83D\uDD04 Updating ALL preserved credentials with new owner UUID: " + newOwnerUuid);
|
|
199
|
+
var updatedCount = 0;
|
|
200
|
+
this.nodeCredentials.forEach(function (credentials, addressStr) {
|
|
201
|
+
if (credentials.ownerUuid !== newOwnerUuid) {
|
|
202
|
+
var oldOwnerUuid = credentials.ownerUuid;
|
|
203
|
+
credentials.ownerUuid = newOwnerUuid;
|
|
204
|
+
updatedCount++;
|
|
205
|
+
_this.logger.info('CredentialPreservationService', "\uD83D\uDD04 Updated " + addressStr + ": ownerUuid " + oldOwnerUuid + " \u2192 " + newOwnerUuid);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
this.logger.info('CredentialPreservationService', "\u2705 Updated " + updatedCount + " credential entries with new owner UUID");
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Gets the current owner UUID from preserved credentials
|
|
212
|
+
* @returns The current owner UUID or null if not found
|
|
213
|
+
*/
|
|
214
|
+
CredentialPreservationService.prototype.getCurrentOwnerUuid = function () {
|
|
215
|
+
// Find any credential that has isOwner=true
|
|
216
|
+
for (var _i = 0, _a = Array.from(this.nodeCredentials.values()); _i < _a.length; _i++) {
|
|
217
|
+
var credentials = _a[_i];
|
|
218
|
+
if (credentials.isOwner) {
|
|
219
|
+
return credentials.ownerUuid;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// If no owner found, return the first available ownerUuid
|
|
223
|
+
for (var _b = 0, _c = Array.from(this.nodeCredentials.values()); _b < _c.length; _b++) {
|
|
224
|
+
var credentials = _c[_b];
|
|
225
|
+
if (credentials.ownerUuid) {
|
|
226
|
+
return credentials.ownerUuid;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Validates that all credentials have consistent owner UUIDs
|
|
233
|
+
* @returns True if all credentials are consistent, false otherwise
|
|
234
|
+
*/
|
|
235
|
+
CredentialPreservationService.prototype.validateOwnerUuidConsistency = function () {
|
|
236
|
+
var ownerUuids = new Set();
|
|
237
|
+
this.nodeCredentials.forEach(function (credentials, addressStr) {
|
|
238
|
+
if (credentials.ownerUuid) {
|
|
239
|
+
ownerUuids.add(credentials.ownerUuid);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
var isConsistent = ownerUuids.size <= 1;
|
|
243
|
+
if (!isConsistent) {
|
|
244
|
+
this.logger.warn('CredentialPreservationService', "\u26A0\uFE0F Owner UUID inconsistency detected: " + Array.from(ownerUuids).join(', '));
|
|
245
|
+
}
|
|
246
|
+
return isConsistent;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Invalidates ALL credentials that have a specific owner UUID
|
|
250
|
+
* This is called when cluster membership changes and old owner UUIDs become invalid
|
|
251
|
+
* @param oldOwnerUuid The old owner UUID that is no longer valid
|
|
252
|
+
*/
|
|
253
|
+
CredentialPreservationService.prototype.invalidateCredentialsWithOwnerUuid = function (oldOwnerUuid) {
|
|
254
|
+
var _this = this;
|
|
255
|
+
this.logger.info('CredentialPreservationService', "\uD83D\uDDD1\uFE0F Invalidating ALL credentials with old owner UUID: " + oldOwnerUuid);
|
|
256
|
+
var invalidatedCount = 0;
|
|
257
|
+
var addressesToRemove = [];
|
|
258
|
+
this.nodeCredentials.forEach(function (credentials, addressStr) {
|
|
259
|
+
if (credentials.ownerUuid === oldOwnerUuid) {
|
|
260
|
+
_this.logger.info('CredentialPreservationService', "\uD83D\uDDD1\uFE0F Invalidating credentials for " + addressStr + ": old ownerUuid=" + oldOwnerUuid);
|
|
261
|
+
addressesToRemove.push(addressStr);
|
|
262
|
+
invalidatedCount++;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
// Remove the invalidated credentials
|
|
266
|
+
addressesToRemove.forEach(function (addressStr) {
|
|
267
|
+
_this.nodeCredentials.delete(addressStr);
|
|
268
|
+
});
|
|
269
|
+
this.logger.info('CredentialPreservationService', "\u2705 Invalidated " + invalidatedCount + " credential entries with old owner UUID: " + oldOwnerUuid);
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Invalidates ALL credentials that don't match the current cluster owner UUID
|
|
273
|
+
* This ensures complete credential consistency across the entire cluster
|
|
274
|
+
* @param currentClusterOwnerUuid The current cluster owner UUID that should be valid
|
|
275
|
+
*/
|
|
276
|
+
CredentialPreservationService.prototype.invalidateAllCredentialsExceptCurrentOwner = function (currentClusterOwnerUuid) {
|
|
277
|
+
var _this = this;
|
|
278
|
+
this.logger.info('CredentialPreservationService', "\uD83D\uDDD1\uFE0F Comprehensive credential cleanup: Invalidating ALL credentials except those with current owner UUID: " + currentClusterOwnerUuid);
|
|
279
|
+
var invalidatedCount = 0;
|
|
280
|
+
var addressesToRemove = [];
|
|
281
|
+
this.nodeCredentials.forEach(function (credentials, addressStr) {
|
|
282
|
+
if (credentials.ownerUuid !== currentClusterOwnerUuid) {
|
|
283
|
+
_this.logger.info('CredentialPreservationService', "\uD83D\uDDD1\uFE0F Invalidating credentials for " + addressStr + ": old ownerUuid=" + credentials.ownerUuid + " \u2260 current=" + currentClusterOwnerUuid);
|
|
284
|
+
addressesToRemove.push(addressStr);
|
|
285
|
+
invalidatedCount++;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
_this.logger.debug('CredentialPreservationService', "\u2705 Keeping valid credentials for " + addressStr + ": ownerUuid=" + credentials.ownerUuid + " matches current");
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
// Remove the invalidated credentials
|
|
292
|
+
addressesToRemove.forEach(function (addressStr) {
|
|
293
|
+
_this.nodeCredentials.delete(addressStr);
|
|
294
|
+
});
|
|
295
|
+
this.logger.info('CredentialPreservationService', "\u2705 Comprehensive cleanup completed: Invalidated " + invalidatedCount + " credential entries, kept " + this.nodeCredentials.size + " valid entries");
|
|
296
|
+
// Log remaining valid credentials for debugging
|
|
297
|
+
if (this.nodeCredentials.size > 0) {
|
|
298
|
+
this.logger.info('CredentialPreservationService', "\uD83D\uDCCB Remaining valid credentials after cleanup:");
|
|
299
|
+
this.nodeCredentials.forEach(function (credentials, addressStr) {
|
|
300
|
+
_this.logger.info('CredentialPreservationService', " - " + addressStr + ": uuid=" + credentials.uuid + ", ownerUuid=" + credentials.ownerUuid + ", isOwner=" + credentials.isOwner);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Invalidates only problematic credentials while preserving working ones
|
|
306
|
+
* This prevents breaking working connections (like 192.168.1.108)
|
|
307
|
+
* @param currentClusterOwnerUuid The current cluster owner UUID that should be valid
|
|
308
|
+
*/
|
|
309
|
+
CredentialPreservationService.prototype.invalidateOnlyProblematicCredentials = function (currentClusterOwnerUuid) {
|
|
310
|
+
var _this = this;
|
|
311
|
+
this.logger.info('CredentialPreservationService', "\uD83C\uDFAF Targeted credential cleanup: Only invalidating problematic credentials, preserving working ones");
|
|
312
|
+
var invalidatedCount = 0;
|
|
313
|
+
var addressesToRemove = [];
|
|
314
|
+
this.nodeCredentials.forEach(function (credentials, addressStr) {
|
|
315
|
+
// Only invalidate if the ownerUuid is clearly wrong AND we've had authentication issues
|
|
316
|
+
if (credentials.ownerUuid !== currentClusterOwnerUuid) {
|
|
317
|
+
// Check if this address has had recent authentication failures
|
|
318
|
+
var hasAuthIssues = _this.hasRecentAuthenticationIssues(addressStr);
|
|
319
|
+
if (hasAuthIssues) {
|
|
320
|
+
_this.logger.info('CredentialPreservationService', "\uD83C\uDFAF Invalidating problematic credentials for " + addressStr + ": old ownerUuid=" + credentials.ownerUuid + " \u2260 current=" + currentClusterOwnerUuid + " (has auth issues)");
|
|
321
|
+
addressesToRemove.push(addressStr);
|
|
322
|
+
invalidatedCount++;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
_this.logger.info('CredentialPreservationService', "\u2705 Keeping working credentials for " + addressStr + ": ownerUuid=" + credentials.ownerUuid + " (no auth issues)");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
_this.logger.debug('CredentialPreservationService', "\u2705 Keeping valid credentials for " + addressStr + ": ownerUuid=" + credentials.ownerUuid + " matches current");
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
// Remove only the problematic credentials
|
|
333
|
+
addressesToRemove.forEach(function (addressStr) {
|
|
334
|
+
_this.nodeCredentials.delete(addressStr);
|
|
335
|
+
});
|
|
336
|
+
this.logger.info('CredentialPreservationService', "\u2705 Targeted cleanup completed: Invalidated " + invalidatedCount + " problematic credential entries, kept " + this.nodeCredentials.size + " working entries");
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Checks if an address has had recent authentication issues
|
|
340
|
+
* This helps determine which credentials to invalidate
|
|
341
|
+
* @param addressStr The address to check
|
|
342
|
+
* @returns True if the address has recent auth issues
|
|
343
|
+
*/
|
|
344
|
+
CredentialPreservationService.prototype.hasRecentAuthenticationIssues = function (addressStr) {
|
|
345
|
+
// For now, we'll be conservative and only invalidate if we're certain
|
|
346
|
+
// In the future, we could track authentication failure history
|
|
347
|
+
return false; // Don't invalidate anything for now - revert to previous working behavior
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Clears all credentials for a specific address
|
|
351
|
+
* This is called when we need to force fresh authentication for a node
|
|
352
|
+
* @param address The address to clear credentials for
|
|
353
|
+
*/
|
|
354
|
+
CredentialPreservationService.prototype.clearCredentialsForAddress = function (address) {
|
|
355
|
+
var addressStr = address.toString();
|
|
356
|
+
if (this.nodeCredentials.has(addressStr)) {
|
|
357
|
+
this.logger.info('CredentialPreservationService', "\uD83D\uDDD1\uFE0F Clearing credentials for " + addressStr);
|
|
358
|
+
this.nodeCredentials.delete(addressStr);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Gets all addresses that have credentials with a specific owner UUID
|
|
363
|
+
* @param ownerUuid The owner UUID to search for
|
|
364
|
+
* @returns Array of addresses that have credentials with this owner UUID
|
|
365
|
+
*/
|
|
366
|
+
CredentialPreservationService.prototype.getAddressesWithOwnerUuid = function (ownerUuid) {
|
|
367
|
+
var addresses = [];
|
|
368
|
+
this.nodeCredentials.forEach(function (credentials, addressStr) {
|
|
369
|
+
if (credentials.ownerUuid === ownerUuid) {
|
|
370
|
+
addresses.push(addressStr);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
return addresses;
|
|
374
|
+
};
|
|
375
|
+
return CredentialPreservationService;
|
|
376
|
+
}());
|
|
377
|
+
exports.CredentialPreservationService = CredentialPreservationService;
|