Skip to content

Developed a Recipe Webapp where users' karma and location affect their permissions to perform operations.

License

Notifications You must be signed in to change notification settings

RS-labhub/OPAL-K8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

58 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RECIPE πŸ§‘β€πŸ³
where karma decides role


πŸ§‘β€πŸ³ Recipe

Recipe Web Application Built a k8s controller that will allow the deployment of OPAL as part of the k8s platform. Developed a Recipe Webapp where users' karma and location affect their permissions to perform operations. Fetched the data dynamically from a MySQL server.


πŸͺΆ Features

  • πŸ“– User Karma and Location-Based Permissions :

    • Dynamic Permission Management: Users' permissions to perform various operations within the application are dynamically managed based on their karma and location. This ensures personalized and context-specific access control.
    • Karma System: Users accumulate karma points through their interactions and contributions within the app, which affects their permissions and access levels.
    • Location-Based Access: Users' locations are used to further refine their access permissions, allowing for location-specific content and operations.
  • βœ’οΈ Recipe Sharing Platform :

    • User-Generated Content: Users can create, share, and browse recipes. This includes the ability to add detailed instructions, ingredients, and multimedia content such as images and videos.
    • Search and Filter Options: The app provides advanced search and filtering options to help users find recipes based on various criteria, including ingredients, cuisine, and user ratings.
  • πŸš€ Kubernetes Integration :

    • OPAL Deployment as a Kubernetes Controller: The application includes a Kubernetes controller to manage the deployment of OPAL as part of the Kubernetes platform, ensuring scalability and reliability.
    • Containerized Services: The app's backend services are containerized using Docker and deployed on Kubernetes, providing a robust and scalable infrastructure.
  • πŸ“° Database Integration :

    • MySQL Backend: User data, recipes, and other relevant information are stored in a MySQL database. The app dynamically fetches data from the MySQL server as needed.
    • API Endpoints: The app provides RESTful API endpoints to interact with the MySQL database, enabling operations such as fetching user information and retrieving recipes based on permissions.
  • πŸ” Authentication and Authorization :

    • User Authentication: Secure user authentication mechanisms are implemented to ensure that only authorized users can access and interact with the application.
    • Role-Based Access Control (RBAC): The application supports role-based access control, where different user roles have varying levels of access and permissions.
  • πŸ–₯️ Monitoring and Logging :

    • Responsive Design: The application is designed to be fully responsive, ensuring a seamless experience across different devices and screen sizes.
    • User-Friendly Interface: Intuitive navigation and a user-friendly interface enhance the overall user experience, making it easy for users to interact with the app.
  • πŸ•ΈοΈ Next.js Frontend :

    • React-Based User Interface: The frontend is built using Next.js, providing a fast and responsive user experience.
    • Server-Side Rendering (SSR): Next.js enables server-side rendering, which improves performance and SEO for the web application.
    • Real-Time Updates: The app fetches data dynamically and updates the user interface in real-time as users interact with the application.

πŸ“š Index


πŸŽ₯ Demo

  • After a brief introduction, let's dive a little more inside the project.
  • Here is the walk-through of Recipe πŸ§‘β€πŸ³. If you want to witness a more a hd version, click here

Recipe πŸ§‘β€πŸ³

Video Demonstration, please πŸ”ˆπŸ”‰πŸ”Š

In case, the video is not visible, refer this link: https://youtu.be/lLmQM-04PTc

Screenshots

working demo


landing page


users and live permission



Project Tree

