Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate file system type for EBS-backed task attachment payload #3954

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

mye956
Copy link
Contributor

@mye956 mye956 commented Oct 10, 2023

Summary

This PR will introduce a new validation check for the attachment payload of EBS-backed task. Specifically if the file system type is included within the attachment payload then we want to ensure that they are of the following types:

  • xfs
  • ext2
  • ext3
  • ext4
  • ntfs

Implementation details

Implemented a new functionality called ValidateFileSystemType that checks if the filesystem value is one of the specified types listed above. These types are essentially stored as a set called AllowedFSTypes.

Testing

Modified the existing unit tests within the attachment resource responder to now also check if we receive any errors if the file system type is some invalid value as well as empty.

New tests cover the changes: Yes

Description for the changelog

Validate file system type within attachment payload of EBS-backed tasks

Does this PR include breaking model changes? If so, Have you added transformation functions?

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mye956 mye956 marked this pull request as ready for review October 10, 2023 17:10
@mye956 mye956 requested a review from a team as a code owner October 10, 2023 17:10
@mye956 mye956 changed the title WIP Validate file system type for EBS-backed task attachment payload Validate file system type for EBS-backed task attachment payload Oct 10, 2023
ecs-agent/acs/session/attach_resource_responder.go Outdated Show resolved Hide resolved
@@ -202,6 +202,10 @@ func validateAttachmentAndReturnProperties(message *ecsacs.ConfirmAttachmentMess
if err != nil {
return nil, errors.Wrap(err, "resource attachment validation by attachment type failed")
}
err = resource.ValidateFileSystemType(attachmentProperties[resource.FileSystemKey])
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - can we have some unit tests to enforce/make sure

  • all allowed file system are allowed as expected
  • others will be disallowed/failed as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, changes were made to the attach resource responder unit test to check for invalid values for file system types. I'll add some changes for happy cases as well

Comment on lines 252 to 273
for _, property := range confirmAttachmentMessageCopy.Attachment.AttachmentProperties {
if aws.StringValue(property.Name) == resource.FileSystemKey {
originalPropertyValue := property.Value
property.Value = aws.String("SomeFilesystemType")
_, err = validateAttachmentAndReturnProperties(&confirmAttachmentMessageCopy)
require.Error(t, err)
property.Value = originalPropertyValue

originalPropertyValue = property.Value
property.Value = aws.String("")
_, err = validateAttachmentAndReturnProperties(&confirmAttachmentMessageCopy)
require.Error(t, err)
property.Value = originalPropertyValue
}
}
Copy link
Contributor

@amogh09 amogh09 Oct 10, 2023

Choose a reason for hiding this comment

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

[non-blocking] In future I recommend separating out test cases from test runner code to better readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep I agree, the unit test in our attach resource responder is a bit messy to read. I'll add a todo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, I like the idea of separating this out of the runner code. I made it's own test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

@@ -74,6 +74,16 @@ const (
FileSystemKey = "fileSystem"
)

var (
AllowedFSTypes = map[string]bool{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to export this map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point! I'll restrict this to be private instead of global

@mye956 mye956 force-pushed the ebsFSValidation branch 2 times, most recently from 9422ad4 to 396f5f8 Compare October 10, 2023 18:04
amogh09
amogh09 previously approved these changes Oct 10, 2023
@mye956 mye956 merged commit a81064e into aws:dev Oct 11, 2023
7 checks passed
@mye956 mye956 deleted the ebsFSValidation branch October 11, 2023 00:30
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.

5 participants