-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BLUE-276 Restrict first node selection based on the specified node ip and port #85
Changes from all commits
6d51e9a
9b3252f
22c7919
12b6770
8ae1434
156c2a4
15026bc
84deacd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,36 @@ | |
|
||
if (State.isFirst && NodeList.isEmpty() && !NodeList.foundFirstNode) { | ||
try { | ||
let err = Utils.validateTypes(signedFirstNodeInfo, { | ||
nodeInfo: 'o', | ||
sign: 'o', | ||
}) | ||
if (err) { | ||
reply.send({ success: false, error: err }) | ||
return | ||
} | ||
err = Utils.validateTypes(signedFirstNodeInfo.nodeInfo, { | ||
externalIp: 's', | ||
externalPort: 'n', | ||
publicKey: 's', | ||
}) | ||
if (err) { | ||
reply.send({ success: false, error: err }) | ||
return | ||
} | ||
err = Utils.validateTypes(signedFirstNodeInfo.sign, { | ||
owner: 's', | ||
sig: 's', | ||
}) | ||
if (err) { | ||
reply.send({ success: false, error: err }) | ||
return | ||
} | ||
if (signedFirstNodeInfo.nodeInfo.publicKey !== signedFirstNodeInfo.sign.owner) { | ||
Logger.mainLogger.error('nodeInfo.publicKey does not match signature owner', signedFirstNodeInfo) | ||
reply.send({ success: false, error: 'nodeInfo.publicKey does not match signature owner' }) | ||
return | ||
} | ||
const isSignatureValid = Crypto.verify(signedFirstNodeInfo) | ||
if (!isSignatureValid) { | ||
Logger.mainLogger.error('Invalid signature', signedFirstNodeInfo) | ||
|
@@ -93,16 +123,22 @@ | |
reply.send({ success: false, error: 'Signature verification failed' }) | ||
return | ||
} | ||
const ip = signedFirstNodeInfo.nodeInfo.externalIp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if ip in payload will be different from actual ip of the sender ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IP and Port are not even being checked in here are they? The title of this PR says restricted based off IP and Port, but I only see the public key being checked. |
||
const port = signedFirstNodeInfo.nodeInfo.externalPort | ||
const publicKey = signedFirstNodeInfo.nodeInfo.publicKey | ||
if (config.restrictFirstNodeSelectionByPublicKey) { | ||
if (publicKey !== config.firstNodePublicKey) { | ||
Logger.mainLogger.error('Invalid publicKey of first node info', signedFirstNodeInfo) | ||
Check warning Code scanning / CodeQL Log injection Medium
Log entry depends on a
user-provided value Error loading related location Loading |
||
reply.send({ success: false, error: 'Invalid publicKey of first node info' }) | ||
return | ||
} | ||
} | ||
if (NodeList.foundFirstNode) { | ||
const res = NodeList.getCachedNodeList() | ||
reply.send(res) | ||
return | ||
} | ||
NodeList.toggleFirstNode() | ||
const ip = signedFirstNodeInfo.nodeInfo.externalIp | ||
const port = signedFirstNodeInfo.nodeInfo.externalPort | ||
const publicKey = signedFirstNodeInfo.nodeInfo.publicKey | ||
|
||
const firstNode: NodeList.ConsensusNodeInfo = { | ||
ip, | ||
port, | ||
|
@@ -961,7 +997,7 @@ | |
'ARCHIVER_PUBLIC_KEY', | ||
] | ||
try { | ||
const { sign, ...newConfig } = _request.body | ||
const validKeys = new Set(Object.keys(config)) | ||
const payloadKeys = Object.keys(newConfig) | ||
const invalidKeys = payloadKeys.filter( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,8 @@ export interface Config { | |
txCronSchedule: string | ||
} | ||
workerProcessesDebugLog: boolean // To enable debug logs for worker processes managed by the main process | ||
restrictFirstNodeSelectionByPublicKey: boolean // The flag to pick the first node that matches the PUBLIC_KEY specified in the firstNodeInfo | ||
firstNodePublicKey: string // The public key of the first node to be selected | ||
} | ||
|
||
let config: Config = { | ||
|
@@ -184,6 +186,8 @@ let config: Config = { | |
txCronSchedule: '*/5 * * * *', | ||
}, | ||
workerProcessesDebugLog: false, | ||
restrictFirstNodeSelectionByPublicKey: false, | ||
firstNodePublicKey: '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be an environment variable? When and how does this get set? |
||
} | ||
// Override default config params from config file, env vars, and cli args | ||
export async function overrideDefaultConfig(file: string): Promise<void> { | ||
|
Check warning
Code scanning / CodeQL
Log injection Medium