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

Not honouring parameters configuration file for generated Config Rule Resource Names #414

Open
julienbonastre opened this issue Apr 6, 2023 · 1 comment

Comments

@julienbonastre
Copy link

Problem

  • A reproducible test case or series of steps
    Easy. Just use any recent version of rdk to deploy or create_rule_template and take note of the AWS Config Rule "Name" value. It is not what is configured in the parameters.json file under the Parameters.RuleName field as expected but the actual directory name it discovers the file within

This can be clearly seen in the source:

aws-config-rdk/rdk/rdk.py

Lines 3319 to 3328 in ff944bc

rule_names = []
if self.args.all:
d = "."
for obj_name in os.listdir("."):
obj_path = os.path.join(".", obj_name)
if os.path.isdir(obj_path) and not obj_name == "rdk":
for file_name in os.listdir(obj_path):
if obj_name not in rule_names:
if os.path.exists(os.path.join(obj_path, "parameters.json")):
rule_names.append(obj_name)

  • The version of our code being used
    This is seen in latest: https://github.com/awslabs/aws-config-rdk/releases/tag/0.12.0 but no doubt extends for the lifespan of this solution

  • Any modifications you've made relevant to the bug
    None

  • Anything unusual about your environment or deployment
    None, this will occur in a stock, clean build environment

Suggestion

Extend a method that is used to actually read the configured RuleName value from the parameters.json file during Resource instance creation, rather than the directory name.

It would be nice to use that name consistently throughout the framework however I can see it is used and referenced heavily throughout as an index for many other mappings so it's probably easiest to just perform this step at some point where it parses the JSON config and generate a new class property to capture/hold this PublishedRuleName or something akin

@julienbonastre julienbonastre changed the title Bug - Not honouring parameters configuration file for generated Config Rule Resource Names Not honouring parameters configuration file for generated Config Rule Resource Names Apr 17, 2023
@bmorrissirromb
Copy link
Collaborator

bmorrissirromb commented Jun 21, 2023

The validation that parameters.json exists is already done in line 3327, so this could be a short fix to change line 3328 to this:

params_file = open(os.path.join(obj_path, "parameters.json"))
rule_names.append(json.load(params_file)["Parameters"]["RuleName"])
params_file.close()

Before implementing a change like this, I'm curious why it's necessary. rdk create's default behavior is to match the rule name and directory name. In the use case where they're different, why should the parameters.json value be "truthier" than the directory name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants