A secure file storage and key-value API with namespace-based access control and API key authentication.
- Namespace-based data isolation: Separate data by namespaces (public, user-specific, admin)
- Role-based access control: ReadOnly, ReadWrite, and Admin roles
- API Key authentication: Secure API access with database-stored keys
- Public read access: Allow public GET requests to 'public' namespace
- File storage: Upload, download, and manage files with namespace isolation
- Entity Framework Core: SQLite database with migrations
- RESTful API: Full CRUD operations for both key-value pairs and files
- Monorepo structure: CoreVault.API (main application) + CoreVault.Shared (common library)
- Middleware: API key validation and namespace access control
- Controllers: RESTful endpoints with authorization
- Models: KeyValueItem, ApiKey, and FileStorage entities
- Database: SQLite with Entity Framework Core
- Docker support: Multi-stage Dockerfile for containerized deployment
- .NET 9.0 SDK
- SQLite
- Docker (optional, for containerized deployment)
- Clone the repository
- Copy
appsettings.Example.jsontoappsettings.json - Configure your database connection string
- Run migrations:
dotnet ef database update --project src/CoreVault.API
- Start the API:
dotnet run --project src/CoreVault.API
- Build the image:
docker build -t corevault-api . - Run the container:
docker run -p 8080:8080 corevault-api
# Get all public data
curl http://localhost:8080/api/kv/keyvalue
# Get specific public item
curl http://localhost:8080/api/kv/keyvalue/public/welcome# Get data from specific namespace
curl -H "X-Api-Key: your-api-key" http://localhost:8080/api/kv/keyvalue?namespace=user123
# Create new item
curl -X POST -H "X-Api-Key: your-api-key" -H "Content-Type: application/json" \
-d '{"namespace":"user123","key":"test","value":"data"}' \
http://localhost:8080/api/kv/keyvalue
# Update item
curl -X PUT -H "X-Api-Key: your-api-key" -H "Content-Type: application/json" \
-d 'new value' \
http://localhost:8080/api/kv/keyvalue/user123/test
# Delete item
curl -X DELETE -H "X-Api-Key: your-api-key" \
http://localhost:8080/api/kv/keyvalue/user123/testcurl -X POST -H "X-Api-Key: your-api-key" \
-F "file=@/path/to/your/file.jpg" \
-F "namespace=user123" \
-F "description=My profile picture" \
http://localhost:8080/api/storage/file/upload# Get all files in namespace
curl -H "X-Api-Key: your-api-key" \
http://localhost:8080/api/storage/file?namespace=user123# Download by ID
curl -H "X-Api-Key: your-api-key" \
http://localhost:8080/api/storage/file/{file-id}/download
# View file metadata
curl -H "X-Api-Key: your-api-key" \
http://localhost:8080/api/storage/file/{file-id}curl -X DELETE -H "X-Api-Key: your-api-key" \
http://localhost:8080/api/storage/file/{file-id}API keys are stored in the database with the following structure:
- Key: Unique API key string
- Role: ReadOnly (0), ReadWrite (1), or Admin (2)
- AllowedNamespaces: Comma-separated list of accessible namespaces
- Admin: Full access to all namespaces
- User: Access to specific namespaces only
- Public: Read-only access to public namespace
- API key validation for write operations
- Namespace-based data isolation
- Role-based permissions
- Public read access for non-sensitive data
- Configuration files excluded from version control
- File hash verification (SHA-256) for integrity
- KeyValueItems: Stores key-value data with namespace support
- ApiKeys: Stores API keys with permissions
- FileStorage: Stores file metadata with namespace isolation
- Run migrations:
dotnet ef database update --project src/CoreVault.API - Create new migration:
dotnet ef migrations add MigrationName --project src/CoreVault.API - Run tests:
dotnet test tests/CoreVault.Tests - Generate API key: Use admin endpoint or database seeding
The project includes comprehensive test coverage:
- Unit tests for business logic
- Integration tests for API endpoints
- Test coverage reporting with codecov
- Configure environment variables for production
- Use secure key management (Azure Key Vault, etc.)
- Set up proper logging and monitoring
- Docker containerization support
- Port 8080 for HTTP traffic
The application uses the following configuration structure:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=corevault.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"FileStorage": {
"UploadPath": "uploads"
}
}MIT License