OPAL-K8/
β”œβ”€β”€ api/
β”‚   └── v1alpha1/
β”‚       β”œβ”€β”€ groupversion_info.go
β”‚       β”œβ”€β”€ opalcontroller_types.go
β”‚       └── zz_generated.deepcopy.go
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ certmanager/
β”‚   β”‚   β”œβ”€β”€ certificate.yaml
β”‚   β”‚   β”œβ”€β”€ kustomization.yaml
β”‚   β”‚   └── kustomizeconfig.yaml
β”‚   β”œβ”€β”€ crd/
β”‚   β”‚   β”œβ”€β”€ bases/
β”‚   β”‚   β”‚   └── rs-labhub.github.io_opalcontrollers.yaml
β”‚   β”‚   β”œβ”€β”€ kustomization.yaml
β”‚   β”‚   └── patches/
β”‚   β”‚       └── cainjection_in_opalcontrollers.yaml
β”‚   β”œβ”€β”€ default/
β”‚   β”‚   β”œβ”€β”€ kustomization.yaml
β”‚   β”‚   └── manager_auth_proxy_patch.yaml
β”‚   β”œβ”€β”€ manager/
β”‚   β”‚   β”œβ”€β”€ controller_manager_config.yaml
β”‚   β”‚   β”œβ”€β”€ kustomization.yaml
β”‚   β”‚   └── manager.yaml
β”‚   β”œβ”€β”€ prometheus/
β”‚   β”‚   β”œβ”€β”€ kustomization.yaml
β”‚   β”‚   └── monitor.yaml
β”‚   β”œβ”€β”€ rbac/
β”‚   β”‚   β”œβ”€β”€ auth_proxy_client_clusterrole.yaml
β”‚   β”‚   β”œβ”€β”€ auth_proxy_role.yaml
β”‚   β”‚   β”œβ”€β”€ auth_proxy_role_binding.yaml
β”‚   β”‚   β”œβ”€β”€ auth_proxy_service.yaml
β”‚   β”‚   β”œβ”€β”€ kustomization.yaml
β”‚   β”‚   β”œβ”€β”€ leader_election_role.yaml
β”‚   β”‚   β”œβ”€β”€ leader_election_role_binding.yaml
β”‚   β”‚   β”œβ”€β”€ opalcontroller_editor_role.yaml
β”‚   β”‚   β”œβ”€β”€ opalcontroller_viewer_role.yaml
β”‚   β”‚   β”œβ”€β”€ role_binding.yaml
β”‚   β”‚   └── service_account.yaml
β”‚   β”œβ”€β”€ samples/
β”‚   β”‚   └── rs-labhub_v1alpha1_opalcontroller.yaml
β”‚   └── webhook/
β”‚       β”œβ”€β”€ kustomization.yaml
β”‚       β”œβ”€β”€ kustomizeconfig.yaml
β”‚       β”œβ”€β”€ service.yaml
β”‚       └── webhook.yaml
β”œβ”€β”€ controllers/
β”‚   └── opalcontroller_controller.go
β”œβ”€β”€ database/
β”‚   └── SQL/
β”‚       β”œβ”€β”€ karma_location.sql
β”‚       β”œβ”€β”€ karma_location_with_output.sql
β”‚       β”œβ”€β”€ recipe.sql
β”‚       └── user.sql
β”œβ”€β”€ deployment/
β”‚   β”œβ”€β”€ mysql-deployment.yaml
β”‚   β”œβ”€β”€ opal-controller-deployment.yaml
β”‚   β”œβ”€β”€ opal-service.yaml
β”‚   β”œβ”€β”€ recipe-deployment.yaml
β”‚   └── recipe-service.yaml
β”œβ”€β”€ hack/
β”‚   └── boilerplate.go.txt
β”œβ”€β”€ recipe-sharing-app/
β”‚   β”œβ”€β”€ backend/
β”‚   β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”‚   β”œβ”€β”€ app.py
β”‚   β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”‚   └── templates/
β”‚   β”‚       └── index.html
β”‚   └── frontend/
β”‚       β”œβ”€β”€ Dockerfile
β”‚       β”œβ”€β”€ package-lock.json
β”‚       β”œβ”€β”€ package.json
β”‚       └── src/
β”‚           β”œβ”€β”€ App.js
β”‚           β”œβ”€β”€ App.test.js
β”‚           β”œβ”€β”€ index.css
β”‚           β”œβ”€β”€ index.js
β”‚           β”œβ”€β”€ logo.svg
β”‚           β”œβ”€β”€ reportWebVitals.js
β”‚           └── setupTests.js
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .gitpod.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ Makefile
β”œβ”€β”€ PROJECT
β”œβ”€β”€ README.md
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ main.go
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ policy.yaml
└── rbac.rego

Policy Management Flow:

    +-----------+    Policy Definition    +---------+
    | Policy    |  <--------------------  | YAML    |
    | Admin     |                         | File    |
    +-----------+                         +---------+
          |
          | Policy Loading
          v
    +-----------+     Policy Enforcement    +-----------+
    | OPAL      |  <----------------------  | Application|
    | Service   |                          |  Requests   |
    +-----------+                          +-----------+
          |
          | Decision
          v
    +-----------+
    | Access    |
    | Granted/  |
    | Denied    |
    +-----------+

