This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch signer-connector in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit eeceb5af5980cad882a7186bb62bf30aa2f140d4 Author: lahiruj <[email protected]> AuthorDate: Sun Nov 8 16:47:08 2026 -0500 Signer connector implementation --- .env.example | 5 + config/custos.yaml | 6 + connectors/Signer/README.md | 50 +++++++ connectors/Signer/internal/handlers.go | 127 ++++++++++++++++++ connectors/Signer/internal/handlers_test.go | 146 +++++++++++++++++++++ connectors/Signer/internal/privileges.go | 30 +++++ .../Signer/internal/privileges_integration_test.go | 89 +++++++++++++ connectors/Signer/pkg/signer/loader.go | 56 ++++++++ docs/architecture.md | 1 + docs/privileges.md | 13 +- extensions/SSH-Certificate-Signer/README.md | 4 +- internal/connectors/loader.go | 2 + 12 files changed, 524 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index da7b15299..cfa8fdfb9 100644 --- a/.env.example +++ b/.env.example @@ -98,3 +98,8 @@ EMAIL_PORTAL_URL= EMAIL_CLUSTER_HOST= EMAIL_LOGO_URL= EMAIL_TEMPLATES_DIR= + +# --- SSH certificate signer connector -------------------------------------- + +# Leave SIGNER_BASE_URL empty to run without the signer routes. +SIGNER_BASE_URL= diff --git a/config/custos.yaml b/config/custos.yaml index 8ff4a2795..0af8bb9dc 100644 --- a/config/custos.yaml +++ b/config/custos.yaml @@ -216,3 +216,9 @@ connectors: logo_url: "${EMAIL_LOGO_URL}" # Optional. A directory with custom email templates. templates_dir: "${EMAIL_TEMPLATES_DIR}" + + signer: + type: "signer" + enabled: true + base_url: "${SIGNER_BASE_URL}" + timeout_seconds: 10 diff --git a/connectors/Signer/README.md b/connectors/Signer/README.md new file mode 100644 index 000000000..5a1d31dec --- /dev/null +++ b/connectors/Signer/README.md @@ -0,0 +1,50 @@ +<!-- + 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. +--> + +# Signer + +The Signer connector puts the [SSH certificate signer](../../extensions/SSH-Certificate-Signer/README.md) behind the +Custos server. It registers the `signer:` privileges and forwards the certificate routes to the signer with the caller's +own token, so the signer applies its owner and privilege checks to the real user. + +## Routes + +| Route | Needs | Forwards to | +|--------------------------------------------------------|-----------------------------|-------------------------------------------------------------------| +| `GET /connectors/signer/certificates` | `signer:certificates:read` | `GET /api/v1/admin/certificates` | +| `GET /connectors/signer/certificates/{serial}` | `signer:certificates:read` | `GET /api/v1/admin/certificates/{serial}` | +| `POST /connectors/signer/certificates/{serial}/revoke` | `signer:certificates:write` | `POST /api/v1/certificates/{serial}/revoke` | +| `GET /connectors/signer/me/certificates` | Signed in | `GET /api/v1/certificates` | +| `GET /connectors/signer/me/certificates/{serial}` | Signed in | `GET /api/v1/certificates/{serial}` | +| `GET /connectors/signer/status` | `signer:certificates:read` | Reports whether the signer answers its health route, and how fast | + +Query strings, request bodies and the signer's response pass through unchanged. The certificate list is keyset-paged: +pass `limit` and the last `next_cursor` as `cursor`. A signer that cannot be reached returns 502. + +## Configuration + +Settings are in the `connectors.signer` block of [`config/custos.yaml`](../../config/custos.yaml). With an empty +`base_url` the connector skips loading and reports the gap on `GET /connectors`. + +| Key | Variable in `config/custos.yaml` | Required | Purpose | +|-------------------|----------------------------------|----------|-------------------------------| +| `base_url` | `SIGNER_BASE_URL` | yes | The signer's URL | +| `timeout_seconds` | | no | Request timeout, default `10` | + +The connector holds no signer client credentials. Those stay with the applications that call `POST /api/v1/sign`. diff --git a/connectors/Signer/internal/handlers.go b/connectors/Signer/internal/handlers.go new file mode 100644 index 000000000..5c765f59c --- /dev/null +++ b/connectors/Signer/internal/handlers.go @@ -0,0 +1,127 @@ +// 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 internal + +import ( + "context" + "errors" + "fmt" + "io" + "log/slog" + "net/http" + "net/url" + "strings" + "time" + + "github.com/apache/airavata-custos/internal/connectors/health" + "github.com/apache/airavata-custos/pkg/common" + "github.com/apache/airavata-custos/pkg/identity" +) + +const Type = "signer" + +// The raw error has the signer's internal address, so callers get this instead. +var errSignerUnavailable = errors.New("signer unavailable") + +type Handlers struct { + client *http.Client + baseURL string +} + +func NewHandlers(baseURL string, timeout time.Duration) *Handlers { + return &Handlers{ + client: &http.Client{Timeout: timeout}, + baseURL: strings.TrimSuffix(baseURL, "/"), + } +} + +func (h *Handlers) RegisterRoutes(router *identity.Router) { + router.RequirePrivilege("GET /connectors/signer/certificates", CertificatesRead, h.forwardTo("/api/v1/admin/certificates")) + router.RequirePrivilege("GET /connectors/signer/certificates/{serial}", CertificatesRead, h.forwardTo("/api/v1/admin/certificates/{serial}")) + router.RequirePrivilege("POST /connectors/signer/certificates/{serial}/revoke", CertificatesWrite, h.forwardTo("/api/v1/certificates/{serial}/revoke")) + router.RequireAuth("GET /connectors/signer/me/certificates", h.forwardTo("/api/v1/certificates")) + router.RequireAuth("GET /connectors/signer/me/certificates/{serial}", h.forwardTo("/api/v1/certificates/{serial}")) + router.RequirePrivilege("GET /connectors/signer/status", CertificatesRead, h.status) +} + +// The caller's own token goes to the signer, so the signer checks the real user. +func (h *Handlers) forwardTo(path string) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + target := h.baseURL + strings.Replace(path, "{serial}", url.PathEscape(r.PathValue("serial")), 1) + if r.URL.RawQuery != "" { + target += "?" + r.URL.RawQuery + } + req, err := http.NewRequestWithContext(r.Context(), r.Method, target, r.Body) + if err != nil { + common.WriteError(w, http.StatusInternalServerError, errSignerUnavailable) + return + } + req.Header.Set("Authorization", r.Header.Get("Authorization")) + if ct := r.Header.Get("Content-Type"); ct != "" { + req.Header.Set("Content-Type", ct) + } + resp, err := h.client.Do(req) + health.Record(Type, Type, callResult(resp, err)) + if err != nil { + slog.Warn("signer request failed", "path", path, "error", err) + common.WriteError(w, http.StatusBadGateway, errSignerUnavailable) + return + } + defer resp.Body.Close() + w.Header().Set("Content-Type", resp.Header.Get("Content-Type")) + w.WriteHeader(resp.StatusCode) + io.Copy(w, resp.Body) + } +} + +// A 5xx counts as a failure. A 4xx is the signer working and refusing the caller. +func callResult(resp *http.Response, err error) error { + if err == nil && resp.StatusCode >= http.StatusInternalServerError { + return fmt.Errorf("signer returned %d", resp.StatusCode) + } + return err +} + +type statusResponse struct { + Reachable bool `json:"reachable"` + LatencyMs int64 `json:"latency_ms"` + BaseURL string `json:"base_url"` +} + +func (h *Handlers) CheckHealth(ctx context.Context) error { + req, err := http.NewRequestWithContext(ctx, http.MethodGet, h.baseURL+"/api/v1/health", nil) + if err != nil { + return err + } + resp, err := h.client.Do(req) + if err == nil { + resp.Body.Close() + if resp.StatusCode != http.StatusOK { + err = fmt.Errorf("signer health returned %d", resp.StatusCode) + } + } + health.Record(Type, Type, err) + return err +} + +// An unreachable signer is still a 200 here, so the caller can show it. +func (h *Handlers) status(w http.ResponseWriter, r *http.Request) { + start := time.Now() + err := h.CheckHealth(r.Context()) + common.WriteJSON(w, http.StatusOK, statusResponse{Reachable: err == nil, LatencyMs: time.Since(start).Milliseconds(), BaseURL: h.baseURL}) +} diff --git a/connectors/Signer/internal/handlers_test.go b/connectors/Signer/internal/handlers_test.go new file mode 100644 index 000000000..18e22e5ec --- /dev/null +++ b/connectors/Signer/internal/handlers_test.go @@ -0,0 +1,146 @@ +// 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 internal + +import ( + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/apache/airavata-custos/internal/connectors/health" + "github.com/apache/airavata-custos/pkg/identity" + "github.com/apache/airavata-custos/pkg/models" +) + +// signerCall is what the fake signer saw on its last request. +type signerCall struct { + path, query, auth string +} + +// mockSignerServer stands in for the signer. Health is always ok. Every other path gets the status and body the test gives it. +func mockSignerServer(t *testing.T, status int, body string) (*httptest.Server, *signerCall) { + t.Helper() + seen := &signerCall{} + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + *seen = signerCall{r.URL.Path, r.URL.RawQuery, r.Header.Get("Authorization")} + w.Header().Set("Content-Type", "application/json") + if r.URL.Path == "/api/v1/health" { + w.Write([]byte(`{"status":"ok"}`)) + return + } + w.WriteHeader(status) + w.Write([]byte(body)) + })) + t.Cleanup(srv.Close) + return srv, seen +} + +func serve(baseURL string, r *http.Request, privs ...models.PrivilegeKey) *httptest.ResponseRecorder { + mux := http.NewServeMux() + NewHandlers(baseURL, 2*time.Second).RegisterRoutes(identity.NewRouter(mux)) + r.Header.Set("Authorization", "Bearer user-token") + r = r.WithContext(identity.WithPrivilegesForTest(r.Context(), privs)) + rec := httptest.NewRecorder() + mux.ServeHTTP(rec, r) + return rec +} + +// Make sure the caller's token and paging go to the signer, and the signer's answer comes back unchanged. +func TestCertificates_ForwardsCallerTokenAndPaging(t *testing.T) { + srv, seen := mockSignerServer(t, http.StatusOK, `{"items":[],"next_cursor":"c2"}`) + + rec := serve(srv.URL, httptest.NewRequest(http.MethodGet, "/connectors/signer/certificates?limit=20&cursor=c1", nil), CertificatesRead) + + if seen.path != "/api/v1/admin/certificates" || seen.query != "limit=20&cursor=c1" || seen.auth != "Bearer user-token" { + t.Fatalf("signer got %+v", *seen) + } + if rec.Code != http.StatusOK || rec.Body.String() != `{"items":[],"next_cursor":"c2"}` { + t.Fatalf("got %d %s", rec.Code, rec.Body) + } +} + +// Make sure a caller without the write privilege cannot revoke, and the signer is never called. +func TestRevoke_WithoutWritePrivilegeNeverReachesSigner(t *testing.T) { + srv, seen := mockSignerServer(t, http.StatusOK, `{}`) + + rec := serve(srv.URL, httptest.NewRequest(http.MethodPost, "/connectors/signer/certificates/42/revoke", nil), CertificatesRead) + + if rec.Code != http.StatusForbidden || seen.path != "" { + t.Fatalf("got %d, signer saw %q", rec.Code, seen.path) + } +} + +// Make sure the status check calls the signer's health route without the caller's token. +func TestStatus_ReportsReachable(t *testing.T) { + srv, seen := mockSignerServer(t, http.StatusOK, `{}`) + + rec := serve(srv.URL, httptest.NewRequest(http.MethodGet, "/connectors/signer/status", nil), CertificatesRead) + + var got statusResponse + if err := json.NewDecoder(rec.Body).Decode(&got); err != nil { + t.Fatal(err) + } + if !got.Reachable || got.BaseURL != srv.URL { + t.Fatalf("got %+v", got) + } + if seen.path != "/api/v1/health" || seen.auth != "" { + t.Fatalf("health request was %+v", *seen) + } +} + +// Make sure a 5xx from the signer shows as a failed check on GET /connectors. +func TestForward_SignerServerErrorRecordsFailedCheck(t *testing.T) { + srv, _ := mockSignerServer(t, http.StatusInternalServerError, `{}`) + + serve(srv.URL, httptest.NewRequest(http.MethodGet, "/connectors/signer/me/certificates", nil)) + + checks := health.For(Type) + if len(checks) != 1 || checks[0].OK { + t.Fatalf("got %+v", checks) + } +} + +// Make sure a signer that is down does not show its internal address to the caller. +func TestForward_SignerDownHidesItsAddress(t *testing.T) { + srv, _ := mockSignerServer(t, http.StatusOK, `{}`) + srv.Close() + + rec := serve(srv.URL, httptest.NewRequest(http.MethodGet, "/connectors/signer/me/certificates", nil)) + + if rec.Code != http.StatusBadGateway || strings.Contains(rec.Body.String(), srv.Listener.Addr().String()) { + t.Fatalf("got %d %s", rec.Code, rec.Body) + } +} + +// Make sure a signer that is down shows as not reachable instead of failing the request. +func TestStatus_SignerDownIsNotReachable(t *testing.T) { + srv, _ := mockSignerServer(t, http.StatusOK, `{}`) + srv.Close() + + rec := serve(srv.URL, httptest.NewRequest(http.MethodGet, "/connectors/signer/status", nil), CertificatesRead) + + body, _ := io.ReadAll(rec.Body) + var got statusResponse + if err := json.Unmarshal(body, &got); err != nil || rec.Code != http.StatusOK || got.Reachable { + t.Fatalf("got %d %s", rec.Code, body) + } +} diff --git a/connectors/Signer/internal/privileges.go b/connectors/Signer/internal/privileges.go new file mode 100644 index 000000000..f072ca236 --- /dev/null +++ b/connectors/Signer/internal/privileges.go @@ -0,0 +1,30 @@ +// 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 internal + +import "github.com/apache/airavata-custos/pkg/models" + +// The signer checks these same keys on the caller's /me, so they must match its names. +const ( + CertificatesRead models.PrivilegeKey = "signer:certificates:read" + CertificatesWrite models.PrivilegeKey = "signer:certificates:write" +) + +func init() { + models.Register(CertificatesRead, CertificatesWrite) +} diff --git a/connectors/Signer/internal/privileges_integration_test.go b/connectors/Signer/internal/privileges_integration_test.go new file mode 100644 index 000000000..eb63a0f25 --- /dev/null +++ b/connectors/Signer/internal/privileges_integration_test.go @@ -0,0 +1,89 @@ +//go:build integration + +// 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 internal + +import ( + "os" + "slices" + "testing" + + "github.com/google/uuid" + + "github.com/apache/airavata-custos/internal/db" + "github.com/apache/airavata-custos/internal/tracing/tracingtest" + "github.com/apache/airavata-custos/pkg/events" + "github.com/apache/airavata-custos/pkg/models" + coreservice "github.com/apache/airavata-custos/pkg/service" +) + +// Make sure the super admin holds the signer privileges and can grant read to another user, since the signer reads these keys from that user's /me. +func TestSignerPrivileges_GrantableAndHeldBySuperAdmin(t *testing.T) { + dsn := os.Getenv("CORE_TEST_DATABASE_DSN") + if dsn == "" { + t.Skip("integration env not set: CORE_TEST_DATABASE_DSN required") + } + database, err := db.Open(db.Config{DSN: dsn, MaxOpenConns: 5, MaxIdleConns: 2}) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { database.Close() }) + if err := db.MigrateEmbedded(database); err != nil { + t.Fatal(err) + } + if _, err := database.Exec("TRUNCATE TABLE user_roles, role_privileges, roles, user_privileges, audit_events, user_identities, users, organizations CASCADE"); err != nil { + t.Fatal(err) + } + ctx := tracingtest.Context() + bus, err := events.New(ctx, database) + if err != nil { + t.Fatal(err) + } + svc := coreservice.New(database, bus) + + if err := svc.BootstrapSuperAdmin(ctx, "[email protected]", "oidc"); err != nil { + t.Fatal(err) + } + var adminID string + if err := database.Get(&adminID, "SELECT id FROM users WHERE email = $1", "[email protected]"); err != nil { + t.Fatal(err) + } + adminPrivs, err := svc.EffectivePrivileges(ctx, adminID) + if err != nil { + t.Fatal(err) + } + if !slices.Contains(adminPrivs, CertificatesRead) || !slices.Contains(adminPrivs, CertificatesWrite) { + t.Fatalf("super admin privileges %v lack the signer keys", adminPrivs) + } + + operatorID := uuid.NewString() + if _, err := database.Exec("INSERT INTO users (id, organization_id, first_name, last_name, middle_name, email, status) SELECT $1, organization_id, 'Jane', 'Doe', '', '[email protected]', $2 FROM users WHERE id = $3", operatorID, string(models.UserActive), adminID); err != nil { + t.Fatal(err) + } + if _, err := svc.GrantPrivilege(ctx, operatorID, CertificatesRead, adminID, "certificate audits"); err != nil { + t.Fatal(err) + } + operatorPrivs, err := svc.EffectivePrivileges(ctx, operatorID) + if err != nil { + t.Fatal(err) + } + if !slices.Equal(operatorPrivs, []models.PrivilegeKey{CertificatesRead}) { + t.Fatalf("operator privileges %v, want only %s", operatorPrivs, CertificatesRead) + } +} diff --git a/connectors/Signer/pkg/signer/loader.go b/connectors/Signer/pkg/signer/loader.go new file mode 100644 index 000000000..8643b733d --- /dev/null +++ b/connectors/Signer/pkg/signer/loader.go @@ -0,0 +1,56 @@ +// 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 signer + +import ( + "context" + "errors" + "log/slog" + "sync" + "time" + + "github.com/jmoiron/sqlx" + + "github.com/apache/airavata-custos/connectors/Signer/internal" + "github.com/apache/airavata-custos/internal/config" + "github.com/apache/airavata-custos/internal/connectors/health" + "github.com/apache/airavata-custos/pkg/events" + "github.com/apache/airavata-custos/pkg/identity" + "github.com/apache/airavata-custos/pkg/service" +) + +const Type = internal.Type + +func LoadConnector(ctx context.Context, _ *sqlx.DB, _ *events.Bus, _ *service.Service, _ *sync.WaitGroup, router *identity.Router, cfg *config.ConnectorConfig) error { + baseURL, _ := cfg.GetStringField("base_url") + if baseURL == "" { + slog.Info("signer: base_url not set; skipping") + health.Record(Type, "config", errors.New("required setting base_url not set")) + return nil + } + timeout, err := cfg.GetIntField("timeout_seconds") + if err != nil { + timeout = 10 + } + handlers := internal.NewHandlers(baseURL, time.Duration(timeout)*time.Second) + handlers.RegisterRoutes(router) + // In the background so a down signer does not hold up startup. + go handlers.CheckHealth(ctx) + slog.Info("signer: routes registered", "base_url", baseURL) + return nil +} diff --git a/docs/architecture.md b/docs/architecture.md index 2ee1497c8..95b506b0e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -104,6 +104,7 @@ shutdown the HTTP server gets 15 seconds to finish in-flight requests. The serve | `email-notifier` | `connectors/Notification/Email` | Emails users about their cluster account requests | | `analytics` | `connectors/Analytics` | Usage summaries and job lists for allocation participants | | `temp-account` | `connectors/TempAccount` | Creates temporary accounts and assigns them allocations | +| `signer` | `connectors/Signer` | Forwards certificate list and revoke calls to the SSH certificate signer | `connectors/SLURM/Rest-Client` is the shared `slurmrestd` client library, not a connector. `GET /connectors` lists the configured connectors with their load status and requires `core:clusters:read`. diff --git a/docs/privileges.md b/docs/privileges.md index 8642e175b..9e6d69718 100644 --- a/docs/privileges.md +++ b/docs/privileges.md @@ -78,6 +78,7 @@ These routes need a verified caller but no key. | `RequireScoped` | `GET /projects/{id}` | `core:projects:read`, or a participant in the project; `404` otherwise | | `RequireScoped` | `GET /compute-allocations/{id}`<br>`GET /compute-allocations/{id}/resources`<br>`GET /compute-allocations/{id}/memberships`<br>`GET /compute-allocations/{id}/usages`<br>`GET /compute-allocations/{id}/usages/total` | `core:allocations:read`, or a participant in the allocation; `404` otherwise | | `RequireAuth` | `GET /connectors/analytics/contexts`<br>`GET /connectors/analytics/allocations/{id}/usage-summary`<br>`GET /connectors/analytics/allocations/{id}/jobs` | Decided by allocation role alone: PI, CO_PI and ALLOCATION_MANAGER see all members, plain members see their own records | +| `RequireAuth` | `GET /connectors/signer/me/certificates`<br>`GET /connectors/signer/me/certificates/{serial}` | The caller's own certificates, as decided by the signer | ## AMIE connector (`connectors/ACCESS/AMIE-Processor/server/privileges.go`) @@ -97,14 +98,20 @@ These routes need a verified caller but no key. | `temp-account:accounts:read` | `GET /connectors/temp-account/membership/{user_id}` | | `temp-account:accounts:write` | `POST /connectors/temp-account/create`<br>`POST /connectors/temp-account/assign-allocation`<br>`POST /connectors/temp-account/update-allocation`<br>`DELETE /connectors/temp-account/remove/{user_id}` | +## Signer connector (`connectors/Signer/internal/privileges.go`) + +| Privilege | Routes it gates | +|---|---| +| `signer:certificates:read` | `GET /connectors/signer/certificates`<br>`GET /connectors/signer/certificates/{serial}`<br>`GET /connectors/signer/status` | +| `signer:certificates:write` | `POST /connectors/signer/certificates/{serial}/revoke` | + +The SSH-Certificate-Signer extension checks the same two keys in the privileges that core `GET /me` returns. + ## Other connectors The VAST-Provisioner routes use the core `core:clusters:*` keys, listed above. The remaining connectors gate no route on a key. -The SSH-Certificate-Signer extension looks for `signer:certificates:read` and `signer:certificates:write` in the -privileges that core `GET /me` returns. Core does not register these keys, so they cannot be granted. - ## System roles Two roles are created by the server and marked `is_system`. diff --git a/extensions/SSH-Certificate-Signer/README.md b/extensions/SSH-Certificate-Signer/README.md index d7b582709..f79eb3158 100644 --- a/extensions/SSH-Certificate-Signer/README.md +++ b/extensions/SSH-Certificate-Signer/README.md @@ -245,8 +245,8 @@ The signer reads the caller's privileges from `GET /me` at `core_api_base_url`: | Revoke another user's certificate | `signer:certificates:write` | | Revoke one's own certificate | No privilege | -The Custos server does not register the `signer:` privileges ([docs/privileges.md](../../docs/privileges.md#other-connectors)). -Calls that need one return 403. +The Custos server registers the `signer:` privileges through its [Signer connector](../../connectors/Signer/README.md), +which also forwards the certificate routes under `/connectors/signer` ([docs/privileges.md](../../docs/privileges.md#signer-connector-connectorssignerinternalprivilegesgo)). `GET /api/v1/admin/certificates` uses keyset pagination. Pass `limit`, and `cursor` set to the last `next_cursor`. It returns no total or offset. diff --git a/internal/connectors/loader.go b/internal/connectors/loader.go index 2754a1c9a..1a9848246 100644 --- a/internal/connectors/loader.go +++ b/internal/connectors/loader.go @@ -28,6 +28,7 @@ import ( "github.com/apache/airavata-custos/connectors/Notification/Email/pkg/email" "github.com/apache/airavata-custos/connectors/SLURM/Association-Mapper/pkg/smapper" "github.com/apache/airavata-custos/connectors/SLURM/Usage-Monitor/pkg/monitor" + "github.com/apache/airavata-custos/connectors/Signer/pkg/signer" "github.com/apache/airavata-custos/connectors/Storage/VAST-Provisioner/pkg/vast" "github.com/apache/airavata-custos/connectors/TempAccount/pkg/tempaccount" "github.com/apache/airavata-custos/internal/config" @@ -51,6 +52,7 @@ func LoadConnectorsFromConfig(ctx context.Context, cfg *config.Config, database analytics.Type: analytics.LoadConnector, vast.Type: vast.LoadConnector, email.Type: email.LoadConnector, + signer.Type: signer.LoadConnector, } for connectorName, connectorCfg := range cfg.Connectors {
