oso-cloud 1.9.1 → 1.10.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/oso/api.rb +21 -5
- data/lib/oso/oso.rb +20 -4
- data/lib/oso/parity_handle.rb +79 -0
- data/lib/oso/version.rb +4 -1
- data/lib/oso-cloud.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dac67a8075972556f7ae65a0536ec256633cb2262e09bc846c0d9abd5d076b7
|
4
|
+
data.tar.gz: 5f99588ce46c6aa63eec48ba8c157f493a86f6341f7c3983ebaaef82712d424d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e208dbfa5c8d680d6887369deb5acaf157ab3d06ed408b9fa375823a00c39a9c7a2bf397d1fb14d0716d71b9518bd1f7124900d7dc0ae586a2b12f964ff23315
|
7
|
+
data.tar.gz: c4485eaf638f9e262c8b035c5b6606b0162fea19babe548f1ffd14cbee977e1ee0408f3679bc2f87eb984debeef86f176c4e0dcbed5c3164dea3acd7066fc515
|
data/Gemfile.lock
CHANGED
data/lib/oso/api.rb
CHANGED
@@ -403,9 +403,9 @@ module OsoCloud
|
|
403
403
|
ApiResult.new(**result)
|
404
404
|
end
|
405
405
|
|
406
|
-
def post_authorize(data)
|
406
|
+
def post_authorize(data, parity_handle = nil)
|
407
407
|
url = '/authorize'
|
408
|
-
result = POST(url, nil, data, false)
|
408
|
+
result = POST(url, nil, data, false, parity_handle: parity_handle)
|
409
409
|
AuthorizeResult.new(**result)
|
410
410
|
end
|
411
411
|
|
@@ -445,10 +445,10 @@ module OsoCloud
|
|
445
445
|
StatsResult.new(**result)
|
446
446
|
end
|
447
447
|
|
448
|
-
def post_authorize_query(query)
|
448
|
+
def post_authorize_query(query, parity_handle = nil)
|
449
449
|
url = '/authorize_query'
|
450
450
|
data = LocalAuthQuery.new(query: query, data_bindings: @data_bindings)
|
451
|
-
result = POST(url, nil, data, false)
|
451
|
+
result = POST(url, nil, data, false, parity_handle: parity_handle)
|
452
452
|
LocalQueryResult.new(**result)
|
453
453
|
end
|
454
454
|
|
@@ -532,7 +532,7 @@ module OsoCloud
|
|
532
532
|
handle_faraday_error e
|
533
533
|
end
|
534
534
|
|
535
|
-
def POST(path, params, body, isMutation)
|
535
|
+
def POST(path, params, body, isMutation, parity_handle: nil)
|
536
536
|
max_body_size = 10 * 1024 * 1024
|
537
537
|
hash = OsoCloud::Helpers.to_hash(body) unless body.nil?
|
538
538
|
json_str = JSON.generate(hash)
|
@@ -550,6 +550,12 @@ module OsoCloud
|
|
550
550
|
|
551
551
|
create_api_error(response, "Unexpected status #{response.status}") if response.status >= 300 || response.status < 200
|
552
552
|
|
553
|
+
if parity_handle && response.headers['X-Request-ID']
|
554
|
+
parity_handle.set(response.headers['X-Request-ID'], self)
|
555
|
+
elsif parity_handle && !response.headers['X-Request-ID']
|
556
|
+
raise ApiError.new(message: "unable to use Parity Handle: no request ID returned from Oso")
|
557
|
+
end
|
558
|
+
|
553
559
|
@last_offset = response.headers[:OsoOffset] if isMutation
|
554
560
|
response.body
|
555
561
|
# only attempt fallback on 5xx, and connection failure conditions
|
@@ -609,6 +615,16 @@ module OsoCloud
|
|
609
615
|
end
|
610
616
|
raise ApiError.new(message: err + formatted_request_id)
|
611
617
|
end
|
618
|
+
|
619
|
+
def post_expected_result(expected_result)
|
620
|
+
url = '/expect'
|
621
|
+
unless expected_result.is_a?(OsoCloud::Core::ExpectedResult)
|
622
|
+
raise ArgumentError, "Expected parameter to be an ExpectedResult object, got #{expected_result.class}"
|
623
|
+
end
|
624
|
+
|
625
|
+
result = POST(url, nil, expected_result, false)
|
626
|
+
ApiResult.new(**result)
|
627
|
+
end
|
612
628
|
end
|
613
629
|
end
|
614
630
|
end
|
data/lib/oso/oso.rb
CHANGED
@@ -38,12 +38,19 @@ module OsoCloud
|
|
38
38
|
#
|
39
39
|
# Returns a SQL query to run against the local database
|
40
40
|
#
|
41
|
+
# This method has an optional parameter `parity_handle` which is used to compare
|
42
|
+
# the result of your Oso authorization check with your legacy authorization system.
|
43
|
+
# Learn more about using the parity_handle with Oso Migrate here:
|
44
|
+
#
|
45
|
+
# https://www.osohq.com/docs/app-integration/client-apis/ruby#oso-migrate
|
46
|
+
#
|
41
47
|
# @param actor [OsoCloud::Value]
|
42
48
|
# @param action [String]
|
43
49
|
# @param resource [OsoCloud::Value]
|
44
50
|
# @param context_facts [Array<fact>]
|
51
|
+
# @param parity_handle [OsoCloud::ParityHandle, nil] Optional handle for parity checks with Oso Migrate.
|
45
52
|
# @return [String]
|
46
|
-
def authorize_local(actor, action, resource, context_facts = [])
|
53
|
+
def authorize_local(actor, action, resource, context_facts = [], parity_handle: nil)
|
47
54
|
actor_typed_id = actor.to_api_value
|
48
55
|
resource_typed_id = resource.to_api_value
|
49
56
|
result = @api.post_authorize_query(
|
@@ -54,7 +61,7 @@ module OsoCloud
|
|
54
61
|
resource_type: resource_typed_id.type,
|
55
62
|
resource_id: resource_typed_id.id,
|
56
63
|
context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
|
57
|
-
)
|
64
|
+
), parity_handle
|
58
65
|
)
|
59
66
|
result.sql
|
60
67
|
end
|
@@ -134,13 +141,20 @@ module OsoCloud
|
|
134
141
|
# Returns true if the actor can perform the action on the resource;
|
135
142
|
# otherwise false.
|
136
143
|
#
|
144
|
+
# This method has an optional parameter `parity_handle` which is used to compare
|
145
|
+
# the result of your Oso authorization check with your legacy authorization system.
|
146
|
+
# Learn more about using the parity_handle with Oso Migrate here:
|
147
|
+
#
|
148
|
+
# https://www.osohq.com/docs/app-integration/client-apis/ruby#oso-migrate
|
149
|
+
#
|
137
150
|
# @param actor [OsoCloud::Value]
|
138
151
|
# @param action [String]
|
139
152
|
# @param resource [OsoCloud::Value]
|
140
153
|
# @param context_facts [Array<fact>]
|
154
|
+
# @param parity_handle [OsoCloud::ParityHandle, nil] Optional handle for parity checks with Oso Migrate.
|
141
155
|
# @return [Boolean]
|
142
156
|
# @see Oso for more information about facts
|
143
|
-
def authorize(actor, action, resource, context_facts = [])
|
157
|
+
def authorize(actor, action, resource, context_facts = [], parity_handle: nil)
|
144
158
|
actor_typed_id = actor.to_api_value
|
145
159
|
resource_typed_id = resource.to_api_value
|
146
160
|
result = @api.post_authorize(OsoCloud::Core::AuthorizeQuery.new(
|
@@ -150,7 +164,9 @@ module OsoCloud
|
|
150
164
|
resource_type: resource_typed_id.type,
|
151
165
|
resource_id: resource_typed_id.id,
|
152
166
|
context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
|
153
|
-
)
|
167
|
+
),
|
168
|
+
parity_handle
|
169
|
+
)
|
154
170
|
result.allowed
|
155
171
|
end
|
156
172
|
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oso/api'
|
4
|
+
|
5
|
+
module OsoCloud
|
6
|
+
# @!visibility private
|
7
|
+
module Core
|
8
|
+
# @!visibility private
|
9
|
+
class ExpectedResult
|
10
|
+
attr_reader :request_id, :expected
|
11
|
+
|
12
|
+
def initialize(request_id:, expected:)
|
13
|
+
@request_id = request_id
|
14
|
+
@expected = expected
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# ParityHandle is a testing utility in Oso Migrate for comparing expected authorization
|
20
|
+
# decisions with actual Oso results.
|
21
|
+
class ParityHandle
|
22
|
+
attr_reader :request_id, :expected
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@api = nil
|
26
|
+
@request_id = nil
|
27
|
+
@expected = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
# Set is an internal method called by the API class after authorize.
|
31
|
+
#
|
32
|
+
# @param request_id [String] The ID of the authorization request.
|
33
|
+
# @param api [OsoCloud::Core::Api] Reference to the API instance.
|
34
|
+
# @return [nil]
|
35
|
+
# @raise [StandardError] If request_id is set twice.
|
36
|
+
# @!visibility private
|
37
|
+
def set(request_id, api)
|
38
|
+
unless @request_id.nil?
|
39
|
+
raise StandardError,
|
40
|
+
"attempted to set request_id twice. Only one request is allowed per ParityHandle instance. (Original request ID: #{@request_id})"
|
41
|
+
end
|
42
|
+
|
43
|
+
@request_id = request_id
|
44
|
+
@api = api
|
45
|
+
|
46
|
+
send_expected_result unless @expected.nil?
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# Expect is a public method for users to indicate the expected result of an authorization query.
|
51
|
+
#
|
52
|
+
# @param expected [Boolean] Boolean indicating the expected authorization result.
|
53
|
+
# @return [nil]
|
54
|
+
# @raise [StandardError] If expected result is set twice.
|
55
|
+
def expect(expected)
|
56
|
+
raise StandardError, 'attempted to set expected result twice' unless @expected.nil?
|
57
|
+
|
58
|
+
@expected = expected
|
59
|
+
|
60
|
+
send_expected_result unless @request_id.nil?
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# Send the expected result to the API
|
67
|
+
# @!visibility private
|
68
|
+
def send_expected_result
|
69
|
+
raise StandardError, 'ParityHandle not properly initialized' if @api.nil? || @request_id.nil? || @expected.nil?
|
70
|
+
|
71
|
+
expected_result = OsoCloud::Core::ExpectedResult.new(
|
72
|
+
request_id: @request_id,
|
73
|
+
expected: @expected
|
74
|
+
)
|
75
|
+
|
76
|
+
@api.post_expected_result(expected_result)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/oso/version.rb
CHANGED
data/lib/oso-cloud.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oso-cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oso Security, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/oso/api.rb
|
114
114
|
- lib/oso/helpers.rb
|
115
115
|
- lib/oso/oso.rb
|
116
|
+
- lib/oso/parity_handle.rb
|
116
117
|
- lib/oso/version.rb
|
117
118
|
- oso-cloud.gemspec
|
118
119
|
homepage: https://www.osohq.com/
|