aserto-rails 0.20.2 → 0.30.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -2
- data/VERSION +1 -1
- data/lib/aserto/rails/controller_additions.rb +21 -0
- data/lib/aserto/rails/controller_resource.rb +16 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d645132ed1cd5757c6c1d8c795b0cddab950f2be5cf90ef74411a86567b470d
|
4
|
+
data.tar.gz: f9cb34952224a4195a3322afc81f6f4e138d2c845fb9da6e55fe0ae7dac54f3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 124e32e4d2c36f91b07509414eead1811dfe92401137d027bec6ebd677baf01e2cc35502b4918760f220470a13fd8a85e36d7960bdbf52f454473f362d6fca47
|
7
|
+
data.tar.gz: f1f984fcae8dbbf6d457c0681d8d7bd01524716bddb466f3902c11e076b0b1f40342e5e2385214f21d75a720c4ea675e139eee30c5c286184a3078d287297a46
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Aserto authorization library for Ruby and Ruby on Rails.
|
|
10
10
|
Built on top of [aserto](https://github.com/aserto-dev/aserto-ruby) and [aserto-grpc-authz](https://github.com/aserto-dev/ruby-grpc-authz).
|
11
11
|
|
12
12
|
## Prerequisites
|
13
|
-
* [Ruby](https://www.ruby-lang.org/en/downloads/)
|
13
|
+
* [Ruby](https://www.ruby-lang.org/en/downloads/) 3.0 or newer.
|
14
14
|
* [Rails](https://rubyonrails.org/) 6 or newer.
|
15
15
|
* An [Aserto](https://console.aserto.com) account.
|
16
16
|
|
@@ -138,6 +138,8 @@ end
|
|
138
138
|
|
139
139
|
## Controller helpers
|
140
140
|
|
141
|
+
### aserto_authorize!
|
142
|
+
|
141
143
|
The `aserto_authorize!` method in the controller will raise an exception if the user is not able to perform the given action.
|
142
144
|
|
143
145
|
```ruby
|
@@ -167,6 +169,38 @@ class PostsController < ApplicationController
|
|
167
169
|
end
|
168
170
|
```
|
169
171
|
|
172
|
+
### check!
|
173
|
+
|
174
|
+
The `check!` method in the controller will raise an exception if the user is not able to perform the given action.
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
def show
|
178
|
+
# only users in the "evil_genius" group are allowed to get this resource
|
179
|
+
check!(object_id: "evil_genius", object_type: "group", relation: "member")
|
180
|
+
@post = Post.find(params[:id])
|
181
|
+
end
|
182
|
+
```
|
183
|
+
|
184
|
+
Setting this for every action can be tedious, therefore the `aserto_check_resource` method is provided to
|
185
|
+
automatically authorize all actions in a RESTful style resource controller.
|
186
|
+
It will use a before action to load the resource into an instance variable and authorize it for every action.
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
class PostsController < ApplicationController
|
190
|
+
aserto_authorize_resource
|
191
|
+
# aserto_check_resource only: %i[show], params: { object_id: "evil_genius", object_type: "group", relation: "member" }
|
192
|
+
# aserto_check_resource except: %i[index], params: { object_id: "evil_genius", object_type: "group", relation: "member" }
|
193
|
+
|
194
|
+
def show
|
195
|
+
# getting a single post authorized
|
196
|
+
end
|
197
|
+
|
198
|
+
def index
|
199
|
+
# getting all posts is authorized
|
200
|
+
end
|
201
|
+
end
|
202
|
+
```
|
203
|
+
|
170
204
|
## Check Permissions
|
171
205
|
|
172
206
|
The current user's permissions can then be checked using the `allowed?`, `visible?` and `enabled?` methods in views and controllers.
|
@@ -181,7 +215,7 @@ The current user's permissions can then be checked using the `allowed?`, `visibl
|
|
181
215
|
Prerequisites:
|
182
216
|
|
183
217
|
- go >= 1.17 to run mage
|
184
|
-
- Ruby >=
|
218
|
+
- Ruby >= 3.0 to run the code
|
185
219
|
|
186
220
|
|
187
221
|
Run `bundle install` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.30.1
|
@@ -8,6 +8,10 @@ module Aserto
|
|
8
8
|
aserto_resource_class.add_before_action(self, :authorize_resource, *args)
|
9
9
|
end
|
10
10
|
|
11
|
+
def aserto_check_resource(*args)
|
12
|
+
aserto_resource_class.add_before_action(self, :check_resource, *args)
|
13
|
+
end
|
14
|
+
|
11
15
|
def aserto_resource_class
|
12
16
|
ControllerResource
|
13
17
|
end
|
@@ -38,6 +42,23 @@ module Aserto
|
|
38
42
|
raise Aserto::AccessDenied unless Aserto::AuthClient.new(request).is
|
39
43
|
end
|
40
44
|
|
45
|
+
#
|
46
|
+
# Authorization call based on check relation
|
47
|
+
#
|
48
|
+
# @param [String] object_id
|
49
|
+
# @param [String] object_type
|
50
|
+
# @param [String] relation
|
51
|
+
#
|
52
|
+
# @return [nil]
|
53
|
+
#
|
54
|
+
# @raise Aserto::AccessDenied
|
55
|
+
#
|
56
|
+
def check!(object_id:, object_type:, relation:, options: {})
|
57
|
+
raise Aserto::AccessDenied unless Aserto::AuthClient.new(request).check(
|
58
|
+
object_id: object_id, object_type: object_type, relation: relation, options: options
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
41
62
|
private
|
42
63
|
|
43
64
|
def augment_request!(action, path, resource)
|
@@ -10,6 +10,22 @@ module Aserto
|
|
10
10
|
@name = args.first
|
11
11
|
end
|
12
12
|
|
13
|
+
#
|
14
|
+
# Authorization call based on check relation
|
15
|
+
#
|
16
|
+
# @param [String] object_id
|
17
|
+
# @param [String] object_type
|
18
|
+
# @param [String] relation
|
19
|
+
#
|
20
|
+
# @return [nil]
|
21
|
+
#
|
22
|
+
# @raise Aserto::AccessDenied
|
23
|
+
#
|
24
|
+
def check_resource
|
25
|
+
client = Aserto::AuthClient.new(@controller.request)
|
26
|
+
raise Aserto::AccessDenied unless client.check(**(@options[:params] || {}))
|
27
|
+
end
|
28
|
+
|
13
29
|
def authorize_resource
|
14
30
|
raise Aserto::AccessDenied unless Aserto::AuthClient.new(@controller.request).is
|
15
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aserto-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.30.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aserto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aserto
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.30.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.30.6
|
27
27
|
description: Aserto authorization library for Ruby and Ruby on Rails
|
28
28
|
email:
|
29
29
|
- aserto@aserto.com
|