This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch signer-hardening in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 95a654709e41df0e5416de9f24022c08480a7964 Author: lahiruj <[email protected]> AuthorDate: Sun Nov 8 14:38:04 2026 -0500 Drop the CA rotation route --- extensions/SSH-Certificate-Signer/README.md | 11 +-- .../SSH-Certificate-Signer/config.example.yaml | 2 +- .../internal/config/config.go | 9 +++ .../internal/handler/admin.go | 85 ---------------------- .../internal/server/routes.go | 2 - .../internal/vault/client.go | 57 --------------- extensions/SSH-Certificate-Signer/main.go | 7 +- 7 files changed, 16 insertions(+), 157 deletions(-) diff --git a/extensions/SSH-Certificate-Signer/README.md b/extensions/SSH-Certificate-Signer/README.md index b72d1974c..d7b582709 100644 --- a/extensions/SSH-Certificate-Signer/README.md +++ b/extensions/SSH-Certificate-Signer/README.md @@ -40,7 +40,7 @@ SSH public key and the principal. The principal is the Unix username the certifi | `principal_validator` | Principal check | |---|---| -| `noop` | Accepts the principal | +| `noop` | Accepts the principal. Allowed only in dev mode; the signer refuses to start with it otherwise. | | `ldap` | Finds the LDAP entry for the OIDC subject and requires the principal to equal its `username_attribute`. Credentials are in Vault. | | `comanage` | Not implemented. Rejects every request with `COMANAGE_NOT_IMPLEMENTED`. | @@ -225,7 +225,6 @@ The service handles SIGTERM and SIGINT for graceful shutdown: | `POST` | `/api/v1/revoke` | Client credentials | Revoke a certificate by `serial_number`, `key_id` or `ca_fingerprint` | | `GET` | `/api/v1/jwks` | Client credentials | CA public keys as JWKs | | `GET` | `/api/v1/ca-public-key` | Client credentials | CA public key | -| `POST` | `/api/v1/admin/rotate-ca` | Client credentials | Rotate the CA keys | | `GET` | `/api/v1/certificates` | OIDC Bearer | Certificates of the signed-in user | | `GET` | `/api/v1/certificates/{serial}` | OIDC Bearer | One certificate | | `POST` | `/api/v1/certificates/{serial}/revoke` | OIDC Bearer | Revoke an owned active certificate, or any active certificate with `signer:certificates:write` | @@ -297,14 +296,6 @@ curl -s http://localhost:8084/api/v1/jwks \ -H "X-Client-Secret: your-secret" | jq . ``` -**Rotate CA Keys** - -```bash -curl -s -X POST http://localhost:8084/api/v1/admin/rotate-ca \ - -H "X-Client-Id: webapp" \ - -H "X-Client-Secret: your-secret" | jq . -``` - ## Troubleshooting | Error | Cause | Fix | diff --git a/extensions/SSH-Certificate-Signer/config.example.yaml b/extensions/SSH-Certificate-Signer/config.example.yaml index 1185672e5..5b72378e8 100644 --- a/extensions/SSH-Certificate-Signer/config.example.yaml +++ b/extensions/SSH-Certificate-Signer/config.example.yaml @@ -59,7 +59,7 @@ signer: jwks_max_providers: 10 timeout_seconds: 10 validation: - principal_validator: noop # "noop", "ldap", or "comanage" + principal_validator: ldap # "ldap" or "comanage"; "noop" only with dev_mode cache_ttl_seconds: 300 # Vault credential cache TTL for validators dev_mode: diff --git a/extensions/SSH-Certificate-Signer/internal/config/config.go b/extensions/SSH-Certificate-Signer/internal/config/config.go index 77db2b2aa..d92eb9a74 100644 --- a/extensions/SSH-Certificate-Signer/internal/config/config.go +++ b/extensions/SSH-Certificate-Signer/internal/config/config.go @@ -17,6 +17,7 @@ package config import ( + "fmt" "os" "strconv" "strings" @@ -207,6 +208,14 @@ func Load(path string) (*Config, error) { return cfg, nil } +// Validate refuses the noop principal validator outside dev mode. +func (c *Config) Validate() error { + if v := c.Signer.Validation.PrincipalValidator; (v == "" || v == "noop") && !c.DevMode.Enabled { + return fmt.Errorf("principal_validator %q is allowed only in dev mode", v) + } + return nil +} + func applyEnvOverrides(cfg *Config) { if v := os.Getenv("DB_HOST"); v != "" { cfg.Database.Host = v diff --git a/extensions/SSH-Certificate-Signer/internal/handler/admin.go b/extensions/SSH-Certificate-Signer/internal/handler/admin.go deleted file mode 100644 index 0b6855450..000000000 --- a/extensions/SSH-Certificate-Signer/internal/handler/admin.go +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package handler - -import ( - "encoding/json" - "log/slog" - "net/http" - "time" - - "github.com/apache/airavata-custos/signer/internal/cert" - "github.com/apache/airavata-custos/signer/internal/httputil" - vaultpkg "github.com/apache/airavata-custos/signer/internal/vault" -) - -type RotateCAResponse struct { - Success bool `json:"success"` - CurrentCAFingerprint string `json:"current_ca_fingerprint"` - NextCAFingerprint string `json:"next_ca_fingerprint"` - RotationTimestamp int64 `json:"rotation_timestamp"` -} - -type AdminHandler struct { - vaultClient *vaultpkg.Client - logger *slog.Logger -} - -func NewAdminHandler(vaultClient *vaultpkg.Client, logger *slog.Logger) *AdminHandler { - return &AdminHandler{ - vaultClient: vaultClient, - logger: logger, - } -} - -func (h *AdminHandler) Handle(w http.ResponseWriter, r *http.Request) { - clientCfg := httputil.ClientConfigFromContext(r.Context()) - if clientCfg == nil { - writeError(w, http.StatusInternalServerError, "internal_error", "Missing client config") - return - } - - _, _, err := h.vaultClient.RotateCA(r.Context()) - if err != nil { - h.logger.Error("failed to rotate CA", "error", err) - writeError(w, http.StatusInternalServerError, "internal_error", "Failed to rotate CA keys") - return - } - - currentKey, err := h.vaultClient.GetCurrentCAKey(r.Context()) - if err != nil { - writeError(w, http.StatusInternalServerError, "internal_error", "Failed to read rotated keys") - return - } - currentFP, _ := cert.CAFingerprint(currentKey.PublicKey) - - nextKey, err := h.vaultClient.GetNextCAKey(r.Context()) - nextFP := "" - if err == nil && nextKey != nil { - nextFP, _ = cert.CAFingerprint(nextKey.PublicKey) - } - - resp := RotateCAResponse{ - Success: true, - CurrentCAFingerprint: currentFP, - NextCAFingerprint: nextFP, - RotationTimestamp: time.Now().UTC().Unix(), - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(resp) -} diff --git a/extensions/SSH-Certificate-Signer/internal/server/routes.go b/extensions/SSH-Certificate-Signer/internal/server/routes.go index ddc4f0064..b7678573e 100644 --- a/extensions/SSH-Certificate-Signer/internal/server/routes.go +++ b/extensions/SSH-Certificate-Signer/internal/server/routes.go @@ -31,7 +31,6 @@ type Handlers struct { JWKS http.HandlerFunc CAPublicKey http.HandlerFunc Health http.HandlerFunc - Admin http.HandlerFunc Certificates http.HandlerFunc CertificateDetail http.HandlerFunc CertificateRevoke http.HandlerFunc @@ -72,7 +71,6 @@ func NewRouter( r.Post("/api/v1/revoke", handlers.Revoke) r.Get("/api/v1/jwks", handlers.JWKS) r.Get("/api/v1/ca-public-key", handlers.CAPublicKey) - r.Post("/api/v1/admin/rotate-ca", handlers.Admin) }) // User-authenticated routes (OIDC Bearer token) diff --git a/extensions/SSH-Certificate-Signer/internal/vault/client.go b/extensions/SSH-Certificate-Signer/internal/vault/client.go index 6fa9aba6e..611216f73 100644 --- a/extensions/SSH-Certificate-Signer/internal/vault/client.go +++ b/extensions/SSH-Certificate-Signer/internal/vault/client.go @@ -162,63 +162,6 @@ func (c *Client) IncrementSerialCounter(ctx context.Context) (int64, error) { return newSerial, nil } -// RotateCA promotes next to current and generates a new next key. -func (c *Client) RotateCA(ctx context.Context) (currentFP, nextFP string, err error) { - nextKey, err := c.readCAKey(ctx, "next") - if err != nil { - return "", "", err - } - - if nextKey != nil { - // Promote next to current - if err := c.writeCAKey(ctx, "current", nextKey); err != nil { - return "", "", err - } - } else { - // Generate fresh current - newCurrent, err := generateEd25519CAKey() - if err != nil { - return "", "", err - } - if err := c.writeCAKey(ctx, "current", newCurrent); err != nil { - return "", "", err - } - } - - // Generate new next key - newNext, err := generateEd25519CAKey() - if err != nil { - return "", "", err - } - if err := c.writeCAKey(ctx, "next", newNext); err != nil { - return "", "", err - } - - now := time.Now().UTC() - meta, err := c.readMetadata(ctx) - if err != nil { - return "", "", err - } - if meta == nil { - meta = &CAMetadata{SerialCounter: 0} - } - meta.LastRotationAt = now.Format(time.RFC3339) - meta.NextRotationAt = now.Add(time.Duration(c.rotationCfg.PeriodHours) * time.Hour).Format(time.RFC3339) - meta.RotationPeriodH = c.rotationCfg.PeriodHours - meta.OverlapHours = c.rotationCfg.OverlapHours - if err := c.writeMetadata(ctx, meta); err != nil { - return "", "", err - } - - // Read back keys to get fingerprints - currentKey, err := c.readCAKey(ctx, "current") - if err != nil { - return "", "", err - } - - return string(currentKey.PublicKey), string(newNext.PublicKey), nil -} - func (c *Client) GetMetadata(ctx context.Context) (*CAMetadata, error) { return c.readMetadata(ctx) } diff --git a/extensions/SSH-Certificate-Signer/main.go b/extensions/SSH-Certificate-Signer/main.go index 081160846..c46ca2d9f 100644 --- a/extensions/SSH-Certificate-Signer/main.go +++ b/extensions/SSH-Certificate-Signer/main.go @@ -129,6 +129,11 @@ func runMigrate(cfg *config.Config, logger *slog.Logger) { } func runServer(cfg *config.Config, logger *slog.Logger, autoMigrate bool) { + if err := cfg.Validate(); err != nil { + logger.Error("invalid configuration", "error", err) + os.Exit(1) + } + db, err := store.NewDB(cfg.Database) if err != nil { logger.Error("failed to connect to database", "error", err) @@ -179,7 +184,6 @@ func runServer(cfg *config.Config, logger *slog.Logger, autoMigrate bool) { jwksHandler := handler.NewJWKSHandler(vaultClient, logger) caPublicKeyHandler := handler.NewCAPublicKeyHandler(vaultClient, logger) healthHandler := handler.NewHealthHandler(db, vaultClient) - adminHandler := handler.NewAdminHandler(vaultClient, logger) certificatesHandler := handler.NewCertificatesHandler(db, logger).WithRevocation(coreAuthorizer, revocationService) userInfoHandler := handler.NewUserInfoHandler() @@ -189,7 +193,6 @@ func runServer(cfg *config.Config, logger *slog.Logger, autoMigrate bool) { JWKS: jwksHandler.Handle, CAPublicKey: caPublicKeyHandler.Handle, Health: healthHandler.Handle, - Admin: adminHandler.Handle, Certificates: certificatesHandler.HandleList, CertificateDetail: certificatesHandler.HandleGet, CertificateRevoke: certificatesHandler.HandleRevoke,
