Skip to content
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

Provide option for change of owner of tables in Database which already exists #57

Open
nv1-0 opened this issue Jan 21, 2021 · 3 comments

Comments

@nv1-0
Copy link

nv1-0 commented Jan 21, 2021

Currently when we apply Postgres CR it creates a DB if it doesn't exists and if it exists it changes its owner to the role created by the Postgres CRs. But the owner of the tables inside it remain unaltered due to which if we try to access it using credentials created by Postgres CRs then we get this error

<database>=> select * from <table>;
ERROR:  permission denied for table <table>

It would be great if we get an option to migrate the owners of all the tables in the database to the role created by Postgres CRs

@nv1-0
Copy link
Author

nv1-0 commented Jan 22, 2021

I have created a pull request for this topic :- #58.
Its missing tests right now. It can be reviewed

@hitman99
Copy link
Member

hitman99 commented Jul 7, 2021

I think we already covered this in discussion on #58 - you can specify a masterRole that already owns the database and schemas and postgres-operator will not create a new owner role:

owner := instance.Spec.MasterRole
if owner == "" {
owner = fmt.Sprintf("%s-group", instance.Spec.Database)
}

It will then try to create this role and will just use the role provided in spec if it already exists:

// Error code 42710 is duplicate_object (role already exists)
_, err := c.db.Exec(fmt.Sprintf(CREATE_GROUP_ROLE, role))
if err != nil && err.(*pq.Error).Code != "42710" {
return err
}
return nil

@sambonbonne
Copy link

I know this issue is more than half and a year old but it seems I have the same problem, even using masterRole with the existing role: new users access is denied on existing tables (I tried with OWNER privilege and it doesn't work better).

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

No branches or pull requests

3 participants