Skip to content

Security: Create self-contained Bun CLI deployment tool #294

Closed

Description

@larryro

Problem Statement

DigitalOcean security scan detected that demo.tale.dev is exposing FalkorDB (Redis protocol) on port 6379 to the public internet. This is a critical security vulnerability that could allow unauthorized access to the knowledge graph data.

Additional exposed ports discovered during investigation:

  • PostgreSQL: 5432
  • RAG service: 8001
  • Crawler: 8002
  • Search: 8003

Root Cause

The deployment script (scripts/deploy.sh) depends on repository compose files (compose.yml, compose.blue.yml, compose.green.yml) which expose ports for development convenience. Docker modifies iptables directly, bypassing UFW rules.

Current State

  • compose.yml exposes ports: 6379 (FalkorDB), 5432 (PostgreSQL), 8001-8003 (services)
  • compose.blue.yml and compose.green.yml are separate files for blue-green deployment
  • Development and production share the same configuration
  • All inter-service communication happens via Docker internal network (working correctly)

Proposed Solution

Create a self-contained Bun CLI tool (tools/deploy/) that:

  1. Generates Docker Compose configs inline - No external file dependencies
  2. Only exposes ports 80/443 - All other ports internal only
  3. Compiles to single binary - Easy deployment to any server
  4. Replaces bash script entirely - Type-safe, maintainable TypeScript

Why Bun CLI instead of Bash refactoring?

  • Type safety: Catch errors at compile time
  • Maintainability: Easier to test and extend
  • Portability: Single binary, no runtime dependencies on server
  • Modern tooling: Better error handling, structured code

Affected Components

  • tools/deploy/ - Create new Bun CLI tool
  • scripts/deploy.sh - Delete (after CLI is working)
  • compose.blue.yml - Delete
  • compose.green.yml - Delete
  • compose.yml - Keep (development only, add clarifying comment)

Acceptance Criteria

  • Bun CLI generates compose config inline (no external file dependencies)
  • Only ports 80 and 443 exposed in production
  • telnet demo.tale.dev 6379 fails (FalkorDB not accessible)
  • telnet demo.tale.dev 5432 fails (PostgreSQL not accessible)
  • Blue-green deployment works correctly (tale-deploy deploy v1.0.0)
  • Rollback functionality preserved (tale-deploy rollback)
  • Status command shows deployment state (tale-deploy status)
  • All services can communicate via Docker internal network
  • Caddy routes traffic correctly to platform-blue/green
  • Binary compiles for Linux x64 target

Security Impact

Before: 5 ports exposed to public internet
After: Only 2 ports (80, 443) exposed via Caddy proxy


🤖 Generated with Claude Code

