manheim / manheim-c7n-tools

Manheim's Cloud Custodian (c7n) wrapper package, policy generator, runner, and supporting tools.
https://manheim-c7n-tools.readthedocs.io/
Apache License 2.0
45 stars 25 forks source link

Config file does not support AWS account numbers starting with 0 #18

Closed rctheinventor closed 4 years ago

rctheinventor commented 4 years ago

I have a policy repo set up with a manheim-c7n-tools-yml file. There are 4 accounts specified and I also have some defaults some account and region specific policies, as well as some policies for all accounts.

Everything works as expected for all the accounts with an account number that does not start with a 0. I have on account that starts with a 0, and whenever I include that in my config file, policygen, dryrun, and run operations start to fail with the following exception. (details are redacted for security purposes but you can see below that the account number starts with 09.

(py37) rc-mpb2:rchaseio-c7n-manheim rchase$ make manheim-dryrun-app docker run -it --rm \ -v /Users/rchase/repo/rchaseio-c7n-manheim:/configs \ --workdir /configs \ -e "AWS_ACCESS_KEY_ID=AKxxxxxxxxxxxxxxxxx6G" \ -e "AWS_SECRET_ACCESS_KEY=Wxxxxxxxxxxxxxxxxxxxxu" \ manheim/manheim-c7n-tools:latest \ manheim-c7n-runner -r us-east-1 -v -v \ --step=policygen --step=validate \ run rchaseio.app 2020-03-25 20:57:05,577 [INFO config.py:139 - manheim_c7n_tools.config.from_file() ] Loading config from: manheim-c7n-tools.yml 2020-03-25 20:57:05,603 [DEBUG config.py:118 - manheim_c7n_tools.config.init() ] Validating configuration... Traceback (most recent call last): File "/usr/local/bin/manheim-c7n-runner", line 11, in load_entry_point('manheim-c7n-tools', 'console_scripts', 'manheim-c7n-runner')() File "/manheim_c7n_tools/manheim_c7n_tools/runner.py", line 618, in main cr = CustodianRunner(args.ACCT_NAME, args.config) File "/manheim_c7n_tools/manheim_c7n_tools/runner.py", line 413, in init self.config = ManheimConfig.from_file(config_path, account_name) File "/manheim_c7n_tools/manheim_c7n_tools/config.py", line 145, in from_file return ManheimConfig(**acct_conf) File "/manheim_c7n_tools/manheim_c7n_tools/config.py", line 119, in init jsonschema.validate(kwargs, MANHEIM_CONFIG_SCHEMA) File "/usr/local/lib/python3.7/site-packages/jsonschema/validators.py", line 934, in validate raise error jsonschema.exceptions.ValidationError: '091xxxxxxxx71' is not of type 'number'

Failed validating 'type' in schema['properties']['account_id']: {'type': 'number'}

On instance['account_id']: '09xxxxxxx71'

I've tried to force it to be interpreted as a number by using !!int but that's also not working:

File "/usr/local/lib/python3.7/site-packages/yaml/constructor.py", line 92, in construct_object data = constructor(self, node) File "/usr/local/lib/python3.7/site-packages/yaml/constructor.py", line 244, in construct_yaml_int return sign*int(value, 8) ValueError: invalid literal for int() with base 8: '09xxxxxxxx71'

Any suggestions? We have several accounts with account numbers that start with zero. I'm hoping there is some yaml solution that I'm missing here before I have to go start digging into the manheim code itself.

jantman commented 4 years ago

@rctheinventor Apologies for this, Ryan. This is definitely a bug in manheim-c7n-tools, that we haven't discovered yet because we haven't yet run this code in an account with a 0 ID.

I'll get to work on a fix for this ASAP.

jantman commented 4 years ago

Thanks so much for reporting this issue, and apologies about it!

This has been fixed in 0.8.3 which is now live on Docker Hub with the master, latest, and 0.8.3 tags.

rctheinventor commented 4 years ago

Thanks for the quick response and turnaround Jason, much appreciated. I'll test it out today.

rctheinventor commented 4 years ago

I've tested the fix, it works. Thanks!