Skip to content

Commit 022c829

Browse files
committed
test: Check AWS CLI's credential provider work with MMDS
The test ensures workloads that work with EC2 IMDS also work with Firecracker MMDS out of the box. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent c6890ad commit 022c829

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

resources/rebuild.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ for d in $dirs; do tar c "/$d" | tar x -C $rootfs; done
6565
mkdir -pv $rootfs/{dev,proc,sys,run,tmp,var/lib/systemd}
6666
# So apt works
6767
mkdir -pv $rootfs/var/lib/dpkg/
68+
69+
# Install AWS CLI v2
70+
apt update
71+
apt install -y unzip
72+
curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o "awscliv2.zip"
73+
unzip awscliv2.zip
74+
./aws/install
75+
rm -rf awscliv2.zip aws/
6876
EOF
6977

7078
# TBD what abt /etc/hosts?

tests/integration_tests/functional/test_mmds.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import random
77
import string
88
import time
9+
import json
10+
from datetime import datetime, timedelta, timezone
911

1012
import pytest
1113

@@ -748,3 +750,53 @@ def test_deprecated_mmds_config(uvm_plain):
748750
)
749751
== 2
750752
)
753+
754+
755+
def test_aws_credential_provider(uvm_plain):
756+
"""
757+
Test AWS CLI credential provider
758+
"""
759+
test_microvm = uvm_plain
760+
test_microvm.spawn()
761+
test_microvm.basic_config()
762+
test_microvm.add_net_iface()
763+
# V2 requires session tokens for GET requests
764+
configure_mmds(test_microvm, iface_ids=["eth0"], version="V2")
765+
now = datetime.now(timezone.utc)
766+
credentials = {
767+
"Code": "Success",
768+
"LastUpdated": now.strftime("%Y-%m-%dT%H:%M:%SZ"),
769+
"Type": "AWS-HMAC",
770+
"AccessKeyId": "ACCESS_KEY_ID",
771+
"SecretAccessKey": "SECRET_ACCESS_KEY",
772+
"Token": "TOKEN",
773+
"Expiration": (now + timedelta(seconds=60)).strftime("%Y-%m-%dT%H:%M:%SZ")
774+
}
775+
data_store = {
776+
"latest": {
777+
"meta-data": {
778+
"iam": {
779+
"security-credentials": {
780+
"role": json.dumps(credentials, indent=2)
781+
}
782+
},
783+
"placement": {
784+
"availability-zone": "us-east-1a"
785+
}
786+
}
787+
}
788+
}
789+
populate_data_store(test_microvm, data_store)
790+
test_microvm.start()
791+
792+
_, stdout, stderr = test_microvm.ssh.check_output("aws configure list --debug")
793+
assert stdout == (
794+
"""
795+
Name Value Type Location
796+
---- ----- ---- --------
797+
profile <not set> None None
798+
access_key ****************Y_ID iam-role
799+
secret_key ****************_KEY iam-role
800+
region us-east-1 imds
801+
""".strip()
802+
), stderr

0 commit comments

Comments
 (0)