-
Notifications
You must be signed in to change notification settings - Fork 758
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
feat: Add external_data
function to Gator Test command
#2789
Conversation
ebf63e4
to
4fbc9be
Compare
@maxsmythe @sozercan Can I please get some initial feedback here? I'll add tests afterward. |
4fbc9be
to
fdffa22
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #2789 +/- ##
==========================================
- Coverage 53.56% 53.41% -0.16%
==========================================
Files 128 128
Lines 11411 11462 +51
==========================================
+ Hits 6112 6122 +10
- Misses 4822 4861 +39
- Partials 477 479 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
fdffa22
to
6551ae3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR! Excited to see this take shape. Before acting on any feedback, please wait on max/ sertac to see what other comments they may have
cmd/gator/test/test.go
Outdated
Cmd.Flags().BoolVarP(&flagEnableExternalData, "external-data", "e", false, "enable external_data function in Constraint Templates.") | ||
Cmd.Flags().StringArrayVarP(&flagExternalDataProviders, "external-data-providers", "", []string{}, "a file containing External Data Provider. Can be specified multiple times.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the existence of external-data-providers
implies that external-data
is true so we could get away with just using the latter flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, probably don't need two options in test.Opts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for using a different flag to source providers vs. the rest of the cluster config? Avoiding letting untrusted config reach out to arbitrary HTTP endpoints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No specific reason. :) I agree with Alex's suggestion that the existence of external-data-providers
implies that external-data
is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. I think security is a good consideration as far as separating out the providers folder (at least potentially). And, if we do have a providers folder, that can probably take the place of an enabled/disabled flag. Maybe users who have a hard requirement of "absolutely no reaching out to external services" might take comfort in an explicit flag though.
@sozercan thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sozercan Kind reminder. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on having an explicit flag to enable/disable external data. though I prefer something like enable-external-data
@maxsmythe @sozercan A kind reminder. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in review
cmd/gator/test/test.go
Outdated
Cmd.Flags().BoolVarP(&flagEnableExternalData, "external-data", "e", false, "enable external_data function in Constraint Templates.") | ||
Cmd.Flags().StringArrayVarP(&flagExternalDataProviders, "external-data-providers", "", []string{}, "a file containing External Data Provider. Can be specified multiple times.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for using a different flag to source providers vs. the rest of the cluster config? Avoiding letting untrusted config reach out to arbitrary HTTP endpoints?
pkg/gator/test/test.go
Outdated
// this has to happen before creating the client, because rego.AddExternalDataProviderCache arg to the driver must have | ||
// a ProviderCache already set up | ||
providerCache := frameworksexternaldata.NewCache() | ||
for _, obj := range objs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If having a separate flag is for security purposes, we'd also need to load in the data separately, currently providers defined in any file would be ingested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should figure out our stance vis-a-vis security in the other comment (link below). Then this comment will either be irrelevant, or very relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxsmythe Could you please give me some pointers on how to implement this?
Should ReadSources() function contain something like
s, err = readExternalDataSourceFiles(externalDataProviderFiles)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to load the external data provider config from its dedicated directory, then we should change this line to skip over external data provider config, and then either
- Reuse
readFiles
function like:s, err = readFiles(externalDataProviderFiles)
- Create a new function like:
readExternalDataSourceFiles(externalDataProviderFiles)
.
and then append the result to sources
. Am I on the right path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxsmythe @ritazh Please take another look. I'll add the tests afterward.
Sorry for the delay. +1 on @acpana and @maxsmythe's comments. |
6551ae3
to
b283ea9
Compare
In terms of unit tests, what do we do about the |
for go http unit tests, we might be able to use https://pkg.go.dev/net/http/httptest for mock rego tests, see #2826 |
83e9946
to
e322225
Compare
@fardin01 thanks again your PR here and for your contributions. I'm curious if you still had the bandwidth to follow up here. I think there's still the issue of figuring out the right semantics for the flags here @maxsmythe @sozercan and testing IIUC. |
@acpana No problem! I do have the bandwidth, just been waiting for input before I spend time on it. We are actually going to go live soon with Gator CLI built off of this PR (to give our developers a tool to verify their changes before deploying), so we are very eager for this PR to be merged and released. 😃 |
To be clear, I'd prefer having a separate flag for specifying provider configs (for security purposes), and provider configs should be loaded from a different path from the rest of the code. This is to make it possible to avoid loading malicious configurations. |
Let's also make sure to add the new flag(s) to docs. |
5bd79e2
to
4e07859
Compare
Signed-off-by: Fardin Khanjani <fardin.khanjani@tradeshift.com>
4e07859
to
49eb331
Compare
@fardin01 Let us know if this is ready for review! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
Signed-off-by: Fardin Khanjani fardin.khanjani@tradeshift.com
What this PR does / why we need it:
gator test
should be able to handle external data providers.gator test
returnsundefined function external_data
ifexternal_data
is being used in a ConstraintTemplate. This means that policies that query an external data source cannot be tested except for manual tests against a live cluster.Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when the PR gets merged):Fixes #2659
Special notes for your reviewer: