This is an automated email from the ASF dual-hosted git repository.

yasithdev pushed a commit to branch airavata-connector
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git

commit c0a8bb33b4688a051994a3504abe67d37304e202
Author: Yasith Jayawardana <[email protected]>
AuthorDate: Wed Nov 11 13:40:39 2026 -0500

    Add Airavata connector
---
 .env.example                               |   5 ++
 CONFIG.md                                  |   1 +
 config/custos.yaml                         |   6 ++
 connectors/Airavata/pkg/airavata/loader.go | 136 +++++++++++++++++++++++++++++
 docs/architecture.md                       |   1 +
 internal/connectors/loader.go              |   2 +
 6 files changed, 151 insertions(+)

diff --git a/.env.example b/.env.example
index da7b15299..5e113c1f7 100644
--- a/.env.example
+++ b/.env.example
@@ -98,3 +98,8 @@ EMAIL_PORTAL_URL=
 EMAIL_CLUSTER_HOST=
 EMAIL_LOGO_URL=
 EMAIL_TEMPLATES_DIR=
+
+# --- Airavata connector --------------------------------------------------
+
+AIRAVATA_URL=
+AIRAVATA_ROOT_TOKEN=
diff --git a/CONFIG.md b/CONFIG.md
index 710c2ef91..f2090f827 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -136,6 +136,7 @@ At startup the server goes through the blocks:
 | `amie-processor` | [AMIE 
Processor](connectors/ACCESS/AMIE-Processor/README.md#configuration) |
 | `email-notifier` | [Email 
Notifier](connectors/Notification/Email/README.md#configuration) |
 | `temp-account`, `analytics` | [Temporary accounts and 
analytics](#temporary-accounts-and-analytics), below |
+| `airavata` | `url`, the Airavata server. `root_token`, its root account 
token. Skipped when either is empty. |
 
 To add a connector type, follow 
[docs/contributing/writing-a-connector.md](docs/contributing/writing-a-connector.md).
 
diff --git a/config/custos.yaml b/config/custos.yaml
index 8ff4a2795..f08a82021 100644
--- a/config/custos.yaml
+++ b/config/custos.yaml
@@ -196,6 +196,12 @@ connectors:
     type: "temp-account"
     enabled: true
 
+  airavata:
+    type: "airavata"
+    enabled: true
+    url: "${AIRAVATA_URL}"
+    root_token: "${AIRAVATA_ROOT_TOKEN}"
+
   analytics:
     type: "analytics"
     enabled: true
diff --git a/connectors/Airavata/pkg/airavata/loader.go 
b/connectors/Airavata/pkg/airavata/loader.go
new file mode 100644
index 000000000..31b8a6738
--- /dev/null
+++ b/connectors/Airavata/pkg/airavata/loader.go
@@ -0,0 +1,136 @@
+// 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 airavata registers each Custos user in Airavata and shares the 
Airavata root
+// account's Slurm cluster configs with them, so a user who signs in to 
Airavata can submit
+// jobs at once. Airavata names a user by their OIDC subject, so a user is 
registered when
+// an identity carrying that subject is created, which is their first sign-in 
to Custos.
+// Every call is made as the root account and is safe to repeat.
+package airavata
+
+import (
+       "bytes"
+       "cmp"
+       "context"
+       "encoding/json"
+       "fmt"
+       "io"
+       "log/slog"
+       "net/http"
+       "strings"
+       "sync"
+
+       "github.com/jmoiron/sqlx"
+
+       "github.com/apache/airavata-custos/internal/config"
+       "github.com/apache/airavata-custos/pkg/events"
+       "github.com/apache/airavata-custos/pkg/identity"
+       "github.com/apache/airavata-custos/pkg/models"
+       "github.com/apache/airavata-custos/pkg/service"
+)
+
+// Type is the connector type in the config file and the subscriber name on 
the bus.
+const Type = "airavata"
+
+// LoadConnector registers the identity subscriber.
+func LoadConnector(_ context.Context, _ *sqlx.DB, eventBus *events.Bus, 
coreService *service.Service, _ *sync.WaitGroup, _ *identity.Router, cfg 
*config.ConnectorConfig) error {
+       url, _ := cfg.GetStringField("url")
+       token, _ := cfg.GetStringField("root_token")
+       if url == "" || token == "" {
+               slog.Info("airavata: url or root_token not set; skipping")
+               return nil
+       }
+       p := &provisioner{core: coreService, url: strings.TrimSuffix(url, "/"), 
token: token}
+       eventBus.SubscribeUserIdentityCreated(Type, p.provision)
+       return nil
+}
+
+type provisioner struct {
+       core       *service.Service
+       url, token string
+}
+
+func (p *provisioner) provision(ctx context.Context, created 
models.UserIdentity) error {
+       // Registering overwrites the Airavata user, so only the identity that 
carries the
+       // subject may do it: one from another source would undo a suspension 
there.
+       if created.OIDCSub == "" {
+               return nil
+       }
+       user, err := p.core.GetUser(ctx, created.UserID)
+       if err != nil {
+               return err
+       }
+       id := airavataUserID(created.OIDCSub)
+       // Airavata refuses a registration with no name, and a Custos user may 
have none.
+       if err := p.call(ctx, http.MethodPost, "/api/v1/users", 
map[string]string{
+               "userId": id, "email": user.Email, "authMethod": "CILOGON",
+               "firstName": cmp.Or(user.FirstName, user.Email), "lastName": 
cmp.Or(user.LastName, user.Email),
+       }, nil); err != nil {
+               return err
+       }
+       var configs []struct {
+               ID string `json:"slurmClusterConfigId"`
+       }
+       if err := p.call(ctx, http.MethodGet, 
"/api/v1/slurm-cluster-configs/me", nil, &configs); err != nil {
+               return err
+       }
+       for _, c := range configs {
+               if err := p.call(ctx, http.MethodPost, 
"/api/v1/slurm-cluster-configs/"+c.ID+"/shares",
+                       map[string]string{"principalType": "USER", 
"principalId": id}, nil); err != nil {
+                       return err
+               }
+       }
+       slog.InfoContext(ctx, "airavata: user registered", "user_id", user.ID, 
"airavata_user_id", id, "cluster_configs", len(configs))
+       return nil
+}
+
+// airavataUserID names a subject the way Airavata does when that user signs 
in:
+// "http://cilogon.org/serverE/users/12345"; is the user "cilogon:12345".
+func airavataUserID(sub string) string {
+       if i := strings.LastIndexByte(sub, '/'); strings.HasPrefix(sub, 
"http://cilogon.org";) && i < len(sub)-1 {
+               return "cilogon:" + sub[i+1:]
+       }
+       return sub
+}
+
+// call sends one request as the root account. 409 means the share already 
exists.
+func (p *provisioner) call(ctx context.Context, method, path string, body 
map[string]string, out any) error {
+       var payload io.Reader
+       if body != nil {
+               b, _ := json.Marshal(body)
+               payload = bytes.NewReader(b)
+       }
+       req, err := http.NewRequestWithContext(ctx, method, p.url+path, payload)
+       if err != nil {
+               return err
+       }
+       req.Header.Set("Authorization", "Bearer "+p.token)
+       req.Header.Set("Content-Type", "application/json")
+       resp, err := http.DefaultClient.Do(req)
+       if err != nil {
+               return err
+       }
+       defer resp.Body.Close()
+       if resp.StatusCode >= 300 && resp.StatusCode != http.StatusConflict {
+               msg, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
+               return fmt.Errorf("airavata %s %s: %s: %s", method, path, 
resp.Status, msg)
+       }
+       if out == nil {
+               return nil
+       }
+       return json.NewDecoder(resp.Body).Decode(out)
+}
diff --git a/docs/architecture.md b/docs/architecture.md
index 2c90573a0..5447a6e3d 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 |
+| `airavata` | `connectors/Airavata` | Registers users in Airavata and shares 
the root account's Slurm cluster configs with them |
 
 `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/internal/connectors/loader.go b/internal/connectors/loader.go
index 2754a1c9a..569721305 100644
--- a/internal/connectors/loader.go
+++ b/internal/connectors/loader.go
@@ -23,6 +23,7 @@ import (
        "sync"
 
        
"github.com/apache/airavata-custos/connectors/ACCESS/AMIE-Processor/pkg/amie"
+       "github.com/apache/airavata-custos/connectors/Airavata/pkg/airavata"
        "github.com/apache/airavata-custos/connectors/Analytics/pkg/analytics"
        
"github.com/apache/airavata-custos/connectors/COmanage/Identity-Provisioner/pkg/comanage"
        
"github.com/apache/airavata-custos/connectors/Notification/Email/pkg/email"
@@ -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,
+               airavata.Type:    airavata.LoadConnector,
        }
 
        for connectorName, connectorCfg := range cfg.Connectors {

Reply via email to