rls_multi_tenant 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fb27124134b3487ef6f83347eca26c0ac64431e44a01d92cf70bd3dd5a03e20
4
- data.tar.gz: a4fceedb11cdc42c788aad2c8c8ac11f6344d497ec2f62b002719c7cfc5a6179
3
+ metadata.gz: 49b6d40d5e29350f1911f16aa361beaad5b1ad28dfab6da452260cd535ff6dd1
4
+ data.tar.gz: ba39dd57c6690a60b5d8e1ed466d7b42e25b745920ff5016030a405d89360f88
5
5
  SHA512:
6
- metadata.gz: adff1ce5bde6c15d358e67041982e0506c97fa5b1e7eee02fd69fbf9eab3799fa67be034a8b584ea8cf5864a556751d1d8a679e3adf49cddbedc995d988b98d7
7
- data.tar.gz: 0c125b52250a2fce049e4f0965af09c4ae13f75f8a7516b58f6a6d136179821471a2f7ff24340ba3654f2cfa1ec4bcf2af29d4ab76ddb58ddad2e3643edc5dbd
6
+ metadata.gz: 7f8c83ceedec1aa0dfee0bb9ab01c8123ce6bf58a1b75a5f6b6ea5ec083803ec917d526504c9f5897a274f40bf3eb2dd6ccd856b7f9ecee69b36c0ac2d90642a
7
+ data.tar.gz: 6e673789ff292c0258411c9e46cf3a7a899f862771b760651acdc9c8662540fb9b1674650238a3472ac80275004f910f673ca516099b86eddc26c2151929ed23
@@ -4,4 +4,5 @@ class <%= RlsMultiTenant.tenant_class_name %> < ApplicationRecord
4
4
  include RlsMultiTenant::Concerns::TenantContext
5
5
 
6
6
  validates :name, presence: true
7
+ validates :subdomain, presence: true, uniqueness: true
7
8
  end
@@ -23,9 +23,9 @@ class CreateAppUser < ActiveRecord::Migration[<%= Rails.version.to_f %>]
23
23
  execute "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO #{app_user};"
24
24
  execute "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT ON SEQUENCES TO #{app_user};"
25
25
 
26
- # Grant permissions on system tables
27
- execute "GRANT SELECT ON TABLE schema_migrations TO #{app_user};"
28
- execute "GRANT SELECT ON TABLE ar_internal_metadata TO #{app_user};"
26
+ # Grant permissions on all existing tables
27
+ execute "GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO #{app_user};"
28
+ execute "GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO #{app_user};"
29
29
  end
30
30
 
31
31
  def down
@@ -35,6 +35,10 @@ class CreateAppUser < ActiveRecord::Migration[<%= Rails.version.to_f %>]
35
35
  execute "REVOKE ALL ON SCHEMA public FROM #{app_user};"
36
36
  execute "REVOKE CONNECT ON DATABASE #{ActiveRecord::Base.connection.current_database} FROM #{app_user};"
37
37
 
38
+ # Revoke permissions from all existing tables and sequences
39
+ execute "REVOKE ALL ON ALL TABLES IN SCHEMA public FROM #{app_user};"
40
+ execute "REVOKE ALL ON ALL SEQUENCES IN SCHEMA public FROM #{app_user};"
41
+
38
42
  # Revoke default permissions for future tables in public schema
39
43
  execute "ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE SELECT, INSERT, UPDATE, DELETE ON TABLES FROM #{app_user};"
40
44
  execute "ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE USAGE, SELECT ON SEQUENCES FROM #{app_user};"
@@ -19,7 +19,8 @@ module RlsMultiTenant
19
19
 
20
20
  if superuser_check && superuser_check['rolsuper']
21
21
  raise SecurityError, "Database user '#{username}' has SUPERUSER privileges. " \
22
- "In order to use RLS Multi-tenant, you must use a non-privileged user without SUPERUSER rights."
22
+ "In order to use RLS Multi-tenant, you must use a non-privileged user without SUPERUSER rights." \
23
+ "Did you remember to edit database.yml in order to use the POSTGRES_APP_USER and POSTGRES_APP_PASSWORD?"
23
24
  end
24
25
 
25
26
  # Log the security check result
@@ -41,7 +42,8 @@ module RlsMultiTenant
41
42
  raise ConfigurationError, "#{RlsMultiTenant.app_user_env_var} environment variable must be set"
42
43
  elsif ["postgres", "root"].include?(app_user)
43
44
  raise SecurityError, "Cannot use privileged PostgreSQL user '#{app_user}'. " \
44
- "In order to use RLS Multi-tenant, you must use a non-privileged user without SUPERUSER rights."
45
+ "In order to use RLS Multi-tenant, you must use a non-privileged user without SUPERUSER rights." \
46
+ "Did you remember to edit database.yml in order to use the POSTGRES_APP_USER and POSTGRES_APP_PASSWORD?"
45
47
  end
46
48
  end
47
49
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RlsMultiTenant
4
- VERSION = "0.1.8"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rls_multi_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coding Ways