From da4b3e5574e9f75ee14ec6da3cdd19ffac860c9d Mon Sep 17 00:00:00 2001 From: burak-58 <39169933+burak-58@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:22:36 +0300 Subject: [PATCH] use IMDSv2 queries in init script --- init.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/init.sh b/init.sh index 4a90ef13..f6bacdde 100644 --- a/init.sh +++ b/init.sh @@ -5,9 +5,10 @@ INITIALIZED=/usr/local/antmedia/conf/initialized if [ ! -f "$INITIALIZED" ] then + TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` ## Local IPV4 - export LOCAL_IPv4=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4` + export LOCAL_IPv4=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/local-ipv4` # $HOSTNAME ip-172-30-0-216 HOST_NAME=`hostname` @@ -27,7 +28,7 @@ then fi fi ## Instance ID - export INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id` + export INSTANCE_ID=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id` ## Add Initial User with curl RESULT=`curl -s -X POST -H "Content-Type: application/json" -d '{"email": "JamesBond", "password": "'$INSTANCE_ID'", "scope": "system", "userType": "ADMIN"}' http://localhost:5080/rest/v2/users/initial` @@ -46,8 +47,4 @@ then fi touch $INITIALIZED - ## Add default ServerSecretKey - SECRET_KEY=$(openssl rand -base64 32 | head -c 32) - sudo sed -i "/^server.jwtServerControlEnabled=/s|.*|server.jwtServerControlEnabled=true|" /usr/local/antmedia/conf/red5.properties - sudo sed -i "/^server.jwtServerSecretKey=/s|.*|server.jwtServerSecretKey=$SECRET_KEY|" /usr/local/antmedia/conf/red5.properties fi