Skip to content

feat(mysql): Allow to Grant permissions on specific columns in table#330

Open
ymaniukevich wants to merge 2 commits intocrossplane-contrib:masterfrom
ymaniukevich:feature/mysql-grant-perms-to-column
Open

feat(mysql): Allow to Grant permissions on specific columns in table#330
ymaniukevich wants to merge 2 commits intocrossplane-contrib:masterfrom
ymaniukevich:feature/mysql-grant-perms-to-column

Conversation

@ymaniukevich
Copy link
Copy Markdown

@ymaniukevich ymaniukevich commented Feb 23, 2026

Description of your changes

Improved regexp expression for granting permission to specific columns in MySQL.

Fixes #214, #176

I have:

  • Read and followed Crossplane's [contribution process].
  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

apiVersion: mysql.sql.crossplane.io/v1alpha1
kind: Grant
metadata:
  name: user-example
spec:
  forProvider:
    databaseRef:
      name: example-db
    privileges:
      - UPDATE (`status`, `updated_at`)
      - SELECT
    table: requests
    user: user-example@%
  providerConfigRef:
    name: example

@ymaniukevich ymaniukevich force-pushed the feature/mysql-grant-perms-to-column branch from ce36e61 to b41ee96 Compare February 23, 2026 08:09
@chlunde
Copy link
Copy Markdown
Collaborator

chlunde commented Feb 23, 2026

@ymaniukevich would it make sense to update the examples to get e2e coverage here? We'll also need to rebase this PR after #328 is in because e2e will fail now

@ymaniukevich ymaniukevich force-pushed the feature/mysql-grant-perms-to-column branch from b41ee96 to 21e7234 Compare February 23, 2026 16:00
@chlunde
Copy link
Copy Markdown
Collaborator

chlunde commented Feb 24, 2026

@ymaniukevich I guess this also fixes #176 ?

@ymaniukevich
Copy link
Copy Markdown
Author

@chlunde I'll add an e2e test to cover the case of granting table permissions. I've checked issue #176 — you're right, this will fix it as well.

@ymaniukevich ymaniukevich force-pushed the feature/mysql-grant-perms-to-column branch 6 times, most recently from 6fdc292 to 9c8f974 Compare February 24, 2026 21:10
@ymaniukevich
Copy link
Copy Markdown
Author

@ymaniukevich would it make sense to update the examples to get e2e coverage here?

@chlunde I've updated the examples to improve e2e coverage.

@ymaniukevich ymaniukevich force-pushed the feature/mysql-grant-perms-to-column branch 2 times, most recently from 95e20ec to 69512e6 Compare March 3, 2026 11:45
- DROP
- INSERT
- SELECT
- UPDATE (status, updated_at)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will mysql store this as a string and not normalize it, like reorder or change whitespace (UPDATE(status, updated_at) or UPDATE (updated_at, status))?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL normalizes the statement: uppercases keywords (even if you write update, it will be stored as UPDATE), adds missing spaces/backticks, and sorts column names alphabetically.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ymaniukevich cool, thanks for researching. This will likely burn som users, if they write it in another order. We should at minimum document it, or normalize it outselves in our observe method?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or disallow it via CEL expression, similar to this, but that's not very pretty 😮‍💨

x-kubernetes-validations:                           
  - rule: >-
      self.spec.forProvider.privileges.all(p,                                       
        !p.contains('(') ||
        p.split('(')[1].split(')')[0].split(', ').isSorted()                        
      )         
    message: "Column names in column-level privileges must be listed alphabetically"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think this is actually an issue if the user specifies the order differently. The provider will treat the resource as synced. I already have a managed resource with a different order, and everything works as expected.

Or did I misunderstand your concern?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is if it reconciles (does an update) every poll interval if the user specifies a different order

Copy link
Copy Markdown
Author

@ymaniukevich ymaniukevich Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chlunde you are right — on each loop I see Successfully requested update of external resource for Grant.
I’ll come back with changes (need to fix parseGrant function so it doesn't do the split if we have string with permission on the column)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some changes:

  1. Improved the regexp to allow only DML_COMMAND (`col1`, `col2`) or just DML_COMMAND
  2. Sort privileges alphabetically when comparing observed and desired state

@chlunde could you take a look when you have time?

@ymaniukevich ymaniukevich force-pushed the feature/mysql-grant-perms-to-column branch from 69512e6 to 6fdc505 Compare March 23, 2026 14:09
@ymaniukevich ymaniukevich marked this pull request as draft March 23, 2026 14:10
@ymaniukevich ymaniukevich force-pushed the feature/mysql-grant-perms-to-column branch 6 times, most recently from 6c15f61 to fd0e4fd Compare March 23, 2026 14:49
mysql: add e2e tests to cover granting permission on table

Signed-off-by: ymaniukevich <yauheni.maniukevich@gmail.com>
Signed-off-by: Yauheni Maniukevich <yauheni.maniukevich@gmail.com>
…privilege comparison

Signed-off-by: Yauheni Maniukevich <yauheni.maniukevich@gmail.com>
@ymaniukevich ymaniukevich force-pushed the feature/mysql-grant-perms-to-column branch from fd0e4fd to b833d4f Compare March 23, 2026 14:49
@ymaniukevich ymaniukevich marked this pull request as ready for review March 23, 2026 15:05
@chlunde chlunde self-requested a review March 24, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mysql] Unable to Grant permissions on specific columns in table

2 participants