-
Notifications
You must be signed in to change notification settings - Fork 537
fix: Database_observability: grant check only require SELECT *.* on perf_schema #5294
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
Changes from all commits
f7d17b1
e774419
b6c3a3b
d89ceee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,8 @@ func checkAlloyVersion(ctx context.Context, db *sql.DB) healthCheckResult { | |
| } | ||
|
|
||
| // checkRequiredGrants verifies required privileges are present. | ||
| // Requires: PROCESS, REPLICATION CLIENT, SHOW VIEW on *.* | ||
| // and SELECT on performance_schema.* | ||
| func checkRequiredGrants(ctx context.Context, db *sql.DB) healthCheckResult { | ||
| r := healthCheckResult{name: "RequiredGrantsPresent"} | ||
| req := map[string]bool{ | ||
|
|
@@ -160,28 +162,60 @@ func checkRequiredGrants(ctx context.Context, db *sql.DB) healthCheckResult { | |
| } | ||
| up := strings.ToUpper(grantLine) | ||
|
|
||
| // Mark individual privileges if present on *.* scope. | ||
| for k := range req { | ||
| if strings.Contains(up, " ON *.*") && strings.Contains(up, k) { | ||
| req[k] = true | ||
| if strings.Contains(up, "SELECT") { | ||
| if strings.Contains(up, " ON `PERFORMANCE_SCHEMA`.*") || | ||
| strings.Contains(up, " ON PERFORMANCE_SCHEMA.*") || | ||
| strings.Contains(up, " ON `PERFORMANCE_SCHEMA`.") || | ||
| strings.Contains(up, " ON *.*") { | ||
|
|
||
| req["SELECT"] = true | ||
| } | ||
| } | ||
|
|
||
| if strings.Contains(up, "ALL PRIVILEGES") { | ||
| if strings.Contains(up, " ON `PERFORMANCE_SCHEMA`.*") || | ||
| strings.Contains(up, " ON PERFORMANCE_SCHEMA.*") || | ||
| strings.Contains(up, " ON `PERFORMANCE_SCHEMA`.") || | ||
| strings.Contains(up, " ON *.*") { | ||
|
|
||
| req["SELECT"] = true | ||
| } | ||
| } | ||
|
|
||
| if strings.Contains(up, "SHOW VIEW") { | ||
| req["SHOW VIEW"] = true | ||
| } | ||
|
|
||
| if strings.Contains(up, "PROCESS") && strings.Contains(up, " ON *.*") { | ||
| req["PROCESS"] = true | ||
| } | ||
|
|
||
| if strings.Contains(up, "REPLICATION CLIENT") && strings.Contains(up, " ON *.*") { | ||
| req["REPLICATION CLIENT"] = true | ||
| } | ||
| } | ||
| if err := rows.Err(); err != nil { | ||
| r.err = fmt.Errorf("iterate SHOW GRANTS: %w", err) | ||
| return r | ||
| } | ||
|
|
||
| r.result = true | ||
| for k, found := range req { | ||
| if !found { | ||
| r.result = false | ||
| if r.value == "" { | ||
| r.value = "missing: " + k | ||
| } else { | ||
| r.value += "," + k | ||
| } | ||
| r.result = req["PROCESS"] && req["REPLICATION CLIENT"] && req["SELECT"] && req["SHOW VIEW"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This comment seems similar to #5294 (comment) in which we attach more information about which grant is missing?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry I confused the two fields. But yeah, basically I was thinking of attaching more info like I mentioned in the other comment. |
||
|
|
||
| if !r.result { | ||
| var missing []string | ||
| if !req["PROCESS"] { | ||
| missing = append(missing, "PROCESS") | ||
| } | ||
| if !req["REPLICATION CLIENT"] { | ||
| missing = append(missing, "REPLICATION CLIENT") | ||
| } | ||
| if !req["SELECT"] { | ||
| missing = append(missing, "SELECT on performance_schema.*") | ||
| } | ||
| if !req["SHOW VIEW"] { | ||
| missing = append(missing, "SHOW VIEW") | ||
| } | ||
| r.value = fmt.Sprintf("missing grants: %s", strings.Join(missing, ", ")) | ||
| } | ||
|
|
||
| return r | ||
|
|
||
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.
Maybe for a followup: would be cool to show on which objects
SHOW VIEWis granted (e.g.*.*vspayments.*or something else), as it helps debug why e.g. a specific schema is not reported.