Are gitlab deployment keys read only? I need to clone on ci server using a deployment key and then push the tag created by the ci process. is that possible using a deployment key?
相关问题
- Gitlab-runner without Docker
- How to get Gitlab merge request description in Git
- How do i give parameters to SonarQube.Scanner.MSBu
- 请问 GitLab 如何连接一个已有的 Kubernetes 集群
- Maven install-file not effective in GitLab/Docker:
相关文章
- 请问 GitLab 如何连接一个已有的 Kubernetes 集群
- gitlab升级失败
- ssh: Could not resolve hostname git: Name or servi
- How do you center text in Gitlab markdown?
- .gitlab-ci.yml after_script section: how can I tel
- Gitlab CI / Docker: Use custom image for job
- Move .git repo to parent directory [duplicate]
- Migrate gitlab self hosted to gitlab hosted
Update 2017
GitLab 8.16 (January 2017) does introduce deploy keys with write-access!
Merge Request 5807
Original answer 2013:
Last time I checked (in "Push to GitLab repository within CI server (deploy keys)", no, you don't have the right to use a deploy key to push to a repo.
Litmus adds in the comments, and I agree with him:
Curt J. Sampson mentions in the comments:
Not just in
GitLab
, even onBitbucket
,Github
etc. deploy keys are readonly.Given that deploy keys are used to deploy on
production
, it should be a oneway flow. Code should flow from DVCS toproduction
but never the other way.Also
production
servers should have as less privilege as possible... that is a security best practice.And most often there is a need to share deploy keys with non-developers, or automation tools. Making them readonly (at least) ensures that an unauthorized person does not screw up with the code base (of course git lets you recover almost everything, but isn't prevention better than cure?)
CI runs in
test
environment. Never use same keys forproduction
andtest
. That will be a disaster.Here is a short workaround to archive following on a per-key basis:
Make
My SSH keys
readonly. This allows to add machines with readonly access to all repos of an account. Good if you work with trainloads ofgit
subprojects.Make Deploy-Keys read-write on developer level.
This is archived by prepending the key's title with some special characters:
*
to make aMy SSH keys
readonly!
to make Deploy-Keys read-write!!
to make Deploy-Keys master (write to protected branches)So instead naming the key "My global key" you name it "* my global readonly key" etc.
Edit1: This patch now is available as
cherry-pick
on GitHub, see https://github.com/hilbix/gitlabhq/wikiEdit3: You probably want following workaround, too, in case you push through a deployment key. This is not perfect, as it does not trigger all those hooks, but it invalidates the caches such that the web pages no more show stale data:
There still is are some problems left:
A minor one, you cannot use the same key on the account level and on the deploy level at the same time. So for keys which only have read-only access on a global basis (which probably is the default key used), you need a second special "push only" key, which allows push access to the repos.
Edit3: And the major one that deployment keys do not have a user attached, so that all the convenience things do not work. If this is a problem for you the only way is, for each SSH key create a dummy-user, and add it to the group/project and give this dummy-users the correct permissions.
Complete example under Linux for a test repo at
git@gitlab.example.com:root/test.git
Apply above patch to GitLab
Restart GitLab to read in the new code
Add your
~/.ssh/id_rsa.pub
to GitLab Admin underMy SSH keys
and name it* my readonly key
(or something different, starting with*
).Verify, that following works:
git clone git@gitlab.example.com:root/test.git
Verify, that following fails on the
git push
step:Create a second SSH key
~/.ssh/id_push
:ssh-keygen -b 4096 -f ~/.ssh/id_push
Add
~/.ssh/id_push.pub
as Deploy-Key to reporoot/test.git
. Name it! my push key
(or something different, starting with!
)Add following to
~/.ssh/config
Add this target to your cloned repo:
git remote add to gitlab-push:root/test.git
Verify following works:
git push to master
Notes:
I used copy+paste to insert the patch. It is likely it will not apply cleanly. Sorry.
Yes, this is really a very crude hack which should not make it into the mainline. The correct implementation would be to have a flag in the database which does this, such that you can edit it through the GUI.
For deploy keys this "key-level"-flag should be in the interesection table between key and project. And in the non-deploy-key variant it should be on the key itself. Perhaps this field can then act as a
default
value when adding a deploy key to another project and record the last usage of such key.Unfortunately I am not able to implement this properly myself as I lack the knowledge how to add the necessary elements to the GUI, sorry. ;(