How osusec/beavercds-ng works
Project type and purpose
• This is a Rust-based command-line tool (“beavercds-ng”) implementing the RCDS/beavercds challenge distribution and deployment system.
• It reads contest/challenge definitions, builds challenge artifacts, and then deploys them to Docker registries, S3 buckets, Kubernetes clusters, and a frontend service.
Top-level modules & directories
• CLI entrypoints: src/main.rs + src/cli.rs use Clap to parse subcommands.
• src/commands/…: one module per subcommand (build, deploy, check_access, validate, cluster_setup).
• Core library:
• src/configparser/… loads & validates YAML challenge/config files
• src/builder/… builds artifacts (Docker images, binaries)
• src/deploy/… renders templates & applies deployments (frontend, S3, Kubernetes)
• src/access_handlers/… trait implementations for each external system (Docker, S3, Kube API, frontend)
• src/clients.rs wraps HTTP, AWS SDK, Kubernetes client calls
• src/asset_files/… Jinja2 templates for K8s manifests & frontend config
• src/cluster_setup/… sets up cluster prerequisites (helm charts, cert-manager, DNS)
• Supporting code: src/utils/… and tests in both src/tests/… and the top-level tests/… folder.
External systems & services
• Docker daemon/registry
• Kubernetes cluster (via K8s API server)
• AWS S3 (challenge registry)
• HTTP frontend service (serving challenge assets)
• Helm/cert-manager/ingress-nginx/external-dns for cluster setup
• Asset_files should feed into deploy (template engine).
• cluster_setup module also points to Kubernetes, Helm & DNS systems.
Key relationships & data flows
• User runs rcds build → CLI parses args → configparser loads YAML → builder generates images/artifacts → access_handlers/docker pushes to registry.
• rcds deploy → templates from asset_files + config → deploy module → access_handlers/kube applies K8s manifests → access_handlers/s3 uploads static assets → access_handlers/frontend updates UI.
• rcds cluster_setup → cluster_setup applies Helm charts → sets up ingress, cert-manager, external-dns.
• rcds check_access and rcds validate call respective handlers and clients to test connectivity, configuration, and challenge accessibility.
Architectural patterns & design principles
• Command pattern: each CLI subcommand is a self-contained module under src/commands.
• Separation of concerns: parsing, building, templating, and deployment are in distinct modules.
• Handler trait pattern: access_handlers/mod.rs defines a trait implemented by each system handler.
• Template-driven manifest generation: all K8s/HTTP configs are Jinja2 templates under asset_files.
• Dependency injection via module boundaries—clients.rs abstracts protocol/SDK details.