Skip to content

Add EC2 ops workflow driving the testnet node over SSM - #157

Open
ronkq wants to merge 9 commits into
zebra-ec2-configurationfrom
ops-ec2-workflow
Open

Add EC2 ops workflow driving the testnet node over SSM#157
ronkq wants to merge 9 commits into
zebra-ec2-configurationfrom
ops-ec2-workflow

Conversation

@ronkq

@ronkq ronkq commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Add EC2 ops workflow

One manual dispatch (Zebra EC2 Ops) to operate the EC2 zebra-testnet node,
replacing the ECS deploy-ecs / stop-ecs workflows.

The box has no inbound SSH and no key: commands run over SSM Run Command, which
invokes /opt/zebra/ops.sh on the instance. Auth is OIDC - no AWS access keys.

Inputs: action, image_tag (deploy only), instance_name_tag, confirm.

Actions

Action What it does
deploy Points .env at the given ECR tag, pulls it, recreates the container
restart Restarts the zebrad container
stop Stops the container
start Starts the container
recreate Force-recreates the container from the current image
logs Prints the last 200 log lines
status docker compose ps plus the running image ID
wipe-state Deletes the chain state, then restarts — requires confirm=wipe-state
reboot-instance Reboots the machine, waits for the SSM agent, then restarts the container

Only reboot-instance touches the machine; the rest act on the container.

Notes

  • Inputs are read through env, never interpolated into run bodies
    (template-injection sink).
  • deploy prepends a fresh docker login: the box's boot-time ECR token
    expires after 12h.
  • Command output is mirrored into the job summary.

@ronkq ronkq self-assigned this Aug 10, 2026
@ronkq
ronkq marked this pull request as ready for review August 11, 2026 13:08

@PaulLaux PaulLaux left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Added comments.
Also,
No environment, all other three workflows use environment: dev. Do we need an env?

Comment thread .github/workflows/ops-ec2.yaml Outdated
--parameters "commands=[\"bash /opt/zebra/ops.sh ${{ inputs.action }} ${{ inputs.image_tag }}\"]" \
--query Command.CommandId --output text)
aws ssm wait command-executed --command-id "$CMD" \
--instance-id "${{ steps.target.outputs.id }}" || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

true will swallow a fail here, is that what we want?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes for the true itself, as otherwise the step aborts before printing the output. So I added an explicit status check that still prints the result and fails the job on anything except Success

Comment thread .github/workflows/ops-ec2.yaml Outdated
contents: read

env:
AWS_REGION: eu-central-1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why hardcore and not env.AWS_REGION?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Switched to ${{ vars.AWS_REGION }}

Comment thread .github/workflows/ops-ec2.yaml Outdated
ops:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's pin it to a specific hash

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment thread .github/workflows/ops-ec2.yaml Outdated
--instance-id "${{ steps.target.outputs.id }}" || true
aws ssm get-command-invocation --command-id "$CMD" \
--instance-id "${{ steps.target.outputs.id }}" \
--query '[Status,StandardOutputContent,StandardErrorContent]' --output text \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

StandardOutputContent is capped at 24,000 chars. Is it enough?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, even the logs which have an internal cap that's smaller than that

Comment thread .github/workflows/ops-ec2.yaml Outdated
--document-name AWS-RunShellScript \
--parameters "commands=[\"bash /opt/zebra/ops.sh ${{ inputs.action }} ${{ inputs.image_tag }}\"]" \
--query Command.CommandId --output text)
aws ssm wait command-executed --command-id "$CMD" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

aws ssm wait command-executed gives up after 100 seconds. is it enough?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes except for deploy, for that changed to 15min

Comment thread .github/workflows/ops-ec2.yaml Outdated
run: |
CMD=$(aws ssm send-command --instance-ids "${{ steps.target.outputs.id }}" \
--document-name AWS-RunShellScript \
--parameters "commands=[\"bash /opt/zebra/ops.sh ${{ inputs.action }} ${{ inputs.image_tag }}\"]" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image_tag is a potential shell injection into the testnet node - nothing is checked and the user can input any value.

Constrain the image_tag using printf '%s' "$IMAGE_TAG" | grep -Eq '^[A-Za-z0-9._-]{1,128}$' || exit 1 or similar - no free text and escape chars.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point, and instance_id and confirm had a similar problem.
All inputs now go via env, so they arrive as variables, not spliced text, and added your regex on image_tag

@ronkq
ronkq changed the base branch from testnet-configuration to zebra-ec2-configuration August 14, 2026 20:28
@ronkq

ronkq commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Added comments. Also, No environment, all other three workflows use environment: dev. Do we need an env?

Fixed all comments, it's not mandatory, but added env to align.

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