cased-rails 0.4.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +155 -19
- data/app/views/cased/cli/sessions/steps/_reason_required.html.erb +1 -1
- data/lib/cased/rails/config.rb +1 -21
- data/lib/cased/rails/railtie.rb +3 -2
- data/lib/cased/rails/version.rb +1 -1
- data/lib/tasks/cased.rake +11 -0
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ac813e954f77f140af1bd3134fb4452008e807e42aa28eadc36ec9cb0466393
|
4
|
+
data.tar.gz: 2e05ad602523cb8d85bb0f015ef0322729f8b3a0372ab1d94a50d08882235d79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7720462c3af78d86a2c331d75b62578d049cc04a33a4c246faabed779083237e02afe05780a496e09b25f746ab136ac20eb0f19f3ff943e032c385a1b82ca6e1
|
7
|
+
data.tar.gz: 5fe323c945bfb912929d7c8a777763fc0071bd3f1a8f13326eca84d512f195f881be6dba40820bebb1c16cc23b4b21eb72cdb3128439000fdc2046a6f0ab6627
|
data/README.md
CHANGED
@@ -7,15 +7,19 @@ A Cased client for Ruby on Rails applications in your organization to control an
|
|
7
7
|
- [Installation](#installation)
|
8
8
|
- [Configuration](#configuration)
|
9
9
|
- [Usage](#usage)
|
10
|
-
- [
|
11
|
-
|
12
|
-
|
13
|
-
- [
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
- [Cased CLI](#cased-cli)
|
11
|
+
- [Recording console sessions](#recording-console-sessions)
|
12
|
+
- [Approval workflows for sensitive operations](#approval-workflows-for-sensitive-operations)
|
13
|
+
- [Audit trails](#audit-trails)
|
14
|
+
- [Publishing events to Cased](#publishing-events-to-cased)
|
15
|
+
- [Publishing audit events for all record creation, updates, and deletions automatically](#publishing-audit-events-for-all-record-creation-updates-and-deletions-automatically)
|
16
|
+
- [Retrieving events from a Cased audit trail](#retrieving-events-from-a-cased-audit-trail)
|
17
|
+
- [Retrieving events from multiple Cased audit trails](#retrieving-events-from-multiple-cased-audit-trails)
|
18
|
+
- [Exporting events](#exporting-events)
|
19
|
+
- [Masking & filtering sensitive information](#masking-and-filtering-sensitive-information)
|
20
|
+
- [Disable publishing events](#disable-publishing-events)
|
21
|
+
- [Context](#context)
|
22
|
+
- [Testing](#testing)
|
19
23
|
- [Customizing cased-rails](#customizing-cased-rails)
|
20
24
|
- [Contributing](#contributing)
|
21
25
|
|
@@ -41,6 +45,26 @@ All configuration options available in cased-rails are available to be configure
|
|
41
45
|
|
42
46
|
```ruby
|
43
47
|
Cased.configure do |config|
|
48
|
+
# GUARD_APPLICATION_KEY=guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH
|
49
|
+
config.guard_application_key = 'guard_application_1ntKX0P4vUbKoc0lMWGiSbrBHcH'
|
50
|
+
|
51
|
+
# GUARD_USER_TOKEN=user_1oFqlROLNRGVLOXJSsHkJiVmylr
|
52
|
+
config.guard_user_token = 'user_1oFqlROLNRGVLOXJSsHkJiVmylr'
|
53
|
+
|
54
|
+
# DENY_IF_UNREACHABLE=1
|
55
|
+
config.guard_deny_if_unreachable = true
|
56
|
+
|
57
|
+
# Attach metadata to all CLI requests. This metadata will appear in Cased and
|
58
|
+
# any notification source such as email or Slack.
|
59
|
+
#
|
60
|
+
# You are limited to 20 properties and cannot be a nested dictionary. Metadata
|
61
|
+
# specified in the CLI request overrides any configured globally.
|
62
|
+
config.cli.metadata = {
|
63
|
+
rails_env: ENV['RAILS_ENV'],
|
64
|
+
heroku_application: ENV['HEROKU_APP_NAME'],
|
65
|
+
git_commit: ENV['GIT_COMMIT'],
|
66
|
+
}
|
67
|
+
|
44
68
|
# CASED_POLICY_KEY=policy_live_1dQpY5JliYgHSkEntAbMVzuOROh
|
45
69
|
config.policy_key = 'policy_live_1dQpY5JliYgHSkEntAbMVzuOROh'
|
46
70
|
|
@@ -76,7 +100,119 @@ end
|
|
76
100
|
|
77
101
|
## Usage
|
78
102
|
|
79
|
-
###
|
103
|
+
### Cased CLI
|
104
|
+
|
105
|
+
#### Playback console sessions
|
106
|
+
|
107
|
+
Having visibility into production terminal sessions is essential to providing
|
108
|
+
access to sensitive data and critical systems. `cased-rails` can provide complete
|
109
|
+
command line session recordings with minimal configuration.
|
110
|
+
|
111
|
+
First, enable the "Record output" option in your application's settings page on Cased.
|
112
|
+
|
113
|
+
Next grab the application's key from the same settings page and configure
|
114
|
+
`cased-rails` with it either by using an environment variable or manually.
|
115
|
+
|
116
|
+
**Environment variable**
|
117
|
+
|
118
|
+
```
|
119
|
+
GUARD_APPLICATION_KEY=guard_application_1rBCh8o3YMaI1eAKxbrNvnLki3x rails console
|
120
|
+
```
|
121
|
+
|
122
|
+
**Manually**
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
Cased.configure do |config|
|
126
|
+
config.guard_application_key = 'guard_application_1rBCh8o3YMaI1eAKxbrNvnLki3x'
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
By default playback will be saved only when a Rails console is started outside
|
131
|
+
of development and test. When the playback is being saved, by default all
|
132
|
+
parameters other than `id`, `action`, and `controller` will be filtered out.
|
133
|
+
For example:
|
134
|
+
|
135
|
+
```
|
136
|
+
#<User id: "user_1qwkKB8IGxQFlu3C4lI53tCIyZI", organization: "Enterprise">
|
137
|
+
```
|
138
|
+
|
139
|
+
Would become:
|
140
|
+
|
141
|
+
```
|
142
|
+
#<User id: "user_1qwkKB8IGxQFlu3C4lI53tCIyZI", organization: [FILTERED]>
|
143
|
+
```
|
144
|
+
|
145
|
+
If you'd like to configure if filtering is enabled or specify which attributes
|
146
|
+
are not filtered you can do so with:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
Cased.configure do |config|
|
150
|
+
config.unfiltered_parameters = ['id', 'action', 'controller']
|
151
|
+
config.filter_parameters = Rails.env.production?
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
#### Approval workflows for sensitive operations
|
156
|
+
|
157
|
+
Adding approval workflows to your controllers is a two step process in your
|
158
|
+
Rails applications.
|
159
|
+
|
160
|
+
First, mount the Rails engine in your routes. The included Rails engine in
|
161
|
+
cased-rails is necessary for the approval workflow to know whether or not it has
|
162
|
+
been requested, approved, denied, canceled or timed out.
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
Rails.application.routes.draw do
|
166
|
+
mount Cased::Rails::Engine => '/cased'
|
167
|
+
|
168
|
+
root to: 'home#show'
|
169
|
+
end
|
170
|
+
```
|
171
|
+
|
172
|
+
To control the requirements for an approval workflow, that must be configured
|
173
|
+
within your CLI application settings on Cased. Some controls include restricting
|
174
|
+
which users or groups can approve the request, if a reason is required, how long
|
175
|
+
until the request times out, and more.
|
176
|
+
|
177
|
+
To start an your approval workflow all that is needed is to call the `guard`
|
178
|
+
method before a request using `before_action`.
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
class AccountsController < ApplicationController
|
182
|
+
before_action :guard, only: %i[update destroy]
|
183
|
+
|
184
|
+
def update
|
185
|
+
if current_account.update(account_params)
|
186
|
+
redirect_to current_account
|
187
|
+
else
|
188
|
+
render :edit
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def destroy
|
193
|
+
if current_account.destroy
|
194
|
+
redirect_to accounts_path
|
195
|
+
else
|
196
|
+
redirect_to current_account
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
private
|
201
|
+
|
202
|
+
def account_params
|
203
|
+
params.require(:account).permit(:name, :description, :email)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
```
|
207
|
+
|
208
|
+
Approval workflows are best started just before data is about to be created,
|
209
|
+
updated, or destroyed. Approval workflows are not intended to control permission
|
210
|
+
to view resources. The actions we recommend guarding are `create`, `update`, and
|
211
|
+
`destroy` based on your needs.
|
212
|
+
|
213
|
+
### Audit trails
|
214
|
+
|
215
|
+
#### Publishing events to Cased
|
80
216
|
|
81
217
|
Once Cased is setup there are two ways to publish your first audit trail event.
|
82
218
|
The first is using the `cased` helper method included in all ActiveRecord models.
|
@@ -151,7 +287,7 @@ end
|
|
151
287
|
|
152
288
|
By publishing the `team.create` audit event within the controller directly as shown you risk not having a complete and comprehensive audit trail for each team created in your application as it may happen in your API, model callbacks, and more.
|
153
289
|
|
154
|
-
|
290
|
+
#### Publishing audit events for all record creation, updates, and deletions automatically
|
155
291
|
|
156
292
|
Cased provides a mixin you can include in your models or in `ApplicationRecord` to automatically publish when new models are created, updated, or destroyed.
|
157
293
|
|
@@ -173,7 +309,7 @@ end
|
|
173
309
|
|
174
310
|
This mixin is intended to get you up and running quickly. You'll likely need to configure your own callbacks to control what exactly gets published to Cased.
|
175
311
|
|
176
|
-
|
312
|
+
#### Retrieving events from a Cased audit trail
|
177
313
|
|
178
314
|
If you plan on retrieving events from your audit trails to power a user facing audit trail or API you must use a Cased API key.
|
179
315
|
|
@@ -200,7 +336,7 @@ class AuditTrailController < ApplicationController
|
|
200
336
|
end
|
201
337
|
```
|
202
338
|
|
203
|
-
|
339
|
+
#### Retrieving events from multiple Cased audit trails
|
204
340
|
|
205
341
|
To retrieve events from one or more Cased audit trails you can configure multiple Cased API keys and retrieve events for each one by fetching their respective clients.
|
206
342
|
|
@@ -227,7 +363,7 @@ results.each do |event|
|
|
227
363
|
end
|
228
364
|
```
|
229
365
|
|
230
|
-
|
366
|
+
#### Exporting events
|
231
367
|
|
232
368
|
Exporting events from Cased allows you to provide users with exports of their own data or to respond to data requests.
|
233
369
|
|
@@ -243,7 +379,7 @@ export = Cased.policy.exports.create(
|
|
243
379
|
export.download_url # => https://api.cased.com/exports/export_1dSHQSNtAH90KA8zGTooMnmMdiD/download?token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlcl8xZFFwWThiQmdFd2RwbWRwVnJydER6TVg0ZkgiLCJ
|
244
380
|
```
|
245
381
|
|
246
|
-
|
382
|
+
#### Masking & filtering sensitive information
|
247
383
|
|
248
384
|
If you are handling sensitive information on behalf of your users you should consider masking or filtering any sensitive information.
|
249
385
|
|
@@ -258,7 +394,7 @@ Cased.publish(
|
|
258
394
|
)
|
259
395
|
```
|
260
396
|
|
261
|
-
|
397
|
+
#### Console Usage
|
262
398
|
|
263
399
|
Most Cased events will be created by users from actions on the website from
|
264
400
|
custom defined events or lifecycle callbacks. The exception is any console
|
@@ -275,7 +411,7 @@ Rails.application.console do
|
|
275
411
|
end
|
276
412
|
```
|
277
413
|
|
278
|
-
|
414
|
+
#### Disable publishing events
|
279
415
|
|
280
416
|
Although rare, there may be times where you wish to disable publishing events to Cased. To do so wrap your transaction inside of a `Cased.disable` block:
|
281
417
|
|
@@ -291,7 +427,7 @@ Or you can configure the entire process to disable publishing events.
|
|
291
427
|
CASED_DISABLE_PUBLISHING=1 bundle exec ruby crawl.rb
|
292
428
|
```
|
293
429
|
|
294
|
-
|
430
|
+
#### Context
|
295
431
|
|
296
432
|
When you include `cased-rails` in your application your Ruby on Rails application is configures a [Rack middleware](https://github.com/cased/cased-ruby/blob/master/lib/cased/rack_middleware.rb) that populates `Cased.context` with the following information for each request:
|
297
433
|
|
@@ -364,7 +500,7 @@ To clear/reset the context:
|
|
364
500
|
Cased.context.clear
|
365
501
|
```
|
366
502
|
|
367
|
-
|
503
|
+
#### Testing
|
368
504
|
|
369
505
|
`cased-rails` provides a Cased::TestHelper test helper class that you can use to test events are being published to Cased.
|
370
506
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<div>
|
5
5
|
<%= form.label 'guard_session[reason]', 'Reason', class: 'block text-sm font-medium text-gray-700' %>
|
6
6
|
<div class="mt-1">
|
7
|
-
<%= form.text_field 'guard_session[reason]', required: true, autocomplete: '
|
7
|
+
<%= form.text_field 'guard_session[reason]', required: true, autocomplete: 'off', placeholder: 'Provide a reason', class: 'appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm' %>
|
8
8
|
</div>
|
9
9
|
</div>
|
10
10
|
|
data/lib/cased/rails/config.rb
CHANGED
@@ -18,16 +18,6 @@ module Cased
|
|
18
18
|
].freeze
|
19
19
|
end
|
20
20
|
|
21
|
-
def skip_recording_console=(should_skip_recording_console)
|
22
|
-
@skip_recording_console = should_skip_recording_console
|
23
|
-
end
|
24
|
-
|
25
|
-
def skip_recording_console?
|
26
|
-
return @skip_recording_console if defined?(@skip_recording_console)
|
27
|
-
|
28
|
-
@skip_recording_console = ::Rails.env.development? || ::Rails.env.test?
|
29
|
-
end
|
30
|
-
|
31
21
|
def filter_parameters=(new_filter_parameters)
|
32
22
|
@filter_parameters = new_filter_parameters
|
33
23
|
end
|
@@ -38,19 +28,9 @@ module Cased
|
|
38
28
|
@filter_parameters = if ENV['CASED_FILTER_PARAMETERS']
|
39
29
|
parse_bool(ENV['CASED_FILTER_PARAMETERS'])
|
40
30
|
else
|
41
|
-
|
31
|
+
::Rails.env.staging? || ::Rails.env.production?
|
42
32
|
end
|
43
33
|
end
|
44
|
-
|
45
|
-
def url=(url)
|
46
|
-
@url = url
|
47
|
-
end
|
48
|
-
|
49
|
-
def url
|
50
|
-
return @url if defined?(@url)
|
51
|
-
|
52
|
-
@url = ENV.fetch('CASED_URL', 'https://app.cased.com')
|
53
|
-
end
|
54
34
|
end
|
55
35
|
end
|
56
36
|
end
|
data/lib/cased/rails/railtie.rb
CHANGED
@@ -57,8 +57,9 @@ module Cased
|
|
57
57
|
console do
|
58
58
|
Cased.console
|
59
59
|
|
60
|
-
# We only want to
|
61
|
-
|
60
|
+
# We only want to start an interactive session if Cased CLI is
|
61
|
+
# configured.
|
62
|
+
next if Cased.config.guard_application_key.blank?
|
62
63
|
|
63
64
|
session = Cased::CLI::InteractiveSession.start(command: "#{Dir.pwd}/bin/rails console")
|
64
65
|
Cased.context.merge(guard_session: session)
|
data/lib/cased/rails/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
desc 'Enforce your Cased CLI controls before the Rake task is executed'
|
4
|
+
task :guard do
|
5
|
+
next if Cased.config.guard_application_key.blank?
|
6
|
+
|
7
|
+
session = Cased::CLI::InteractiveSession.start
|
8
|
+
next unless session.record_output?
|
9
|
+
|
10
|
+
exit unless Cased::CLI::Session.current&.approved?
|
11
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cased-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garrett Bjerkhoel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cased-ruby
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.5.1
|
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.5.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jbuilder
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '6.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rexml
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.5
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.5
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: mocha
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +100,14 @@ dependencies:
|
|
86
100
|
requirements:
|
87
101
|
- - '='
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
103
|
+
version: 0.93.1
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - '='
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
110
|
+
version: 0.93.1
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: webmock
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,11 +161,12 @@ files:
|
|
147
161
|
- lib/cased/rails/model.rb
|
148
162
|
- lib/cased/rails/railtie.rb
|
149
163
|
- lib/cased/rails/version.rb
|
164
|
+
- lib/tasks/cased.rake
|
150
165
|
homepage: https://github.com/cased/cased-rails
|
151
166
|
licenses:
|
152
167
|
- MIT
|
153
168
|
metadata: {}
|
154
|
-
post_install_message:
|
169
|
+
post_install_message:
|
155
170
|
rdoc_options: []
|
156
171
|
require_paths:
|
157
172
|
- lib
|
@@ -166,8 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
181
|
- !ruby/object:Gem::Version
|
167
182
|
version: '0'
|
168
183
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
170
|
-
signing_key:
|
184
|
+
rubygems_version: 3.2.15
|
185
|
+
signing_key:
|
171
186
|
specification_version: 4
|
172
187
|
summary: Ruby on Rails SDK/client library for Cased
|
173
188
|
test_files: []
|