Skip to content

fix: Hostnames list parsing function - #73

Merged
sewhyte merged 2 commits into
gremlin:mainfrom
pagbrl:fix-hostnames-parsing
Jul 1, 2022
Merged

sewhyte merged 2 commits into
gremlin:mainfrom
pagbrl:fix-hostnames-parsing

Conversation

@pagbrl

@pagbrl pagbrl commented Jun 14, 2022 •

Copy link
Copy Markdown
Contributor

This PR fixes an inconsistency we identified in the SDK (probably a bug).

Currently, passing a list of hostnames to the SDK is not correctly supported. In this example, we assume that it is possible to pass a list to the hostnames arg, consistent with what can be done with the ips and egress_ports args.

Code

        black_hole_attack = GremlinScenarioILFINode(
            command=GremlinBlackholeAttack(
                length=300,
                hostnames=['1.1.1.1', '2.2.2.2'],
                ips=['3.3.3.3', '4.4.4.4'],
                egress_ports=['54', '4405'],
            ),
            target=GremlinKubernetesAttackTargetHelper(
                percentage=100,
                targets=k8s_objects
            )
        )

        scenario.add_node(black_hole_attack)

        pprint.pprint(scenario.api_model())

Api model result :

        "impact_definition": {
          "infra_command_args": {
            "cli_args": [
              "blackhole",
              "-l",
              "300",
              "-i",
              "3.3.3.3,4.4.4.4",
              "-p",
              "54,4405",
              "-h",
              "2,.,2,.,2,.,2"
            ],
            "type": "blackhole"
          },
          "infra_command_type": "blackhole"
        },

As we can see, the parsing of the hostnames arg is not correct. That is because we're only using the last element of the list to the hostnames in the parsing function, returning a string, not a list. This in turn makes python split the string later (for hostname in hostnames on a string)

Here's the api model for this same snippet, with my proposed change :

        "impact_definition": {
          "infra_command_args": {
            "cli_args": [
              "blackhole",
              "-l",
              "300",
              "-i",
              "3.3.3.3,4.4.4.4",
              "-p",
              "54,4405",
              "-h",
              "1.1.1.1,2.2.2.2"
            ],
            "type": "blackhole"
          },
          "infra_command_type": "blackhole"
        },

Now the list is correctly represented in the API model. I have reused the same logic used for the ips.setter method ( (l. 863-869 attack_helpers.py), which I think is the correct one.

This change does not break the current SDK API, rather enforces it. It is still possible to use a Union[str, list] for this arg.

@pagbrl
pagbrl force-pushed the fix-hostnames-parsing branch from f379a37 to d0f3951 Compare June 14, 2022 10:07

@sewhyte sewhyte left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've tested this locally and it has the intended change.

@sewhyte
sewhyte merged commit 920f219 into gremlin:main Jul 1, 2022
sewhyte added a commit that referenced this pull request Jan 11, 2024
fix: Hostnames list parsing function
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.

2 participants