Skip to content
Snippets Groups Projects
Commit 7365034d authored by Edward Hicks's avatar Edward Hicks :8ball:
Browse files

determine ec2 instance id instead of node's dns name - it's safer to

reference
parent a354b079
No related branches found
No related tags found
No related merge requests found
Pipeline #92209 passed
......@@ -184,7 +184,7 @@ args = parser.parse_args()
ret = 1 # init as a failure code
logFile = False
Session = {}
Session['nodename'] = str(os.uname().nodename.split('.')[0])
Session['ec2id'] = "This is the actual EC2 instance name (i-blahblahblah)"
Config = {}
Config['debug'] = False
......@@ -319,6 +319,17 @@ except Exception as e:
sys.exit(ret)
# Get the EC2 session ID for this node
printLog("Retrieving EC2 instance ID", loglevels.INFO)
try:
Session['ec2'] = boto3.resource('ec2')
Session['ec2id'] = str(Session['ec2'].Instance('id'))
except Exception as e:
printLog(e)
cleanup()
sys.exit(ret)
printLog("This instance is "+Session['ec2id'], loglevels.DEBUG)
# Retrieve the account number from the session so we can build arns
printLog("Retrieving account info for generating ARNs", loglevels.INFO)
try:
......@@ -335,7 +346,7 @@ except Exception as e:
# Create an SQS queue to subscribe to the SNS topic
Session['queue'] = Config['sqsQueuePrefix']+Session['nodename']
Session['queue'] = Config['sqsQueuePrefix'] + str(os.uname().nodename.split('.')[0])
printLog("Creating SQS queue "+Session['queue'], loglevels.INFO)
try:
Session['sqs'] = Session['boto3'].client('sqs')
......@@ -440,16 +451,14 @@ while True:
raise Exception("Invalid JSON in message body")
# TODO: Add crypto signing support to verify message's origin
# TODO: Add crypto signing support to verify message's origin
# Verify the message is sane
sanityCheckMessage(body, payload)
# Only proceed if the message is meant for either everyone or us explicitly
if '*' not in payload['nodes'] and Session['nodename'] not in payload['nodes']:
if '*' not in payload['nodes'] and Session['ec2id'] not in payload['nodes']:
printLog("Message not meant for us - ignoring it", loglevels.DEBUG)
continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment