Scaffolding an install with Ansible or Terraform (Pro)

The files dojo-deploy scaffold writes are boilerplate, not a supported product. They are a starting point for your own automation: read them, adapt them to your environment, and own them from then on. DefectDojo does not support them as written and does not keep your copy up to date. What DefectDojo supports is dojo-deploy itself: dojo-deploy install for Docker Compose, and the Helm chart with the values dojo-deploy install would use for Kubernetes. Each set of files carries a README that says the same.

If you manage hosts with Ansible or infrastructure with Terraform, dojo-deploy scaffold gives you a commented starting point that installs DefectDojo Pro the same way dojo-deploy install does. It writes files and nothing else: it changes no host and no cluster.

dojo-deploy scaffold is newer than the other dojo-deploy commands: dojo-deploy 3.5.300 and earlier do not have it, and answer "scaffold" is not a command group. Run dojo-deploy scaffold --help to check that yours does, and see Moving to dojo-deploy to get or update dojo-deploy.

What it writes

There are two tools and two targets:

--target compose--target kubernetes
ansibleAn Ansible role, with an example playbook, that runs dojo-deploy install on hosts you already haveA playbook that installs the Helm chart with kubernetes.core.helm on a cluster you already have
terraformA Terraform module that runs dojo-deploy install over SSH on a host you already haveA Terraform configuration that installs the Helm chart with helm_release on a cluster you already have

None of them creates a virtual machine, a network or a cluster. You bring those, with your own resources.

# Docker Compose
dojo-deploy scaffold ansible   --target compose --out ./dojo-ansible
dojo-deploy scaffold terraform --target compose --out ./dojo-terraform

# Kubernetes: also give your install file and the chart package
dojo-deploy scaffold ansible   --target kubernetes --config install.json --chart dojopro-<version>.tgz --out ./dojo-ansible
dojo-deploy scaffold terraform --target kubernetes --config install.json --chart dojopro-<version>.tgz --out ./dojo-terraform

--out is created when it is missing. scaffold never overwrites a file: if any file it would write is already in --out, it writes none of them and says which one is in the way, so run it into a new or empty directory. It exits 0 when it wrote the files, 1 when it did not, and 2 on a usage error, such as an unknown tool or target (it lists the valid ones). When it succeeds, it lists the files it wrote. Start with the README.md in --out.

dojo-deploy scaffold --help describes the options.

Docker Compose

Both Docker Compose scaffolds do the same thing on a Linux host you already have. As root, they:

  1. Install the dojo-deploy binary at /usr/local/bin/dojo-deploy.
  2. Put your license, your install file and the CLI key (DOJO_CLI_KEY) in /etc/dojo-deploy, readable by root only. The install file placed there has its license.path pointed at that copy of the license. The install keeps its own copy of the license in /etc/defectdojo, and the scaffold never touches that one.
  3. Run dojo-deploy prereqs. If it finds Docker Engine or Docker Compose missing, they run the commands prereqs printed for the distribution (Docker’s apt or dnf repository), then run prereqs again. Ubuntu, Debian and RHEL 8 or later (including Rocky Linux and AlmaLinux) have commands. On any other distribution, install Docker yourself and turn this step off.
  4. Run dojo-deploy install --config /etc/dojo-deploy/install.json once. After a successful install they write /etc/dojo-deploy/installed, and later runs skip the install.

They do not upgrade. To move to a newer release, run dojo-deploy upgrade on the host as root, with DOJO_CLI_KEY set to the CLI key the install was made with. The scaffold keeps that key only in /etc/dojo-deploy/cli-key, readable by root, so read it from there:

sudo sh -c 'DOJO_CLI_KEY="$(cat /etc/dojo-deploy/cli-key)" exec /usr/local/bin/dojo-deploy upgrade --config /etc/dojo-deploy/install.json'

Both also write install.example.json, a minimal install file (a database container on the host and a self-signed certificate) to start your own from. Run dojo-deploy check --help to see the install file’s settings, and dojo-deploy check --config <install file> to check yours before you run the scaffold. The scaffold sets license.path itself.

Both keep secrets out of logs and command lines. The CLI key is written to /etc/dojo-deploy/cli-key (root, 0600) and the install reads it from there. A first install prints the generated admin password, and the scaffolds keep that line out of Ansible’s and Terraform’s output, so you will not see it. Set a new password on the host with dojo-deploy compose app change-password. The install’s own log, with secrets redacted, is under /var/log/dojo-deploy.

Keep the same CLI key for the life of the install. It encrypts the install’s stored configuration, and every later dojo-deploy command on the host needs it.

Neither covers air-gapped installs: the host needs to reach Docker’s package repository and the DefectDojo Pro registry, directly or through a proxy you set in the scaffold’s environment variable.

Docker Compose with Ansible

dojo-deploy scaffold ansible --target compose writes:

