diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-07 17:10:00 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-07 17:10:21 +0800 |
commit | 0c5f8b4b639e48176f1cbf78b732cb20d5abf0a4 (patch) | |
tree | c91b09e3c3bb53f989b66b6edd56d96baf30aa92 /ssh_handle_receive_pack.go | |
parent | hooks: Remove debug printf (diff) | |
download | forge-0c5f8b4b639e48176f1cbf78b732cb20d5abf0a4.tar.gz forge-0c5f8b4b639e48176f1cbf78b732cb20d5abf0a4.tar.zst forge-0c5f8b4b639e48176f1cbf78b732cb20d5abf0a4.zip |
hooks, fedauth: Add basic federated authentication for git push
Diffstat (limited to 'ssh_handle_receive_pack.go')
-rw-r--r-- | ssh_handle_receive_pack.go | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/ssh_handle_receive_pack.go b/ssh_handle_receive_pack.go index 45610bb..b77b717 100644 --- a/ssh_handle_receive_pack.go +++ b/ssh_handle_receive_pack.go @@ -15,15 +15,17 @@ import ( ) type pack_to_hook_t struct { - session glider_ssh.Session - repo *git.Repository - pubkey string - direct_access bool - repo_path string - user_id int - repo_id int - group_path []string - repo_name string + session glider_ssh.Session + repo *git.Repository + pubkey string + direct_access bool + repo_path string + user_id int + user_type string + repo_id int + group_path []string + repo_name string + contrib_requirements string } var pack_to_hook_by_cookie = cmap.Map[string, pack_to_hook_t]{} @@ -65,6 +67,8 @@ func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_ide return errors.New("You need to be a registered user to push to this repo.") } case "ssh_pubkey": + fallthrough + case "federated": if pubkey == "" { return errors.New("You need to have an SSH public key to push to this repo.") } @@ -74,7 +78,9 @@ func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_ide return err } fmt.Fprintln(session.Stderr(), "You are now registered as user ID", user_id) + user_type = "pubkey_only" } + case "public": default: panic("unknown contrib_requirements value " + contrib_requirements) @@ -87,15 +93,17 @@ func ssh_handle_receive_pack(session glider_ssh.Session, pubkey string, repo_ide } pack_to_hook_by_cookie.Store(cookie, pack_to_hook_t{ - session: session, - pubkey: pubkey, - direct_access: direct_access, - repo_path: repo_path, - user_id: user_id, - repo_id: repo_id, - group_path: group_path, - repo_name: repo_name, - repo: repo, + session: session, + pubkey: pubkey, + direct_access: direct_access, + repo_path: repo_path, + user_id: user_id, + repo_id: repo_id, + group_path: group_path, + repo_name: repo_name, + repo: repo, + contrib_requirements: contrib_requirements, + user_type: user_type, }) defer pack_to_hook_by_cookie.Delete(cookie) // The Delete won't execute until proc.Wait returns unless something |