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

Commit c22a490

Browse files
committed
apps: #show_environment_variables has audit event
The environment can contain sensitive information, access to sensitive information should be audited Signed-off-by: toby lorne <toby@toby.codes>
1 parent 874360a commit c22a490

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

app/controllers/v3/apps_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ def show_environment_variables
261261

262262
FeatureFlag.raise_unless_enabled!(:space_developer_env_var_visibility)
263263

264+
Repositories::AppEventRepository.new.record_app_show_environment_variables(app, user_audit_info)
265+
264266
render status: :ok, json: Presenters::V3::AppEnvironmentVariablesPresenter.new(app)
265267
end
266268

app/repositories/app_event_repository.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ def record_app_show_env(app, user_audit_info)
160160
create_app_audit_event('audit.app.environment.show', app, app.space, actor_hash, {})
161161
end
162162

163+
def record_app_show_environment_variables(app, user_audit_info)
164+
actor_hash = { name: user_audit_info.user_email, guid: user_audit_info.user_guid, user_name: user_audit_info.user_name, type: 'user' }
165+
create_app_audit_event('audit.app.environment_variables.show', app, app.space, actor_hash, {})
166+
end
167+
163168
private
164169

165170
def create_app_audit_event(type, app, space, actor, metadata)

spec/unit/controllers/v3/apps_controller_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,27 @@
19961996
})
19971997
end
19981998
end
1999+
2000+
it 'records an audit event' do
2001+
set_current_user_as_admin(user: user, email: 'mona@example.com')
2002+
2003+
expect {
2004+
get :show_environment_variables, params: { guid: app_model.guid }, as: :json
2005+
}.to change { VCAP::CloudController::Event.count }.by(1)
2006+
2007+
event = VCAP::CloudController::Event.find(type: 'audit.app.environment_variables.show')
2008+
expect(event).not_to be_nil
2009+
expect(event.actor).to eq(user.guid)
2010+
expect(event.actor_type).to eq('user')
2011+
expect(event.actor_name).to eq('mona@example.com')
2012+
expect(event.actee).to eq(app_model.guid)
2013+
expect(event.actee_type).to eq('app')
2014+
expect(event.actee_name).to eq(app_model.name)
2015+
expect(event.timestamp).to be
2016+
expect(event.space_guid).to eq(app_model.space_guid)
2017+
expect(event.organization_guid).to eq(app_model.space.organization.guid)
2018+
expect(event.metadata).to eq({})
2019+
end
19992020
end
20002021

20012022
describe '#update_environment_variables' do

0 commit comments

Comments
 (0)