This repository demonstrates the implementation of Attribute-Based Access Control (ABAC) in a Golang-based document management system using Permify.
The Golang ABAC Demo is an internal document management system that illustrates how ABAC can provide granular and dynamic access control based on various attributes such as user roles, department, document classification, and more. The backend is built with Golang, and Permify is used to manage ABAC policies and evaluations.
- User authentication and authorization
- Document upload, view, edit, and delete functionalities
- Granular access control using ABAC with Permify
- Middleware for access checks
- Logging of all requests
- Go 1.16+
- Docker
-
Clone the repository
git clone https://github.com/TropicolX/golang-abac-demo.git cd golang-abac-demo
-
Set up Permify
Run the Permify Docker container:
docker run -p 3476:3476 -p 3478:3478 ghcr.io/permify/permify serve
-
Install Go dependencies
go mod tidy
-
Start the server
go run cmd/server/main.go
-
Verify the setup
Access the API endpoints using a tool like Postman or cURL.
- POST /login: User login
- POST /api/documents: Upload a document
- GET /api/documents/{id}: View a document
- PUT /api/documents/{id}: Edit a document
- DELETE /api/documents/{id}: Delete a document
Login
curl -X POST http://localhost:8080/login \
-H "Content-Type: application/json" \
-d '{
"username": "user",
"password": "password"
}'
Upload Document
curl -X POST http://localhost:8080/api/documents \
-H "Authorization: Bearer <your-token>" \
-H "Content-Type: application/json" \
-d '{
"title": "Sample Document",
"content": "This is a sample document.",
"classification": "internal",
"department": "IT"
}'
View Document
curl -X GET http://localhost:8080/api/documents/<document-id> \
-H "Authorization: Bearer <your-token>"
Edit Document
curl -X PUT http://localhost:8080/api/documents/<document-id> \
-H "Authorization: Bearer <your-token>" \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Document Title",
"content": "Updated content."
}'
Delete Document
curl -X DELETE http://localhost:8080/api/documents/<document-id> \
-H "Authorization: Bearer <your-token>"