Commit 3d1694ce authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'sh-log-container-registry-access-warnings' into 'master'

Log when container registry permissions are denied

See merge request gitlab-org/gitlab!31536
parents 91e3b8f9 49573bf6
......@@ -103,17 +103,19 @@ module Auth
return unless requested_project
actions = actions.select do |action|
authorized_actions = actions.select do |action|
can_access?(requested_project, action)
end
return unless actions.present?
log_if_actions_denied(type, requested_project, actions, authorized_actions)
return unless authorized_actions.present?
# At this point user/build is already authenticated.
#
ensure_container_repository!(path, actions)
ensure_container_repository!(path, authorized_actions)
{ type: type, name: path.to_s, actions: actions }
{ type: type, name: path.to_s, actions: authorized_actions }
end
##
......@@ -222,5 +224,22 @@ module Auth
REGISTRY_LOGIN_ABILITIES.include?(ability)
end
end
def log_if_actions_denied(type, requested_project, requested_actions, authorized_actions)
return if requested_actions == authorized_actions
log_info = {
message: "Denied container registry permissions",
scope_type: type,
requested_project_path: requested_project.full_path,
requested_actions: requested_actions,
authorized_actions: authorized_actions,
username: current_user&.username,
user_id: current_user&.id,
project_path: project&.full_path
}.compact
Gitlab::AuthLogger.warn(log_info)
end
end
end
---
title: Log when container registry permissions are denied
merge_request: 31536
author:
type: other
......@@ -205,6 +205,20 @@ describe Auth::ContainerRegistryAuthenticationService do
it_behaves_like 'an inaccessible'
it_behaves_like 'not a container repository factory'
it 'logs an auth warning' do
expect(Gitlab::AuthLogger).to receive(:warn).with(
message: 'Denied container registry permissions',
scope_type: 'repository',
requested_project_path: project.full_path,
requested_actions: ['*'],
authorized_actions: [],
user_id: current_user.id,
username: current_user.username
)
subject
end
end
context 'disallow developer to delete images since registry 2.7' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment