Skip to content

Commit 0134404

Browse files
authored
Merge pull request #579 from zalando-stups/fix/force-metadataoptions-httptokens-optional
Always set HttpTokens to optional
2 parents 6c53449 + 60f771d commit 0134404

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

senza/components/auto_scaling_group.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from senza.utils import ensure_keys
1212

1313
# properties evaluated by Senza
14-
SENZA_PROPERTIES = frozenset(["SecurityGroups", "Tags"])
14+
SENZA_PROPERTIES = frozenset(["SecurityGroups", "Tags", "MetadataOptions"])
1515

1616
# additional CF properties which can be overwritten
1717
ADDITIONAL_PROPERTIES = {
@@ -78,6 +78,9 @@ def component_auto_scaling_group(
7878
"AssociatePublicIpAddress", False
7979
),
8080
"EbsOptimized": configuration.get("EbsOptimized", False),
81+
"MetadataOptions": {
82+
"HttpTokens": "optional" # we want to still be able to use IMDSv1
83+
},
8184
},
8285
}
8386

tests/test_components.py

+44
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,50 @@ def test_component_auto_scaling_group_optional_metric_type():
743743
assert "FooNetworkAlarmHigh" not in result["Resources"]
744744

745745

746+
def test_component_auto_scaling_hardcoded_metadata_http_tokens():
747+
# we have MetadataOptions->HttpTokens 'optional' enforcement hardcoded
748+
definition = {"Resources": {}}
749+
configurations = [
750+
{
751+
'Name': 'Foo',
752+
'InstanceType': 't2.micro',
753+
'Image': 'foo',
754+
},
755+
{
756+
'Name': 'Foo',
757+
'InstanceType': 't2.micro',
758+
'Image': 'foo',
759+
'MetadataOptions': {
760+
'HttpTokens': 'required',
761+
}
762+
},
763+
{
764+
'Name': 'Foo',
765+
'InstanceType': 't2.micro',
766+
'Image': 'foo',
767+
'MetadataOptions': {
768+
'HttpTokens': 'optional',
769+
'HttpPutResponseHopLimit': 42,
770+
}
771+
},
772+
]
773+
774+
args = MagicMock()
775+
args.region = "foo"
776+
info = {
777+
'StackName': 'FooStack',
778+
'StackVersion': 'FooVersion'
779+
}
780+
781+
for configuration in configurations:
782+
result = component_auto_scaling_group(definition, configuration, args, info, False, MagicMock())
783+
784+
err_msg = "Failed configuration: {}".format(str(configuration))
785+
assert result["Resources"]["FooConfig"]["Properties"]["MetadataOptions"]["HttpTokens"] == \
786+
"optional", err_msg
787+
assert len(result["Resources"]["FooConfig"]["Properties"]["MetadataOptions"]) == 1, err_msg
788+
789+
746790
def test_to_iso8601_duration():
747791
with pytest.raises(click.UsageError):
748792
to_iso8601_duration("")

0 commit comments

Comments
 (0)