Skip to content

Commit

Permalink
feat: check for syringe client version
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Jul 17, 2024
1 parent 4c64cb5 commit 7783854
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ Secrets can be managed using 'projects' and 'environments'.

### P1

- [ ] Genericise storage solution so whole thing can self-hosted and backed by sqlite databases
- [ ] Build and publish artifact on GitHub
- [ ] Build and publish deployable Docker image for server
- [ ] Install script that downloads cli binary into path.
- [ ] E2E tests with the CLI (or SSH?) client, including a couple like trying to create secrets for a non-existent project or environmnet
- Work out how to start/stop server asynchronously and run tests. Could be containerised using testcontainers?
- Just use testcontainers??
- [ ] Genericise storage solution so whole thing can self-hosted and backed by sqlite databases
- [ ] Build and publish deployable Docker image for server

### P2

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package config

const Version = "0.0.3"
const Client = "SSH-2.0-Syringe"
12 changes: 11 additions & 1 deletion internal/middleware/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package middleware

import (
"fmt"

"github.com/charmbracelet/ssh"
"github.com/nixpig/syringe.sh/config"
"github.com/nixpig/syringe.sh/internal/auth"
"github.com/nixpig/syringe.sh/pkg/ctxkeys"
"github.com/rs/zerolog"
Expand All @@ -13,14 +16,21 @@ func NewMiddlewareAuth(
) func(next ssh.Handler) ssh.Handler {
return func(next ssh.Handler) ssh.Handler {
return func(sess ssh.Session) {
clientVersion := sess.Context().ClientVersion()

if clientVersion != config.Client {
logger.Warn().Str("clientVersion", clientVersion).Msg("invalid client")
sess.Stderr().Write([]byte(fmt.Sprintf("Unsupported client %s.\nPlease use the syringe CLI, available at: \n https://github.com/nixpig/syringe.sh\n", clientVersion)))
return
}
user, err := authService.AuthenticateUser(auth.AuthenticateUserRequest{
Username: sess.User(),
PublicKey: sess.PublicKey(),
})
if err != nil {
logger.Warn().Msg("user not authenticated")

sess.Write([]byte("Public key not recognised.\n"))
sess.Stderr().Write([]byte("Public key not recognised.\n"))

return
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/ssh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"os"

"github.com/nixpig/syringe.sh/config"
"github.com/skeema/knownhosts"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
Expand Down Expand Up @@ -54,8 +55,9 @@ func NewSSHClient(
knownHosts string,
) (*SSHClient, error) {
sshConfig := &gossh.ClientConfig{
User: username,
Auth: []gossh.AuthMethod{authMethod},
User: username,
ClientVersion: config.Client,
Auth: []gossh.AuthMethod{authMethod},

HostKeyCallback: gossh.HostKeyCallback(
func(hostname string, remote net.Addr, key gossh.PublicKey) error {
Expand Down

0 comments on commit 7783854

Please sign in to comment.