【问题标题】:What's the simplest least-privilege way to enable UUIDs in a Rails schema?在 Rails 模式中启用 UUID 的最简单的最低权限方法是什么?
【发布时间】:2016-05-11 03:41:44
【问题描述】:

我正在通过 uuid-ossp 扩展处理使用 UUID 的 Rails 项目。

这是通过在我看来像是标准迁移的方式完成的:

class EnableExtensions < ActiveRecord::Migration
  def change
    enable_extension 'plpgsql'
    enable_extension 'uuid-ossp' if Rails.env.development? || Rails.env.test?
  end
end

但是,使用此功能需要我手动设置扩展,以使用每个数据库的 postgres 超级用户启用:

-- enable_extension("uuid-ossp")
rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied to create extension "uuid-ossp"
HINT:  Must be superuser to create this extension.
: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"

我不会授予我的用户或 rails 项目用户对我的任何数据库的超级用户权限——这似乎不是一个好习惯。那我该怎么做呢?

注意:this question's accepted answer doesn't answer the larger question in the title.

【问题讨论】:

  • 基于this 对有关heroku 的类似问题的回答(与您提到的不重复的问题相关联),github.com/dimitri/pgextwlist 将允许您将扩展列入白名单,而无需授予超级用户权限。
  • @BM5k 如果你发布一个关于它的答案,我会接受这个答案。

标签: ruby-on-rails postgresql privileges


【解决方案1】:

显然https://github.com/dimitri/pgextwlist 将允许您将扩展列入白名单,而无需授予超级用户权限。

发现为 answerWhy can only a superuser CREATE EXTENSION hstore, but not on Heroku?

【讨论】:

    【解决方案2】:

    如果您无法通过标准迁移过程,最好的方法可能是启用 template1 中的扩展,这样它们就会出现在您创建的每个新数据库中。请记住,如果恢复使用 pg_dump 复制模板 0 而不是默认模板 1 的备份。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-06
      • 2014-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-01
      • 1970-01-01
      相关资源
      最近更新 更多