Synchronization Workflow

    +------------------+    Policy Pull    +-----------------+
    | Policy Repository|  <--------------  | OPAL Server     |
    | (Permit.io)      |                   |                 |
    +------------------+                   +-----------------+
          |
          | Policy Push
          v
    +-----------+   Policy Synchronization   +-----------+
    | OPAL      |  ----------------------->  | OPA       |
    | Service   |                            | Instances |
    +-----------+                            +-----------+
          |
          | Real-time Policy Updates
          v
    +-----------+
    | Application|
    | Access     |
    +-----------+

Other Real-World Use Cases of OPAL (Open Policy Administration Layer)

Open Policy Administration Layer (OPAL) is a powerful tool for managing dynamic authorization policies in real-time. By integrating OPAL into your application, you can leverage dynamic, context-aware policies that respond to changes in user attributes, environmental conditions, and application state. Below, we explore several real-world use cases of OPAL with detailed examples to demonstrate its versatility and effectiveness.

Use Case 1: Dynamic Access Control in Financial Services

A financial services application needs to implement dynamic access control for various user roles, such as customers, financial advisors, and administrators. The access rights need to adapt based on factors like the user's location, the type of account they are accessing, and real-time risk assessments.

Example

  1. Customer Access:
  • Policy: Customers can only access their own financial data.
  • Dynamic Conditions: Access is restricted based on the customer's current location. For example, access may be denied if the customer is accessing their account from a high-risk country.
  • OPAL Implementation:
{
"subject": "customer",
"action": "view",
"resource": "financial_data",
"conditions": {
  "location": "not_in_high_risk_country",
  "risk_assessment": "low"
  }
}
  1. Advisor Access:
  • Policy: Financial advisors can access customer financial data, but only during business hours and if the customer has granted explicit permission.
  • Dynamic Conditions: Access is restricted based on the advisor's location and current time.
  • OPAL Implementation:
{
"subject": "advisor",
"action": "view",
"resource": "customer_financial_data",
"conditions": {
  "location": "in_office",
  "time": "within_business_hours",
  "customer_permission": "granted"
  }
}
  1. Administrator Access:
  • Policy: Administrators have full access to all financial data but must undergo multi-factor authentication (MFA) if accessing from outside the office network.
  • Dynamic Conditions: MFA requirement is triggered based on the administrator's access location.
  • OPAL Implementation:
{
"subject": "administrator",
"action": "manage",
"resource": "all_financial_data",
"conditions": {
  "location": "outside_office_network",
  "mfa_status": "completed"
  }
}

Use Case 2: Context-Aware Permissions in Healthcare Applications

A healthcare application needs to enforce strict access control to patient records, ensuring that only authorized personnel can access sensitive information based on their role, the time of access, and the specific patient's condition.

Example

  1. Doctor Access:
  • Policy: Doctors can access the records of patients they are treating.
  • Dynamic Conditions: Access is limited to active treatment periods and emergency situations.
  • OPAL Implementation:
{
"subject": "doctor",
"action": "view",
"resource": "patient_records",
"conditions": {
  "treatment_status": "active",
  "emergency_status": "true"
  }
}
  1. Nurse Access:
  • Policy: Nurses can access patient records for the ward they are assigned to, but only during their shift.
  • Dynamic Conditions: Access is restricted based on shift times and assigned ward.
  • OPAL Implementation:
{
"subject": "nurse",
"action": "view",
"resource": "ward_patient_records",
"conditions": {
  "shift_status": "active",
  "assigned_ward": "true"
  }
}
  1. Researcher Access:
  • Policy: Researchers can access anonymized patient data for approved studies.
  • Dynamic Conditions: Access is restricted to anonymized data sets and only for the duration of the study.
  • OPAL Implementation:
{
"subject": "researcher",
"action": "view",
"resource": "anonymized_patient_data",
"conditions": {
  "study_status": "approved",
  "study_duration": "active"
  }
}

Use Case 3: Fine-Grained Access Control in E-commerce Platforms

An e-commerce platform needs to manage access to different functionalities for various user roles, such as customers, sellers, and administrators, with dynamic adjustments based on user behavior, purchase history, and account status.

Example

  1. Customer Access:
  • Policy: Customers can view and purchase products, but their spending limit is dynamically adjusted based on their purchase history and account status.
  • Dynamic Conditions: Spending limit and product access are influenced by customer behavior and account health.
  • OPAL Implementation:
{
"subject": "customer",
"action": "purchase",
"resource": "products",
"conditions": {
  "spending_limit": "not_exceeded",
  "account_status": "active"
  }
}
  1. Seller Access:
  • Policy: Sellers can manage their product listings and view sales data.
  • Dynamic Conditions: Access to sales data is restricted to their own products and influenced by seller performance metrics.
  • OPAL Implementation:
{
"subject": "seller",
"action": "manage",
"resource": "product_listings",
"conditions": {
  "seller_performance": "satisfactory"
  }
}
  1. Administrator Access:
  • Policy: Administrators have full control over the platform but must follow enhanced security protocols for high-privilege actions.
  • Dynamic Conditions: High-privilege actions require additional verification steps based on the administrator's recent activity and system health.
  • OPAL Implementation:
{
"subject": "administrator",
"action": "control",
"resource": "platform",
"conditions": {
  "verification_status": "completed",
  "recent_activity": "safe"
  }
}

