Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 874360a

Browse files
committed
revisions: #show_environment_variables audit event
Revisions environment variables can contain sensitive information, access to sensitive information should be audited Signed-off-by: toby lorne <toby@toby.codes>
1 parent 31af9fd commit 874360a

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

app/controllers/v3/revisions_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'actions/revisions_update'
33
require 'presenters/v3/revision_presenter'
44
require 'presenters/v3/revision_environment_variables_presenter'
5+
require 'repositories/revision_event_repository'
56

67
class RevisionsController < ApplicationController
78
def show
@@ -22,6 +23,7 @@ def update
2223

2324
def show_environment_variables
2425
revision = fetch_revision(hashed_params[:revision_guid], needs_secrets_read_permission: true)
26+
Repositories::RevisionEventRepository.record_show_environment_variables(revision, revision.app, user_audit_info)
2527
render status: :ok, json: Presenters::V3::RevisionEnvironmentVariablesPresenter.new(revision)
2628
end
2729

app/repositories/revision_event_repository.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ def self.record_create(revision, app, user_audit_info)
2222
organization_guid: app.space.organization_guid,
2323
)
2424
end
25+
26+
def self.record_show_environment_variables(revision, app, user_audit_info)
27+
Event.create(
28+
type: 'audit.app.revision.environment_variables.show',
29+
actor: user_audit_info.user_guid,
30+
actor_type: 'user',
31+
actor_name: user_audit_info.user_email,
32+
actor_username: user_audit_info.user_name,
33+
actee: app.guid,
34+
actee_type: 'app',
35+
actee_name: app.name,
36+
timestamp: Sequel::CURRENT_TIMESTAMP,
37+
metadata: {
38+
revision_guid: revision.guid,
39+
revision_version: revision.version
40+
},
41+
space_guid: app.space_guid,
42+
organization_guid: app.space.organization_guid,
43+
)
44+
end
2545
end
2646
end
2747
end

spec/unit/controllers/v3/revisions_controller_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343
}
344344

345345
before do
346-
set_current_user(user)
346+
set_current_user(user, email: 'mona@example.com')
347347
allow_user_read_access_for(user, spaces: [space])
348348
allow_user_secret_access(user, space: space)
349349
end
@@ -355,6 +355,28 @@
355355
expect(parsed_body['var']).to eq({ 'key' => 'value' })
356356
end
357357

358+
it 'records an audit event' do
359+
expect {
360+
get :show_environment_variables, params: { revision_guid: revision.guid }
361+
}.to change { VCAP::CloudController::Event.count }.by(1)
362+
363+
event = VCAP::CloudController::Event.find(type: 'audit.app.revision.environment_variables.show')
364+
expect(event).not_to be_nil
365+
expect(event.actor).to eq(user.guid)
366+
expect(event.actor_type).to eq('user')
367+
expect(event.actor_name).to eq('mona@example.com')
368+
expect(event.actee).to eq(app_model.guid)
369+
expect(event.actee_type).to eq('app')
370+
expect(event.actee_name).to eq(app_model.name)
371+
expect(event.timestamp).to be
372+
expect(event.space_guid).to eq(app_model.space_guid)
373+
expect(event.organization_guid).to eq(app_model.space.organization.guid)
374+
expect(event.metadata).to eq({
375+
'revision_guid' => revision.guid,
376+
'revision_version' => revision.version,
377+
})
378+
end
379+
358380
context 'when retrieving env variables for revision that do not exist' do
359381
it '404s' do
360382
get :show_environment_variables, params: { revision_guid: 'nonsense' }

0 commit comments

Comments
 (0)