platform

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README

FTL Platform Integration Package

The pkg/platform package provides the official API for integrating FTL with cloud platforms that deploy applications to WebAssembly runtimes like Fermyon Cloud.

Installation

import "github.com/fastertools/ftl/platform"

Quick Start

config := platform.DefaultConfig()
client := platform.NewClient(config)

request := &platform.DeploymentRequest{
    Application: &platform.Application{
        Name:    "my-app",
        Version: "1.0.0",
        Components: []platform.Component{
            {
                ID: "api",
                Source: map[string]interface{}{
                    "registry": "ghcr.io",
                    "package":  "myorg/api",
                    "version":  "v1.0.0",
                },
            },
        },
    },
}

result, err := client.ProcessDeployment(request)
if err != nil {
    return err
}

// Deploy to Fermyon using result.SpinTOML

Configuration

Default Configuration
config := platform.DefaultConfig()

This provides:

  • Gateway injection enabled
  • Authorizer injection for non-public apps
  • Registry-only components required
  • 50 component limit
Custom Configuration
config := platform.Config{
    InjectGateway:     true,
    InjectAuthorizer:  true,
    GatewayVersion:    "0.0.13-alpha.0",
    AuthorizerVersion: "0.0.15-alpha.0",
    
    RequireRegistryComponents: true,
    AllowedRegistries: []string{
        "ghcr.io",
        "123456789012.dkr.ecr.us-west-2.amazonaws.com",
    },
    
    MaxComponents:      100,
    DefaultEnvironment: "production",
}

Platform Components

The platform automatically injects security components:

mcp-gateway
  • Always injected when InjectGateway is true
  • Handles routing and request processing
  • Source: ghcr.io/fastertools:mcp-gateway
mcp-authorizer
  • Injected for non-public applications when InjectAuthorizer is true
  • Handles JWT authentication
  • Source: ghcr.io/fastertools:mcp-authorizer

Access Modes

  • public: No authentication required
  • private: Organization authentication required
  • org: Organization with specific roles
  • custom: Custom JWT authentication

Component Sources

Components can be from registries or local paths:

// Registry source
Source: map[string]interface{}{
    "registry": "ghcr.io",
    "package":  "myorg/component",
    "version":  "1.0.0",
}

// Local source (may be rejected in production)
Source: "./build/component.wasm"

Validation

Pre-validate components before processing:

err := client.ValidateComponents(components)
if err != nil {
    // Handle validation error
}

AWS Lambda Integration Example

package lambda

import (
    "context"
    "github.com/fastertools/ftl/platform"
)

func HandleDeployment(ctx context.Context, req APIGatewayRequest) (APIGatewayResponse, error) {
    config := platform.DefaultConfig()
    config.RequireRegistryComponents = true
    config.AllowedRegistries = []string{
        "ghcr.io",
        getECRRegistry(),
    }
    
    client := platform.NewClient(config)
    
    deployReq := &platform.DeploymentRequest{
        Application: parseApplication(req.Body),
        Environment: "production",
    }
    
    result, err := client.ProcessDeployment(deployReq)
    if err != nil {
        return errorResponse(err), nil
    }
    
    // Deploy to Fermyon
    err = deployToFermyon(result.SpinTOML)
    if err != nil {
        return errorResponse(err), nil
    }
    
    return successResponse(result.Metadata), nil
}

Security Features

  1. Component Source Validation: Reject local sources in production
  2. Registry Whitelist: Only allow components from approved registries
  3. Component Limits: Prevent resource abuse
  4. Automatic Auth Injection: Add authentication for non-public apps

Error Handling

The package returns detailed errors for common issues:

  • Invalid component sources
  • Registry not in whitelist
  • Too many components
  • Missing required fields
  • Synthesis failures

Testing

func TestPlatformIntegration(t *testing.T) {
    config := platform.DefaultConfig()
    client := platform.NewClient(config)
    
    request := &platform.DeploymentRequest{
        Application: &platform.Application{
            Name:    "test-app",
            Version: "1.0.0",
            Components: []platform.Component{
                {
                    ID: "test",
                    Source: map[string]interface{}{
                        "registry": "ghcr.io",
                        "package":  "test/component",
                        "version":  "1.0.0",
                    },
                },
            },
        },
    }
    
    result, err := client.ProcessDeployment(request)
    assert.NoError(t, err)
    assert.NotNil(t, result.Manifest)
    assert.NotEmpty(t, result.SpinTOML)
}