FileWhat it is
README.mdWhat the role does and how to run it
playbook.ymlAn example playbook that applies the role to the dojo group
inventory.example.iniAn example inventory
install.example.jsonA minimal install file
roles/dojo_deploy/defaults/main.ymlEvery variable the role reads, with its description
roles/dojo_deploy/tasks/main.ymlThe role’s tasks
roles/dojo_deploy/files/prereqs.shRuns dojo-deploy prereqs and installs Docker when it is missing
roles/dojo_deploy/meta/main.ymlThe role’s metadata

What you must edit:

  • Your install file. Write it from install.example.json or your own.

  • The inventory. Copy inventory.example.ini to inventory.ini and name your hosts in the dojo group.

  • The four required variables: dojo_deploy_binary (the dojo-deploy binary for the host’s architecture, linux/amd64 or linux/arm64, on the controller), dojo_deploy_license_file, dojo_deploy_install_file and dojo_deploy_cli_key. Keep the CLI key in Ansible Vault:

    # group_vars/dojo.yml
    dojo_deploy_binary: ./dojo-deploy
    dojo_deploy_license_file: ./dojopro.lic
    dojo_deploy_install_file: ./install.json
    dojo_deploy_cli_key: "{{ vault_dojo_deploy_cli_key }}"
  • Optional: dojo_deploy_environment for a proxy, and dojo_deploy_install_prereqs: false when you install Docker yourself.

Then run it:

ansible-playbook -i inventory.ini playbook.yml --ask-vault-pass

It needs Ansible 2.14 or later on the controller and Python 3 on the host.

Docker Compose with Terraform

dojo-deploy scaffold terraform --target compose writes a module that uses Terraform’s file and remote-exec provisioners over SSH and no provider:

FileWhat it is
README.mdWhat the module does and how to use it
main.tfThe terraform_data resource and its provisioners
variables.tfEvery variable, with its description
outputs.tfsite_url and install_file_on_host
versions.tfThe Terraform version it needs (1.4 or later)
terraform.tfvars.exampleHow to run the module on its own
install.example.jsonA minimal install file
files/install.shThe script it runs on the host as root
files/prereqs.shRuns dojo-deploy prereqs and installs Docker when it is missing

The module uploads its files to a new staging directory under /tmp that only ssh_user can read, runs files/install.sh as root (through sudo -n unless ssh_user is root), and removes the staging directory afterwards. The provisioners run only when the resource is created, so a later terraform apply changes nothing unless host changes.

What you must edit:

  • Your install file. Write it from install.example.json or your own.
  • The host: host, ssh_user and ssh_private_key (and ssh_port if it is not 22). Create the host with your own resources and pass its address.
  • ssh_host_key, so Terraform checks the host’s identity before it uploads the license and the key. Give it the host’s ECDSA key when the host has one (/etc/ssh/ssh_host_ecdsa_key.pub): Terraform’s SSH client prefers ECDSA, and with another key type the connection fails with knownhosts: key mismatch.
  • The inputs: dojo_deploy_binary (linux/amd64 or linux/arm64, for the host), license_file, install_file and cli_key (sensitive; for example from TF_VAR_dojo_cli_key).
  • Optional: environment for a proxy, install_prereqs = false when you install Docker yourself, and staging_parent for a staging directory outside /tmp.
module "defectdojo" {
  source = "./dojo-terraform"

  host               = aws_instance.dojo.public_ip # or any host you already have
  ssh_user           = "ubuntu"
  ssh_private_key    = file("~/.ssh/id_ed25519")
  dojo_deploy_binary = "./dojo-deploy"
  license_file       = "./dojopro.lic"
  install_file       = "./install.json"
  cli_key            = var.dojo_cli_key
}

Terraform does not keep cli_key in its state: the key reaches only a file provisioner. A saved plan (terraform plan -out) does hold it, with every other variable, so keep plan files private. Of the install file, the state keeps only its site.url.

Kubernetes

The Kubernetes scaffolds install the dojopro Helm chart on a cluster you already have, from the machine they run on. They do not run dojo-deploy install. Instead they carry the chart values dojo-deploy install would use for your install file, so they need two inputs:

  • --config: your Kubernetes install file. A file dojo-deploy install would refuse, scaffold refuses with the same message. Run dojo-deploy check --config <install file> first.

  • --chart: the chart package (dojopro-<version>.tgz) for the version your install file asks for. Download it with your license’s registry token:

    helm registry login us-south1-docker.pkg.dev --username _json_key_base64   # the password is the license's registry token
    helm pull oci://us-south1-docker.pkg.dev/defectdojo-container-registry/dojo-pro-helm-v2/dojopro --version <version>

Both Kubernetes scaffolds write:

FileWhat it is
README.mdWhat the files do, every variable, and how to run them
files/values.yamlThe chart values dojo-deploy install would use for your install file, without the secret ones
files/presets/platforms/<platform>.yamlThe chart’s platform preset for your install file’s cluster.platform, copied from the package
files/presets/profiles/<profile>.yamlThe chart’s sizing profile preset, copied from the package

