Skip to content

Emis test backend#325

Draft
rebkwok wants to merge 7 commits intomainfrom
emistest-backend
Draft

Emis test backend#325
rebkwok wants to merge 7 commits intomainfrom
emistest-backend

Conversation

@rebkwok
Copy link
Copy Markdown
Contributor

@rebkwok rebkwok commented Apr 7, 2026

Adds packer configuration at backends/emistest/packer/emis-base.pkr.hcl which defines the steps required to build both an EC2 AMI and a vagrant test box.

It defines 2 sources, emis-base, which uses the amazon-ebs builder, and contains the information needed to build an AMI, and emis-test, which uses the vagrant builder. Builds should be run through the just packer-build-aws/vagrant recipes, which specify an -only parameter and will build the specified source only.

As much as possible, the 2 sources do the same things, so we can use the vagrant source to test the provisioning.

It also runs using the same just commands and scripts as all the other backends as much as possible. The first step in the provisioning clones this repo using the specified branch, so that commands can be run from within the /srv/backend-server dir, as for any other backend.

It has 2 additional custom scripts:

  1. backends/emistest/scripts/install_aws_cli.sh, for the awscli installation, which is specific to emis.
  2. clean-image.sh does some cleanup that's copied from backends/tpp/clean-image.sh
    Note that cloud-init files are not copied over for the aws source, they'll be used at instance launch.

We also define different cloud-init config for vagrant and aws. In the aws cloud-init user-date, as an example, we fetch some test (secureString) secrets from aws parameter store and use it to populate a value in an env file. This will get run when we launch an ec2 instance from this AMI.

@rebkwok rebkwok force-pushed the emistest-backend branch 5 times, most recently from ea48844 to 63b743f Compare April 8, 2026 12:30
rebkwok added 7 commits April 15, 2026 08:46
Airlock needs it to be set to _something_ in order to start up.
Add a pyproject.toml and minimal dependencies
Mimics test backend env, plus:
Adds BACKENDS: The agent typically uses the default BACKENDS to verify that its
BACKEND is valid; emistest isn't one of the default values yet, so
we add an explicit BACKENDS var for this backend which will let the
agent service start.

Set TEST=true which will mean Airlock skips trying to update certicates when just
autodeploy runs.

Add a django allowed host that will let us connect to airlock from outside.
This adds a packer configuration file at
backends/emistest/packer/emis-base.pkr.hcl which defines the steps
required to build both an EC2 AMI and a vagrant test box.

It defines 2 sources, emis-base, which uses the amazon-ebs builder,
and contains the information needed to build an AMI, and emis-test,
which uses the vagrant builder.  Builds should be run through the
just packer-build-aws/vagrant recipes, which specify an -only parameter
and will build the specified source only.

As much as possible, the 2 sources do the same things, so we can use
the vagrant source to test the provisioning.

It also runs using the same just commands and scripts as all the other
backends as much as possible. The first step in the provisioning clones
this repo using the specified branch, so that commands can be run from
within the /srv/backend-server dir, as for any other backend.

It has 2 additional custom scripts:
1) backends/emistest/scripts/install_aws_cli.sh, for the awscli installation,
which is specific to emis.
2) clean-image.sh does some cleanup that's copied from backends/tpp/clean-image.sh
Note that cloud-init files are not copied over for the aws source,
they'll be used at instance launch.

We also define different cloud-init config for vagrant and aws.
In the aws cloud-init user-date, as an example, we fetch some test
(secureString) secrets from aws parameter store and use it to populate a value in an
env file. This will get run when we launch an ec2 instance from this AMI.
The cracklib-runtime package is needed for the forced password change
on initial login. It seems to already be there in other backends (or
maybe it's manually installed). In any case, it's not installed after
the packer builder finishes, so include it in the list.

Also check for the existence of motd scripts before chmod'ing them.
# This file is safe to edit by hand: it will not be overwritten by config management

# Credentials for logging into the job server for this backend
JOB_SERVER_TOKEN=
Copy link
Copy Markdown
Member

@bloodearnest bloodearnest Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think hardcoding a dummy value this is fine for our own bearer tokens, as they are simple bearer tokens that must exactly matche, and a dummy value like this making it into production would be broken, but not insecure.

I wouldn't want to use it for django secret key type secret though, where a lack of randomness or known value in production would be a problem.

We could generate some randomness when we first copy the template, perhaps.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I agree, but we do actually already do it for the django secret key, in this very file. I'm guessing it was for the same reason that I've added this dummy value, Airlock won't start successfully without it

@@ -0,0 +1,34 @@
#cloud-config
# having an explict user specified disables the default ubuntu user
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely.

We've never had much control over the first instatiation of a VM image before.

Can we also set the uid to 10000 here? The install_opensafely_user.sh script will DTRT if needed, but wonder if it might be worth ensuring it here first?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can, I'm going to give that a try now.

Comment thread packages.txt
unattended-upgrades
libpam-pwquality
# required for password changes
cracklib-runtime
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this because emistest is using 24.04 image, and all our others use 22.04

Looks like cracklib-runtime is not installed in 24.04 by default.

We had the same issue in TED backend work.

There's some work here I think.

We may want to think about standardising them all on 24.04 (which means upgrading TPP in place).

Or we may want to support/test on multiple versions of ubuntu.

@@ -0,0 +1,30 @@
#!/bin/bash
set -euo pipefail
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per other comment, worth noting that the tests harness currently runs everything in a 22.04 image.

Ideally, we'd want to run emistest tests in 24.04 image. In practice, there's likely little that would break. But we'd want to know when it did.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think whilst its good to have local tests, we'll also want AMI/AWS deployed test as well? That will use 24.04, and so might cover that case well enough for now

Copy link
Copy Markdown
Member

@bloodearnest bloodearnest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, fits quite cleanly in the end.

The AWS side of things definitely makes this the most different backend so far from all the rest.

@@ -0,0 +1,30 @@
#!/bin/bash
set -euo pipefail
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think whilst its good to have local tests, we'll also want AMI/AWS deployed test as well? That will use 24.04, and so might cover that case well enough for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants