Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codeberg user authorized key support #256

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ Host a session with specified client public key(s) authorized to connect:
upterm host --authorized-key PATH_TO_PUBLIC_KEY
```

Authorize specified GitHub, GitLab, or SourceHut users with their corresponding public keys:
Authorize specified Codeberg, GitHub, GitLab, or SourceHut users with their corresponding public keys:

```console
upterm host --codeberg-user username
upterm host --github-user username
upterm host --gitlab-user username
upterm host --srht-user username
Expand Down
9 changes: 9 additions & 0 deletions cmd/upterm/command/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
flagPrivateKeys []string
flagKnownHostsFilename string
flagAuthorizedKeys string
flagCodebergUsers []string
flagGitHubUsers []string
flagGitLabUsers []string
flagSourceHutUsers []string
Expand Down Expand Up @@ -73,6 +74,7 @@ private key. To authorize client connections, specify a authorized_key file with
cmd.PersistentFlags().StringSliceVarP(&flagPrivateKeys, "private-key", "i", defaultPrivateKeys(homeDir), "Specify private key files for public key authentication with the upterm server (required).")
cmd.PersistentFlags().StringVarP(&flagKnownHostsFilename, "known-hosts", "", defaultKnownHost(homeDir), "Specify a file containing known keys for remote hosts (required).")
cmd.PersistentFlags().StringVar(&flagAuthorizedKeys, "authorized-keys", "", "Specify a authorize_keys file listing authorized public keys for connection.")
cmd.PersistentFlags().StringSliceVar(&flagCodebergUsers, "codeberg-user", nil, "Authorize specified Codeberg users by allowing their public keys to connect.")
cmd.PersistentFlags().StringSliceVar(&flagGitHubUsers, "github-user", nil, "Authorize specified GitHub users by allowing their public keys to connect. Configure GitHub CLI environment variables as needed; see https://cli.github.com/manual/gh_help_environment for details.")
cmd.PersistentFlags().StringSliceVar(&flagGitLabUsers, "gitlab-user", nil, "Authorize specified GitLab users by allowing their public keys to connect.")
cmd.PersistentFlags().StringSliceVar(&flagSourceHutUsers, "srht-user", nil, "Authorize specified SourceHut users by allowing their public keys to connect.")
Expand Down Expand Up @@ -158,6 +160,13 @@ func shareRunE(c *cobra.Command, args []string) error {
}
authorizedKeys = append(authorizedKeys, aks)
}
if flagCodebergUsers != nil {
codebergUserKeys, err := host.CodebergUserAuthorizedKeys(flagCodebergUsers)
if err != nil {
return fmt.Errorf("error reading Codeberg user keys: %w", err)
}
authorizedKeys = append(authorizedKeys, codebergUserKeys...)
}
if flagGitHubUsers != nil {
gitHubUserKeys, err := host.GitHubUserAuthorizedKeys(flagGitHubUsers, logger)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions docs/upterm_host.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ upterm host [flags]
```
--accept Automatically accept client connections without prompts.
--authorized-keys string Specify a authorize_keys file listing authorized public keys for connection.
--codeberg-user strings Authorize specified Codeberg users by allowing their public keys to connect.
-f, --force-command string Enforce a specified command for clients to join, and link the command's input/output to the client's terminal.
--github-user strings Authorize specified GitHub users by allowing their public keys to connect. Configure GitHub CLI environment variables as needed; see https://cli.github.com/manual/gh_help_environment for details.
--gitlab-user strings Authorize specified GitLab users by allowing their public keys to connect.
Expand Down
2 changes: 2 additions & 0 deletions etc/completion/upterm.bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ _upterm_host()

flags+=("--accept")
flags+=("--authorized-keys=")
flags+=("--codeberg-user=")
two_word_flags+=("--codeberg-user")
two_word_flags+=("--authorized-keys")
flags+=("--force-command=")
two_word_flags+=("--force-command")
Expand Down
4 changes: 4 additions & 0 deletions etc/man/man1/upterm-host.1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ private key. To authorize client connections, specify a authorized_key file with
\fB--authorized-keys\fP=""
Specify a authorize_keys file listing authorized public keys for connection.

.PP
\fB--codeberg-user\fP=[]
Authorize specified Codeberg users by allowing their public keys to connect.

.PP
\fB-f\fP, \fB--force-command\fP=""
Enforce a specified command for clients to join, and link the command's input/output to the client's terminal.
Expand Down
5 changes: 5 additions & 0 deletions host/authorizedkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

const (
codebergKeysUrlFmt = "https://codeberg.org/%s"
gitHubKeysUrlFmt = "https://github.com/%s"
gitLabKeysUrlFmt = "https://gitlab.com/%s"
sourceHutKeysUrlFmt = "https://meta.sr.ht/~%s"
Expand All @@ -34,6 +35,10 @@ func AuthorizedKeysFromFile(file string) (*AuthorizedKey, error) {
return parseAuthorizedKeys(authorizedKeysBytes, file)
}

func CodebergUserAuthorizedKeys(usernames []string) ([]*AuthorizedKey, error) {
return usersPublicKeys(codebergKeysUrlFmt, usernames)
}

func GitHubUserAuthorizedKeys(usernames []string, logger *logrus.Logger) ([]*AuthorizedKey, error) {
var (
authorizedKeys []*AuthorizedKey
Expand Down