Helm gets the values in the order dojo-deploy install uses, later ones winning: the platform preset, the profile preset, files/values.yaml, then the secret values from your variables.

Before the release, both create the namespace and the Secrets and ConfigMaps the release reads and the chart does not create: the license Secret, the image pull Secret (from the license’s registry token, unless you use a mirror), and the certificates, CA bundle and broker password your install file names. The README lists the exact ones for your install file.

They do not create the Secrets your install file names by reference. database.existingSecret (the database password), registry.pullSecret (the pull Secret for your mirror) and tls.ingressSecretName (the ingress certificate) must already exist in the namespace before you run the scaffold: files/values.yaml points the release at them. Without the database Secret its pods cannot start, and without the mirror’s pull Secret its images cannot be pulled, while the scaffold waits up to 30 minutes for them. With Terraform, create the namespace yourself first and set create_namespace = false.

No secret is written into the files. Every secret, both the ones dojo-deploy install would generate and the ones your install file holds, becomes a variable you set. The README lists them for your install file. They typically include:

  • dojo_secret_key (DD_SECRET_KEY) and dojo_credential_aes256_key (DD_CREDENTIAL_AES_256_KEY)
  • dojo_cloud_portal_secret_key, dojo_admin_password and dojo_metrics_password
  • the internal service certificate (dojo_internal_ca_pem, dojo_internal_cert_pem, dojo_internal_key_pem) and the ddorch server certificate (dojo_orch_ca_pem, dojo_orch_cert_pem, dojo_orch_key_pem)
  • dojo_license_path, and passwords for an external broker or a proxy when your install file uses them

What you must edit, for either tool:

  • The secret values. Generate them once and keep them. A new secret key, AES key or database password on a later run breaks the install: stored credentials become unreadable.
  • The two certificates. dojo-deploy install makes them itself, but here they are yours to make: two CAs, and a server certificate signed by each, PEM-encoded. The README lists the DNS names each certificate needs for your namespace and release name.
  • The kubeconfig and context that reach the cluster.
  • Anything else in files/values.yaml you want to differ from the install file. To change the values from scratch, edit the install file and run scaffold again into a new directory.

The Kubernetes scaffolds do not run dojo-deploy check or dojo-deploy verify, and do not compare the chart’s resource requests with your nodes. They also do not read back the secrets an earlier dojo-deploy install generated: to take over such an install, read them from the release’s Secret into your variables first.

Kubernetes with Ansible

dojo-deploy scaffold ansible --target kubernetes also writes:

FileWhat it is
playbook.ymlThe playbook (hosts: localhost)
vars/release.ymlWhat the install file says: release, namespace, chart and its version, license and CA bundle paths. Nothing secret
secrets.example.ymlEvery variable with no default, to copy, fill in and encrypt

The playbook creates the namespace when it is missing, creates the Secrets and ConfigMaps with kubernetes.core.k8s, logs helm in to the registry with the license’s token when the chart comes from there, and runs helm upgrade --install with kubernetes.core.helm. kubernetes.core.helm cannot wait for the chart’s Jobs, so the playbook then waits up to 30 minutes for the initializer Job (migrations and the admin user) and fails when it failed.

cp secrets.example.yml secrets.yml   # fill it in
ansible-vault encrypt secrets.yml
ansible-playbook playbook.yml -e @secrets.yml --ask-vault-pass

It needs helm on the PATH, the kubernetes.core collection and the Python kubernetes package: with helm 3 (3.8 or later), kubernetes.core 5.1 or later; with helm 4, kubernetes.core 6.6.0 or later. Set dojo_kubeconfig and dojo_kube_context, or leave them unset to use your default kubeconfig’s current context.

Ansible reads a value holding {{, {% or {# as a template, and the task then fails. Mark such a value !unsafe in the Vault file, for example dojo_admin_password: !unsafe "pa{{ss". Every task that handles a secret has no_log: true, so a failure there prints no detail.

Kubernetes with Terraform

dojo-deploy scaffold terraform --target kubernetes also writes:

FileWhat it is
main.tfThe namespace, the Secrets and ConfigMaps, and the helm_release
variables.tfEvery variable. The defaults are what the install file says; the secret ones are sensitive
terraform.tfvars.exampleEvery variable with no default
versions.tfTerraform 1.5 or later, with the hashicorp/helm 3.x and hashicorp/kubernetes 3.x providers

The configuration creates the namespace with kubernetes_namespace_v1 (set create_namespace = false when it is already there), the Secrets and ConfigMaps, and the release with helm_release, waiting up to 30 minutes for its pods and Jobs. Set kubeconfig and kube_context to reach the cluster.

terraform init
terraform apply   # with the secret variables from TF_VAR_... or a terraform.tfvars you keep private

The state holds every secret value, so use a state backend that encrypts it.

Getting help

DefectDojo supports dojo-deploy, the install file and the Helm chart, not the scaffold’s files or your changes to them. For questions about those, contact your account representative or support@defectdojo.com, and say which scaffold your automation started from.