Skip to content

Commit 8079b89

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 8079b89

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

resources/chroot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PS4='+\t '
1111

1212
cp -ruv $rootfs/* /
1313

14-
packages="udev systemd-sysv openssh-server iproute2 curl socat python3-minimal iperf3 iputils-ping fio kmod tmux hwloc-nox vim-tiny trace-cmd linuxptp strace"
14+
packages="udev systemd-sysv openssh-server iproute2 curl socat python3-minimal iperf3 iputils-ping fio kmod tmux hwloc-nox vim-tiny trace-cmd linuxptp strace unzip"
1515

1616
# msr-tools is only supported on x86-64.
1717
arch=$(uname -m)

resources/rebuild.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function build_rootfs {
5454
# sudo tar xaf ubuntu-22.04-minimal-cloudimg-amd64-root.tar.xz -C $rootfs
5555
# sudo systemd-nspawn --resolv-conf=bind-uplink -D $rootfs
5656
docker run --env rootfs=$rootfs --privileged --rm -i -v "$PWD:/work" -w /work "$FROM_CTR" bash -s <<'EOF'
57+
set -x
5758
5859
./chroot.sh
5960
@@ -65,6 +66,12 @@ for d in $dirs; do tar c "/$d" | tar x -C $rootfs; done
6566
mkdir -pv $rootfs/{dev,proc,sys,run,tmp,var/lib/systemd}
6667
# So apt works
6768
mkdir -pv $rootfs/var/lib/dpkg/
69+
70+
# Install AWS CLI v2
71+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
72+
unzip awscliv2.zip
73+
./aws/install
74+
rm -rf awscliv2.zip aws
6875
EOF
6976

7077
# 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)