Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# RDS_TYPE : RDS Type (Instance or Cluster)
############################################
AWS_PROFILE=
AWS_REGION=
RDS_TYPE=
PMA_HOSTS=
PMA_VERBOSES=
Expand Down
4 changes: 2 additions & 2 deletions Docker/aws-host-tunnel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ else
AWS_CMD=describe-db-clusters
fi

AWS_MYSQL_ENDPOINT=$(aws rds $AWS_CMD --query "DB${RDS_TYPE}s[*].Endpoint" --output json --profile $AWS_PROFILE)
export AWS_RDS_ENDPOINT=$(aws rds $AWS_CMD --query "DB${RDS_TYPE}s[?DBInstanceStatus=='available'].Endpoint" --output json --profile $AWS_PROFILE)
BASTION_INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=bastion" --query "Reservations[*].Instances[*].InstanceId" --output text --profile $AWS_PROFILE)
SSM_PARAM=$(echo $AWS_MYSQL_ENDPOINT | jq '{"portNumber": [(.[] | .Port | tostring)], "localPortNumber": [(.[] | .Port | tostring)], "host": [(.[] | .Address)]}')
SSM_PARAM=$(echo $AWS_RDS_ENDPOINT | jq '{"portNumber": [(.[] | .Port | tostring)], "localPortNumber": [(.[] | .Port | tostring)], "host": [(.[] | .Address)]}')
aws ssm start-session --target $BASTION_INSTANCE_ID --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters "$SSM_PARAM" --profile $AWS_PROFILE
23 changes: 21 additions & 2 deletions Docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#!/bin/sh -eu
/docker-entrypoint.sh php-fpm &
nginx &
nginx -g "daemon off;" &
/workspace/aws-host-tunnel >>/proc/1/fd/2 &
while [ -z "$AWS_RDS_ENDPOINT" ]; do
sleep 1
done
RDS_HOST=$(echo $AWS_RDS_ENDPOINT | jq "(.[] | .Address)" | tr -d '"')
RDS_PORT=$(echo $AWS_RDS_ENDPOINT | jq "(.[] | .Port)")
RDS_VERBOSE="$(echo $RDS_HOST | cut -d '.' -f 1)(RDS)"

if [ -z "$PMA_HOSTS" ]; then
export PMA_HOST=$RDS_HOST
export PMA_PORT=$RDS_PORT
else
export PMA_HOSTS=$PMA_HOSTS,$RDS_HOST
export PMA_VERBOSES=$PMA_VERBOSES,$RDS_VERBOSE
export PMA_PORTS=$PMA_PORT,$RDS_PORT
fi
/docker-entrypoint.sh php-fpm &
echo -e "127.0.0.1\t$RDS_HOST" >>/etc/hosts
if [ ! -f "/etc/ssl/$AWS_REGION-bundle.pem" ]; then
curl "https://truststore.pki.rds.amazonaws.com/$AWS_REGION/$AWS_REGION-bundle.pem" -o "/etc/ssl/$AWS_REGION-bundle.pem"
fi
wait
11 changes: 11 additions & 0 deletions phpmyadmin/config.user.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
for ($i = 1; isset($hosts[$i - 1]); $i++) {
$aws_region = getenv('AWS_REGION');
if (str_contains($cfg['Servers'][$i]['verbose'], 'RDS')) {
$cfg['Servers'][$i]['ssl'] = true;
// You need to have the region CA file and the authority CA file (2019 edition CA for example) in the PEM bundle for it to work
$cfg['Servers'][$i]['ssl_ca'] = "/etc/ssl/{$aws_region}-bundle.pem";
// Enable SSL verification
$cfg['Servers'][$i]['ssl_verify'] = true;
}
}