-
Notifications
You must be signed in to change notification settings - Fork 940
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
Prevent cluster groups from being deleted when referenced by a projects' configuration #15119
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
This duplicates `(*cluster.ClusterGroup).ToAPI`. Signed-off-by: Mark Laing <mark.laing@canonical.com>
This function queries for projects that have the group name present in the value for the config key `restricted.cluster.groups`. Then it parses the config value properly to check for an exact match. Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
This includes a small refactor of `GET /1.0/cluster/groups` where the handler was unnecessarily iterating over the list of groups twice. Signed-off-by: Mark Laing <mark.laing@canonical.com>
Signed-off-by: Mark Laing <mark.laing@canonical.com>
…ced by a project. Signed-off-by: Mark Laing <mark.laing@canonical.com>
JOIN projects_config ON projects.id = projects_config.project_id | ||
WHERE projects_config.key = 'restricted.cluster.groups' AND projects_config.value LIKE '%` + groupName + `%'` | ||
|
||
stmt, err := tx.Prepare(q) |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
q := ` | ||
SELECT projects.name, projects_config.value FROM projects | ||
JOIN projects_config ON projects.id = projects_config.project_id | ||
WHERE projects_config.key = 'restricted.cluster.groups' AND projects_config.value LIKE '%` + groupName + `%'` |
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.
This is a SQL injection security risk.
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.
Also the use of LIKE here seems potentially incorrect as it might match partial group names.
Can we use JSON collation and direct matching with query parameters instead?
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.
Looks good, except the SQL injection flaw ;)
Whoopsie 😆 Thank you CodeQL 🙏 Not sure how I convinced myself that this was ok... |
Adds an API extension
clustering_groups_used_by
and adds aUsedBy
field toapi.ClusterGroup
. On GET requests, theUsedBy
URLs are projects that contain the cluster group inrestricted.cluster.groups
. DELETE requests will fail if the cluster group is used by a project.Closes #15118