Skip to content

Commit 3163e0c

Browse files
authored
Merge pull request #13 from abhay-krishna/pod-identity-agent-support
Add bootstrap changes to support eks-pod-identity-agent with IAM-RA
2 parents 69ef56e + 98f593b commit 3163e0c

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ RUN dnf update -y && \
4040
xfsprogs \
4141
lvm2 \
4242
mdadm \
43-
rsync && \
43+
rsync \
44+
gettext && \
4445
dnf clean all
4546

4647
# Verify that all packages are installed
@@ -52,12 +53,14 @@ RUN \
5253
command -v mkfs.xfs && \
5354
command -v lvm && \
5455
command -v mdadm && \
55-
command -v rsync
56+
command -v rsync && \
57+
command -v envsubst
5658

5759
# Copy the wrapper script and EKS Hybrid setup scripts into the container
5860
COPY bootstrap-script.sh /usr/local/bin/bootstrap-script.sh
5961
COPY eks-hybrid-ssm-setup.sh /usr/local/bin/eks-hybrid-ssm-setup
6062
COPY eks-hybrid-iam-ra-setup.sh /usr/local/bin/eks-hybrid-iam-ra-setup
63+
COPY aws-signing-helper-update.service.in /usr/share/bootstrap/aws-signing-helper-update.service.in
6164

6265
# Copy the SSM agent from the builder stage
6366
COPY --from=builder /usr/bin/amazon-ssm-agent /usr/local/bin/amazon-ssm-agent

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ check-iam-ra-setup:
7373
@echo "Running IAM-RA setup check"
7474
@OUTPUT=$$(docker run --rm --entrypoint /usr/bin/bash \
7575
$(IMAGE_NAME) \
76-
-c "cp /usr/bin/true /usr/bin/apiclient; eks-hybrid-iam-ra-setup --certificate=${TEST_NODE_CERT} --key=${TEST_NODE_KEY} --dry-run=true 2>&1 || true"); \
76+
-c "eks-hybrid-iam-ra-setup --certificate=${TEST_NODE_CERT} --key=${TEST_NODE_KEY} --dry-run=true 2>&1 || true"); \
7777
if echo "$$OUTPUT" | grep -q "${TEST_NODE_CERT}"; then \
7878
echo "Test failed: certificate content found in output"; \
7979
exit 1; \
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Service that runs aws_signing_helper update to keep the AWS credentials refreshed in ${EKS_HYBRID_SHARED_CREDENTIALS_FILE}.
3+
4+
[Service]
5+
User=root
6+
Environment=AWS_SHARED_CREDENTIALS_FILE=${EKS_HYBRID_SHARED_CREDENTIALS_FILE}
7+
ExecStart=${SIGNING_HELPER_UPDATE_COMMAND}
8+
StandardOutput=journal
9+
StandardError=inherit
10+
Restart=always
11+
RestartSec=10
12+
13+
[Install]
14+
WantedBy=multi-user.target

eks-hybrid-iam-ra-setup.sh

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
exec >&2
44
set -eu -o pipefail
55

6-
declare -r SECRETS_DIR="/.bottlerocket/rootfs/root/.aws"
6+
declare -r HOST_ROOTFS="/.bottlerocket/rootfs"
7+
declare -r SECRETS_DIR="${HOST_ROOTFS}/root/.aws"
8+
declare -r EKS_HYBRID_AWS_DIR="/root/.aws/eks-hybrid"
9+
declare -r EKS_HYBRID_SHARED_CREDENTIALS_FILE="${EKS_HYBRID_AWS_DIR}/credentials"
10+
declare -r EKS_HYBRID_POD_IDENTITY_AWS_DIR="${HOST_ROOTFS}/var/eks-hybrid/.aws"
11+
declare -r SIGNING_HELPER_SERVICE="aws-signing-helper-update.service"
12+
declare -r SIGNING_HELPER_SERVICE_TEMPLATE_PATH="/usr/share/bootstrap/${SIGNING_HELPER_SERVICE}.in"
13+
declare -r SYSTEMD_UNIT_DIR="${HOST_ROOTFS}/run/systemd/system"
14+
declare -r SIGNING_HELPER_SERVICE_PATH="${SYSTEMD_UNIT_DIR}/${SIGNING_HELPER_SERVICE}"
715

816
DRY_RUN="false"
917
for opt in "$@"; do
@@ -43,6 +51,17 @@ if ! [ "${DRY_RUN}" = "true" ]; then
4351
fi
4452
fi
4553

54+
get_aws-signing-helper-update_command() {
55+
local credential_process_from_config
56+
credential_process_from_config="$(AWS_CONFIG_FILE="$1" aws configure get profile.default.credential_process)"
57+
if [ -n "${credential_process_from_config}" ]; then
58+
echo "${credential_process_from_config/aws_signing_helper credential-process/aws_signing_helper update}"
59+
else
60+
echo "Error: No credential_process found in default profile" >&2
61+
return 1
62+
fi
63+
}
64+
4665
cat << EOF > "${SECRETS_DIR}/node.crt"
4766
${NODE_CERT_DATA}
4867
EOF
@@ -51,6 +70,20 @@ cat << EOF > "${SECRETS_DIR}/node.key"
5170
${NODE_KEY_DATA}
5271
EOF
5372

73+
if [ "${DRY_RUN}" = "true" ]; then
74+
exit 0
75+
fi
76+
77+
SIGNING_HELPER_UPDATE_COMMAND="$(get_aws-signing-helper-update_command ${SECRETS_DIR}/config)"
78+
export EKS_HYBRID_SHARED_CREDENTIALS_FILE SIGNING_HELPER_UPDATE_COMMAND
79+
# shellcheck disable=SC2016 # we want to replace the variables verbatim
80+
envsubst '${EKS_HYBRID_SHARED_CREDENTIALS_FILE}:${SIGNING_HELPER_UPDATE_COMMAND}' \
81+
< "${SIGNING_HELPER_SERVICE_TEMPLATE_PATH}" \
82+
> "${SIGNING_HELPER_SERVICE_PATH}"
83+
chroot "${HOST_ROOTFS}" systemctl enable "${SIGNING_HELPER_SERVICE}" --no-reload --quiet
84+
mkdir -p "$(dirname "${EKS_HYBRID_POD_IDENTITY_AWS_DIR}")"
85+
ln -sf "${EKS_HYBRID_AWS_DIR}" "${EKS_HYBRID_POD_IDENTITY_AWS_DIR}"
86+
5487
variant_id="$(apiclient get os.variant_id | jq -r '.os.variant_id')"
5588
version_id="$(apiclient get os.version_id | jq -r '.os.version_id')"
5689
apiclient set \

0 commit comments

Comments
 (0)