Closed boonew2 closed 3 months ago
Hello! Thanks for the report - we're looking into this.
@boonew2 Can you please provide your Invoke-LMFunction
wrapper function? I'd like to reproduce this exactly as you have it and that's one missing piece here.
In your examples:
# this throws the error
Invoke-CfnGuardLambda -TemplatePath C:\temp\template.yml -RulesetPath C:\temp\rules.ruleset
errorType errorMessage
--------- ------------
&alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync> trailing characters at line 1 column 19
# this returns the verbose response as expected
Invoke-CfnGuardLambda -Verbose | ConvertTo-Json -Compress
{"message":[{"context":"File(rules=1)","container":"@{FileCheck=}","children":""}]}
Regarding this: Invoke-CfnGuardLambda -Verbose | ConvertTo-Json -Compress
How does that work with the missing parameters? Do you have a default set in your lambda invoker function for rules/files? I'm not sure the verbose
flag is having an impact here as the example commands appear to be doing different things entirely.
Additionally, It doesn't look like template files are getting passed in based on the output FileCheck=
and since you mention that you're on Windows, using pwsh, and commenting paths in and out with success I'd wager it's something to do with paths on windows or just illegal characters from windows when reading the files in using Get-Content
and trying to create valid JSON to pass as a payload.
By default Windows paths aren't valid JSON since they use backslash as a separator and most parsers are going to treat that as an escape. If the filenames are at all included in the payload and you are trying to convert back and forth to JSON using powershell, that may actually be the problem but I'd like to narrow down the exact root cause of your pain.
Can you also send over the template as it's getting logged in CloudWatch? I'd be interested to see how the paths are rendered after being sent through to the lambda.
HI @boonew2, checking in here. Please provide my colleague @dannyvassallo with the information he requested when you have a moment.
Hi, I am going to close this issue out. Feel free to reopen if you feel the need.
Thanks
@dannyvassallo @joshfried-aws sorry for the delay in response. Apparently updates on this got caught in an email filter on my end. Invoke-LMFunction
is the default function in the powershell sdk; nothing i've implemented on my end.
Regarding this:
Invoke-CfnGuardLambda -Verbose | ConvertTo-Json -Compress
It doesn't. That is definitely a typo on my end and should have been Invoke-CfnGuardLambda -Verbose -TemplatePath C:\temp\template.yml -RulesetPath C:\temp\rules.ruleset | ConvertTo-Json -Compress
By default Windows paths aren't valid JSON since they use backslash as a separator and most parsers are going to treat that as an escape. If the filenames are at all included in the payload and you are trying to convert back and forth to JSON using powershell, that may actually be the problem but I'd like to narrow down the exact root cause of your pain.
Invoke-CfnGuardLambda
dumps the file output into the payload; the file paths themselves aren't preserved in it.
Can you also send over the template as it's getting logged in CloudWatch? I'd be interested to see how the paths are rendered after being sent through to the lambda.
Attaching the cloudwatch stream; I don't recommend looking at the csv in excel.. the formatting is messed up log-events-viewer-result (2).csv
Feel free to reopen if you feel the need.
I don't think i can re-open from my end. ~I haven't tested this for awhile though, i'll pull latest bits and confirm that it is still an issue~ 3.1.1 is still latest it looks like so there aren't newer bits to pull
Describe the bug When invoking the cfnGuard lambda with
"verbose": false
in the payload it seems to break parsing of the template in a hard to pin down way.. Error from the lambda is:To Reproduce Please supply:
Sample ruleset
I'm invoking the lambda through a small powershell wrapper while testing, but i'm pretty sure another language would have the same results:
Logs: cloudwatch logs dump the template that i already pasted, the ruleset, and then the error message returned in the response. I don't want to spam this to much so i'll just include the ruleset/error logs:
NOTE: Please be sure that the templates, rules and logs you provide as part of your bug report do not contain any sensitive information.
Expected behavior Specifying
verbose: false
in the payload doesn't break the lambdaOperating System: Windows
OS Version 11
Additional context The exact thing in the provided template that causes the error is really weird to pin down. If i comment out some of the paths in the api resource it will stop failing with
verbose: false
. If i comment out specific lines it will also start to work as expected, but i can't see anything in those lines that would be remotely problematic. The template is very trimmed down so it has someRef
s to things that aren't provided in it, but i don't think that should matter to Guard (and the full template has the same behavior)