fix: mtls for agent, problems with auth

This commit is contained in:
d3m0k1d
2026-04-04 05:44:11 +03:00
parent f1fc52bd6b
commit ad92439770
5 changed files with 38 additions and 6 deletions
+13 -3
View File
@@ -51,15 +51,25 @@ func main() {
log.Println("Agent registration complete")
err = func() error {
creds, err := mtls.LoadMTLSCredentials(certs.CACertPEM, certs.ClientCertPEM, certs.ClientKeyPEM)
creds, err := mtls.LoadMTLSCredentialsFromFiles(
cfg.CertDir+"/ca.crt",
cfg.CertDir+"/client.crt",
cfg.CertDir+"/client.key",
)
if err != nil {
return err
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cmdexe := new(commander.CommandExecutor)
ccli := client.New(cmdexe, cfg.RegistrationToken, cfg.Label)
return ccli.HandleCommands(ctx, cfg.BackendURL, creds)
ccli := client.New(cmdexe, cfg.Label, cfg.Label)
grpcAddr := cfg.GRPCURL
if grpcAddr == "" {
grpcAddr = cfg.BackendURL
}
grpcAddr = strings.TrimPrefix(grpcAddr, "http://")
grpcAddr = strings.TrimPrefix(grpcAddr, "https://")
return ccli.HandleCommands(ctx, grpcAddr, creds)
}()
if err != nil {
log.Fatalf("Failed to generate key and CSR: %v", err)