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!")
Check-In
- What is an IP address? An IP address is a internet protocol that is used for communication between different computers.
- What is a TCP port? A safe way to send your information over the internet.
Slide Questions
- What does DNS stand for?
- DNS stands for domain name system
- What is the purpose of DNS?
- Change the domain ip (123.131431) to something my legible. ex. youtube.com.
- How does DNS work?
- Your computer sends a message for another machine so that you can get the ip address of the site you are trying to reach. This then gets returned to your browser which is used to get to you desired site.
- What is a DNS resolver?
- A DNS resolver is helps find the associated ip address and its domain name. First step in above process.
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:9099;
}
}
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.
- Content type tells what type of data is going to be used.
- Write a line in a sample NGINX configuration that will add that specific header to the
/information
locationlocation/information {add_header secret header}
- Explain the purpose of the load balancing performed by NGINX
- Distrubute traffic so that it is not going to have too much traffic all in one place.
- Modify the following code block to obtain the value of the secret header on
/products
of the AWS site
aws = "3.130.255.192"
response = requests.get("http://" + aws+ "/products")
print("The secret header is:", "...")
CORS Hacks
- Explain what CORS is and what it stands for. Cross origin resource sharing. It is used for security so that it stops cross origin requests.
- Describe how you would be able to implement CORS into your own websites. You need to control who can access your stuff.
- Describe why you would want to implement CORS into your own websites. security reasons.
- How could use CORS to benefit yourself in the future? I can make my own project more secure.
Total: 0.2 points
KASM Hacks
- What is the purpose of "sudo" when running commands in terminal? Allows you to run things as administrator. Basically more things you can do.
- What are some commands which allow us to look at how the storage of a machine is set up as? lsblk to see what storage devices you have.
- What do you think are some alternatives to running "curl -O" to get the zip file for KASM? wget. like we use daily.
- What kind of commands do you think the "install.sh" command has and why is it necessary to call it? The install.sh command installs what you want onto your system. It is import to call it this because it would allow you to easily recognize what it is doing.
- 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 needs you to know how to set up your netowk system so that data can be transmitted. you also need to know how to use firewalls so that there is more safety. and need to know how to use kasm with other stuff.
Total: 0.2 points
Total: 0.3