Skip to content

Commit

Permalink
skip ownership test if user is super
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Feb 15, 2024
1 parent 2b9cb33 commit 02a64ba
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions flow/connectors/postgres/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,19 @@ func (c *PostgresConnector) CheckPublicationPermission(ctx context.Context, tabl
return errors.New("user does not have superuser or create database privileges")
}

// for each table, check if the user is an owner
for _, table := range tableNames {
var owner string
err := c.conn.QueryRow(ctx, fmt.Sprintf("SELECT tableowner FROM pg_tables WHERE schemaname=%s AND tablename=%s",
QuoteLiteral(table.Schema), QuoteLiteral(table.Table))).Scan(&owner)
if err != nil {
return fmt.Errorf("error while checking table owner: %w", err)
}

if owner != c.config.User {
return fmt.Errorf("user %s is not the owner of table %s", c.config.User, table.String())
if !hasSuper {
// for each table, check if the user is an owner
for _, table := range tableNames {
var owner string
err := c.conn.QueryRow(ctx, fmt.Sprintf("SELECT tableowner FROM pg_tables WHERE schemaname=%s AND tablename=%s",
QuoteLiteral(table.Schema), QuoteLiteral(table.Table))).Scan(&owner)
if err != nil {
return fmt.Errorf("error while checking table owner: %w", err)
}

if owner != c.config.User {
return fmt.Errorf("user %s is not the owner of table %s", c.config.User, table.String())
}
}
}

Expand Down

0 comments on commit 02a64ba

Please sign in to comment.