Documentation

Overview

Package platform provides the API for FTL platform deployments. This is used by deployment platforms to process FTL applications consistently.

Package platform provides the official API for FTL platform integrations.

This package is designed for cloud platforms that deploy FTL applications to WebAssembly runtimes like Fermyon Cloud. It provides a clean, explicit API for processing deployments with proper security controls.

Basic Usage

Create a client with your platform configuration:

config := platform.DefaultConfig()
config.RequireRegistryComponents = true
config.AllowedRegistries = []string{"ghcr.io", "your-ecr.amazonaws.com"}

client := platform.NewClient(config)

Process deployment requests:

result, err := client.ProcessDeployment(request)
if err != nil {
    return handleError(err)
}

deployToFermyon(result.SpinTOML)

Platform Components

The platform automatically injects security components:

  • mcp-gateway: Always injected for routing and request handling
  • mcp-authorizer: Injected for non-public applications

These components are configurable through the Config struct.

Security

The platform enforces several security policies:

  • Component source validation (local vs registry)
  • Registry whitelist enforcement
  • Component count limits
  • Automatic auth component injection

Index

Constants

View Source
const (
	// DefaultECRRegistry is the FTL platform's ECR registry
	DefaultECRRegistry = "795394005211.dkr.ecr.us-west-2.amazonaws.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Gateway component settings
	GatewayRegistry string // Default: ghcr.io
	GatewayPackage  string // Default: fastertools:mcp-gateway
	GatewayVersion  string // Default: latest stable version

	// Authorizer component settings
	AuthorizerRegistry string // Default: ghcr.io
	AuthorizerPackage  string // Default: fastertools:mcp-authorizer
	AuthorizerVersion  string // Default: latest stable version

	// Security settings
	RequireRegistryComponents bool     // If true, reject local file sources
	AllowedRegistries         []string // Whitelist of allowed registries (empty = allow all)
}

Config defines platform-specific settings.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns production-ready default configuration.

type DeploymentContext

type DeploymentContext struct {
	// Actor type performing the deployment
	ActorType string // "user" or "machine"

	// Organization ID for org-scoped deployments
	OrgID string

	// Claims to forward as headers (claim_name -> header_name)
	// Example: {"sub": "X-User-ID", "org_id": "X-Org-ID"}
	ForwardClaims map[string]string
}

DeploymentContext provides actor and organization context for deployments

type ProcessMetadata

type ProcessMetadata struct {
	AppName            string
	AppVersion         string
	ComponentCount     int
	AccessMode         string
	InjectedGateway    bool
	InjectedAuthorizer bool
	SubjectsInjected   int // Number of allowed subjects that were injected
}

ProcessMetadata provides information about the processing.

type ProcessRequest

type ProcessRequest struct {
	// The FTL application configuration (YAML or JSON)
	ConfigData []byte

	// Format of the config data
	Format string // "yaml" or "json"

	// Computed allowed user subjects from WorkOS (only used for private/org access modes)
	// For private mode: platform provides the single authenticated user
	// For org mode: platform provides all org members (filtered by allowed_roles if specified)
	// For public/custom modes: this field is ignored
	AllowedSubjects []string

	// Deployment context for M2M authentication and claim forwarding
	DeploymentContext *DeploymentContext
}

ProcessRequest represents a deployment request from the platform.

type ProcessResult

type ProcessResult struct {
	// The complete Spin TOML manifest ready for deployment
	SpinTOML string

	// Metadata about what was processed (for platform logging/tracking)
	Metadata ProcessMetadata
}

ProcessResult contains the deployment-ready Spin TOML.

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor handles FTL application processing for platform deployments.

func NewProcessor

func NewProcessor(config Config) *Processor

NewProcessor creates a new platform processor.

func (*Processor) Process

func (p *Processor) Process(req ProcessRequest) (*ProcessResult, error)

Process handles an FTL deployment request.

The platform only needs to provide:

  • The raw FTL configuration (YAML/JSON)
  • Computed allowed subjects for private/org modes (from WorkOS)

The processor handles all FTL-specific logic internally:

  • Validation against CUE schema
  • Component registry validation
  • Synthesis to Spin TOML
  • Gateway/authorizer injection

For access modes:

  • public: No allowed subjects needed
  • private: Platform provides single authenticated user
  • org: Platform provides org members (filtered by allowed_roles if specified in config)
  • custom: No allowed subjects needed (app handles its own auth)

Jump to

Keyboard shortcuts

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