Group 4 (DevOps) Lesson and Hacks
import socket
# Change the following host and see what IP it prints!
host = "youtube.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://youtube.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
print("Content-Type:", response.headers.get("Content-Type"))
# Try an image URL!
response = requests.get("https://user-images.githubusercontent.com/111482658/234948199-e0e5437c-afac-4f61-a861-e706c6054c4f.jpg")
print("Status code:", response.status_code)
print("Headers:", response.headers)
print("Response text:", response.text[:100])
print("Content-Type:", response.headers.get("Content-Type"))
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.
- This is an example of an HTTP header a user could include in their HTTP request:
- User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36
- This header is very useful for the server that needs to respond to the request. Since the user sent this information along with the request, it gives much more helpful information that can help the server with things like compatiability, security, and analyitics.
-
Write a line in a sample NGINX configuration that will add that specific header to the
/information
location-
using your code/server from earlier, I can add a specific header to the '/information' location with this code
```nginx server { add_header X-Cool-Header "I love APCSP!";
location /pages { add_header X-Cooler-Header "This is my secret header!"; }
location /information { add_header Alexa-Header "This is cool"; } }
-
-
Explain the purpose of the load balancing performed by NGINX
- Load balancing by NGINX distributes network traffic among many servers/computers. This improves efficiency, reliability and availability of the application.
- Modify the following code block to obtain the value of the secret header on
/products
of the AWS site
import requests
aws = "3.130.255.192"
response = requests.get("http://" + aws + "/products")
secret_header = response.headers.get('X-Cooler-Header')
print("The secret header is:", secret_header)
CORS Hacks
-
Explain what CORS is and what it stands for
- CORS stands for Cross-Origin Resource Sharing. CORS prevents unauthorized access or manipulation of data since it blocks applications from making requests to a different domain or origin than originally specified.
-
Describe how you would be able to implement CORS into your own websites
- I could implement CORS into my own websites by determining what orgins I want to restrict. I can then implement Access-Control-Allow-Origin: https://example.com to only allow this example origin. I could also use other CORS headers.
-
Describe why you would want to implement CORS into your own websites
- I would want to implement CORS into my websites for security purposes. CORS can prevent unwanted attacks and manipulation.
-
How could use CORS to benefit yourself in the future?
- CORS could benefit me in the future since I could have more secure websites as well as better preforming ones.
Total: 0.2 points
KASM Hacks
-
What is the purpose of "sudo" when running commands in terminal?
- "Sudo" overrides any issue needing permmision in the terminal. So, if I need to do a command that requires a higher-permmision than the root-user, I would put "sudo" in front of it.
-
What are some commands which allow us to look at how the storage of a machine is set up as?
- Some command whoch allow us to look at how the storage of a machine is set up as are "dir", "diskpart", "wmic logicaldisk get" and "diskmgmt.msc" (on windows).
-
What do you think are some alternatives to running "curl -O" to get the zip file for KASM?
- Some alternatives to running "curl -O" are to manually download the zip file using "wget" or to download and transfer it through something like Google-Drive.
-
What kind of commands do you think the "install.sh" command has and why is it necessary to call it?
- Checking for system requirements
- Downloading necessary files
- Setting up environment
- Installing necessary packages or libraries
- "install.sh" is called to make the the installation process easier and more likely to be sucessful.
-
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, the container-based streaming service, requires several components such as headers, NGINX, load balancing, configuration, DNS, and CORS. Headers are important for configuring security settings and enabling CORS for KASM. NGINX is used as a reverse proxy to handle incoming web traffic and load balancing is necessary for distributing the traffic among multiple server instances running KASM. Configuration is required to set up the KASM service and define the specific settings for the environment in which it will run. DNS is used to map the KASM domain name to its IP address, so users can access the service through a web browser. Overall, deploying KASM requires a comprehensive understanding of the technologies involved, including headers, NGINX, load balancing, configuration, DNS, and CORS. It is a complex process that requires careful planning and execution to ensure the service runs smoothly and securely.
Total: 0.2 points