this repo has no description smallweb.run
smallweb
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

automatically trust the ssh private key

pomdtr ce37cbe5 d618658e

+27 -7
+27 -4
cmd/up.go
··· 193 193 } 194 194 195 195 if flags.sshAddr != "" { 196 - sshPrivateKey := flags.sshPrivateKey 196 + sshPrivateKeyPath := flags.sshPrivateKey 197 197 if flags.sshPrivateKey == "" { 198 198 homeDir, err := os.UserHomeDir() 199 199 if err != nil { ··· 202 202 203 203 for _, keyType := range []string{"id_rsa", "id_ed25519"} { 204 204 if _, err := os.Stat(filepath.Join(homeDir, ".ssh", keyType)); err == nil { 205 - sshPrivateKey = filepath.Join(homeDir, ".ssh", keyType) 205 + sshPrivateKeyPath = filepath.Join(homeDir, ".ssh", keyType) 206 206 break 207 207 } 208 208 } 209 209 } 210 210 211 + if sshPrivateKeyPath == "" { 212 + return fmt.Errorf("ssh private key not found") 213 + } 214 + 215 + privateKeyBytes, err := os.ReadFile(sshPrivateKeyPath) 216 + if err != nil { 217 + return fmt.Errorf("failed to read private key: %v", err) 218 + } 219 + 220 + privateKey, err := gossh.ParseRawPrivateKey(privateKeyBytes) 221 + if err != nil { 222 + fmt.Fprintf(os.Stderr, "Failed to parse private key: %v\n", err) 223 + os.Exit(1) 224 + } 225 + 226 + signer, err := gossh.NewSignerFromKey(privateKey) 227 + if err != nil { 228 + fmt.Fprintf(os.Stderr, "Failed to create signer: %v\n", err) 229 + os.Exit(1) 230 + } 231 + 232 + authorizedKey := string(gossh.MarshalAuthorizedKey(signer.PublicKey())) 211 233 srv, err := wish.NewServer( 212 234 wish.WithAddress(flags.sshAddr), 213 - wish.WithHostKeyPath(sshPrivateKey), 235 + wish.WithHostKeyPath(sshPrivateKeyPath), 214 236 wish.WithPublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool { 215 - authorizedKeys := k.Strings("authorizedKeys") 237 + authorizedKeys := []string{authorizedKey} 238 + authorizedKeys = append(authorizedKeys, k.Strings("authorizedKeys")...) 216 239 if ctx.User() != "_" { 217 240 authorizedKeys = append(authorizedKeys, k.Strings(fmt.Sprintf("apps.%s.authorizedKeys", ctx.User()))...) 218 241 }
-3
workspace/.smallweb/config.json
··· 2 2 "$schema": "../../schemas/config.schema.json", 3 3 "domain": "smallweb.localhost", 4 4 "openauth.issuer": "https://auth.smallweb.localhost", 5 - "authorizedKeys": [ 6 - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJW+GQk0KCvSreL+y3AZdtCu82+13E2eEled+sGRkIEv" 7 - ], 8 5 "apps": { 9 6 "ls": { 10 7 "admin": true,