-
Notifications
You must be signed in to change notification settings - Fork 70
DRIVERS-2945 AWS EKS Pod Identity #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9d0d66c
1875814
6c35120
4cc9730
f3aaafe
fb7468c
103c3a1
47998bb
23560a8
28fa4c1
c01fb49
e6dce8e
d97e184
16a0d9a
027baa4
023e968
04cb95b
db69f0f
3cc32bf
0e16391
2f1bc3d
c15fa8d
9d228d6
7763406
f85a3dc
c860f6f
b56b10e
449eeba
c645306
c8969ab
d3214c3
200a212
1c0902e
324f0b3
addfa3d
b90ffd7
9f8b949
2aa420a
f3da76e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
echo "Installing dependencies ... begin" | ||
rm -rf .venv | ||
python3 -m venv .venv | ||
source .venv/bin/activate | ||
pip install -U -q pip "pymongo[aws]" | ||
echo "Installing dependencies ... end" | ||
|
||
# Run the Python Driver Self Test | ||
SCRIPT_DIR=$(realpath "$(dirname ${BASH_SOURCE[0]})") | ||
pushd $SCRIPT_DIR | ||
export MONGODB_URI=$1 | ||
python test.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
# Write the secrets-export.sh file to the k8s/eks directory. | ||
EKS_DIR="../../k8s/eks" | ||
|
||
cat <<EOF >> $EKS_DIR/secrets-export.sh | ||
export EKS_CLUSTER_NAME=$EKS_CLUSTER_NAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the required setting of these variables be documented in the README? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, no, this is set automatically by |
||
export EKS_SERVICE_ACCOUNT_NAME=$EKS_SERVICE_ACCOUNT_NAME | ||
export EKS_REGION=$EKS_REGION | ||
EOF | ||
|
||
bash $EKS_DIR/setup.sh | ||
source $EKS_DIR/secrets-export.sh | ||
|
||
NAME="$1" | ||
MONGODB_URI="mongodb://${NAME}:27017" | ||
APP_LABEL=mongodb-deployment | ||
MONGODB_VERSION=${MONGODB_VERSION:-latest} | ||
|
||
. ../../ensure-binary.sh kubectl | ||
|
||
# Delete mongodb servers over one hour old in case they were not torn down. | ||
echo "Deleting old mongodb servers..." | ||
if [ "$(uname -s)" = "Darwin" ]; then | ||
DATE="gdate" | ||
else | ||
DATE="date" | ||
fi | ||
# shellcheck disable=SC2046 | ||
kubectl get deployments -l app=$APP_LABEL -o go-template --template '{{range .items}}{{.metadata.name}} {{.metadata.creationTimestamp}}{{"\n"}}{{end}}' | awk '$2 <= "'$($DATE -d'now-1 hours' -Ins --utc | sed 's/+0000/Z/')'" { print $1 }' | xargs --no-run-if-empty kubectl delete deployment | ||
# shellcheck disable=SC2046 | ||
kubectl get services -l app=$APP_LABEL -o go-template --template '{{range .items}}{{.metadata.name}} {{.metadata.creationTimestamp}}{{"\n"}}{{end}}' | awk '$2 <= "'$($DATE -d'now-1 hours' -Ins --utc | sed 's/+0000/Z/')'" { print $1 }' | xargs --no-run-if-empty kubectl delete service | ||
echo "Deleting old mongodb servers... done." | ||
|
||
cat <<EOF | kubectl apply -f - | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: ${NAME} | ||
labels: | ||
app: ${APP_LABEL} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: ${NAME} | ||
template: | ||
metadata: | ||
labels: | ||
app: ${NAME} | ||
spec: | ||
containers: | ||
- name: mongodb | ||
image: mongodb/mongodb-enterprise-server:${MONGODB_VERSION} | ||
ports: | ||
- containerPort: 27017 | ||
env: | ||
- name: MONGO_INITDB_ROOT_USERNAME | ||
value: "bob" | ||
- name: MONGO_INITDB_ROOT_PASSWORD | ||
value: "pwd123" | ||
- name: MONGODB_AWS_ACCOUNT_ARN | ||
value: "${EKS_ROLE_ARN}" | ||
args: | ||
- "--setParameter" | ||
- "authenticationMechanisms=MONGODB-AWS,SCRAM-SHA-256" | ||
EOF | ||
|
||
cat <<EOF | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: ${NAME} | ||
labels: | ||
app: ${APP_LABEL} | ||
spec: | ||
selector: | ||
app: ${NAME} | ||
ports: | ||
- protocol: TCP | ||
port: 27017 | ||
targetPort: 27017 | ||
type: ClusterIP | ||
EOF | ||
|
||
# Set up the server. | ||
echo "Setting up the server..." | ||
MONGODB_POD=$(kubectl get pods -l app=${NAME} -o jsonpath='{.items[0].metadata.name}') | ||
# Wait for the pod to be ready. | ||
kubectl wait --for=condition=Ready pod/${MONGODB_POD} --timeout=2000s | ||
kubectl exec ${MONGODB_POD} -- bash -c "rm -rf /tmp/test && mkdir /tmp/test" | ||
kubectl cp ./eks_pod_setup_server.js ${MONGODB_POD}:/tmp/test/setup_server.js | ||
kubectl exec ${MONGODB_POD} -- mongosh /tmp/test/setup_server.js | ||
echo "Setting up the server... done." | ||
|
||
# Run the self test. | ||
echo "Running self test on eks pod..." | ||
kubectl exec ${K8S_POD_NAME} -- bash -c "rm -rf /tmp/self-test && mkdir /tmp/self-test" | ||
kubectl cp ./eks-pod-run-self-test.sh ${K8S_POD_NAME}:/tmp/self-test/run-self-test.sh | ||
kubectl cp ./eks_pod_self_test.py ${K8S_POD_NAME}:/tmp/self-test/test.py | ||
kubectl exec ${K8S_POD_NAME} -- /tmp/self-test/run-self-test.sh $MONGODB_URI | ||
echo "Running self test on eks pod... done." | ||
|
||
# Set up driver test. | ||
echo "Setting up driver test files..." | ||
kubectl exec ${K8S_POD_NAME} -- bash -c "rm -rf /tmp/src" | ||
kubectl cp $PROJECT_DIRECTORY ${K8S_POD_NAME}:/tmp/src/ | ||
echo "Setting up driver test files... done." | ||
|
||
echo "Running the driver test command... done." | ||
echo "export MONGODB_URI=${MONGODB_URI}" >> secrets-export.sh | ||
kubectl cp ./secrets-export.sh ${K8S_POD_NAME}:/tmp/src/secrets-export.sh | ||
echo "Setting up driver test files... done." | ||
|
||
# Run the driver test. | ||
echo "Running the driver test command..." | ||
MONGODB_URI="${MONGODB_URI}/aws?authMechanism=MONGODB-AWS" | ||
kubectl exec ${K8S_POD_NAME} -- bash -c "cd /tmp && source src/secrets-export.sh && bash src/.evergreen/run-mongodb-aws-eks-test.sh $MONGODB_URI" | ||
echo "Running the driver test command... done." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
EKS_APP_NAME=$1 | ||
|
||
echo "Tearing down EKS assets..." | ||
. ../../ensure-binary.sh kubectl | ||
kubectl delete deployment $EKS_APP_NAME | ||
kubectl delete services $EKS_APP_NAME | ||
bash ../../k8s/eks/teardown.sh | ||
echo "Tearing down EKS assets... done." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
|
||
from pymongo import MongoClient | ||
|
||
mongodb_uri = os.environ["MONGODB_URI"] | ||
|
||
print("Testing MONGODB-AWS on eks...") | ||
c = MongoClient(f"{mongodb_uri}/?authMechanism=MONGODB-AWS") | ||
c.aws.test.find_one({}) | ||
c.close() | ||
print("Testing MONGODB-AWS on eks... done.") | ||
print("Self test complete!") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(function() { | ||
"use strict"; | ||
|
||
const AWS_ACCOUNT_ARN=process.env["MONGODB_AWS_ACCOUNT_ARN"]; | ||
const admin = Mongo().getDB("admin"); | ||
const external = admin.getMongo().getDB("$external"); | ||
assert(admin.auth("bob", "pwd123")); | ||
|
||
external.runCommand({createUser: AWS_ACCOUNT_ARN, roles:[{role: 'read', db: "aws"}]}); | ||
}()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this return value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to be a dict, with the values that will get exposed in
test-env.sh
. In this case no variables are needed.