Skip to content
Snippets Groups Projects
Commit 1b4fd5ff6954 authored by Andrew Patterson's avatar Andrew Patterson
Browse files

Merge branch '8959-ami-fix-metadata-call' into 'master'

Use AWS Metadata token for fetching instance info

Closes #8959

See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/8230



Merged-by: default avatarAndrew Patterson <apatterson@gitlab.com>
Approved-by: default avatarDustin Collins <714871-dustinmm80@users.noreply.gitlab.com>
Approved-by: default avatarAndrew Patterson <apatterson@gitlab.com>
Co-authored-by: default avatarBalasankar 'Balu' C <balasankar@gitlab.com>
No related branches found
No related tags found
No related merge requests found
#!/bin/bash #!/bin/bash
# If the instance has enabled only IMDSv2 Metadata server, we need to use a token.
METADATA_TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 300")
get_ec2_address() get_ec2_address()
{ {
url=$1 url=$1
# Try collecting fqdn if it is set correctly # Try collecting fqdn if it is set correctly
...@@ -3,8 +6,8 @@ ...@@ -3,8 +6,8 @@
get_ec2_address() get_ec2_address()
{ {
url=$1 url=$1
# Try collecting fqdn if it is set correctly # Try collecting fqdn if it is set correctly
fqdn=$(/opt/gitlab/embedded/bin/curl -s ${url}) fqdn=$(/opt/gitlab/embedded/bin/curl -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" -s ${url})
if [ -n "${fqdn}" ]; then if [ -n "${fqdn}" ]; then
# Checking if curl returned an XML message # Checking if curl returned an XML message
word="<?xml" word="<?xml"
...@@ -32,7 +35,7 @@ ...@@ -32,7 +35,7 @@
# some other means. # some other means.
EXISTING_ROOT_PASSWORD=$(sudo grep "^gitlab_rails.*initial_root_password.*" /etc/gitlab/gitlab.rb | cut -d '=' -f2- | xargs) EXISTING_ROOT_PASSWORD=$(sudo grep "^gitlab_rails.*initial_root_password.*" /etc/gitlab/gitlab.rb | cut -d '=' -f2- | xargs)
if [ -z "${EXISTING_ROOT_PASSWORD}" ] && [ -z "${GITLAB_ROOT_PASSWORD}" ]; then if [ -z "${EXISTING_ROOT_PASSWORD}" ] && [ -z "${GITLAB_ROOT_PASSWORD}" ]; then
GITLAB_ROOT_PASSWORD=$(curl http://169.254.169.254/latest/meta-data/instance-id) GITLAB_ROOT_PASSWORD=$(curl -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" http://169.254.169.254/latest/meta-data/instance-id)
fi fi
sudo GITLAB_ROOT_PASSWORD=${GITLAB_ROOT_PASSWORD} gitlab-ctl reconfigure sudo GITLAB_ROOT_PASSWORD=${GITLAB_ROOT_PASSWORD} gitlab-ctl reconfigure
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