cservice-api

module
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2025 License: MIT

README ΒΆ

Channel Services API

CI Codacy Badge Codacy Badge

A modern, RESTful API service for IRC Channel Services management, providing secure authentication, channel registration, user management, and administrative functions for IRC networks.

Warning

THIS IS A WORK IN PROGRESS. The API is not stable and may change at any time. DO NOT USE IN PRODUCTION.

Table of Contents

Overview

What is Channel Services API?

The Channel Services API is a Go-based RESTful service that modernizes IRC channel management operations. It provides:

  • User Authentication: JWT-based authentication with RSA key support
  • Channel Management: Registration, configuration, and administrative controls
  • User Management: Account creation, password resets, and profile management
  • Administrative Tools: Role-based access control and system administration
  • 2FA Support: TOTP and backup code authentication
  • Rate Limiting: Protection against abuse and spam
  • Comprehensive Logging: Audit trails and monitoring capabilities
Key Features
  • πŸ” Secure Authentication: RSA-signed JWT tokens with refresh token support
  • πŸ“Š Comprehensive Metrics: OpenTelemetry integration for monitoring
  • πŸ›‘οΈ Security First: Input validation, SQL injection protection, rate limiting
  • πŸ—οΈ Clean Architecture: Modular design with dependency injection
  • πŸ“ Extensive Testing: Unit and integration tests with high coverage
  • 🐳 Docker Ready: Complete containerization with docker-compose
  • πŸ“– API Documentation: Interactive Swagger/OpenAPI documentation
  • πŸ”„ Channel Manager Change: Secure workflow for transferring channel ownership with email confirmation

Quick Start

Get the API running in under 5 minutes:

# Clone the repository
git clone https://github.com/UndernetIRC/cservice-api.git
cd cservice-api

# Start services with Docker
docker-compose up -d

# The API will be available at http://localhost:8080
# API docs at http://localhost:8080/docs
# Mailpit (email testing) at http://localhost:8025

For detailed development setup, see docs/DEVELOPMENT.md.

Requirements

Runtime Requirements
  • Go >= 1.24 (for compiling)
  • PostgreSQL >= 11.0 (for running)
  • Valkey (opensource Redis alternative)
Development Tools
  • migrate - Database migrations
  • sqlc - Type-safe SQL code generation
  • air - Live reload for development
Supported Platforms
  • Linux (amd64, arm64)
  • FreeBSD (amd64)
  • macOS (Intel, Apple Silicon)
  • Windows (amd64)
  • Docker containers

Configuration

The API can be configured using either a YAML configuration file or environment variables. Environment variables take precedence over the configuration file.

Quick Configuration
# Copy example configuration
cp config.yml.example config.yml

# Generate JWT keys
openssl genrsa -out access_jwt.key 4096
openssl rsa -in access_jwt.key -pubout -out access_jwt.pub
openssl genrsa -out refresh_jwt.key 4096
openssl rsa -in refresh_jwt.key -pubout -out refresh_jwt.pub
Environment Variables

All configuration options can be set using environment variables following the pattern:

CSERVICE_<SECTION>_<KEY>

Example:

# Server configuration
export CSERVICE_SERVICE_HOST=localhost
export CSERVICE_SERVICE_PORT=8080

# Database configuration
export CSERVICE_DATABASE_HOST=localhost
export CSERVICE_DATABASE_PORT=5432
export CSERVICE_DATABASE_USERNAME=cservice
export CSERVICE_DATABASE_PASSWORD=cservice
export CSERVICE_DATABASE_NAME=cservice
JWT Configuration

Configure JWT in config.yml:

jwt:
    signing_method: "RS256"
    signing_key: /path/to/access_jwt.key
    public_key: /path/to/access_jwt.pub
    refresh_signing_key: /path/to/refresh_jwt.key
    refresh_public_key: /path/to/refresh_jwt.pub

The JWKS endpoint is available at /.well-known/jwks.json (RS256 only).

Docker Setup

Quick Start with Docker Compose
# Start all services
docker-compose up -d

# View logs
docker-compose logs -f api

# Stop services
docker-compose down
Services Included
  • API Service: The main Channel Services API (port 8080)
  • PostgreSQL: Database server (port 5432)
  • Valkey: Redis-compatible cache (port 6379)
  • Mailpit: Email testing interface (ports 1025/8025)

API Documentation

The API provides comprehensive documentation and testing tools:

Interactive Documentation
  • Swagger UI: http://localhost:8080/docs - Interactive API explorer with request/response examples
  • OpenAPI Spec: http://localhost:8080/docs/swagger.json - Machine-readable API specification
  • JWKS Endpoint: http://localhost:8080/.well-known/jwks.json - JWT public keys for token verification
Testing Tools

