Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

feat(aws): add multi-arch support #407

Closed
wants to merge 1 commit into from
Closed

Conversation

chrisgacsal
Copy link
Contributor

Description

Extend AWS provider config to support setting architecure specific AMI and Instance Type used for Scanner Instance creation.

Type of Change

[ ] Bug Fix
[x] New Feature
[ ] Breaking Change
[ ] Refactor
[x] Documentation
[ ] Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@chrisgacsal chrisgacsal self-assigned this Jun 13, 2023
@chrisgacsal chrisgacsal added enhancement New feature or request work in progress Pull requests which are being actively worked on and are not ready for review labels Jun 13, 2023
@chrisgacsal
Copy link
Contributor Author

This PR relies on #388 to be merged first.

@chrisgacsal chrisgacsal force-pushed the aws-multiarch-support branch 4 times, most recently from 07089a7 to 77715e9 Compare June 14, 2023 19:44
@chrisgacsal chrisgacsal marked this pull request as ready for review June 14, 2023 20:16
@chrisgacsal chrisgacsal requested a review from a team as a code owner June 14, 2023 20:16
@chrisgacsal chrisgacsal removed the work in progress Pull requests which are being actively worked on and are not ready for review label Jun 15, 2023
@chrisgacsal chrisgacsal added this to the v0.5.0 milestone Jun 15, 2023
VMCLARITY_AWS_IMAGE_OWNERS=${ScannerAMIOwnersFilter}
# Comma separated list of architecture:instance_type pairs used by the Provider to determine the instance type
# for the Scanner instance based on the Targets architecture.
VMCLARITY_AWS_INSTANCE_MAPPING=${ScannerInstanceTypeMapping}
Copy link

Choose a reason for hiding this comment

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

nit: can we change this to "AWS_INSTANCE_TYPE_MAPPING"?

Honestly I wonder if using a single environment variable is a good idea, I think it might be nicer to utilise viper's ability to unmarshal into a struct then we could have:

type InstanceTypeMapping struct {
    X8664 string `mapstructure:"x86_64"`
    Arm64 string `mapstructure:"arm64"`
}

and then do:

_ = BindEnv("instance_type_mapping.x86_64")
_ = BindEnv("instance_type_mapping.arm64")

Which would translate the the environment vars:

VMCLARITY_AWS_INSTANCE_MAPPING.X86_64=...
VMCLARITY_AWS_INSTANCE_MAPPING.ARM64=...

if we add a StringReplace to switch . for _ then it could be even nicer. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did exactly this in the first iteration and I like the current one better. Having separate env var for each architecture will bloat the configuration when we start support more than 2 architectures. I have no strong preference so I can change this to use separate env vars.

Copy link

Choose a reason for hiding this comment

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

I can see how this is more flexible and less messy from an environment var perspective. I'm kind of thinking about it from a yaml configuration perspective if we want to switch (or support both eventually):

instance_type_mapping:
  x86_64: foo
  arm64: bar

I like the idea that if we separate the structure in the Config struct that we can do things like this too:

v.SetDefault("instance_type_mapping.x86_64", "....")
v.SetDefault("instance_type_mapping.ARM64", "....")

That way you don't override the whole instance_type mapping if you only specify the x64 instance type. If we can unmarshal that into the map[string]string{} then continues to give us flexibility, if we need to add another arch we just need to add another BindEnv. (The regex validation means we have to make a code change to add a new arch today anyway, so adding another BindEnv and SetDefault is the same effort)

I think if I'm right @sagikazarmark might be able to correct me. If we go the route above (combined with your code) we can support both:

If you only want to override the default for x86_64:

INSTANCE_TYPE_MAPPING.x86_64=...

If you want to override everything:

INSTANCE_TYPE_MAPPING=x86_64:<instance type>,arm64:<instance type>

# for the Scanner instance based on the Targets architecture.
VMCLARITY_AWS_INSTANCE_MAPPING=${ScannerInstanceTypeMapping}
# Optional. Always use this architecture for Scanner instance. Make sure that there is a valid mapping defined in VMCLARITY_AWS_INSTANCE_MAPPING
# for this architecture.
Copy link

Choose a reason for hiding this comment

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

Maybe worth specifying that if not provided then the Scanner will attempt to match the arch of the target system?

Do we need this option? Could we just not specify a mapping for a specific arch, and the default behaviour if we don't have a mapping can be use the first arch specified in the mapping or something?

It looks like the current behaviour is to fail if we have a target with an arch we don't understand, I'm not sure this is the best option as we should be able to at least try to scan with a scanner of a different arch and if the scanners fail then so be it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need this option? Could we just not specify a mapping for a specific arch, and the default behaviour if we don't have a mapping can be use the first arch specified in the mapping or something?

We can do this too. I just wanted to allow the user to explicitly set the arch they want to use instead of the implicit behaviour.

It looks like the current behaviour is to fail if we have a target with an arch we don't understand, I'm not sure this is the best option as we should be able to at least try to scan with a scanner of a different arch and if the scanners fail then so be it.

I am not sure about falling back to a different arch is a good idea either. It is hard to predict the outcome of the scan as the scanner may fail, may report false positives, etc.
Anyways, will change this too to do a fallback.

}

return imageID, nil
}
Copy link

Choose a reason for hiding this comment

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

not sure I like getting the random latest release for an AMI, if they publish a bad release it means that randomly scans which were working will start failing with no change to the system's configuration. I think I would much rather pre-determine this ahead of time as part of the configuration and then if we want to move to a newer version it be a stack upgrade or configuration change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not think this is an issue as the chance for us encountering a bad image is slim. While the burden of keeping the AMI list update is real. Anyways, will make it a static config.

@@ -1633,6 +1633,8 @@ components:
launchTime:
type: string
format: date-time
architecture:
type: string
Copy link

Choose a reason for hiding this comment

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

Should this be an enum so that it can be standardised among cloud providers? I'm aware of at least 3 different ways things represent x64 it can be: x86_64 or x64 or AMD64.

I would prefer that we pick one and make that the standard for the API and UI this will be especially important when we start mixing multiple cloud providers reporting assets and you want to use an odata filter to find all the x64 VMs for example.

@chrisgacsal chrisgacsal modified the milestones: v0.5.0, v0.6.0 Jun 19, 2023
@lgecse
Copy link
Member

lgecse commented Aug 17, 2023

@Tehsmash @akpsgit Are we waiting for something regarding this PR? Last activity seems like was 2 months ago.

@chrisgacsal chrisgacsal marked this pull request as draft August 21, 2023 10:51
@lgecse lgecse modified the milestones: v0.6.0, v0.7.0 Sep 28, 2023
@chrisgacsal chrisgacsal added the no-stale Marks an issue so that it never goes stale. label Oct 2, 2023
@ramizpolic ramizpolic modified the milestones: v0.7.0, v0.8.0 May 14, 2024
@ramizpolic ramizpolic modified the milestones: v0.8.0, future Jul 29, 2024
@ramizpolic
Copy link
Member

We will be addressing this feature in a separate repo. Lots of useful feedback here that we were able to use for the revisited design. Closing due to unification

@ramizpolic ramizpolic closed this Aug 9, 2024
@ramizpolic ramizpolic deleted the aws-multiarch-support branch August 27, 2024 08:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request no-stale Marks an issue so that it never goes stale.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants