Add PostgreSQL auto-user deletion#32792
Conversation
| // function to make sure no 2 processes run user activation simultaneously. | ||
| func (a *UserProvisioner) Activate(ctx context.Context, sessionCtx *Session) (func(), error) { | ||
| if !sessionCtx.AutoCreateUser { | ||
| if !services.IsCreateDatabaseUserEnabled(sessionCtx.AutoCreateUserMode) { |
There was a problem hiding this comment.
I would throw errors if the Backend doesn't support the new mode yet (somewhere in this function). IMO, it's better to alert the user the mode configuration is wrong than silently falling back to another mode. But certainly up for discussion.
greedy52
left a comment
There was a problem hiding this comment.
LGTM, assuming a debug log will be added somewhere to show if the user is actually deleted or a fallback is done.
| func (e *Engine) DeleteUser(ctx context.Context, sessionCtx *common.Session) error { | ||
| // TODO(gabrielcorado): implement delete database user. for now, just | ||
| // fallback to deactivate user. | ||
| return e.DeactivateUser(ctx, sessionCtx) |
There was a problem hiding this comment.
nit: I am adding Redshift (postgres engine) auto-user provisioning so there is a chance Redshift will start with only keep mode too. I am wondering if it would be easier to return not implemented in backend.DeleteUser and let common.UserProvisioner to do the fallback. Probably the same thing either way.
|
@greedy52 @smallinsky FYI, I've made the following updates:
|
* feat: add auto-user deletion postgres * refactor: change to IsEnabled func to check auto-user * test: fix linting and test * refactor(db): code review suggestions * refactor: rename option to best effort drop * refactor(api): rename createa database user mode property * refactor(services): review suggestions * feat(postgres): add log for user deletion result * refactor(integrations): regenerate crd manifests * feat(examples): update operator role spec * refactor(db): use common sql state codes
* feat: add auto-user deletion postgres * refactor: change to IsEnabled func to check auto-user * test: fix linting and test * refactor(db): code review suggestions * refactor: rename option to best effort drop * refactor(api): rename createa database user mode property * refactor(services): review suggestions * feat(postgres): add log for user deletion result * refactor(integrations): regenerate crd manifests * feat(examples): update operator role spec * refactor(db): use common sql state codes
Related to #31199 and #29731
Adds a create database user mode (similar to what is done for host and desktop users), where:
off: Disables user creation. (same ascreate_database_user: false).keep: Creates the user but deactivates it when the session ends (keeps the user but removes its roles assignments). This is the current default behavior.best_effort_drop: Tries to drop the database user. If it fails, it returns tokeepmode, deactivating the user.For backward compatibility, the
create_database_user: truerole option is kept, and set the mode value tokeepif it is set totrue.