feat: dont register instance when metadata service give us bad results #188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds validation to prevent worker pool instances from registering when the EC2 metadata service returns null or invalid values for critical instance metadata.
Motivation
In rare cases, the EC2 metadata service can return null, empty, or malformed responses for instance metadata queries. When this happens, worker pool instances would attempt to register with Spacelift using invalid metadata (null instance IDs, AMI IDs, or ASG names), which can cause registration failures, tracking issues, or unexpected behavior in the worker pool management system.
This defensive validation prevents instances from proceeding with the registration process when they receive bad data from the metadata service, failing fast with clear error messages instead of propagating invalid state.
Changes
validate_metadata()function to both SaaS and self-hosted user data templatesinstance_id,ami_id, andasg_idafter retrieval from EC2 metadata service/var/log/spacelift/error.logwhen validation failsFixes
Behavior
When an instance receives invalid metadata from the EC2 metadata service:
spacelift()function returns early (exit code 1), preventing launcher startupThis fail-fast behavior ensures that only instances with valid metadata can register with the worker pool, making it easier to identify and troubleshoot metadata service issues rather than dealing with mysteriously broken instances.
Note
Add EC2 metadata validation to SaaS and self-hosted user data to fail fast on invalid values; bump module version to 5.4.2.
user_data/saas.tftpl: Addvalidate_metadataand validateinstance_id,ami_id,asg_id; log errors andreturn 1to prevent launcher start when invalid.user_data/selfhosted.tftpl: Addvalidate_metadatainrun-launcher.sh; validateinstance_id,ami_id,asg_id; log errors andexit 1on failure..spacelift/config.yml: Bumpmodule_versionto5.4.2.Written by Cursor Bugbot for commit a717566. This will update automatically on new commits. Configure here.