awslabs / amazon-ebs-autoscale

Don't run out of disk space on your EC2 instance when generating or working with large files. Automatically add EBS volumes to a filesystem mount point in response to disk utilization.
MIT License
113 stars 60 forks source link

Issue with parsing of instance tags #43

Closed kgalens closed 2 years ago

kgalens commented 2 years ago

Overview

This refers to the parsing of instance tags in create-ebs-volume. There are 2 issues with the sed portion of the command (see: https://github.com/awslabs/amazon-ebs-autoscale/blob/0a8af79ea442a02c60c439a1ed0628af5b4f03ab/bin/create-ebs-volume#L171)

Issues and Examples (with proposed fixes)

  1. Currently, if the first tag returned by describe-tags is an AWS tag, the full list of tags will be removed. Code simplified for demonstration purposes:
    
    $ echo "{Key=aws:key1,Value=value1},{Key=aws:key2,Value=value2},{Key=custom:key3,Value=value3}" | sed 's/{Key=aws.*}//g ; s/,,/,/g ; s/^,//g'
This prints a blank line and instance_tags will be empty which will cause an error (this is also handled in PR #40, which is possibly caused by this issue). To fix, we can make the AWS regex less greedy:

$ echo "{Key=aws:key1,Value=value1},{Key=aws:key2,Value=value2},{Key=custom:key3,Value=value3}" | sed 's/{Key=aws[^}]*}//g ; s/,,/,/g ; s/^,//g' {Key=custom:key3,Value=value3}

Which I believe was the intended behaviour.

2. If more than 3 AWS tag has been removed, this will leave more than 2 commas in its place. Currently, the regex `s/,,/,/g` seems to handle this but will only work for precisely 2 in a row. To demonstrate:

$ echo "{Key=aws:key1,Value=value1},{Key=aws:key2,Value=value2},{Key=aws:key2a,Value=value2a},{Key=custom:key3,Value=value3}" | sed 's/{Key=aws[^}]*}//g ; s/,,/,/g ; s/^,//g' ,{Key=custom:key3,Value=value3}

After removing AWS tags, there are 3 commas left, the first are replaced by 1 comma (by `s/,,/,/g`) leaving 2 commas. One of which is then removed by `s/^,//g`.  Instead, we should be removing any sequence of 2 or more commas:

$ echo "{Key=aws:key1,Value=value1},{Key=aws:key2,Value=value2},{Key=aws:key2a,Value=value2a},{Key=custom:key3,Value=value3}" | sed 's/{Key=aws[^}]*}//g ; s/,{2,}/,/g ; s/^,//g' {Key=custom:key3,Value=value3}



### Pull Request
Submitted PR #42