Skip to content

Commit 1fef547

Browse files
committed
test: Check AWS SDK credential provider work with MMDS
Add an integration test that checks AWS SDK for Python (boto3) is able to get credentials via MMDS without modification. CI artifacts (guest rootfs) update was needed to install AWS SDK for Python. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 5725ae0 commit 1fef547

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-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: 53 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

@@ -776,3 +778,54 @@ def test_deprecated_mmds_config(uvm_plain):
776778
)
777779
== 2
778780
)
781+
782+
783+
@pytest.mark.parametrize("version", MMDS_VERSIONS)
784+
def test_aws_credential_provider(uvm_plain, version):
785+
"""
786+
Test AWS CLI credential provider
787+
"""
788+
test_microvm = uvm_plain
789+
test_microvm.spawn()
790+
test_microvm.basic_config()
791+
test_microvm.add_net_iface()
792+
# V2 requires session tokens for GET requests
793+
configure_mmds(test_microvm, iface_ids=["eth0"], version=version)
794+
now = datetime.now(timezone.utc)
795+
credentials = {
796+
"Code": "Success",
797+
"LastUpdated": now.strftime("%Y-%m-%dT%H:%M:%SZ"),
798+
"Type": "AWS-HMAC",
799+
"AccessKeyId": "AAA",
800+
"SecretAccessKey": "BBB",
801+
"Token": "CCC",
802+
"Expiration": (now + timedelta(seconds=60)).strftime("%Y-%m-%dT%H:%M:%SZ"),
803+
}
804+
data_store = {
805+
"latest": {
806+
"meta-data": {
807+
"iam": {
808+
"security-credentials": {"role": json.dumps(credentials, indent=2)}
809+
},
810+
"placement": {"availability-zone": "us-east-1a"},
811+
}
812+
}
813+
}
814+
populate_data_store(test_microvm, data_store)
815+
test_microvm.start()
816+
817+
ssh_connection = test_microvm.ssh
818+
819+
run_guest_cmd(ssh_connection, f"ip route add {DEFAULT_IPV4} dev eth0", "")
820+
821+
cmd = r"""python3 - <<EOF
822+
from botocore.session import get_session
823+
824+
sess = get_session()
825+
cred = sess.get_credentials()
826+
827+
print(f"{cred.access_key},{cred.secret_key},{cred.token}")
828+
EOF
829+
"""
830+
_, stdout, stderr = ssh_connection.check_output(cmd)
831+
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)