Postman Collection: A complete Postman collection is available in docs/postman/ covering all API endpoints and workflows:

  • Authentication (JWT and API keys)
  • User management
  • Channel operations
  • Administrative functions
  • 2FA and password reset flows

Quick Start:

  1. Import docs/postman/Complete-API.postman_collection.json into Postman
  2. Configure environment variables (baseUrl, username, password)
  3. Run requests with automatic token management

See docs/postman/README.md for detailed usage instructions.

Security

Security Features
Authentication & Authorization
  • JWT Tokens: RSA-256 signed tokens with configurable expiration
  • Refresh Tokens: Secure token renewal without password re-entry
  • 2FA Support: TOTP (Time-based One-Time Password) implementation
  • Backup Codes: Bcrypt-hashed backup authentication codes
  • Role-Based Access: Granular permission system for administrative functions
Data Protection
  • Password Hashing: bcrypt with configurable cost factor for passwords and backup codes
  • SQL Injection Prevention: Type-safe queries via sqlc
  • Input Sanitization: Comprehensive validation and sanitization
  • HTTPS Enforcement: TLS termination at reverse proxy level
Operational Security
  • Rate Limiting: Configurable per-user and per-endpoint limits
  • Audit Logging: Comprehensive security event logging
  • IP Restrictions: Configurable IP-based access controls
  • Session Management: Secure session handling with proper invalidation
Security Best Practices
JWT Configuration
# Generate secure RSA keys
openssl genrsa -out access_jwt.key 4096
openssl rsa -in access_jwt.key -pubout -out access_jwt.pub

# Set appropriate permissions
chmod 600 access_jwt.key
chmod 644 access_jwt.pub
Environment Security
# Use strong, unique passwords
export CSERVICE_DATABASE_PASSWORD="$(openssl rand -base64 32)"
export CSERVICE_REDIS_PASSWORD="$(openssl rand -base64 32)"

# Restrict file permissions
chmod 600 .env
chmod 600 config.yml

For more security guidelines, see the Security section in docs/DEVELOPMENT.md.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for detailed guidelines on:

  • Development workflow
  • Coding standards
  • Testing requirements
  • Pull request process
  • Reporting issues

Quick Start:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes following our coding standards
  4. Run tests: make test && make integration-test && make lint
  5. Submit a pull request

For detailed development setup, see docs/DEVELOPMENT.md.

Additional Documentation

Developer Resources
Feature Documentation
Testing & Integration
  • Integration Tests: Located in integration/ directory with database-backed tests
  • API Documentation: Interactive Swagger UI at /docs endpoint when server is running

License

This project is licensed under the MIT License - see the LICENSE file for details.

Directories ΒΆ

Path Synopsis
cmd
cservice-api command
Package controllers provides the controllers for the API
Package controllers provides the controllers for the API
admin
Package admin defines the admin controllers.
Package admin defines the admin controllers.
db
Package db defines the database types and functions.
Package db defines the database types and functions.
types/flags
Package flags contains all the bitmask based flags used in the database.
Package flags contains all the bitmask based flags used in the database.
internal
auth/oath/totp
Package totp provides a time-based one-time password (TOTP) implementation.
Package totp provides a time-based one-time password (TOTP) implementation.
auth/password
Package password provides password hashing and validation.
Package password provides password hashing and validation.
auth/reset
Package reset provides password reset token management functionality
Package reset provides password reset token management functionality
checks
Package checks contains functions intended for Is, Has, etc.
Package checks contains functions intended for Is, Has, etc.
config
Package config provides configuration management
Package config provides configuration management
cron
Package cron provides cron job scheduling using the robfig/cron library
Package cron provides cron job scheduling using the robfig/cron library
docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
errors
Package errors provides consistent error handling and response formatting for the API
Package errors provides consistent error handling and response formatting for the API
globals
Package globals contains global variables and functions
Package globals contains global variables and functions
helper
Package helper provides helper functions for channel registration validation
Package helper provides helper functions for channel registration validation
jwks
Package jwks provides functions for generating a JWKS
Package jwks provides functions for generating a JWKS
mail
Package mail provides a mail service
Package mail provides a mail service
metrics
Package metrics provides authentication-specific metrics collection
Package metrics provides authentication-specific metrics collection
ratelimit
Package ratelimit provides rate limiting functionality using Redis
Package ratelimit provides rate limiting functionality using Redis
telemetry
Package telemetry provides OpenTelemetry initialization and management
Package telemetry provides OpenTelemetry initialization and management
testutils
Package testutils provides shared unit test functions
Package testutils provides shared unit test functions
tracing
Package tracing provides business-specific distributed tracing utilities
Package tracing provides business-specific distributed tracing utilities
Package middlewares provides HTTP middleware for business metrics collection
Package middlewares provides HTTP middleware for business metrics collection
Package models contains the database models
Package models contains the database models
Package routes defines the routes for the echo server.
Package routes defines the routes for the echo server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL