DevOps Lesson
import socket
# Change the following host and see what IP it prints!
host = "google.com"
ip = socket.gethostbyname(host)
print(ip)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
print("Successfully connected!")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((ip, 80))
# Send a GET request to "/"
s.sendall(b"GET / HTTP/1.1\r\n\r\n")
# Recieve & print 2048 bytes of data
data = s.recv(2048)
print(data.decode())
import requests
# Change the URL to whatever you'd like
response = requests.get("https://google.com")
print("Status code:", response.status_code)
print("Headers:", response.headers)
print("Response text:", response.text[:100])
# Add a line to print the "Content-Type" header of the response
# Try an image URL!
aws = "3.130.255.192"
response = requests.get("http://" + aws)
print(response.text)
Configuration
server {
// Listen on virtual "port 80"
listen 80;
listen [::]:80;
server_name 3.130.255.192;
location / {
// Inform server about original client
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
// Forward all requests transparently to the server running on our computer
proxy_pass http://localhost:8080;
add_header Date $date_gmt;
}
}
Load Balancing
upstream example.com {
server server1.example.com;
server server1.example.com;
}
HTTP Headers
server {
add_header X-Cool-Header "I love APCSP!";
location /pages {
add_header X-Cooler-Header "This is my secret header!";
}
}
Check In
-
Research 1 HTTP header and describe, in detail, its purpose.
Like shown above, date is a header, it's purpose is to show the date
-
Write a line in a sample NGINX configuration that will add that specific header to the
/information
location"add_header Date $date_gmt;"
-
Explain the purpose of the load balancing performed by NGINX
As NGINX works as a reverse proxy, load balancing is vital to distribute traffic across and make everything run smoother
-
Modify the following code block to obtain the value of the secret header on
/products
of the AWS sitedone
aws = "3.130.255.192"
response = requests.get("http://" + aws+ "/products")
print("The secret header is:", response.headers['X-Cooler-Header'])
Hacks
-
Complete the above check-in questions and change the hosts (0.1)
I dont know if I did it right but I tried
-
Complete the above code-segment to retrieve the secret header (0.1)
got the secret header
Bonus (0.05)
Create a diagram showing the layers of abstraction that allow us to use HTTP (IP, TCP, etc.) Too much work ima be honest
CORS Hacks
-
Explain what CORS is and what it stands for
Cross-Origin Resource Sharing, its a request to access from a site. It is a security feature to block malicious data.
-
Describe how you would be able to implement CORS into your own websites
You have to include CORS in you header and make sure everything matches to what you desire
-
Describe why you would want to implement CORS into your own websites
To protect your users from sending or receiving harmful data
-
How could use CORS to benefit yourself in the future?
I could use it in one of my future projects to add a layer of security to protect my users.
Total: 0.2 points
KASM Hacks
-
What is the purpose of "sudo" when running commands in terminal?
adding sudo makes it have admin access
-
What are some commands which allow us to look at how the storage of a machine is set up as?
The most common one that is used is "df". Some others one are "du", "fdisk", and "parted"
-
What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
Using wget is probably the easiest and fast. You can always download the file or run another type of command.
-
What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
It has all types of configs and necessary files that you have to install in order for KASM and other apps to work
-
Explain in at least 3-4 sentences how deploying KASM is related to/requires other topics talked about in the lesson and/or potential ways to add things mentioned in the lesson to this guide.
Deploying KASM requires a good understanding of some of the things we learned about. Knowing how to configure KASM is important cause you want to keep malware out. You also need to know some things about kernals because each function differently and relate to usage of KASM. You need to also know how to implement KASM into pre-existing programs as its gonna be a different situation for every project
Total: 0.2 points