forked from mtusi2026/mtusi2026lab7
feat: secure service connections and login
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/security/mtlsproxy"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
config := mtlsproxy.Config{
|
||||
ListenAddress: required("PROXY_LISTEN_ADDRESS"), TargetAddress: required("PROXY_TARGET_ADDRESS"),
|
||||
CAPath: required("PROXY_TLS_CA_PATH"), CertificatePath: required("PROXY_TLS_CERTIFICATE_PATH"),
|
||||
PrivateKeyPath: required("PROXY_TLS_PRIVATE_KEY_PATH"), AllowedClientURI: required("PROXY_ALLOWED_CLIENT_URI"),
|
||||
ALPNProtocols: strings.Split(required("PROXY_ALPN_PROTOCOLS"), ","),
|
||||
DialTimeout: 5 * time.Second,
|
||||
}
|
||||
if config.ListenAddress == "" || config.TargetAddress == "" || config.CAPath == "" ||
|
||||
config.CertificatePath == "" || config.PrivateKeyPath == "" || config.AllowedClientURI == "" ||
|
||||
len(config.ALPNProtocols) == 0 || config.ALPNProtocols[0] == "" {
|
||||
return errors.New("mTLS proxy environment is incomplete")
|
||||
}
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
return mtlsproxy.Run(ctx, config)
|
||||
}
|
||||
|
||||
func required(name string) string {
|
||||
return os.Getenv(name)
|
||||
}
|
||||
Reference in New Issue
Block a user