Change:
<!-- Please only use this template for submitting enhancement requests --What would you like to be : The image used in E2E tests is used for testing a wide variety of OS-agnostic features. One of these is , which runs an HTTP server with various endpoints that can be used to validate things like request/response. It would be useful to allow for 's functionality to also support HTTPS so all of that logic can be tested for TLS-based traffic. Currently, can be run like: I'm proposing something along the lines of: The default certificate/private key being basically identical to what provides. Why is this needed: One use case is where the intent is to add HTTPS functionality to lifecycle hooks (postStart/preStop). There is currently no easy way to test this logic because the container which receives the HTTPS request (in this case, ) does not support HTTPS traffic.
There are no sig labels on this issue. Please add an appropriate label by using one of the following commands: - Please see the for a listing of the SIGs, working groups, and committees available. <detailsInstructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/sig testing

Discussion:
### netexec <del> Starts a HTTP server on given port with the following endpoints: </del> <ins> Starts a HTTP(S) server on given port with the following endpoints: </ins> - `/`: Returns the request's timestamp. - `/clientip`: Returns the request's IP address.

Returns a JSON with the fields `output` (containing the file's name on the server) and `error` containing any potential server side errors. <ins> If `--tls-cert-file` is added (ideally in conjunction with `--tls-private-key-file`, the HTTP server will be upgraded to HTTPS. The image has default, `localhost`-based cert/privkey files at `/localhost.crt` and `/localhost.key` (see: [`porter` subcommand](#porter)) </ins> It will also start a UDP server on the indicated UDP port that responds to the following commands: - `hostname`: Returns the server's hostname

Usage: ```console <del> kubectl exec test-agnhost -- /agnhost netexec [--http-port <http-port>] [--udp-port <udp-port>] [--sctp-port <sctp-port>] </del> <ins> kubectl exec test-agnhost -- /agnhost netexec [--http-port <http-port>] [--udp-port <udp-port>] [--sctp-port <sctp-port>] [--tls-cert-file <cert-file>] [--tls-private-key-file <privkey-file>] </ins> ``` ### nettest

<del> 2.14 </del> <ins> 2.15 </ins>

) func main() { <del> rootCmd := &cobra.Command{Use: "app", Version: "2.14"} </del> <ins> rootCmd := &cobra.Command{Use: "app", Version: "2.15"} </ins> rootCmd.AddCommand(auditproxy.CmdAuditProxy) rootCmd.AddCommand(connect.CmdConnect)

sctpPort    = -1 shellPath   = "/bin/sh" serverReady = &atomicBool{0} <ins> certFile    = "" privKeyFile = "" </ins> ) // CmdNetexec is used by agnhost Cobra. var CmdNetexec = &cobra.Command{ Use:   "netexec", <del> Short: "Creates HTTP, UDP, and (optionally) SCTP servers with various endpoints", Long: `Starts a HTTP server on given port with the following endpoints: </del> <ins> Short: "Creates HTTP(S), UDP, and (optionally) SCTP servers with various endpoints", Long: `Starts a HTTP(S) server on given port with the following endpoints: </ins> - /: Returns the request's timestamp. - /clientip: Returns the request's IP address.

func init() { CmdNetexec.Flags().IntVar(&httpPort, "http-port", 8080, "HTTP Listen Port") <ins> CmdNetexec.Flags().StringVar(&certFile, "tls-cert-file", "", "File containing an x509 certificate for HTTPS. (CA cert, if any, concatenated after server cert)") CmdNetexec.Flags().StringVar(&privKeyFile, "tls-private-key-file", "", "File containing an x509 private key matching --tls-cert-file") </ins> CmdNetexec.Flags().IntVar(&udpPort, "udp-port", 8081, "UDP Listen Port") CmdNetexec.Flags().IntVar(&sctpPort, "sctp-port", -1, "SCTP Listen Port") }

if sctpPort != -1 { go startSCTPServer(sctpPort) } <del> startHTTPServer(httpPort) </del> <ins> addRoutes() if len(certFile) > 0 { // only start HTTPS server if a cert is provided startHTTPSServer(httpPort, certFile, privKeyFile) } else { startHTTPServer(httpPort) } </ins> } <del> func startHTTPServer(httpPort int) { </del> <ins> func addRoutes() { </ins> http.HandleFunc("/", rootHandler) http.HandleFunc("/clientip", clientIPHandler) http.HandleFunc("/echo", echoHandler)

// older handlers http.HandleFunc("/hostName", hostNameHandler) http.HandleFunc("/shutdown", shutdownHandler) <ins> } func startHTTPSServer(httpsPort int, certFile, privKeyFile string) { log.Fatal(http.ListenAndServeTLS(fmt.Sprintf(":%d", httpPort), certFile, privKeyFile, nil)) } func startHTTPServer(httpPort int) { </ins> log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", httpPort), nil)) }