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

Templates are not getting scanned recursively. #140

Closed
Black742 opened this issue Sep 7, 2018 · 9 comments · Fixed by #226
Closed

Templates are not getting scanned recursively. #140

Black742 opened this issue Sep 7, 2018 · 9 comments · Fixed by #226
Labels
customer Initiated from, or received feedback about from outside Stelligent

Comments

@Black742
Copy link

Black742 commented Sep 7, 2018

The tool working good, however its not scanning all the files under a directory.
I have dir call templates and had lots file underneath, when i apply the cfn_nag_scan for that directory its scanning only a file file in that directory.

cfn_nag_scan --input-path ~/src/sample/templates/** --template-pattern ..*.template.json

C:/Users/test/src/sample/templates/testStack.template.json

Failures count: 0
Warnings count: 0

Could you please suggest me how to scan all the files underneath the directory?

@ghost
Copy link

ghost commented Sep 8, 2018

hmm..... well mileage may vary under wind0ze - we only run the tests on a *nix variant but..... looking at your command line, i'd suggest two things:

  1. the input-path should just be the root directory you want to "scan". you likely just want ~/src/sample/templates there

  2. the template-pattern is per file within the recursive directory hierarchy specified by input-path so... i'd drop the ".." and just specify '*.template.json'.

also beware of the shell globbing your asterisk/wildcard. in *nix land, you might need a single quote to make it a literal so that the shell doesn't substitute/swallow the specification before cfn-nag sees it.

please let me know if this helps. will have time this weekend to follow-up

@ghost
Copy link

ghost commented Sep 16, 2018

@Black742 any feedback on advice?

@Black742
Copy link
Author

Black742 commented Oct 5, 2018

@erickascic Have tried your suggestion and getting the issue below

CMD: cfn_nag_scan --input-path ~/src/sample/templates --template-pattern '*.template.yaml'
Error: file or url for option 'input_path' cannot be opened: Is a directory @ rb_sysopen - ~/src/sample/templates.
Try --help for help.

But, this syntax is working fine in the Linux machine.

@ghost
Copy link

ghost commented Oct 7, 2018

So this problem is particular to Wind0ze? Are you using cygwin or something so that the tilde will be substituted properly? I guess I'd try with the real path to the template e.g. C:/Users/tests/src/sample/templates

@virtuoushub
Copy link

The problem definitely seems particular to Windows. Although I am not using --template-pattern my inability to recursively traverse the --input-path is the same behavior as above. I have documented my findings below.

on *nix

$ cfn_nag_scan --input-path ./
------------------------------------------------------------
./foo/bar/foo.json
------------------------------------------------------------
Failures count: 0
Warnings count: 0
------------------------------------------------------------
./foo/foo/bar.json
------------------------------------------------------------------------------------------------------------------------
| WARN W12
|
| Resources: ["BarPolicy"]
|
| IAM policy should not allow * resource

Failures count: 0
Warnings count: 1
------------------------------------------------------------
./bar/foo/foo.yml
------------------------------------------------------------
Failures count: 0
Warnings count: 0
------------------------------------------------------------
./bar/foo/bar.json
------------------------------------------------------------
Failures count: 0
Warnings count: 0
$ bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

on Windows

$  cfn_nag_scan --input-path ./
Error: file or url for option 'input_path' cannot be opened: Is a directory @ rb_sysopen - ./.
Try --help for help.

I have also tried cfn_nag_scan --input-path .\, cfn_nag_scan --input-path ".\", cfn_nag_scan --input-path .\*, cfn_nag_scan --input-path .\**\* and combinations of those.

I am able to get the tool to "work"(scan the first item in a directory) on Windows if I do cfn_nag_scan --input-path ./foo/foo/bar/*

$ bash --version
bash --version
GNU bash, version 4.4.19(2)-release (x86_64-pc-msys)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

@sr-101
Copy link

sr-101 commented Oct 26, 2018

I downloaded the zip file, changed the input path argument type to string instead of io, rebuilt, and it works on windows now like it should.

opt :input_path,
'CloudFormation template to nag on or directory of templates. Default is all *.json, *.yaml, *.yml and *.template recursively, but can be constrained by --template-pattern',
type: :io,
required: true

to

opt :input_path,
'CloudFormation template to nag on or directory of templates. Default is all *.json, *.yaml, *.yml and *.template recursively, but can be constrained by --template-pattern',
type: :string,
required: true

@ghost
Copy link

ghost commented Feb 18, 2019

i had a chance to review this and reproduce... underneath trollop/optimist is a call to open-uri that is failing:

require 'open-uri'
open 'c:\some-directory'
BLAMMO

Will try to get back to this to fix this week

@Black742
Copy link
Author

@erickascic Any update?

@ghost ghost added the customer Initiated from, or received feedback about from outside Stelligent label May 29, 2019
jesseadams pushed a commit that referenced this issue Jun 6, 2019
@jesseadams
Copy link

@Black742 - Fix coming shortly!

@ghost ghost closed this as completed in #226 Jun 6, 2019
ghost pushed a commit that referenced this issue Jun 6, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer Initiated from, or received feedback about from outside Stelligent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants