Cosmos Server

repository·master·Indexed 26 days ago

https://github.com/azukaar/cosmos-server

A secure gateway and server manager for self-hosting applications on servers, NAS, or Raspberry Pi. It provides a unified interface for container management, reverse-proxy with automatic HTTPS via Let's Encrypt, authentication, storage management, and security via SmartShield. The system includes a JavaScript/TypeScript SDK (cosmos-cloud-sdk), a Go SDK, and a Terraform provider for programmatic API access and infrastructure automation.

Tokens
11.8K
Snippets
19
Records
85
Agent score
91%

What's inside cosmos-server

  1. Overview of SmartShield API protection

    master

    SmartShield is an API protection package that implements advanced rate-limiting and user restrictions to secure your APIs.

    Key features include:

    • Dynamic Rate Limiting: Calculates limits based on user behavior.
    • Adaptive Actions: Automatically throttles users exceeding limits.
    • User Bans & Strikes: Automatically issues strikes or bans to prevent abuse.
    • Global Request Control: Limits total simultaneous requests via queues.
    • User-based Metrics: Tracks requests, data usage, and simultaneous connections per user.
    • Privileged Access: Allows specific user groups to bypass certain restrictions.
    • Customizable Policies: Allows modification of request limits and time budgets.
  2. Overview of Cosmos Server features

    master

    Cosmos is a secure gateway and server manager designed for self-hosting applications on servers, NAS, or Raspberry Pi. It provides a centralized web UI to manage applications, security, and infrastructure.

    Key capabilities include:

    • App Store: Install and manage applications with automatic updates and security checks. Supports manual methods like importing docker-compose files or using the Docker CLI.
    • Container Manager: Manage containers, settings, and security audits, including docker-compose support.
    • Reverse-Proxy: Targets containers, other servers, or static folders/SPAs with automatic HTTPS.
    • Authentication & Identity: Acts as an Authentication Server with multi-factor authentication (MFA) and multiple strategies (OpenId, forward headers, HTML). It also serves as an Identity Provider to manage users and invites.
    • Storage Management: Manages local disks (Parity Disks, MergerFS) and network storages (RClone-based, including Dropbox, NFS, FTP) via the UI.
    • Security (SmartShield): Provides automatic protection including anti-bot, anti-DDOS (throttling, rate limiting, geo-blacklisting), and TCP protection (FTP, SSH, Games).
    • VPN: Securely access applications remotely without opening router ports.
    • Backups: Incremental, encrypted, and remote backups using Restic.
    • Monitoring: Real-time monitoring with customizable alerts and notifications.
    • CRON: Schedule tasks on the server or inside containers.
    • Customizable Homepage: A single UI to access all managed applications.
  3. Install Cosmos Server using Docker

    master

    The recommended way to install Cosmos Server is using a direct docker run command.

    Important Compatibility Notes:

    • Do NOT use Unraid Templates, CasaOS, or Portainer Stacks; they will not work properly.
    • Linux Users: Use --network host to allow Cosmos to bind ports to itself correctly.
    • Windows/macOS Users: You cannot use host mode. Replace --network host with specific port mappings: -p 80:80 -p 443:443 -p 4242:4242/udp.
    • Privileged Mode: The --privileged flag is optional but required if you use hardening software (AppArmor/SELinux) or if you want to use Constellation. Alternatively, you can add the NET_ADMIN capability for Constellation.
    • Volume Mounting: The -v /:/mnt/host flag is optional and allows Cosmos to manage host folders. If removed, you must create bind folders manually.
    • Docker Socket: You must mount the docker socket (/var/run/docker.sock) so Cosmos can manage containers.
    sudo docker run -d --network host  --privileged --name cosmos-server -h cosmos-server --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket -v /:/mnt/host -v /var/lib/cosmos:/config azukaar/cosmos-server:latest
  4. Configure automatic HTTPS with Let's Encrypt and DNS challenges

    master

    Cosmos Server can automatically generate and renew HTTPS certificates using Let's Encrypt. It supports wildcard certificates via the DNS challenge.

    To enable this:

    1. Add a DNSChallengeProvider to the HTTPConfig in your configuration or via the UI.
    2. Provide the required API token via environment variables.

    Supported providers and their required environment variables can be found in the lego dns providers documentation.

  5. Integrate your application with Cosmos

    master

    Self-hosted application developers can integrate with Cosmos to leverage built-in security and management features. Integration provides:

    • Secure Authentication: A robust system for handling passwords, encryption, and tokens.
    • HTTP Layer Protection: Robust protection for your application's web interface.
    • HTTPS Support: Automatic certificate management.
    • User Management & Encryption: Centralized control over users and data.
    • Logging & Backup: Integrated system monitoring and data protection.

    Applications that do not integrate with Cosmos will still function normally, but will not benefit from these integrated security features.

  6. Complete the Cosmos Server Setup Wizard

    master

    After running the Docker command, access the web interface to complete the installation:

    1. Navigate to http://your-server-ip in your browser.
    2. Crucial: Always use your browser in incognito mode for the initial setup to prevent issues with browser cache.
    3. Follow the on-screen instructions provided by the setup wizard.
  7. Install the Cosmos Terraform Provider

    master

    You can install the Cosmos provider using terraform init, which automatically downloads the provider for your platform. Alternatively, you can perform a manual installation by downloading the binary from GitHub Releases and placing it in the following directory structure:

    ~/.terraform.d/plugins/cosmos-cloud.io/azukaar/cosmos/<VERSION>/<OS>_<ARCH>/

    terraform {
      required_providers {
        cosmos = {
          source = "cosmos-cloud.io/azukaar/cosmos"
        }
      }
    }
  8. Build and install the provider locally for development

    master

    To compile and install the provider locally, use the provided Makefile commands. After installation, you must remove your existing lock file and re-initialize Terraform to use the local version.

    1. Compile and install: make build make install

    2. Update your Terraform project: rm .terraform.lock.hcl && terraform init

    cd terraform-provider-cosmos
    make build    # compile
    make install  # copy to ~/.terraform.d/plugins/
    
    # In your terraform project:
    rm .terraform.lock.hcl && terraform init
  9. Use Dev Overrides for faster Terraform development

    master

    To iterate quickly without running terraform init every time, configure a dev_overrides in your ~/.terraformrc file. This tells Terraform to use your local build directory directly.

    1. Add the following to ~/.terraformrc:
    provider_installation {
      dev_overrides {
        "cosmos-cloud.io/azukaar/cosmos" = "/path/to/terraform-provider-cosmos"
      }
      direct {}
    }
    1. Run make build and then terraform plan directly.