A Go microservice for managing user accounts and authentication. Provides REST API endpoints for account lifecycle operations, social provider management, and role-based access control (RBAC). Built with Echo web framework and MongoDB.
Version: v0.2.0
Go Version: 1.24.0+
Module: github.com/latebit-io/bulwarkauthadmin
- Installation
- Running the Service
- Environment Variables
- API Documentation
- Architecture
- API Endpoints
- Development
- Testing
- Go 1.24.0 or later - Download Go
- MongoDB 4.0+ - For database backend
- Docker (optional) - For containerized MongoDB
git clone https://github.com/latebit-io/bulwarkauthadmin.git
cd bulwarkauthadmingo mod download
go mod verifygo build -o bulwarkauthadmin cmd/bulwarkauthadmin/main.go# Start MongoDB
docker-compose -f docker-compose.test.yml up -d
# Verify MongoDB is running
docker-compose -f docker-compose.test.yml logs mongodb
# Stop MongoDB
docker-compose -f docker-compose.test.yml down
# Remove volumes (clean slate)
docker-compose -f docker-compose.test.yml down -vEnsure MongoDB is running on localhost:27017 (or configure DB_CONNECTION accordingly).
Create a .env file in cmd/bulwarkauthadmin/ or set environment variables. See Environment Variables for details.
# Copy the default .env file
cp cmd/bulwarkauthadmin/.env cmd/bulwarkauthadmin/.env.local
# Edit configuration as needed
# nano cmd/bulwarkauthadmin/.env.localgo run cmd/bulwarkauthadmin/main.go./bulwarkauthadminThe service will start and output:
⇨ http server started on [::]:8081
By default, the service runs on http://localhost:8081.
# Health check
curl http://localhost:8081/api/v1/healthConfigure the service behavior using the following environment variables:
| Variable | Type | Default | Description |
|---|---|---|---|
PORT |
int | 8081 |
Server port to listen on |
BULWARK_AUTH_URL |
string | http://localhost:8080 |
BulwarkAuth service URL |
| Variable | Type | Default | Description |
|---|---|---|---|
DB_CONNECTION |
string | mongodb://localhost:27017/?connect=direct |
MongoDB connection string |
DB_NAME_SEED |
string | `` (empty) | Optional database name suffix (e.g., test creates bulwarkauthtest) |
| Variable | Type | Default | Description |
|---|---|---|---|
CORS_ENABLED |
bool | false |
Enable Cross-Origin Resource Sharing |
ALLOWED_WEB_ORIGINS |
string | http://localhost:5173 |
Comma-separated list of allowed origins (e.g., http://localhost:5173,https://example.com) |
ADMIN_ACCOUNT and ADMIN_ACCOUNT_PASSWORD from the environment and any configuration files or deployment manifests.
| Variable | Type | Default | Description |
|---|---|---|---|
ADMIN_ACCOUNT |
string | `` (empty) | Email address for the initial admin account |
ADMIN_ACCOUNT_PASSWORD |
string | `` (empty) | Password for the initial admin account |
| Variable | Type | Default | Description |
|---|---|---|---|
EMAIL_TEMPLATES_DIR |
string | `` (empty) | Directory path containing email templates. When empty (the default), templates are loaded from the current working directory. If a custom path is provided, it must include a trailing slash (e.g., /path/to/templates/). In Docker deployments, templates are pre-installed at /app/, so this variable typically does not need to be set. |
# Server
PORT=8081
BULWARK_AUTH_URL=http://localhost:8080
# Database
DB_CONNECTION=mongodb://localhost:27017/?connect=direct
DB_NAME_SEED=
# CORS
CORS_ENABLED=false
ALLOWED_WEB_ORIGINS=http://localhost:5173,http://localhost:3000
# Initial Admin (REMOVE AFTER FIRST STARTUP)
ADMIN_ACCOUNT=admin@example.com
ADMIN_ACCOUNT_PASSWORD=SecurePassword123!
# Email Templates
EMAIL_TEMPLATES_DIR=/path/to/email/templates/Place a .env file in the working directory when running the service:
go run cmd/bulwarkauthadmin/main.goexport PORT=8080
export DB_CONNECTION=mongodb://mongodb.example.com:27017/?connect=direct
export CORS_ENABLED=true
go run cmd/bulwarkauthadmin/main.goPORT=8080 DB_CONNECTION=mongodb://localhost:27017 go run cmd/bulwarkauthadmin/main.goThe complete REST API is documented in OpenAPI 3.0 format:
- Specification file:
openapi.yaml - Quick start guide:
API.md- Common workflows and examples
Online viewers (copy-paste the spec):
- Swagger UI Editor - Paste contents of
openapi.yaml - ReDoc - Upload
openapi.yaml
Local viewers:
- Visual Studio Code with OpenAPI extension
- Postman - Import
openapi.yaml - Insomnia - Import
openapi.yaml
# Health check (no auth required)
curl http://localhost:8081/api/v1/health
# List tenants (requires system admin token)
curl -H "Authorization: Bearer <token>" \
http://localhost:8081/api/v1/admin/tenants
# List accounts in tenant (requires tenant admin token)
curl -H "Authorization: Bearer <token>" \
http://localhost:8081/api/v1/tenant/{tenantId}/accountsSee API.md for detailed workflows and examples.
This service follows a layered architecture with clear separation of concerns:
HTTP Layer (api/)
↓
Service Layer (internal/*/accounts.go - business logic)
↓
Repository Layer (internal/*/mongodb_*_repository.go - data access)
↓
MongoDB Database
BulwarkAuthAdmin and BulwarkAuth share the same MongoDB database. This is a critical architectural decision:
- Accounts are stored in the shared database with roles and permissions fields
- JWT tokens issued by BulwarkAuth include roles from the account document in the shared database
- Role assignments made by BulwarkAuthAdmin are immediately reflected in accounts, affecting future JWT issuance
- Current JWTs won't update - only NEW authentications get updated JWTs
- Anemic Models: Data structures are separate from business logic
- Service Layer: Business-oriented method names (
RegisterAccount,GrantPermissionsToRole) - Repository Layer: Technical CRUD terms (
Create,Read,Update,Delete) - Natural Keys for RBAC: Roles and Permissions use names as primary keys (immutable)
- Soft Deletes: Accounts use soft delete flag by default
All routes are under /api/v1/ prefix.
Base: /api/v1/tenant/:tenantid/accounts
POST /accounts- Register new accountGET /accounts- List accounts (paginated)GET /accounts/:id- Get account detailsPUT /accounts/email- Change emailPUT /accounts/disable- Disable accountPUT /accounts/enable- Enable accountPUT /accounts/deactivate- Soft delete accountPUT /accounts/unlink- Unlink social provider
Base: /api/v1/tenant/:tenantid/accounts/:id/apikeys
POST /accounts/:id/apikeys- Generate new API key (returns plaintext key once)GET /accounts/:id/apikeys- List all API keys for accountGET /accounts/:id/apikeys/:apiKeyID- Get API key detailsPUT /accounts/:id/apikeys/:apiKeyID/suspend- Suspend API keyPUT /accounts/:id/apikeys/:apiKeyID/enable- Enable API keyDELETE /accounts/:id/apikeys/:apiKeyID- Revoke (delete) API key
Base: /api/v1/tenant/:tenantid/rbac
POST /roles- Create roleGET /roles- List rolesGET /roles/:name- Get role detailsPUT /roles/:name- Update roleDELETE /roles/:name- Delete rolePOST /permissions- Create permissionGET /permissions- List permissionsDELETE /permissions/:name- Delete permission
Base: /api/v1/admin/tenants (requires system admin role)
POST /tenants- Create tenantGET /tenants- List tenantsGET /tenants/:id- Get tenant detailsPUT /tenants/:id- Update tenantDELETE /tenants/:id- Delete tenant
GET /health- Health check endpoint
api/ # HTTP handlers and routes
accounts/ # Account management endpoints
apikey/ # API key management endpoints
health/ # Health check endpoint
problem/ # RFC 7807 problem details (errors)
rbac/ # RBAC endpoints
tenants/ # Tenant management endpoints
internal/ # Business logic and data access
accounts/ # Account domain
apikey/ # API key domain
rbac/ # RBAC domain
tenants/ # Tenant domain
email/ # Email template management
shared/ # Common utilities
utils/ # Test utilities
version/ # Version info
middleware/ # JWT and tenant middleware
cmd/bulwarkauthadmin/ # Application entry point
main.go # Service initialization
config.go # Configuration management
.env # Default environment variables
tests/integration/ # Integration tests
Run all unit tests (no external dependencies):
go test -v ./internal/...
go test -v -cover ./internal/...Integration tests require MongoDB, BulwarkAuth, and MailHog running. The easiest way is with the provided script:
# Run all integration tests (starts services, runs tests, cleans up)
./run-integration-tests.sh
# Run specific domain tests
go test -v -tags=integration ./tests/integration/accounts
go test -v -tags=integration ./tests/integration/rbac
go test -v -tags=integration ./tests/integration/tenants
# Run specific test
go test -v -tags=integration -run TestAccountHandler_RegisterAccount ./tests/integration/accountsSee tests/integration/README.md for manual setup and troubleshooting.
golangci-lint rungo build -o bulwarkauthadmin cmd/bulwarkauthadmin/main.goRequires Docker:
goreleaser release --snapshot --cleanSee the project's CLAUDE.md for architectural guidelines and coding conventions.
Proprietary - Bulwark Auth Admin