Skip to content

Commit 786c0d0

Browse files
committed
test: Check AWS SDK credential provider work with MMDS
Add a test that ensures AWS SDK for Python (boto3) work with MMDS out of the box. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 4cd8e1b commit 786c0d0

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
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 python3-boto3"
1515

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

resources/rebuild.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ 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+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
71+
unzip awscliv2.zip
72+
./aws/install --install-dir $rootfs/usr/local/aws-cli --bin-dir $rootfs/usr/local/bin
73+
rm -rf awscliv2.zip aws
6874
EOF
6975

7076
# 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
@@ -3,9 +3,11 @@
33
"""Tests that verify MMDS related functionality."""
44

55
# pylint: disable=too-many-lines
6+
import json
67
import random
78
import string
89
import time
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": "AAA",
771+
"SecretAccessKey": "BBB",
772+
"Token": "CCC",
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": {"role": json.dumps(credentials, indent=2)}
780+
},
781+
"placement": {"availability-zone": "us-east-1a"},
782+
}
783+
}
784+
}
785+
populate_data_store(test_microvm, data_store)
786+
test_microvm.start()
787+
788+
ssh_connection = test_microvm.ssh
789+
790+
run_guest_cmd(ssh_connection, f"ip route add {DEFAULT_IPV4} dev eth0", "")
791+
792+
cmd = r"""python3 - <<EOF
793+
from botocore.session import get_session
794+
795+
sess = get_session()
796+
cred = sess.get_credentials()
797+
798+
print(f"{cred.access_key},{cred.secret_key},{cred.token}")
799+
EOF
800+
"""
801+
_, stdout, stderr = ssh_connection.check_output(cmd)
802+
assert stdout == "AAA,BBB,CCC\n", stderr

tools/setup-ci-artifacts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ for SQUASHFS in *.squashfs; do
3939
# Create rw ext4 image from ro squashfs
4040
[ -f $EXT4 ] && continue
4141
say "Converting $SQUASHFS to $EXT4"
42-
truncate -s 400M $EXT4
42+
truncate -s 500M $EXT4
4343
mkfs.ext4 -F $EXT4 -d squashfs-root
4444
rm -rf squashfs-root
4545
done

0 commit comments

Comments
 (0)