-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fail loading an ACL config if the provided file is empty and enforceTableACLConfig is true #17274
base: main
Are you sure you want to change the base?
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Signed-off-by: garfthoffman <[email protected]>
47325bb
to
c636acf
Compare
@@ -367,7 +367,8 @@ func (tsv *TabletServer) initACL(tableACLConfigFile string, enforceTableACLConfi | |||
tsv.ClearQueryPlanCache() | |||
}, | |||
) | |||
if err != nil { | |||
// Log failure if either there was a problem loading the ACL, or if the ACL is empty | |||
if err != nil || tableacl.GetCurrentConfig().String() == "" { |
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'm not sure if this is the correct place to perform this validation. I think a config file containing an empty JSON object should be treated as "valid", but a truncated file seems like a pretty clear configuration mistake. 🤔
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.
Addressed in eca5d61
Signed-off-by: garfthoffman <[email protected]>
Signed-off-by: garfthoffman <[email protected]>
Signed-off-by: garfthoffman <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #17274 +/- ##
=======================================
Coverage 67.37% 67.37%
=======================================
Files 1573 1573
Lines 253113 253116 +3
=======================================
+ Hits 170538 170544 +6
+ Misses 82575 82572 -3 ☔ View full report in Codecov by Sentry. |
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
@garfthoffman did you want to move forward with this? If so, let's mark it ready for review and go from there. Thanks! |
@mattlord Can you take another look? |
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.
From the issue, the problem you're trying to solve seems to be more about whether or not the file contains a valid JSON document. Is that not correct? Unless I'm missing something, we should instead validate that the file contains a valid JSON document rather than just checking that it's empty (which would also be an invalid JSON doc as an empty doc would be "{}").
So instead of:
if len(data) == 0 {
return errors.New("tableACL config file is empty")
}
It would be:
if !json.Valid(data) {
return errors.New("tableACL config file is invalid")
}
I don't have a problem with the current code, but it doesn't seem like it resolves the issue as I read it.
} | ||
defer os.Remove(f.Name()) | ||
if err := f.Close(); err != nil { | ||
t.Fatal(err) |
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.
We should use require/assert in new tests. So e.g. here it would be:
err := f.Close()
require.NoError(t, err)
Or even just: require.NoError(t, f.Close())
I need to have another look as it's been a long time, but I believe the issue is that an empty file is treated as valid Protobuf, while an empty file is invalid JSON. So before it gets a chance to treat it as JSON, it's assumed to be a valid Protobuf file. |
That's true, the file has to be in a valid prototext or json format that can be marshaled into the protobuf message and an empty value is fine in that context. But now that I look at the code in the PR again, we DO check for the file being empty along with validating the contents:
So I think that the PR is good as-is! 🙂 I was too hurried in my initial glance. I apologize about that. I'll approve now. |
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.
LGTM! Note that we should still replace the usage of t.Fatal
in the new test before we merge. But that's a very minor thing.
Thank you, @garfthoffman ! And I apologize for the delay. ❤️
@garfthoffman you'll also need to merge in |
Description
When the ACL file is loaded, add a check to verify that the config is not empty and fail execution if the
--enforce-tableacl-config
flag has been provided.Related Issue(s)
Checklist
Deployment Notes