Activity

  1. larryro commented on Jan 27, 2026

    @larryro
    ContributorAuthor

    Implementation Plan: Bun CLI Deployment Tool

    Directory Structure

    tools/deploy/
    ├── package.json
    ├── tsconfig.json
    ├── src/
    │   ├── index.ts                 # CLI entry point (commander)
    │   ├── commands/
    │   │   ├── deploy.ts
    │   │   ├── rollback.ts
    │   │   ├── status.ts
    │   │   ├── cleanup.ts
    │   │   └── reset.ts
    │   ├── compose/
    │   │   ├── types.ts             # Docker Compose types
    │   │   ├── generator.ts         # YAML generation (security-hardened)
    │   │   └── services/
    │   │       ├── platform.ts
    │   │       ├── rag.ts
    │   │       ├── crawler.ts
    │   │       ├── search.ts
    │   │       ├── db.ts
    │   │       ├── graph-db.ts
    │   │       └── proxy.ts
    │   ├── docker/
    │   │   ├── client.ts            # Docker command execution
    │   │   ├── health.ts            # Health check polling
    │   │   └── images.ts            # Image pull/verify
    │   ├── state/
    │   │   ├── deployment.ts        # Color state management
    │   │   └── lock.ts              # Lock file
    │   └── utils/
    │       ├── logger.ts            # Colored output
    │       └── env.ts               # Environment loading
    └── README.md
    

    Key Technologies

    Need Solution
    Runtime Bun
    CLI parsing commander (npm)
    YAML generation yaml (npm)
    Docker commands Bun.spawn()
    File I/O Bun.file(), Bun.write()
    Compilation bun build --compile

    package.json

    {
      "name": "@tale/deploy",
      "version": "1.0.0",
      "type": "module",
      "scripts": {
        "dev": "bun run src/index.ts",
        "build": "bun build --compile --outfile=dist/tale-deploy src/index.ts",
        "build:linux": "bun build --compile --target=bun-linux-x64 --outfile=dist/tale-deploy-linux src/index.ts"
      },
      "dependencies": {
        "commander": "^12.0.0",
        "yaml": "^2.4.0"
      },
      "devDependencies": {
        "@types/bun": "latest"
      }
    }

    Compose Generator (Security Critical)

    // src/compose/generator.ts - NO PORTS EXPOSED except proxy!
    import { stringify } from "yaml";
    
    export function generateStatefulCompose(version: string): string {
      return stringify({
        services: {
          db: {
            image: `ghcr.io/tale-project/tale/tale-db:${version}`,
            container_name: "tale-db",
            // NO ports exposed!
            volumes: ["db-data:/var/lib/postgresql/data"],
            networks: ["internal"],
            // ...
          },
          "graph-db": {
            image: `ghcr.io/tale-project/tale/tale-graph-db:${version}`,
            container_name: "tale-graph-db",
            // NO ports exposed!
            volumes: ["graph-db-data:/var/lib/falkordb/data"],
            networks: ["internal"],
            // ...
          },
          proxy: {
            image: `ghcr.io/tale-project/tale/tale-proxy:${version}`,
            container_name: "tale-proxy",
            ports: ["80:80", "443:443"], // ONLY exposed ports
            // ...
          },
        },
        // ...
      });
    }
    
    export function generateColorCompose(color: "blue" | "green", version: string): string {
      // Generates platform-blue/green, rag-blue/green, etc.
      // NO ports exposed - all internal
      // Includes network aliases for Caddy routing
    }

    CLI Commands

    tale-deploy deploy <version>      # Deploy specified version (zero-downtime)
    tale-deploy deploy <version> --update-stateful  # Also update db/proxy/graph-db
    tale-deploy rollback              # Rollback to previous version
    tale-deploy status                # Show current deployment status
    tale-deploy cleanup               # Remove inactive containers
    tale-deploy reset [--force]       # Remove ALL blue-green containers

    Files to Modify/Delete

    File Action
    tools/deploy/ Create - New Bun CLI tool
    scripts/deploy.sh Delete (after CLI is working)
    compose.blue.yml Delete
    compose.green.yml Delete
    compose.yml Keep - Add comment: "LOCAL DEVELOPMENT ONLY"

    Build & Deploy Process

    # Development
    cd tools/deploy
    bun install
    bun run dev deploy v1.0.0
    
    # Build for Linux
    bun run build:linux
    # Output: dist/tale-deploy-linux (~30-50MB single binary)
    
    # Deploy to server
    scp dist/tale-deploy-linux user@server:/usr/local/bin/tale-deploy
    chmod +x /usr/local/bin/tale-deploy
    
    # Use on server
    tale-deploy deploy v1.0.0

    Testing Strategy

    1. Security Verification

    # After deployment, verify ports are closed
    nmap -p 5432,6379,8001,8002,8003 demo.tale.dev
    # All should be filtered/closed
    
    telnet demo.tale.dev 6379
    # Should fail to connect

    2. Functionality Check

    tale-deploy deploy v1.0.0
    tale-deploy status
    tale-deploy rollback
    tale-deploy status
    tale-deploy reset --force

    3. Caddy Routing

    curl -k https://demo.tale.dev/api/health
    # Should return 200 OK

    Implementation Order

    1. Create tools/deploy/ directory structure
    2. Implement core modules: docker/client.ts, utils/logger.ts, state/*
    3. Implement compose/generator.ts with security-hardened configs
    4. Implement commands: status, deploy, rollback, cleanup, reset
    5. Test locally with bun run dev
    6. Compile and test binary on Linux server
    7. Delete old files: scripts/deploy.sh, compose.blue.yml, compose.green.yml
    8. Add development-only comment to compose.yml

    🤖 Generated with Claude Code

  2. changed the title [-]Security: Make deploy.sh self-contained and remove exposed ports in production[/-] [+]Security: Create self-contained Bun CLI deployment tool[/+] on Jan 27, 2026
  3. self-assigned this
    on Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: high

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions