BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d45fef88
Commit
d45fef88
authored
Nov 07, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix-mysql-grant-check' into 'master'
Fix TRIGGER checks for MySQL Closes #38372 See merge request gitlab-org/gitlab-ce!15226
parents
dc1e6b43
60526a52
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
28 deletions
+29
-28
fix-mysql-grant-check.yml
changelogs/unreleased/fix-mysql-grant-check.yml
+5
-0
grant.rb
lib/gitlab/database/grant.rb
+19
-11
grant_spec.rb
spec/lib/gitlab/database/grant_spec.rb
+5
-17
No files found.
changelogs/unreleased/fix-mysql-grant-check.yml
0 → 100644
View file @
d45fef88
---
title
:
Fix TRIGGER checks for MySQL
merge_request
:
author
:
type
:
fixed
lib/gitlab/database/grant.rb
View file @
d45fef88
...
...
@@ -6,28 +6,36 @@ module Gitlab
if
Database
.
postgresql?
'information_schema.role_table_grants'
else
'
mysql.user
'
'
information_schema.schema_privileges
'
end
def
self
.
scope_to_current_user
if
Database
.
postgresql?
where
(
'grantee = user'
)
else
where
(
"CONCAT(User, '@', Host) = current_user()"
)
end
end
# Returns true if the current user can create and execute triggers on the
# given table.
def
self
.
create_and_execute_trigger?
(
table
)
priv
=
if
Database
.
postgresql?
where
(
privilege_type:
'TRIGGER'
,
table_name:
table
)
.
where
(
'grantee = user'
)
else
where
(
Trigger_priv
:
'Y'
)
queries
=
[
Grant
.
select
(
1
)
.
from
(
'information_schema.user_privileges'
)
.
where
(
"PRIVILEGE_TYPE = 'SUPER'"
)
.
where
(
"GRANTEE = CONCAT('
\\
'', REPLACE(CURRENT_USER(), '@', '
\\
'@
\\
''), '
\\
'')"
),
Grant
.
select
(
1
)
.
from
(
'information_schema.schema_privileges'
)
.
where
(
"PRIVILEGE_TYPE = 'TRIGGER'"
)
.
where
(
'TABLE_SCHEMA = ?'
,
Gitlab
::
Database
.
database_name
)
.
where
(
"GRANTEE = CONCAT('
\\
'', REPLACE(CURRENT_USER(), '@', '
\\
'@
\\
''), '
\\
'')"
)
]
union
=
SQL
::
Union
.
new
(
queries
).
to_sql
Grant
.
from
(
"(
#{
union
}
) privs"
)
end
priv
.
scope_to_current_user
.
any?
priv
.
any?
end
end
end
...
...
spec/lib/gitlab/database/grant_spec.rb
View file @
d45fef88
require
'spec_helper'
describe
Gitlab
::
Database
::
Grant
do
describe
'.scope_to_current_user'
do
it
'scopes the relation to the current user'
do
user
=
Gitlab
::
Database
.
username
column
=
Gitlab
::
Database
.
postgresql?
?
:
grantee
:
:User
names
=
described_class
.
scope_to_current_user
.
pluck
(
column
).
uniq
expect
(
names
).
to
eq
([
user
])
end
end
describe
'.create_and_execute_trigger'
do
it
'returns true when the user can create and execute a trigger'
do
# We assume the DB/user is set up correctly so that triggers can be
...
...
@@ -18,13 +8,11 @@ describe Gitlab::Database::Grant do
expect
(
described_class
.
create_and_execute_trigger?
(
'users'
)).
to
eq
(
true
)
end
it
'returns false when the user can not create and/or execute a trigger'
do
allow
(
described_class
).
to
receive
(
:scope_to_current_user
)
.
and_return
(
described_class
.
none
)
result
=
described_class
.
create_and_execute_trigger?
(
'kittens'
)
expect
(
result
).
to
eq
(
false
)
it
'returns false when the user can not create and/or execute a trigger'
,
:postgresql
do
# In case of MySQL the user may have SUPER permissions, making it
# impossible to have `false` returned when running tests; hence we only
# run these tests on PostgreSQL.
expect
(
described_class
.
create_and_execute_trigger?
(
'foo'
)).
to
eq
(
false
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment