Skip to content

Conversation

chriselsen
Copy link
Collaborator

@chriselsen chriselsen commented Jun 30, 2025

Fixes #710

Problem

CloudTAK has a chicken-and-egg configuration problem for automated deployments:

  1. Manual Configuration Required: TAK server connection must be configured via web UI on first boot
  2. Authentication Barrier: The /api/server PATCH endpoint requires a bearer token for configuration
  3. Token Generation Impossible: Bearer tokens cannot be generated until the TAK server is already configured
  4. Blocks Automation: This prevents fully automated CloudTAK deployments and container orchestration

Solution

Add support for TAK server configuration via environment variables during CloudTAK startup, bypassing the authentication requirement.

New Environment Variables

Variable Description
CLOUDTAK_Server_name TAK Server name/description
CLOUDTAK_Server_url TAK Server connection URL (e.g., ssl://tak.example.com:8089)
CLOUDTAK_Server_api TAK Server API URL (e.g., https://tak.example.com:8443)
CLOUDTAK_Server_webtak TAK Server WebTAK URL
CLOUDTAK_Server_auth_cert Client certificate (PEM format)
CLOUDTAK_Server_auth_key Client private key (PEM format)
CLOUDTAK_Server_auth_p12_secret_arn AWS Secrets Manager ARN for P12 certificate
CLOUDTAK_Server_auth_password Password for P12/PKCS12 file
CLOUDTAK_ADMIN_USERNAME Admin username for CloudTAK system
CLOUDTAK_ADMIN_PASSWORD Admin password for CloudTAK system

Implementation

  • Modified api/lib/config.ts: Added server environment variable processing during startup
  • Fixed admin user creation: Added required auth field with password for database schema compliance
  • Created comprehensive documentation: Added docs/ENVIRONMENT_VARIABLES.md
  • Follows existing patterns: Uses CLOUDTAK_ prefix consistent with other configuration variables
  • Override behavior: Environment variables override database values when present

Benefits

Enables automated deployment - No manual web UI configuration required
Maintains security - Certificates injected via secure environment variables or AWS Secrets Manager
Backward compatible - Existing functionality unchanged
Container-friendly - Perfect for Docker/Kubernetes deployments
Admin user automation - Automatically creates admin users with system privileges
AWS integration - Supports P12 certificates from AWS Secrets Manager

Usage Example

export CLOUDTAK_Server_name="Production TAK Server"
export CLOUDTAK_Server_url="ssl://tak.example.com:8089"
export CLOUDTAK_Server_api="https://tak.example.com:8443"
export CLOUDTAK_Server_webtak="https://tak.example.com:8446"

# AWS Secrets Manager approach (recommended)
export CLOUDTAK_Server_auth_p12_secret_arn="arn:aws:secretsmanager:region:account:secret:tak-cert"
export CLOUDTAK_Server_auth_password="atakatak"

# Admin user creation
export CLOUDTAK_ADMIN_USERNAME="admin"
export CLOUDTAK_ADMIN_PASSWORD="secure-password"

@chriselsen chriselsen force-pushed the takserver-config-env branch 2 times, most recently from a66d9e4 to f6b429c Compare July 1, 2025 05:46
@chriselsen chriselsen force-pushed the takserver-config-env branch from f6b429c to c479e72 Compare July 1, 2025 05:48
- Test admin creation with CLOUDTAK_ADMIN_USERNAME/PASSWORD
- Test skipping admin creation when credentials missing
@chriselsen
Copy link
Collaborator Author

Added automatic admin user creation when CLOUDTAK_ADMIN_USERNAME and CLOUDTAK_ADMIN_PASSWORD are provided.

- Removing the unused Config import
- Removing the unused err parameter in the catch block for the schema validation test
chriselsen referenced this pull request in TAK-NZ/CloudTAK Jul 4, 2025
- Merge server environment variable configuration from upstream PR #712
- Add Lambda-based Authentik user creation during CDK deployment
- Fix ECS service dependencies to wait for database readiness
- Fix events Lambda TAK_ETL_API URL to include https:// protocol
- Add ECR permissions for coe-ecr-etl repository access
- Update branding script to replace CloudTAKLogo.svg with TAK.NZ logo
- Create separate AuthentikUserCreator construct with retry logic
chriselsen referenced this pull request in TAK-NZ/CloudTAK Jul 4, 2025
- Re-apply server environment variable configuration from upstream PR #712
- Add admin user creation via CLOUDTAK_ADMIN_USERNAME/PASSWORD
- Add ECR_TASKS_REPOSITORY_NAME and ECS_CLUSTER_PREFIX for PR #717
- Restore comprehensive test coverage for environment variable features
- Fix server configuration to prevent /configure endpoint from showing
chriselsen referenced this pull request in TAK-NZ/CloudTAK Jul 4, 2025
- Re-apply server environment variable configuration from upstream PR #712
- Add admin user creation via CLOUDTAK_ADMIN_USERNAME/PASSWORD
- Add ECR_TASKS_REPOSITORY_NAME and ECS_CLUSTER_PREFIX for PR #717
- Restore comprehensive test coverage for environment variable features
- Fix server configuration to prevent /configure endpoint from showing
Works with CDK deployed CloudTAK layer.
Updated tests for working config.ts version
Updated documentation
@chriselsen
Copy link
Collaborator Author

chriselsen commented Jul 5, 2025

Summary of Changes

Key additions to the original PR:

  1. Added AWS Secrets Manager support: CLOUDTAK_Server_auth_p12_secret_arn for P12 certificates stored in AWS Secrets Manager
  2. Added admin user automation: CLOUDTAK_ADMIN_USERNAME and CLOUDTAK_ADMIN_PASSWORD for automatic admin user creation with system privileges
  3. Fixed critical bugs:
    • Admin user creation database schema compliance (added required auth field)
  4. Enhanced documentation: Created comprehensive docs/ENVIRONMENT_VARIABLES.md and docs/GITHUB_AUTO_PULL.md
  5. AWS integration: Full support for AWS deployment patterns with Secrets Manager integration

Testing status: ✅ Successfully tested and deployed - All functionality has been validated in a live deployment environment, confirming automated server configuration, admin user creation, and secrets manager access work correctly.

@ingalls ingalls mentioned this pull request Jul 11, 2025
@chriselsen chriselsen added the authentication User login, certificates, tokens label Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
authentication User login, certificates, tokens
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: TAK Server Configuration via Environment Variables
1 participant