Conclusion

These examples illustrate the flexibility and power of OPAL in implementing dynamic, context-aware access control across various industries. By leveraging OPAL, organizations can ensure that their applications are secure, compliant, and adaptable to changing conditions. Whether it's financial services, healthcare, or e-commerce, OPAL provides a robust framework for managing fine-grained permissions in real-time.

For more detailed information on how to integrate OPAL into your application, visit the Official OPAL documentation.


Dependecies

  1. Next.js
  2. React
  3. Axios
  4. Node.js
  5. Express
  6. MySQL
  7. OPAL
  8. Kubectl
  9. Helm
  10. Docker

πŸ“€ Installation Guide

These are the steps required to install and run the Recipe πŸ§‘β€πŸ³ project:

  1. Clone the Repository: Open a terminal or command prompt and clone the Recipe πŸ§‘β€πŸ³ repository from GitHub using the following command:
  git clone https://github.com/RS-labhub/OPAL-K8.git
  1. Navigate to the Repository Directory: Change your current directory to the cloned Recipe πŸ§‘β€πŸ³ repository:
  cd OPAL-K8
  1. Kubernetes Controller to Deploy OPAL
    • Prerequisites

      • A running Kubernetes cluster (local or cloud-based).
      • Docker installed on your local machine.
      • kubectl configured to interact with your Kubernetes cluster.
      • Go programming language installed.
    • Step 1: Set Up a Kubernetes Cluster

      • You can use Minikube for local development or a cloud provider like GKE, EKS, or AKS for a production-ready cluster.
    • Step 2: Create the Kubernetes Controller

      • Define the Custom Resource Definitions (CRDs)
      • Create the Controller Code
    • Step 3: Build and Deploy the Controller

      1. Build the Controller Image
      docker build -t mycompany/opal-controller:latest .
      
      1. Push the Image to a Registry
      docker push mycompany/opal-controller:latest
      
      1. Deploy the Controller to the Cluster
      2. Apply the deployment
      kubectl apply -f opal_crd.yaml
      kubectl apply -f controller_deployment.yaml
      
  2. Web Application with Dynamic Permissions
    • Prerequisites
      • Node.js and npm installed.
      • MySQL server running and configured.
    • Step 1: Set Up a Next.js Project
      1. Install Required Dependencies
      npm install axios mysql2
      
      1. Run the project
      npm run dev

Note: The running port should look like this: Open http://localhost:3000 in your web browser to see the list of users and recipes filtered by karma and location.



What to do after installation?

Once Recipe πŸ§‘β€πŸ³ is installed and running, by following these guidelines, you will set up and install a Kubernetes controller to deploy OPAL and develop a web application where users' permissions are dynamically influenced by their karma and location, with data fetched from a MySQL server.

$~$

Setup and Contributing Guidelines

Set Up Your Environment

  1. Fork our repository to your GitHub account.
  2. Clone your fork to your local machine. Use the command git clone https://github.com/RS-labhub/OPAL-K8.git.
  3. Create a new branch for your work. Use a descriptive name, like fix-login-bug or add-user-profile-page.

Commit Your Changes

  • Commit your changes with a clear commit message. e.g git commit -m "Fix login bug by updating auth logic".

Submit a Pull Request

  • Push your branch and changes to your fork on GitHub.
  • Create a pull request, compare branches and submit.
  • Provide a detailed description of what changes you've made and why. Link the pull request to the issue it resolves. πŸ”—

Review and Merge

  • I will review your pull request and provide feedback or request changes if necessary.
  • Once your pull request is approved, we will merge it into the main codebase πŸ₯³

$~$

πŸ§‘β€πŸ€β€πŸ§‘ Meet the Author

Author

πŸ“§ Contact


rrs00179 rohan-sharma=9386


Thank you for visting this Repo
If you like it, star ⭐ it

About

Developed a Recipe Webapp where users' karma and location affect their permissions to perform operations.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published