aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/serv.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-02-03 23:56:53 +0000
committerGitHub <noreply@github.com>2019-02-03 23:56:53 +0000
commit01c10a951b9db0b9f020ef657ca71eb5e5882a84 (patch)
tree6cb29db94edda9d90e9a509028bada2a61ade928 /cmd/serv.go
parent634cbaad2b8d091a2a3065de81e0b2b76daa5ef7 (diff)
downloadgitea-01c10a951b9db0b9f020ef657ca71eb5e5882a84.tar.gz
gitea-01c10a951b9db0b9f020ef657ca71eb5e5882a84.zip
Fix ssh deploy and user key constraints (#1357) (#5939)
1. A key can either be an ssh user key or a deploy key. It cannot be both. 2. If a key is a user key - it can only be associated with one user. 3. If a key is a deploy key - it can be used in multiple repositories and the permissions it has on those repositories can be different. 4. If a repository is deleted, its deploy keys must be deleted too. We currently don't enforce any of this and multiple repositories access with different permissions doesn't work at all. This PR enforces the following constraints: - [x] You should not be able to add the same user key as another user - [x] You should not be able to add a ssh user key which is being used as a deploy key - [x] You should not be able to add a ssh deploy key which is being used as a user key - [x] If you add an ssh deploy key to another repository you should be able to use it in different modes without losing the ability to use it in the other mode. - [x] If you delete a repository you must delete all its deploy keys. Fix #1357
Diffstat (limited to 'cmd/serv.go')
-rw-r--r--cmd/serv.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/cmd/serv.go b/cmd/serv.go
index 21a69b24d6..ca0354d06c 100644
--- a/cmd/serv.go
+++ b/cmd/serv.go
@@ -234,19 +234,20 @@ func runServ(c *cli.Context) error {
// Check deploy key or user key.
if key.Type == models.KeyTypeDeploy {
- if key.Mode < requestedMode {
- fail("Key permission denied", "Cannot push with deployment key: %d", key.ID)
- }
-
- // Check if this deploy key belongs to current repository.
- has, err := private.HasDeployKey(key.ID, repo.ID)
+ // Now we have to get the deploy key for this repo
+ deployKey, err := private.GetDeployKey(key.ID, repo.ID)
if err != nil {
fail("Key access denied", "Failed to access internal api: [key_id: %d, repo_id: %d]", key.ID, repo.ID)
}
- if !has {
+
+ if deployKey == nil {
fail("Key access denied", "Deploy key access denied: [key_id: %d, repo_id: %d]", key.ID, repo.ID)
}
+ if deployKey.Mode < requestedMode {
+ fail("Key permission denied", "Cannot push with read-only deployment key: %d to repo_id: %d", key.ID, repo.ID)
+ }
+
// Update deploy key activity.
if err = private.UpdateDeployKeyUpdated(key.ID, repo.ID); err != nil {
fail("Internal error", "UpdateDeployKey: %v", err)