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

Add option to customize admin schema for PostgreSQL auto user provisioning #43338

Closed

Conversation

gabrielcorado
Copy link
Contributor

Closes #37609.

This PR adds a new option, default_schema, to customize the PostgreSQL schema where the procedures will be stored. When establishing a connection, we provide the search_path option. This option ensures the procedures are created on the schema and correctly found when called. This option works for both PostgreSQL and RedShift instances.

In addition, this option requires validation to prevent users from setting it to pg_temp (a per-session schema). This is necessary because procedures are only created once during the Teleport database session, so they are expected to be on the database when the session ends. Also, pg_temp doesn't support creating procedures on RedShift, returning an error like "ERROR: no schema has been selected to create in".

Changelog: Add an option (admin_user.default_schema) to customize the default PostgreSQL schema admin users use when managing auto-provisioned users.

@gabrielcorado gabrielcorado requested a review from greedy52 June 21, 2024 05:02
@github-actions github-actions bot requested a review from ravicious June 21, 2024 05:03
@github-actions github-actions bot added database-access Database access related issues and PRs size/md labels Jun 21, 2024
return nil
}

if db.GetProtocol() != defaults.ProtocolPostgres || (db.GetType() != types.DatabaseTypeSelfHosted && !db.IsRDS() && !db.IsRedshift()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if db.GetProtocol() != defaults.ProtocolPostgres || (db.GetType() != types.DatabaseTypeSelfHosted && !db.IsRDS() && !db.IsRedshift()) {
if db.GetProtocol() != defaults.ProtocolPostgres {

}
conn, err := e.pgxConnect(ctx, sessionCtx.WithUserAndDatabase(sessionCtx.Database.GetAdminUser().Name, loginDatabase))

conn, err := e.pgxConnect(ctx, sessionCtx.WithUserAndDatabase(sessionCtx.Database.GetAdminUser().Name, loginDatabase), loginSchema)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
conn, err := e.pgxConnect(ctx, sessionCtx.WithUserAndDatabase(sessionCtx.Database.GetAdminUser().Name, loginDatabase), loginSchema)
conn, err := e.pgxConnect(ctx, sessionCtx.WithUserAndDatabase(sessionCtx.Database.GetAdminUser().Name, loginDatabase).WithStartupParams(runtimeParams))

What do you think if we update the sessionCtx with runtime params needed for admin instead of changing pgxConnect

}

if sessionCtx.Database.GetAdminUser().DefaultSchema != "" {
loginSchema = sessionCtx.Database.GetAdminUser().DefaultSchema
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we log this schema the above log

@greedy52
Copy link
Contributor

Could you share the documentation change as well? Thanks!

@gabrielcorado gabrielcorado marked this pull request as draft July 2, 2024 13:51
@greedy52
Copy link
Contributor

greedy52 commented Oct 1, 2024

superseded by #44255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database-access Database access related issues and PRs size/md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specify schema for PostgreSQL auto-user provisioning
2 participants