Skip to content

Commit 538de40

Browse files
authored
Merge pull request #39 from persys-dev/Feat/Persys-gateway-routes
Feat/persys gateway routes
2 parents 96352e7 + 8c64cba commit 538de40

17 files changed

Lines changed: 2442 additions & 202 deletions

persys-automation/internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Load() (*Config, error) {
8080
),
8181
VaultPKIMount: envOr("AUTOMATION_VAULT_PKI_MOUNT", "pki"),
8282
VaultPKIRole: envOr("AUTOMATION_VAULT_PKI_ROLE", "persys-automation"),
83-
VaultCertTTL: envDurationOr("AUTOMATION_VAULT_CERT_TTL", 1*time.Hour),
83+
VaultCertTTL: envDurationOr("AUTOMATION_VAULT_CERT_TTL", 24*time.Hour),
8484
VaultServiceName: envOr("AUTOMATION_VAULT_SERVICE_NAME", "persys-automation"),
8585
VaultServiceDomain: strings.TrimSpace(os.Getenv("AUTOMATION_VAULT_SERVICE_DOMAIN")),
8686
VaultRetryInterval: envDurationOr("AUTOMATION_VAULT_RETRY_INTERVAL", 30*time.Second),

persys-gateway/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ mTLS API:
111111
- `GET /clusters/:cluster_id/workloads`
112112
- `GET /clusters/:cluster_id/nodes`
113113
- `GET /clusters/:cluster_id/cluster/metrics`
114+
- `GET/POST /clusters/:cluster_id/disks` — standalone block disks (AgentControl)
115+
- `GET/DELETE /clusters/:cluster_id/disks/:id`
116+
- `GET/POST /clusters/:cluster_id/buckets` — object storage (RGW via scheduler)
117+
- `GET/DELETE /clusters/:cluster_id/buckets/:id`
118+
- `GET /clusters/:cluster_id/buckets/:id/access` — Vault-backed S3 credentials
119+
- `GET /clusters/:cluster_id/buckets/:id/objects` — list objects (prefix/pagination)
114120
- `POST /clusters/:cluster_id/forgery/projects/upsert`
115121
- `POST /clusters/:cluster_id/forgery/builds/trigger`
116122
- `POST /clusters/:cluster_id/forgery/webhooks/test`

