Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
49f6104f
Unverified
Commit
49f6104f
authored
Mar 18, 2024
by
neil
Committed by
GitHub
Mar 18, 2024
Browse files
Merge pull request #4979 from derytim/aws_dns_imdsv2
Aws dns imdsv2
parents
2728d2aa
e3cd52ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_aws.sh
View file @
49f6104f
...
...
@@ -145,7 +145,6 @@ dns_aws_rm() {
fi
_sleep 1
return
1
}
#################### Private functions below ##################################
...
...
@@ -207,24 +206,40 @@ _use_container_role() {
}
_use_instance_role
()
{
_url
=
"http://169.254.169.254/latest/meta-data/iam/security-credentials/"
_debug
"_url"
"
$_url
"
if
!
_get
"
$_url
"
true
1 | _head_n 1 |
grep
-Fq
200
;
then
_instance_role_name_url
=
"http://169.254.169.254/latest/meta-data/iam/security-credentials/"
if
_get
"
$_instance_role_name_url
"
true
1 | _head_n 1 |
grep
-Fq
401
;
then
_debug
"Using IMDSv2"
_token_url
=
"http://169.254.169.254/latest/api/token"
export
_H1
=
"X-aws-ec2-metadata-token-ttl-seconds: 21600"
_token
=
"
$(
_post
""
"
$_token_url
"
""
"PUT"
)
"
_secure_debug3
"_token"
"
$_token
"
if
[
-z
"
$_token
"
]
;
then
_debug
"Unable to fetch IMDSv2 token from instance metadata"
return
1
fi
export
_H1
=
"X-aws-ec2-metadata-token:
$_token
"
fi
if
!
_get
"
$_instance_role_name_url
"
true
1 | _head_n 1 |
grep
-Fq
200
;
then
_debug
"Unable to fetch IAM role from instance metadata"
return
1
fi
_aws_role
=
$(
_get
"
$_url
"
""
1
)
_debug
"_aws_role"
"
$_aws_role
"
_use_metadata
"
$_url$_aws_role
"
_instance_role_name
=
$(
_get
"
$_instance_role_name_url
"
""
1
)
_debug
"_instance_role_name"
"
$_instance_role_name
"
_use_metadata
"
$_instance_role_name_url$_instance_role_name
"
"
$_token
"
}
_use_metadata
()
{
export
_H1
=
"X-aws-ec2-metadata-token:
$2
"
_aws_creds
=
"
$(
_get
"
$1
"
""
1 |
_normalizeJson |
tr
'{,}'
'\n'
|
while
read
-r
_line
;
do
_key
=
"
$(
echo
"
${
_line
%%
:
*
}
"
|
tr
-d
'"'
)
"
_key
=
"
$(
echo
"
${
_line
%%
:
*
}
"
|
tr
-d
'
\
"'
)
"
_value
=
"
${
_line
#*
:
}
"
_debug3
"_key"
"
$_key
"
_secure_debug3
"_value"
"
$_value
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment