Skip to content

Namtayto/spring-boot-oauth2-aks

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SECURING AND ORCHESTRATING OAUTH2 WEB APPLICATION APIs USING SPRING SECURITY AND AZURE SERVICES

👉 This is my project for the network security course at university (NT140) 👈

This report will demonstrate how Spring Security can effectively prevent common security risks in web applications such as authentication-based attacks, authorization errors, CORS attacks, and DDoS. Furthermore, I will provide a detailed explanation of how Azure services can be utilized to deploy and orchestrate the web application.

An actual version of frontend build deployed to Vercel and backend deployed to Azure Kubernetes Service:

https://atmproject.vercel.app

Overview

Sign up page

image

Sign in page

image

After signing in the server fetches your mail, image, and name of your Google and GitHub account then shows to /profile:

image

Used Technologies

  • Back-end: Spring (Boot, Data, Security), JPA / Hibernate, PostgreSQL, Bucket4J
  • Front-end: React.js
  • Security: Oauth2, Rate Limiting
  • Azure: AKS, ACR, AML, Azure Monitor, Application Insights, Grafana, Prometheus
  • Deploy: Vercel, AKS
  • DNS: dnsexit

Features

  • Regular Username/Password authentication.
  • Sign in using either your Google or GitHub account.
  • Monitoring and tracking APIs
  • Implement rate limiting for APIs

Rate Limiting

IP Address-based rate limiting on rest APIs by using Token Bucket Algorithm: image

Rate limiting typically involves tracking the IP addresses where requests originate and identifying the time lapsed between requests. IP addresses are the application's main way to identify who has made each request. When the request quota is consumed, it will throw an error with 429 code which is Too many requests.
The token bucket algorithm enables a network to allow or deny requests based on current traffic. Each bucket holds a certain number of tokens that represent network requests (e.g., attempting to log into an account or sending a message). Whenever a user sends a request, another token gets added to the bucket.

Test rate limit:
Using Postman to spam requests to the server: image

When the request quota is consumed, it will throw an error with 429 code which is Too many requests. image

Azure Services

Azure Container Registry:

  • Write the Dockerfile:
FROM maven:3.8.5-openjdk-17 AS build
COPY . .
RUN mvn clean package -Pprod -DskipTests

FROM openjdk:17.0.1-jdk-slim
EXPOSE 8080
COPY applicationinsights-agent-3.4.19.jar /
COPY applicationinsights.json /
COPY --from=build /target/spring-social-0.0.1-SNAPSHOT.jar spring-social.jar
ENTRYPOINT ["java", "-javaagent:/applicationinsights-agent-3.4.19.jar","-jar","spring-social.jar"]
  • Push the image of the Web application on Azure Container Registry
docker build -t spring-social .
az acr login --name springimage
docker tag spring-social:latest springimage.azurecr.io/spring-social:latest
docker push springimage.azurecr.io/spring-project:latest

image

Azure Kubernetes Service:

  • Expose the image as the service type load balancer in Azure Kubernetes:
kubectl apply -f docker-k8s.yaml
kubectl get deployment
kubectl expose deployment docker-k8s-demo-deployment --port=80 --protocol=TCP --target-port=8080 --type=LoadBalancer

image

  • After exposing we have the public IP: 20.44.199.131. Point the free domain from dnsexit.com to that public IP: image

  • Create the SSL certificates (ZeroSSL) for that domain: image

  • Then we can use that domain instead of using public IP: image

Azure Monitor

Monitoring AKS using Prometheus and Grafana

  • CPU: image

  • Memory: image

  • Network: image

  • Storage: image

  • Containers: image

Alert

  • Set an alert and issue a warning if the RAM usage of the cluster exceeds 50%: image

  • Based on the Alert we can scale up or scale down the Virtual Machine to save money: image

Application Insight

  • On the map of our application, you can see the request being made to the cloud database node: image

  • Trigger the email of users when they log in or signup: image

Azure Machine Learning

  • Retrieve the data monitor from Application Insights and export it as a CSV file to use as the dataset in Azure Machine Learning: image

  • Using Jupyter Notebook connect to workspace has the dataset: image

  • Read the dataset using pandas: image

  • Draw graph: image

image

  • Calculate Mean Squared Error and Coefficients of the model: image

Releases

No releases published

Packages

No packages published

Languages

  • Java 75.3%
  • CSS 21.3%
  • HTML 2.4%
  • Other 1.0%