persys-gateway/cmd/main.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"crypto/tls"
66
"crypto/x509"
7-
"fmt"
87
"log"
98
"net/http"
109
"net/http/pprof"
@@ -171,19 +170,28 @@ func main() {
171170

172171
app.authService = services.NewAuthService(app.db, ctx, jwtSecret)
173172
app.githubService = services.NewGithubService(cnf, webhookTLS)
173+
if gs, ok := app.githubService.(interface{ SetCertManager(*certmanager.Manager) }); ok {
174+
gs.SetCertManager(vaultCertManager)
175+
}
174176
app.clusterControl = services.NewClusterControlService(cnf)
177+
app.clusterControl.SetCertManager(vaultCertManager)
175178
app.clusterControl.Start(ctx)
176179
app.forgeryService = services.NewForgeryService(cnf, webhookTLS)
180+
app.forgeryService.SetCertManager(vaultCertManager)
177181
app.webhookService, err = services.NewWebhookService(cnf, webhookTLS, app.db)
178182
if err != nil {
179183
log.Fatalf("failed to initialize webhook service: %v", err)
180184
}
185+
if ws, ok := app.webhookService.(interface{ SetCertManager(*certmanager.Manager) }); ok {
186+
ws.SetCertManager(vaultCertManager)
187+
}
181188
app.webhookService.Start(ctx)
182189

183190
app.automationService, err = services.NewAutomationService(cnf, webhookTLS)
184191
if err != nil {
185192
log.Fatalf("failed to initialize automation service: %v", err)
186193
}
194+
app.automationService.SetCertManager(vaultCertManager)
187195

188196
app.authController = controllers.NewAuthController(
189197
app.authService, ctx, app.githubService, app.db,
@@ -207,12 +215,12 @@ func main() {
207215
mtlsRouter := gin.New()
208216
nonMTLSRouter := gin.New()
209217

210-
mtlsRouter.Use(gin.Logger())
218+
mtlsRouter.Use(middleware.AccessLogger())
211219
mtlsRouter.Use(cors.New(corsConfig))
212220
mtlsRouter.Use(gootelgin.Middleware("persys-gateway-mtls"))
213221
mtlsRouter.Use(middleware.ServiceIdentityHeader("persys-gateway"))
214222

215-
nonMTLSRouter.Use(gin.Logger())
223+
nonMTLSRouter.Use(middleware.AccessLogger())
216224
nonMTLSRouter.Use(cors.New(corsConfig))
217225
nonMTLSRouter.Use(gootelgin.Middleware("persys-gateway-public"))
218226
nonMTLSRouter.Use(middleware.ServiceIdentityHeader("persys-gateway"))
@@ -318,7 +326,6 @@ func main() {
318326
automationGroup.Use(gwRouter.Resolve(catalog.AuthUser))
319327
automationRouteController := routes.NewAutomationRouteController(app.automationController)
320328
automationRouteController.AutomationRoute(automationGroup)
321-
322329
// Webhook stays unauthenticated at the gateway level by design — its
323330
// own HMAC signature verification (X-Hub-Signature-256) IS its auth
324331
// mechanism, checked inside webhook.service.go. Mounted on the
@@ -359,14 +366,27 @@ func main() {
359366
mtlsServer := &http.Server{Addr: cnf.App.HTTPAddr, Handler: mtlsRouter, TLSConfig: tlsConfig}
360367
nonMTLSServer := &http.Server{Addr: cnf.App.HTTPAddrPublic, Handler: nonMTLSRouter}
361368

369+
// goroutine, heap, allocs, block, mutex, threadcreate are served via pprof.Index
370+
// through /debug/pprof/{profile-name} automatically once Index is registered
362371
debugMux := http.NewServeMux()
363372
debugMux.HandleFunc("/debug/pprof/", pprof.Index)
364373
debugMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
365374
debugMux.HandleFunc("/debug/pprof/profile", pprof.Profile)
366375
debugMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
376+
367377
debugMux.HandleFunc("/debug/pprof/trace", pprof.Trace)
368-
// goroutine, heap, allocs, block, mutex, threadcreate are served via pprof.Index
369-
// through /debug/pprof/{profile-name} automatically once Index is registered
378+
// debugMux.HandleFunc("/debug/force-rotate", func(w http.ResponseWriter, r *http.Request) {
379+
// if r.Method != http.MethodPost {
380+
// http.Error(w, "POST only", http.StatusMethodNotAllowed)
381+
// return
382+
// }
383+
// if err := vaultCertManager.ForceRotate(r.Context()); err != nil {
384+
// http.Error(w, err.Error(), http.StatusInternalServerError)
385+
// return
386+
// }
387+
// w.Header().Set("Content-Type", "application/json")
388+
// _, _ = w.Write([]byte(`{"status":"rotated"}`))
389+
// })
370390

371391
debugServer := &http.Server{
372392
Addr: "0.0.0.0:6060",
@@ -414,17 +434,6 @@ func main() {
414434
}
415435

416436
func buildMTLSClientConfig(cnf *config.Config) (*tls.Config, error) {
417-
cert, err := tls.LoadX509KeyPair(cnf.TLS.CertPath, cnf.TLS.KeyPath)
418-
if err != nil {
419-
return nil, err
420-
}
421-
caCert, err := os.ReadFile(cnf.TLS.CAPath)
422-
if err != nil {
423-
return nil, err
424-
}
425-
caPool := x509.NewCertPool()
426-
if !caPool.AppendCertsFromPEM(caCert) {
427-
return nil, fmt.Errorf("invalid CA bundle")
428-
}
429-
return &tls.Config{Certificates: []tls.Certificate{cert}, RootCAs: caPool}, nil
437+
// Live config: GetClientCertificate reloads from disk after certmanager rotates.
438+
return services.LiveClientTLSConfig(cnf.TLS.CertPath, cnf.TLS.KeyPath, cnf.TLS.CAPath)
430439
}

persys-gateway/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (c *Config) applyDefaults() {
343343
c.Vault.ManagerAddr = "vault-manager:50069"
344344
}
345345
if c.Vault.CertTTL == time.Duration(0) {
346-
c.Vault.CertTTL = 1 * time.Hour
346+
c.Vault.CertTTL = 24 * time.Hour
347347
}
348348
if c.Vault.RetryInterval == time.Duration(0) {
349349
c.Vault.RetryInterval = 30 * time.Second

0 commit comments

Comments
 (0)