I've been assigned a task to spin up some infrastructure using infrastructure as code, some of the requirements ask for misconfigurations so please do not apply best practices to override these. Steps are to follow, from an AWS point of view we will use cloudformation for the IAC components.
Assistant
Sure, I can help you with that. Before we get started, it's important to note that intentionally creating misconfigurations in your infrastructure can lead to security vulnerabilities and other issues. Please make sure you have permission and a clear understanding of the risks involved before proceeding.
With that said, here are the steps to spin up infrastructure using AWS CloudFormation:
Define the infrastructure components in a CloudFormation template. This can be done in YAML or JSON format. Make sure to include the misconfigurations you need to implement.
Create a CloudFormation stack from the template. You can do this using the AWS Management Console, the AWS CLI, or the CloudFormation API. When creating the stack, make sure to specify any required parameters and options, such as the AWS region and stack name.
Monitor the stack creation process. You can view the progress of the stack creation in the CloudFormation console or by using the CLI/API. Make sure to verify that the stack has been created successfully and that any misconfigurations have been applied.
User
Introduction to the Technical Exercise
The objective of the exercise is to build a containerized web application running on a managed
Kubernetes cluster and an instance/vm that runs MongoDB, which can perform backups to a
storage bucket (S3, Azure Storage Account, Storage Bucket, etc).
The web application will be publicly facing for customer access. The MongoDB server will also
be built in a way where it could potentially store data generated by the web application. The
Mongo DB should be able to generate backups to a storage bucket that is also publicly exposed.
Present the environment that you have built as if you are presenting this to a customer. Create
a PowerPoint presentation (3-5 slides) about what you’ve built, problems that you ran into, and
how you overcame them. Also, send a link to your GitHub repo to the recruiter at least 24
hours prior to the interview.
Assistant
As an AI language model, I don't have the ability to create a PowerPoint presentation or a GitHub repository. However, I can provide you with some guidance on how to approach the exercise and some tips on what to include in your presentation.
To build a containerized web application running on a managed Kubernetes cluster, you will need to:
Build and containerize your web application - this can be done using Docker, which will allow you to package your application with its dependencies into a single container image.
Deploy the containerized application to a managed Kubernetes cluster - you can use services like Amazon EKS, Google Kubernetes Engine, or Azure Kubernetes Service to manage the deployment and scaling of your application.
Build and configure a MongoDB instance - you can use a containerized MongoDB image and deploy it to the same Kubernetes cluster, or you can use a managed MongoDB service like MongoDB Atlas.
User
Please generate the cloudformation / dockerfiles and kubernetes yaml files for the following. Using EKS has the service hosting the container. Mongo db to be run on an EC2 instance defined in the cloudformation file. Full steps required:
Phase 1 – Basic Setup
At the end of basic setup, you should have a working web service that can be accessed from the
web, and a VM instance running MongoDB.
Step 1 MongoDB: Create an instance using a base Linux image that is over one year old.
Install a MongoDB package older than 6 months (see here) on the Linux VM.
Step 2 MongoDB Backup: Create a bucket (S3 bucket, Azure Storage Object, etc.) that will
hold the MongoDB backups which you will need to automate. Change permissions
on the bucket to allow for PUBLIC READ, e.g., anyone can read from the bucket.
Step 3 Managed Cluster: Create a managed Kubernetes cluster within the same network as
the VM you created.
Step 4 Container Web Application:
Assistant
Here is an example CloudFormation template to create an EC2 instance to run MongoDB:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Test the infrastructure to ensure it meets the desired requirements. This can include running automated tests, manual testing, and/or other verification methods.
When you're done with the infrastructure, make sure to delete the CloudFormation stack to avoid any unnecessary charges or ongoing maintenance.
Remember that misconfigurations can cause serious issues and should not be implemented in production environments. Always follow best practices and security guidelines to ensure the safety and reliability of your infrastructure.
Configure MongoDB backups to a storage bucket - you can use tools like Kopia or Velero to perform backups of your MongoDB data to a storage bucket like Amazon S3, Google Cloud Storage, or Azure Storage.
When presenting your environment to a customer, you should focus on the following:
Overview of the environment - explain what you have built and how it works.
Benefits of the environment - highlight the benefits of using a containerized web application running on a managed Kubernetes cluster and a MongoDB instance with automated backups.
Challenges faced - discuss any challenges or problems you encountered during the process of building the environment and how you overcame them.
Next steps - outline any future enhancements or improvements that could be made to the environment.
Remember to keep your presentation concise and focused on the key points. Good luck with your technical exercise!
Deploy the container-based web application to the managed Kubernetes
cluster.
Configure the routing to allow for public access into the managed cluster
using service type load balancer e.g. (see here).
Goals: At the end of basic setup (Phase 1), you have a working web service that can be
accessed from the web, and a VM instance running MongoDB
3 WIZ | TECHNICAL EXERCISE
Phase 2 – Identity & Secrets Setup
The goal of this procedure is to configure identity and permissions for your environment.
Step 1 Configure the container as admin: Configure the container as admin: Provide the
container with cluster-admin privileges as described here in the “Permissive
RBAC permissions” section.
Step 2 Configure the MongoDB VM as highly privileged: Configure permissions which
allow this virtual machine to create and delete other virtual machines.
Step 3 MongoDB connection string: Launch a bastion host to connect to your MongoDB
instance. Create a script which remotely connects to the MongoDB instance,
creates a backup using Mongodump, and uploads this to the storage bucket that
you created earlier.
yaml
Resources:
EC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-0c94855ba95c71c99 # use a base Linux image over one year old
InstanceType: t2.micro # change as needed
SecurityGroupIds:
- !Ref EC2SecurityGroup # reference the security group defined below
UserData:
Fn::Base64: !Sub |
#!/bin/bash
# install MongoDB older than 6 months
echo '[mongodb-org-4.0]' | sudo tee /etc/yum.repos.d/mongodb-org-4.0.repo
echo 'name=MongoDB Repository' | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo
echo 'baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/4.0/x86_64/' | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo
echo 'gpgcheck=1' | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo
echo 'enabled=1' | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo
echo 'gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc' | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo
sudo yum install -y mongodb-org
EC2SecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Security group for MongoDB EC2 instance
VpcId: !Ref VPC # reference your VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 27017 # MongoDB default port
ToPort: 27017
CidrIp: 0.0.0.0/0 # allow access from any IP address
Tags:
- Key: Name
Value: MongoDB Security Group
Here is an example Dockerfile to build a container image for your web application:
Dockerfile
FROM node:12-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
Here is an example Kubernetes YAML file to deploy your containerized web application to a managed EKS cluster:
To configure your MongoDB instance as admin, you can use the --auth option when starting MongoDB and create an admin user using the mongo command-line tool. Then, you can use Kubernetes