Skip to content

Commit 5be59f8

Browse files
Merge pull request #377 from bmsiegel/imdsv2
Use IMDSv2
2 parents 708edfd + 7c1f549 commit 5be59f8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

e2e/blog_test.sh

100644100755
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
#!/usr/bin/env bash
22

3+
curl_with_token() {
4+
export TOKEN=${TOKEN:-$(curl --silent -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")}
5+
curl -H "X-aws-ec2-metadata-token: $TOKEN" "$@"
6+
}
7+
38
set_variables() {
49
HOME_DIR=$(pwd)
510
export E2E_DIR="$HOME_DIR/e2e"
611
K8S_NAMESPACE="aws-privateca-issuer"
712
HELM_CHART_NAME="awspca/aws-privateca-issuer"
813
CLUSTER_NAME=pca-external-issuer
914
AWS_REGION="us-east-1"
10-
INTERFACE=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/)
11-
export SUBNET=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/subnet-id)
12-
export SECURITY_GROUP_ID=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/security-group-ids)
13-
export VPC_ID=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/vpc-id)
15+
INTERFACE=$(curl_with_token --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/)
16+
export SUBNET=$(curl_with_token --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/subnet-id)
17+
export SECURITY_GROUP_ID=$(curl_with_token --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/security-group-ids)
18+
export VPC_ID=$(curl_with_token --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/vpc-id)
1419
export PORT=6443
1520
tag_subnet
1621
add_inbound_rule
@@ -28,7 +33,7 @@ add_inbound_rule() {
2833
create_target_group() {
2934
TARGET_GROUP_ARN=$(aws elbv2 create-target-group --name blog-test --target-type instance --protocol TCP --port $PORT --vpc-id $VPC_ID | jq -r ".TargetGroups[0].TargetGroupArn")
3035

31-
aws elbv2 register-targets --target-group-arn $TARGET_GROUP_ARN --targets Id=$(curl --silent http://169.254.169.254/latest/meta-data/instance-id),Port=$PORT
36+
aws elbv2 register-targets --target-group-arn $TARGET_GROUP_ARN --targets Id=$(curl_with_token --silent http://169.254.169.254/latest/meta-data/instance-id),Port=$PORT
3237

3338
export LOAD_BALANCER_HOSTNAME=$(kubectl get service nlb-tls-app -ojson | jq -r ".status.loadBalancer.ingress[0].hostname")
3439

0 commit comments

Comments
 (0)