Access Granted!! Here's the recipe behind my AI DMS

简介: 这是一个基于Next.js的文档管理项目,展示如何通过Permit.io为用户和AI代理实现细粒度授权。用户可基于角色(管理员、编辑者、查看者)及文档所有权进行增删改查操作,AI代理则根据权限级别(无访问、只读、建议、完全访问)协助文档管理。项目包含文档分析、摘要生成和内容优化等AI功能,并支持审批工作流与操作审计。相比前作,本项目功能更强大,配置更灵活,感谢Permit.io简化策略创建流程。源码与文档已开源,欢迎体验并反馈!

Hey there,
Welcome back! This is my 2nd entry for the Permit.io Authorization Challenge. (If you want to see the 1st one, here's the link: https://dev.to/rohan_sharma/access-control-handled-heres-how-i-built-my-dms-212)

This project is not different than the last one. It's still a document management system, but it now has more powerful features and configurations.//..

Welcome to Radhika's AI DocManager
logo

This project demonstrates how to implement fine-grained authorization for both users and AI agents in a Next.js application using Permit.io. It's a document management system where users can create, view, edit, and delete documents based on their roles and document ownership, and AI agents can assist with document management based on their assigned permissions.

Features
1️⃣ User Authorization
Role-Based Access Control (RBAC): Different roles (Admin, Editor, Viewer) have different permissions
Attribute-Based Access Control (ABAC): Document owners have special privileges
Fine-Grained Authorization: Using Permit.io to implement complex authorization rules
2️⃣ AI Authorization
AI Agent Roles: Define different AI agent roles with specific capabilities
Permission Levels: Configure what AI agents can access and modify
No Access: AI agent cannot access the resource at all
Read Only: AI agent can only read but not modify resources
Suggest Only: AI can suggest changes that require human approval
Full Access: AI has full access to read and modify resources
Approval Workflows: Require human approval for sensitive AI operations
Audit and Monitoring: Track all AI actions and approvals
3️⃣ Document Intelligence
Document Analysis: AI-powered analysis of document content and structure
Document Summarization: Generate concise summaries of documents
Content Improvement: AI suggestions for improving document content

Demo

Project Repo
Github Repo: https://github.com/RS-labhub/AI_DOCUMENT_MANAGEMENT_SYSTEM

Documentation: https://rs-labhub.github.io/AI_DOCUMENT_MANAGEMENT_SYSTEM/

My Journey
As said in the last blog, it was quite difficult to create a DMS or document management system, as there are so many brainstorming behind this.

Anyway, thanks to Permit.io for saving a lot of my time while creating policies. It's easy to use and enough to say goodbye to the old methods where we die while writing the code.

I used Permit.io to achieve these things:

Role-Based Access Control or RBAC
Attribute-Based Access Control or ABAC
Also, implemented the roles the AI should have. Here's both RBAC and ABAC are used. I used GROQ Cloud for fast LLM inference and OpenAI compatibility.

Overall, it was a fun experience building this project, and I enjoyed building it.

If you want to see the whole implementation of the Permit.io, please read the project Readme file!

Authorization for AI Applications with Permit.io
landing page

Authorization Model
User Authorization
The application implements the following user authorization model:

Admin: Can create, view, edit, and delete any document, and access the admin panel
Editor: Can create, view, and edit documents, but can only delete their own documents
Viewer: Can only view documents
Additionally, document owners have full control over their own documents regardless of their role.

AI Authorization
ai authz

The application implements the following AI authorization model:

AI Agent Roles:

Assistant: Helps with document organization and basic tasks
Editor: Can edit and improve document content
Analyzer: Analyzes document content and provides insights
AI Capabilities:

read_documents: Ability to read document content
suggest_edits: Ability to suggest edits to documents
edit_documents: Ability to directly edit documents
create_documents: Ability to create new documents
delete_documents: Ability to delete documents
analyze_content: Ability to analyze document content
summarize_content: Ability to summarize documents
translate_content: Ability to translate documents
generate_content: Ability to generate new content
Permission Levels:

NO_ACCESS: AI agent cannot access the resource at all
READ_ONLY: AI agent can only read but not modify resources
SUGGEST_ONLY: AI can suggest changes that require human approval
FULL_ACCESS: AI has full access to read and modify resources

Implementation Details
AI Authorization Implementation
The application implements AI authorization through several key components:

  1. AI Agent Management
    The AIAgent interface defines the structure of AI agents:

export interface AIAgent {
id: string;
name: string;
description: string;
role: AIAgentRole;
capabilities: AICapability[];
createdBy: string;
createdAt: string;
updatedAt: string;
isActive: boolean;
}
Administrators can manage AI agents through the admin panel, defining their roles and capabilities.

  1. Permission Levels
    The AIPermissionLevel enum defines the different levels of access that AI agents can have:

export enum AIPermissionLevel {
NO_ACCESS = "no_access",
READ_ONLY = "read_only",
SUGGEST_ONLY = "suggest_only",
FULL_ACCESS = "full_access",
}

  1. AI Actions
    The AIAction interface defines the structure of actions that AI agents can perform:

export interface AIAction {
id: string;
agentId: string;
actionType: string;
resourceType: string;
resourceId: string;
status: AIActionStatus;
requestedAt: string;
completedAt?: string;
requestedBy: string;
approvedBy?: string;
rejectedBy?: string;
metadata: Record;
result?: any;
}

  1. Permission Checking
    The checkAIPermission function checks if an AI agent has permission to perform an action:

export function checkAIPermission(
agentId: string,
action: string,
resourceType: string,
resourceId?: string
): {
permitted: boolean;
requiresApproval: boolean;
permissionLevel: AIPermissionLevel;
} {
// Implementation details...
}

  1. Approval Workflow
    The application implements an approval workflow for AI actions that require human oversight:

export async function requestAIAction(
agentId: string,
actionType: string,
resourceType: string,
resourceId: string,
documentTitle: string,
documentContent: string,
metadata: Record
): Promise<{ success: boolean; action?: AIAction; message?: string }> {
// Implementation details...
}

export async function approveAIAction(
actionId: string,
userId: string
): Promise<{ success: boolean; action?: AIAction; message?: string }> {
// Implementation details...
}

export async function rejectAIAction(
actionId: string,
userId: string,
reason?: string
): Promise<{ success: boolean; action?: AIAction; message?: string }> {
// Implementation details...
}
Integration with Permit.io
The application integrates with Permit.io through the permit.ts file, which provides functions for checking permissions:

import { Permit } from 'permitio';

// Initialize Permit SDK
const permit = new Permit({
pdp: process.env.PERMIT_PDP_URL,
token: process.env.PERMIT_SDK_TOKEN,
});

// Check if a user can perform an action on a resource
export async function checkPermission(
userId: string,
action: string,
resourceType: string,
resourceAttributes: Record = {}
): Promise {
try {
const permitted = await permit.check(userId, action, {
type: resourceType,
...resourceAttributes,
});
return permitted;
} catch (error) {
console.error('Permission check failed:', error);
return false;
}
}

Conclusion
This project demonstrates how to implement fine-grained authorization for both users and AI agents in a Next.js application using Permit.io. By externalizing authorization, we can create more secure, maintainable, and flexible applications that can safely leverage AI capabilities while maintaining appropriate controls.

Please try to run it locally on your machine and let me know the feedback!

Thank you for taking your time to read this blog. I hope you enjoyed it. Your support means the world to me.

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
相关文章
|
人工智能 关系型数据库 分布式数据库
拥抱Data+AI|“全球第一”雅迪如何实现智能营销?DMS+PolarDB注入数据新活力
针对雅迪“云销通App”的需求与痛点,本文将介绍阿里云瑶池数据库DMS+PolarDB for AI提供的一站式Data+AI解决方案,助力销售人员高效用数,全面提升销售管理效率。
|
8月前
|
人工智能 分布式计算 数据管理
DMS+X:GenAI 时代的一站式 Data+AI 平台
在AI技术快速发展的背景下,阿里云DMS + X平台应运而生,通过OneMeta和OneOps两大创新,提供统一元数据服务及一体化Data + AI开发环境。文章详细介绍了DMS + X在数据治理、开发提效及实际案例中的应用,助力企业在GenAI时代实现数字化转型。
|
人工智能 数据挖掘 数据库
拥抱Data+AI|破解电商7大挑战,DMS+AnalyticDB助力企业智能决策
本文为数据库「拥抱Data+AI」系列连载第1篇,该系列是阿里云瑶池数据库面向各行业Data+AI应用场景,基于真实客户案例&最佳实践,展示Data+AI行业解决方案的连载文章。本篇内容针对电商行业痛点,将深入探讨如何利用数据与AI技术以及数据分析方法论,为电商行业注入新的活力与效能。
拥抱Data+AI|破解电商7大挑战,DMS+AnalyticDB助力企业智能决策
|
10月前
|
人工智能 自然语言处理 关系型数据库
DMS+AnalyticDB助力钉钉AI助理,轻松玩转智能问数
DMS+AnalyticDB助力钉钉AI助理,轻松玩转智能问数
408 3
|
11月前
|
SQL 存储 人工智能
DMS+X构建Gen-AI时代的一站式Data+AI平台
本文整理自阿里云数据库团队Analytic DB、PostgreSQL产品及生态工具负责人周文超和龙城的分享,主要介绍Gen-AI时代的一站式Data+AI平台DMS+X。 本次分享的内容主要分为以下几个部分: 1.发布背景介绍 2.DMS重磅发布:OneMeta 3.DMS重磅发布:OneOps 4.DMS+X最佳实践,助力企业客户实现产业智能化升级
722 3
DMS+X构建Gen-AI时代的一站式Data+AI平台
|
12月前
|
人工智能 数据库 自然语言处理
拥抱Data+AI|DMS+AnalyticDB助力钉钉AI助理,轻松玩转智能问数
「拥抱Data+AI」系列文章由阿里云瑶池数据库推出,基于真实客户案例,展示Data+AI行业解决方案。本文通过钉钉AI助理的实际应用,探讨如何利用阿里云Data+AI解决方案实现智能问数服务,使每个人都能拥有专属数据分析师,显著提升数据查询和分析效率。点击阅读详情。
拥抱Data+AI|DMS+AnalyticDB助力钉钉AI助理,轻松玩转智能问数
|
存储 人工智能 自然语言处理
拥抱Data+AI|B站引入阿里云DMS+X,利用AI赋能运营效率10倍提升
本篇文章针对B站在运营场景中的痛点,深入探讨如何利用阿里云Data+AI解决方案实现智能问数服务,赋能平台用户和运营人员提升自助取数和分析能力,提高价值交付效率的同时为数据平台减负。
拥抱Data+AI|B站引入阿里云DMS+X,利用AI赋能运营效率10倍提升
|
10月前
|
人工智能 数据管理 数据库
Data+AI用户体验升级,阿里云「DMS+UX」焕醒数智一体化新体验
Data+AI用户体验升级,阿里云「DMS+UX」焕醒数智一体化新体验
324 0
|
人工智能 数据库 决策智能
拥抱Data+AI|如何破解电商7大挑战?DMS+AnalyticDB助力企业智能决策
本文为阿里云瑶池数据库「拥抱Data+AI」系列连载第1篇,聚焦电商行业痛点,探讨如何利用数据与AI技术及分析方法论,为电商注入新活力与效能。文中详细介绍了阿里云Data+AI解决方案,涵盖Zero-ETL、实时在线分析、混合负载资源隔离、长周期数据归档等关键技术,帮助企业应对数据在线重刷、实时分析、成本优化等挑战,实现智能化转型。
拥抱Data+AI|如何破解电商7大挑战?DMS+AnalyticDB助力企业智能决策
|
11月前
|
SQL 人工智能 数据管理
跨云数据管理平台DMS:构建Data+AI的企业智能Data Mesh
跨云数据管理平台DMS助力企业构建智能Data Mesh,实现Data+AI的统一管理。DMS提供开放式元数据服务OneMeta、一站式智能开发平台和云原生AI数据平台,支持多模数据管理和高效的数据处理。结合PolarDB、AnalyticDB等核心引擎,DMS在多个垂直场景中展现出显著优势,如智能营销和向量搜索,提升业务效率和准确性。通过DataOps和MLOps的融合,DMS为企业提供了从数据到AI模型的全生命周期管理,推动数据驱动的业务创新。
781 0