eliminated the username.
This commit is contained in:
		
							parent
							
								
									d134f1e944
								
							
						
					
					
						commit
						cd953c5edf
					
				| @ -300,7 +300,7 @@ func main() { | ||||
| 	defer wsConn.Close() | ||||
| 
 | ||||
| 	shell := chooseShell(shells) | ||||
| 	serverInfo, err := comms.AgentInitialization(wsConn, comms.NewAgentInfo(shell)) | ||||
| 	_, err = comms.AgentInitialization(wsConn, comms.NewAgentInfo(shell)) | ||||
| 	if err != nil { | ||||
| 		log.Printf("ERROR: %v", err) | ||||
| 		os.Exit(1) | ||||
| @ -352,10 +352,10 @@ func main() { | ||||
| 	log.Println() | ||||
| 	log.Printf("Clients should use the following commands to connect to this agent:") | ||||
| 	log.Println() | ||||
| 	sshCommand := fmt.Sprintf("ssh -oServerAliveInterval=10 -oProxyCommand=\"wsproxy %s\"  %s@localhost", | ||||
| 		clientUrl, serverInfo.UserPassword.Username) | ||||
| 	sftpCommand := fmt.Sprintf("sftp -oServerAliveInterval=10 -oProxyCommand=\"wsproxy %s\" %s@localhost", | ||||
| 		clientUrl, serverInfo.UserPassword.Username) | ||||
| 	sshCommand := fmt.Sprintf("ssh -oServerAliveInterval=10 -oProxyCommand=\"wsproxy %s\"  localhost", | ||||
| 		clientUrl) | ||||
| 	sftpCommand := fmt.Sprintf("sftp -oServerAliveInterval=10 -oProxyCommand=\"wsproxy %s\" localhost", | ||||
| 		clientUrl) | ||||
| 	log.Println("  # For SSH") | ||||
| 	log.Println("  " + sshCommand) | ||||
| 	log.Println() | ||||
|  | ||||
| @ -1,19 +1,16 @@ | ||||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"converge/pkg/comms" | ||||
| 	"converge/pkg/models" | ||||
| 	"converge/pkg/server/converge" | ||||
| 	"converge/pkg/support/websocketutil" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"math/rand" | ||||
| 	"net" | ||||
| 	"net/http" | ||||
| 	_ "net/http/pprof" | ||||
| 	"os" | ||||
| 	"regexp" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	_ "time/tzdata" | ||||
| ) | ||||
| @ -98,19 +95,6 @@ func main() { | ||||
| 		printHelp("") | ||||
| 	} | ||||
| 
 | ||||
| 	userPassword := comms.UserPassword{ | ||||
| 		Username: strconv.Itoa(rand.Int()), | ||||
| 	} | ||||
| 
 | ||||
| 	username, ok := os.LookupEnv("CONVERGE_USERNAME") | ||||
| 	if ok { | ||||
| 		userPassword.Username = username | ||||
| 	} else { | ||||
| 		os.Setenv("CONVERGE_USERNAME", userPassword.Username) | ||||
| 	} | ||||
| 
 | ||||
| 	log.Printf("Using username '%s'", userPassword.Username) | ||||
| 
 | ||||
| 	notifications := make(chan *models.State, 10) | ||||
| 	admin := converge.NewAdmin(notifications) | ||||
| 	websessions := converge.NewWebSessions(notifications) | ||||
| @ -124,8 +108,7 @@ func main() { | ||||
| 				return | ||||
| 			} | ||||
| 			log.Printf("Got registration connection: '%s'\n", publicId) | ||||
| 			err = admin.Register(publicId, conn, | ||||
| 				userPassword) | ||||
| 			err = admin.Register(publicId, conn) | ||||
| 			if err != nil { | ||||
| 				log.Printf("Error %v\n", err) | ||||
| 			} | ||||
|  | ||||
| @ -8,7 +8,7 @@ import ( | ||||
| 	"strings" | ||||
| ) | ||||
| 
 | ||||
| func getConvergeAccess(r *http.Request, sshRemoteUser string) models.ConvergeAccess { | ||||
| func getConvergeAccess(r *http.Request) models.ConvergeAccess { | ||||
| 
 | ||||
| 	pattern := regexp.MustCompile("^(.*)/usage$") | ||||
| 	matches := pattern.FindStringSubmatch(r.URL.Path) | ||||
| @ -41,6 +41,5 @@ func getConvergeAccess(r *http.Request, sshRemoteUser string) models.ConvergeAcc | ||||
| 		Secure:   secure, | ||||
| 		BaseUrl:  baseUrl, | ||||
| 		Location: location, | ||||
| 		Username: sshRemoteUser, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -6,8 +6,7 @@ import ( | ||||
| ) | ||||
| 
 | ||||
| func pageHandler(w http.ResponseWriter, r *http.Request) { | ||||
| 	username := getAgentSshUser() | ||||
| 	access := getConvergeAccess(r, username) | ||||
| 	access := getConvergeAccess(r) | ||||
| 
 | ||||
| 	switch r.URL.Path { | ||||
| 	case "": | ||||
|  | ||||
| @ -6,7 +6,6 @@ import ( | ||||
| 	"github.com/gliderlabs/ssh" | ||||
| 	"math/rand" | ||||
| 	"net/http" | ||||
| 	"os" | ||||
| 	"regexp" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| @ -37,7 +36,7 @@ func generateCLIExammple(w http.ResponseWriter, r *http.Request) { | ||||
| 			sshPublicKeys = append(sshPublicKeys, line) | ||||
| 		} | ||||
| 	} | ||||
| 	access := getConvergeAccess(r, getAgentSshUser()) | ||||
| 	access := getConvergeAccess(r) | ||||
| 
 | ||||
| 	usageInputs := templates.NewUsageInputs(id, sshPublicKeys, remoteShells, localShells) | ||||
| 	matched, _ := regexp.MatchString("^[a-zA-Z0-9-_]+$", id) | ||||
| @ -68,8 +67,3 @@ func generateCLIExammple(w http.ResponseWriter, r *http.Request) { | ||||
| 		http.Error(w, err.Error(), 500) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func getAgentSshUser() string { | ||||
| 	username, _ := os.LookupEnv("CONVERGE_USERNAME") | ||||
| 	return username | ||||
| } | ||||
|  | ||||
| @ -41,7 +41,6 @@ func main() { | ||||
| 		Secure:   "s", | ||||
| 		BaseUrl:  "example.com", | ||||
| 		Location: netherlands, | ||||
| 		Username: "converge", | ||||
| 	} | ||||
| 
 | ||||
| 	fullindex := func() templ.Component { | ||||
|  | ||||
| @ -7,6 +7,3 @@ services: | ||||
|       context: . | ||||
|     ports: | ||||
|       - 8000:8000 | ||||
|     environment: | ||||
|       CONVERGE_USERNAME: abc | ||||
|       TZ: "Japan" | ||||
|  | ||||
| @ -21,8 +21,5 @@ spec: | ||||
|         name: converge | ||||
|         ports: | ||||
|           - containerPort: 8000 | ||||
|         env: | ||||
|           - name: CONVERGE_USERNAME | ||||
|             value: converge | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -47,14 +47,9 @@ type ProtocolVersion struct { | ||||
| 	Version int | ||||
| } | ||||
| 
 | ||||
| type UserPassword struct { | ||||
| 	Username string | ||||
| } | ||||
| 
 | ||||
| // initialization mesaage when agent connects to server
 | ||||
| 
 | ||||
| type ServerInfo struct { | ||||
| 	UserPassword UserPassword | ||||
| } | ||||
| 
 | ||||
| // confirmation message when agent connects
 | ||||
| @ -106,9 +101,6 @@ func RegisterEventsWithGob() { | ||||
| 	// ConvergeServer to Agent and client
 | ||||
| 	gob.Register(ProtocolVersion{}) | ||||
| 
 | ||||
| 	// ConvergeServer to Agent
 | ||||
| 	gob.Register(UserPassword{}) | ||||
| 
 | ||||
| 	// ConvergeServer to Client
 | ||||
| 	gob.Register(ClientConnectionInfo{}) | ||||
| 
 | ||||
|  | ||||
| @ -7,5 +7,4 @@ type ConvergeAccess struct { | ||||
| 	Secure   string | ||||
| 	BaseUrl  string | ||||
| 	Location *time.Location | ||||
| 	Username string | ||||
| } | ||||
|  | ||||
| @ -266,12 +266,9 @@ func (admin *Admin) RemoveClient(client *ClientConnection) error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (admin *Admin) Register(publicId string, conn io.ReadWriteCloser, | ||||
| 	userPassword comms.UserPassword) error { | ||||
| func (admin *Admin) Register(publicId string, conn io.ReadWriteCloser) error { | ||||
| 
 | ||||
| 	serverInfo := comms.ServerInfo{ | ||||
| 		UserPassword: userPassword, | ||||
| 	} | ||||
| 	serverInfo := comms.ServerInfo{} | ||||
| 
 | ||||
| 	agentInfo, err := comms.ServerInitialization(conn, serverInfo) | ||||
| 	if err != nil { | ||||
|  | ||||
| @ -54,17 +54,14 @@ templ AgentUsage(access models.ConvergeAccess, usageInputs UsageInputs) { | ||||
| 
 | ||||
|     <h2>Connecting to the agent</h2> | ||||
| 
 | ||||
|     <p>The embedded ssh server in the agent supports both ssh and sftp. The user name is fixed | ||||
|        at <code>{ access.Username }</code>. This is the user used to connect to the embedded | ||||
|        SSH server, after logging in however you will be running in a shell that is started | ||||
|        by the same user that started the agent. | ||||
|     <p>The embedded ssh server in the agent supports both ssh and sftp. | ||||
|     </p> | ||||
| 
 | ||||
|      <code-sample id="ssh-connect"> | ||||
|           ssh -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{access.Secure}://{access.BaseUrl}/client/{usageInputs.Id}"  { access.Username }{"@localhost"} | ||||
|           ssh -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{access.Secure}://{access.BaseUrl}/client/{usageInputs.Id}"  {"localhost"} | ||||
|       </code-sample> | ||||
|       <code-sample id="sftp-connect"> | ||||
|           sftp -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{access.Secure}://{access.BaseUrl}/client/{usageInputs.Id}" { access.Username }{"@localhost"} | ||||
|           sftp -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{access.Secure}://{access.BaseUrl}/client/{usageInputs.Id}" {"localhost"} | ||||
|       </code-sample> | ||||
| 
 | ||||
| 
 | ||||
| @ -78,8 +75,8 @@ templ AgentUsage(access models.ConvergeAccess, usageInputs UsageInputs) { | ||||
|     way to connect. In this method, a local port forwarder is started that forwards a local port | ||||
|     to the webserver. Then you can start an ssh client that connects to the local tcp port. | ||||
|     </p> | ||||
|     <code-sample id="tcptows-ssh">ssh -oServerAliveInterval=10 -p 10000  { access.Username }{"@localhost"}</code-sample> | ||||
|     <code-sample id="tcptows-sftp">sftp -oServerAliveInterval=10 -p 10000 { access.Username }{"@localhost"}</code-sample> | ||||
|     <code-sample id="tcptows-ssh">ssh -oServerAliveInterval=10 -p 10000  {"localhost"}</code-sample> | ||||
|     <code-sample id="tcptows-sftp">sftp -oServerAliveInterval=10 -p 10000 {"localhost"}</code-sample> | ||||
| 
 | ||||
|     <p>This requires the <code>tcptows</code> utility which is available in the | ||||
|        <a href="downloads.html">downloads</a> section. The utility must be started beforehand | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user