Rebasing a merge request uses protection rules from wrong repository
Summary
Scenario:
- Master repository with wildcard branch protection for '*'
- All development is done in personal forks and integrated via merge requests
- Fast-forward merges enabled
When trying to rebasing a merge request that is no longer fast-forwardable, the operation fails silently and reproducibly. The symptom is identical to #1774 (closed), but the root cause is not. The githost.log file reveals that the force push into the developer's form is rejected by the pre-receive hook:
August 17, 2017 16:36 -> ERROR -> MergeRequests::RebaseService error (main/firmware!41): Failed to push rebased branch with `/opt/gitlab/embedded/bin/git push -f origin my-bug-fixes`:
August 17, 2017 16:36 -> ERROR -> MergeRequests::RebaseService error (main/firmware!41): remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To /home/gitlab/data/git-data/repositories/ingo/firmware.git
! [remote rejected] my-bug-fixes -> my-bug-fixes (pre-receive hook declined)
error: failed to push some refs to '/home/gitlab/data/git-data/repositories/ingo/firmware.git'
The RebaseService tries to force-push into my personal fork ingo/firmware and fails due to branch protection rules. However, I do not have any protected branches in my fork. Apparently, the hook mistakenly takes the strict protection rules from the master repository.
Steps to reproduce
- Create a repository with the following setup:
- Fast-forward merges enabled
- Protected branches: '*'
- Create a fork of that repository
- Push some commits into both repositories
- Create a merge request
- In the merge request, click the Rebase button
What is the current bug behavior?
- A "Rebase in progress" message is displayed
- After some time (maybe 20 seconds), the GUI changes back to the "fast-forward merge is not possible" message
- The githost.log file shows error messages like listed above
What is the expected correct behavior?
- Provided there are no conflicts, the rebase should succeed
- The rebased commits should be pushed into the source branch of the developer's fork
- After a successful rebase, it should be possible to accept the merge request
Relevant logs and/or screenshots
See above
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
System information System: Scientific 7.3 Proxy: no Current User: gitlab Using RVM: no Ruby Version: 2.3.3p222 Gem Version: 2.6.6 Bundler Version:1.13.7 Rake Version: 10.5.0 Redis Version: 3.2.5 Git Version: 2.13.4 Sidekiq Version:5.0.0 Go Version: unknown
GitLab information Version: 9.4.4-ee Revision: c7bc62c Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql DB Version: 9.6.3 URL: http://repository.company.de/gitlab HTTP Clone URL: http://repository.company.de/gitlab/some-group/some-project.git SSH Clone URL: gitlab@repository.company.de:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: yes Using Omniauth: no
GitLab Shell Version: 5.3.1 Repository storage paths:
- default: /home/gitlab/data/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
Checking GitLab Shell ...
GitLab Shell version >= 5.3.1 ? ... OK (5.3.1) Repo base directory exists? default... yes Repo storage directories are symlinks? default... no Repo paths owned by gitlab:root, or gitlab:gitlab? default... yes Repo paths access is drwxrws---? default... yes hooks directories in repos are links: ... 19/1328 ... ok 19/1329 ... ok 13/1330 ... ok 19/1331 ... repository is empty 19/1332 ... repository is empty 31/1337 ... ok 12/1339 ... ok 12/1340 ... ok 12/1341 ... ok 12/1342 ... ok 12/1343 ... ok 12/1344 ... ok 12/1345 ... ok 12/1346 ... ok 12/1347 ... ok 12/1348 ... ok 12/1349 ... ok 12/1350 ... ok 12/1351 ... ok 12/1352 ... ok 12/1353 ... ok 12/1354 ... ok 12/1355 ... ok 12/1356 ... ok 12/1357 ... ok 12/1358 ... ok 12/1359 ... ok 12/1360 ... ok 12/1361 ... ok 12/1362 ... ok 12/1363 ... ok 12/1364 ... ok 12/1365 ... ok 12/1366 ... ok 12/1367 ... ok 12/1368 ... ok 12/1369 ... ok 12/1370 ... ok 12/1371 ... ok 12/1372 ... ok 12/1373 ... ok 12/1374 ... ok 12/1375 ... ok 12/1376 ... ok 12/1377 ... ok 12/1378 ... ok 12/1379 ... ok 12/1380 ... ok 12/1381 ... ok 12/1382 ... ok 12/1383 ... ok 12/1384 ... ok 12/1385 ... ok 12/1386 ... ok 12/1387 ... ok 12/1388 ... ok 12/1389 ... ok 12/1390 ... ok 12/1391 ... ok 12/1392 ... ok 12/1393 ... ok 12/1394 ... ok 12/1395 ... ok 12/1396 ... ok 12/1397 ... ok 12/1398 ... ok 12/1399 ... ok 12/1400 ... ok 12/1401 ... ok 12/1402 ... ok 12/1403 ... ok 12/1404 ... ok 12/1405 ... ok 12/1406 ... ok 12/1407 ... ok 12/1408 ... ok 12/1409 ... ok 12/1410 ... ok 12/1411 ... ok 12/1412 ... ok 12/1413 ... ok 12/1414 ... ok 12/1415 ... ok 12/1416 ... ok 12/1417 ... ok 12/1418 ... ok 12/1419 ... ok 12/1420 ... ok 12/1421 ... ok 12/1422 ... ok 12/1423 ... ok 12/1424 ... ok 12/1425 ... ok 12/1426 ... ok 12/1427 ... ok 12/1428 ... ok 12/1429 ... ok 12/1430 ... ok 12/1431 ... ok 12/1432 ... ok 12/1433 ... ok 12/1434 ... ok 12/1435 ... ok 12/1436 ... ok 12/1437 ... ok 12/1438 ... ok 12/1439 ... ok 12/1440 ... ok 12/1441 ... ok 12/1442 ... ok 12/1443 ... ok 12/1444 ... ok 12/1445 ... ok 12/1446 ... ok 11/1447 ... ok 4/1448 ... ok 3/1449 ... ok 22/1450 ... ok 14/1451 ... ok 16/1452 ... ok 21/1453 ... ok 25/1454 ... ok 27/1455 ... ok 17/1456 ... ok Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Access to /var/opt/gitlab/.ssh/authorized_keys: OK Send ping to redis server: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Reply by email ...
Reply by email is disabled in config/gitlab.yml
Checking Reply by email ... Finished
Checking LDAP ...
Server: ldapmain LDAP authentication... Success LDAP users with access to your GitLab server (only showing the first 100 results) // REMOVED //
Checking LDAP ... Finished
Checking GitLab ...
Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 19/1328 ... yes 19/1329 ... yes 13/1330 ... yes 19/1331 ... yes 19/1332 ... yes 31/1337 ... yes 12/1339 ... yes 12/1340 ... yes 12/1341 ... yes 12/1342 ... yes 12/1343 ... yes 12/1344 ... yes 12/1345 ... yes 12/1346 ... yes 12/1347 ... yes 12/1348 ... yes 12/1349 ... yes 12/1350 ... yes 12/1351 ... yes 12/1352 ... yes 12/1353 ... yes 12/1354 ... yes 12/1355 ... yes 12/1356 ... yes 12/1357 ... yes 12/1358 ... yes 12/1359 ... yes 12/1360 ... yes 12/1361 ... yes 12/1362 ... yes 12/1363 ... yes 12/1364 ... yes 12/1365 ... yes 12/1366 ... yes 12/1367 ... yes 12/1368 ... yes 12/1369 ... yes 12/1370 ... yes 12/1371 ... yes 12/1372 ... yes 12/1373 ... yes 12/1374 ... yes 12/1375 ... yes 12/1376 ... yes 12/1377 ... yes 12/1378 ... yes 12/1379 ... yes 12/1380 ... yes 12/1381 ... yes 12/1382 ... yes 12/1383 ... yes 12/1384 ... yes 12/1385 ... yes 12/1386 ... yes 12/1387 ... yes 12/1388 ... yes 12/1389 ... yes 12/1390 ... yes 12/1391 ... yes 12/1392 ... yes 12/1393 ... yes 12/1394 ... yes 12/1395 ... yes 12/1396 ... yes 12/1397 ... yes 12/1398 ... yes 12/1399 ... yes 12/1400 ... yes 12/1401 ... yes 12/1402 ... yes 12/1403 ... yes 12/1404 ... yes 12/1405 ... yes 12/1406 ... yes 12/1407 ... yes 12/1408 ... yes 12/1409 ... yes 12/1410 ... yes 12/1411 ... yes 12/1412 ... yes 12/1413 ... yes 12/1414 ... yes 12/1415 ... yes 12/1416 ... yes 12/1417 ... yes 12/1418 ... yes 12/1419 ... yes 12/1420 ... yes 12/1421 ... yes 12/1422 ... yes 12/1423 ... yes 12/1424 ... yes 12/1425 ... yes 12/1426 ... yes 12/1427 ... yes 12/1428 ... yes 12/1429 ... yes 12/1430 ... yes 12/1431 ... yes 12/1432 ... yes 12/1433 ... yes 12/1434 ... yes 12/1435 ... yes 12/1436 ... yes 12/1437 ... yes 12/1438 ... yes 12/1439 ... yes 12/1440 ... yes 12/1441 ... yes 12/1442 ... yes 12/1443 ... yes 12/1444 ... yes 12/1445 ... yes 12/1446 ... yes 11/1447 ... yes 4/1448 ... yes 3/1449 ... yes 22/1450 ... yes 14/1451 ... yes 16/1452 ... yes 21/1453 ... yes 25/1454 ... yes 27/1455 ... yes 17/1456 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.3 ? ... yes (2.3.3) Git version >= 2.7.3 ? ... yes (2.13.4) Active users: ... 24 Elasticsearch version 5.1 - 5.3? ... skipped (elasticsearch is disabled)
Checking GitLab ... Finished