You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ya...@apache.org on 2026/10/02 16:16:44 UTC
(airavata-custos) 01/01: add a local VAST VMS stand-in for testing the VAST connector
This is an automated email from the ASF dual-hosted git repository.
yasithdev pushed a commit to branch vast-standin
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 2031fdc1d1c667344996c3dc2c16f21b5083935b
Author: Yasith Jayawardana <ya...@icloud.com>
AuthorDate: Fri Oct 2 12:16:32 2026 -0400
add a local VAST VMS stand-in for testing the VAST connector
---
dev-ops/local-vast/README.md | 55 ++++++++
dev-ops/local-vast/local-vast.service | 14 +++
dev-ops/local-vast/main.go | 228 ++++++++++++++++++++++++++++++++++
dev-ops/local-vast/main_test.go | 91 ++++++++++++++
4 files changed, 388 insertions(+)
diff --git a/dev-ops/local-vast/README.md b/dev-ops/local-vast/README.md
new file mode 100644
index 000000000..ac408cab0
--- /dev/null
+++ b/dev-ops/local-vast/README.md
@@ -0,0 +1,55 @@
+<!--
+ 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.
+-->
+
+# local-vast
+
+A stand-in for the VAST VMS REST API, run on a test cluster's file server so the VAST Storage-Provisioner can be
+tested end to end: Custos → COmanage → LDAP → directories users see on the cluster.
+
+| VMS call | Stand-in |
+|---|---|
+| `POST /api/token/` | A token for `VAST_USER` / `VAST_PASSWORD`; anything else is `403 authentication_failed` |
+| `POST /api/folders/create_folder/` | Creates the directory, owner and group resolved through NSS, mode applied exactly |
+| `POST /api/folders/stat_path/` | 200 if the path exists, else `503 NOT_FOUND` |
+| `POST /api/quotas/`, `GET /api/quotas/?name=` | Recorded in `/var/lib/local-vast/quotas.json`; not enforced |
+
+It answers as VMS does where the connector depends on it: `503 ALREADY_EXISTS`, `503 Couldn't find user` or `group`
+while LDAP catches up, and `403 token_not_valid` after a restart. Unlike VMS, it keeps the setgid bit.
+
+## Install
+
+```sh
+GOOS=linux GOARCH=amd64 go build -o local-vast ./dev-ops/local-vast
+scp local-vast local-vast.service <host>:
+ssh <host> sudo install -m 755 local-vast /usr/local/bin/
+ssh <host> sudo install -m 644 local-vast.service /etc/systemd/system/
+# /etc/local-vast.env, mode 600: VAST_USER=..., VAST_PASSWORD=..., LISTEN=<private ip>:8443
+ssh <host> sudo systemctl enable --now local-vast
+```
+
+The host needs NSS to resolve COmanage's groups as well as its people (for SSSD, `ldap_group_search_base`), the
+parent directories of the configured paths, and the port open to the Custos host only. Point the connector at it:
+
+```yaml
+ vms:
+ url: "http://<private ip>:8443"
+ username: "<VAST_USER>"
+ password: "${VAST_API_PASSWORD}"
+ tenant_id: 1
+```
diff --git a/dev-ops/local-vast/local-vast.service b/dev-ops/local-vast/local-vast.service
new file mode 100644
index 000000000..c759c9d1b
--- /dev/null
+++ b/dev-ops/local-vast/local-vast.service
@@ -0,0 +1,14 @@
+# Runs as root, since it creates directories owned by cluster accounts.
+# /etc/local-vast.env sets VAST_USER, VAST_PASSWORD and LISTEN (host:port).
+[Unit]
+Description=VAST VMS stand-in for the Custos VAST Storage-Provisioner
+After=network-online.target sssd.service
+
+[Service]
+EnvironmentFile=/etc/local-vast.env
+ExecStart=/usr/local/bin/local-vast -listen ${LISTEN} -state /var/lib/local-vast/quotas.json
+StateDirectory=local-vast
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/dev-ops/local-vast/main.go b/dev-ops/local-vast/main.go
new file mode 100644
index 000000000..0fb24d08c
--- /dev/null
+++ b/dev-ops/local-vast/main.go
@@ -0,0 +1,228 @@
+// 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.
+
+// Command local-vast serves the part of the VAST VMS REST API the VAST
+// Storage-Provisioner calls, on a test cluster's file server. Folders become
+// real directories whose owners resolve through NSS, as VMS resolves them
+// through its directory provider; quotas are recorded, not enforced. Refusals
+// keep VMS's shapes, so the connector's retry paths run as in production. It
+// keeps the setgid bit, which a real VMS drops.
+package main
+
+import (
+ "crypto/rand"
+ "encoding/hex"
+ "encoding/json"
+ "errors"
+ "flag"
+ "fmt"
+ "io/fs"
+ "log"
+ "net/http"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "sync"
+)
+
+type quota struct {
+ Name string `json:"name"`
+ Path string `json:"path"`
+ HardLimit int64 `json:"hard_limit"`
+ HardLimitInodes int64 `json:"hard_limit_inodes"`
+}
+
+type server struct {
+ user, password, state string
+ lookup func(db, name string) (int, error)
+
+ mu sync.Mutex
+ tokens map[string]bool
+ quotas map[string]quota
+}
+
+func main() {
+ listen := flag.String("listen", "127.0.0.1:8443", "address to serve on")
+ state := flag.String("state", "/var/lib/local-vast/quotas.json", "file the quotas are kept in")
+ flag.Parse()
+ s := &server{user: os.Getenv("VAST_USER"), password: os.Getenv("VAST_PASSWORD"), state: *state, lookup: getent,
+ tokens: map[string]bool{}, quotas: map[string]quota{}}
+ if s.user == "" || s.password == "" {
+ log.Fatal("local-vast: VAST_USER and VAST_PASSWORD are required")
+ }
+ if b, err := os.ReadFile(s.state); err == nil {
+ if err := json.Unmarshal(b, &s.quotas); err != nil {
+ log.Fatalf("local-vast: %s: %v", s.state, err)
+ }
+ }
+ log.Printf("local-vast: serving on %s", *listen)
+ log.Fatal(http.ListenAndServe(*listen, s.routes()))
+}
+
+func (s *server) routes() http.Handler {
+ mux := http.NewServeMux()
+ mux.HandleFunc("POST /api/token/", s.token)
+ mux.HandleFunc("POST /api/folders/create_folder/", s.authed(s.createFolder))
+ mux.HandleFunc("POST /api/folders/stat_path/", s.authed(s.statPath))
+ mux.HandleFunc("POST /api/quotas/", s.authed(s.createQuota))
+ mux.HandleFunc("GET /api/quotas/", s.authed(s.listQuotas))
+ return mux
+}
+
+func refuse(w http.ResponseWriter, status int, code, detail string) {
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(status)
+ _ = json.NewEncoder(w).Encode(map[string]string{"code": code, "detail": detail})
+}
+
+func reply(w http.ResponseWriter, v any) {
+ w.Header().Set("Content-Type", "application/json")
+ _ = json.NewEncoder(w).Encode(v)
+}
+
+func (s *server) token(w http.ResponseWriter, r *http.Request) {
+ var b struct{ Username, Password string }
+ if json.NewDecoder(r.Body).Decode(&b) != nil || b.Username != s.user || b.Password != s.password {
+ refuse(w, http.StatusForbidden, "authentication_failed", "No active account found with the given credentials")
+ return
+ }
+ t := make([]byte, 16)
+ _, _ = rand.Read(t)
+ s.mu.Lock()
+ s.tokens[hex.EncodeToString(t)] = true
+ s.mu.Unlock()
+ reply(w, map[string]string{"access": hex.EncodeToString(t)})
+}
+
+func (s *server) authed(h http.HandlerFunc) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ s.mu.Lock()
+ ok := s.tokens[strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")]
+ s.mu.Unlock()
+ if !ok {
+ refuse(w, http.StatusForbidden, "token_not_valid", "Given token not valid for any token type")
+ return
+ }
+ h(w, r)
+ }
+}
+
+func (s *server) createFolder(w http.ResponseWriter, r *http.Request) {
+ var b struct {
+ Path, User, Group string
+ Mode string `json:"create_dir_mode"`
+ }
+ if err := json.NewDecoder(r.Body).Decode(&b); err != nil || !filepath.IsAbs(b.Path) {
+ refuse(w, http.StatusBadRequest, "INVALID", "an absolute path is required")
+ return
+ }
+ if _, err := os.Stat(b.Path); err == nil {
+ refuse(w, http.StatusServiceUnavailable, "ALREADY_EXISTS", b.Path+" already exists")
+ return
+ }
+ uid, err := s.lookup("passwd", b.User)
+ if err != nil {
+ refuse(w, http.StatusServiceUnavailable, "UNKNOWN_USER", "Couldn't find user "+b.User)
+ return
+ }
+ gid, err := s.lookup("group", b.Group)
+ if err != nil {
+ refuse(w, http.StatusServiceUnavailable, "UNKNOWN_GROUP", "Couldn't find group "+b.Group)
+ return
+ }
+ mode, err := strconv.ParseUint(b.Mode, 8, 32)
+ if err != nil {
+ refuse(w, http.StatusBadRequest, "INVALID", "create_dir_mode must be octal")
+ return
+ }
+ perm := fs.FileMode(mode & 0o777)
+ if mode&0o2000 != 0 {
+ perm |= fs.ModeSetgid
+ }
+ // Chmod after Mkdir, since Mkdir is subject to the umask and drops setgid.
+ if err := errors.Join(os.Mkdir(b.Path, 0o700), os.Chown(b.Path, uid, gid), os.Chmod(b.Path, perm)); err != nil {
+ refuse(w, http.StatusServiceUnavailable, "CREATE_FAILED", err.Error())
+ return
+ }
+ log.Printf("local-vast: folder %s %d:%d %s", b.Path, uid, gid, b.Mode)
+ reply(w, map[string]string{"path": b.Path})
+}
+
+func (s *server) statPath(w http.ResponseWriter, r *http.Request) {
+ var b struct{ Path string }
+ _ = json.NewDecoder(r.Body).Decode(&b)
+ if _, err := os.Stat(b.Path); err != nil {
+ refuse(w, http.StatusServiceUnavailable, "NOT_FOUND", b.Path+" does not exist")
+ return
+ }
+ reply(w, map[string]string{"path": b.Path})
+}
+
+func (s *server) createQuota(w http.ResponseWriter, r *http.Request) {
+ var q quota
+ if err := json.NewDecoder(r.Body).Decode(&q); err != nil || q.Name == "" {
+ refuse(w, http.StatusBadRequest, "INVALID", "a quota name is required")
+ return
+ }
+ if _, err := os.Stat(q.Path); err != nil {
+ refuse(w, http.StatusServiceUnavailable, "NOT_FOUND", q.Path+" does not exist")
+ return
+ }
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ if _, taken := s.quotas[q.Name]; taken {
+ refuse(w, http.StatusBadRequest, "DUPLICATE", "quota with this name already exists")
+ return
+ }
+ s.quotas[q.Name] = q
+ b, _ := json.MarshalIndent(s.quotas, "", " ")
+ if err := os.WriteFile(s.state, b, 0o644); err != nil {
+ delete(s.quotas, q.Name)
+ refuse(w, http.StatusServiceUnavailable, "CREATE_FAILED", err.Error())
+ return
+ }
+ log.Printf("local-vast: quota %s %d bytes %d inodes", q.Path, q.HardLimit, q.HardLimitInodes)
+ reply(w, q)
+}
+
+func (s *server) listQuotas(w http.ResponseWriter, r *http.Request) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ found := []quota{}
+ if q, ok := s.quotas[r.URL.Query().Get("name")]; ok {
+ found = append(found, q)
+ }
+ reply(w, found)
+}
+
+// getent resolves a user or group name, or a numeric id, through NSS.
+func getent(db, name string) (int, error) {
+ if id, err := strconv.Atoi(name); err == nil {
+ return id, nil
+ }
+ out, err := exec.Command("getent", db, name).Output()
+ if err != nil {
+ return 0, fmt.Errorf("getent %s %s: %w", db, name, err)
+ }
+ fields := strings.Split(string(out), ":")
+ if len(fields) < 3 {
+ return 0, fmt.Errorf("getent %s %s: unexpected %q", db, name, out)
+ }
+ return strconv.Atoi(fields[2])
+}
diff --git a/dev-ops/local-vast/main_test.go b/dev-ops/local-vast/main_test.go
new file mode 100644
index 000000000..38e373dfd
--- /dev/null
+++ b/dev-ops/local-vast/main_test.go
@@ -0,0 +1,91 @@
+// 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 main
+
+import (
+ "bytes"
+ "encoding/json"
+ "errors"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// Make sure the refusals the connector relies on keep VMS's shapes.
+func TestVMSAnswers(t *testing.T) {
+ dir := t.TempDir()
+ s := &server{user: "u", password: "p", state: filepath.Join(dir, "quotas.json"), tokens: map[string]bool{}, quotas: map[string]quota{},
+ lookup: func(db, name string) (int, error) {
+ if name == "ghost" {
+ return 0, errors.New("no such entry")
+ }
+ if db == "passwd" {
+ return os.Getuid(), nil
+ }
+ return os.Getgid(), nil
+ }}
+ srv := httptest.NewServer(s.routes())
+ defer srv.Close()
+
+ call := func(method, path, token string, body any) (int, string) {
+ b, _ := json.Marshal(body)
+ req, _ := http.NewRequest(method, srv.URL+"/api/"+path, bytes.NewReader(b))
+ req.Header.Set("Authorization", "Bearer "+token)
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer resp.Body.Close()
+ out, _ := io.ReadAll(resp.Body)
+ return resp.StatusCode, string(out)
+ }
+ _, out := call("POST", "token/", "", map[string]string{"username": "u", "password": "p"})
+ var tok struct{ Access string }
+ _ = json.Unmarshal([]byte(out), &tok)
+
+ home := filepath.Join(dir, "home")
+ folder := map[string]string{"path": home, "user": "jdoe", "group": "jdoe", "create_dir_mode": "2750"}
+ cases := []struct {
+ name, method, path, token string
+ body any
+ status int
+ contains string
+ }{
+ {"bad password", "POST", "token/", "", map[string]string{"username": "u", "password": "x"}, 403, "authentication_failed"},
+ {"bad token", "POST", "folders/create_folder/", "stale", folder, 403, "token_not_valid"},
+ {"unknown owner", "POST", "folders/create_folder/", tok.Access, map[string]string{"path": home, "user": "ghost", "group": "g", "create_dir_mode": "700"}, 503, "Couldn't find user ghost"},
+ {"created", "POST", "folders/create_folder/", tok.Access, folder, 200, home},
+ {"exists", "POST", "folders/create_folder/", tok.Access, folder, 503, "ALREADY_EXISTS"},
+ {"stat missing", "POST", "folders/stat_path/", tok.Access, map[string]string{"path": filepath.Join(dir, "nope")}, 503, "NOT_FOUND"},
+ {"quota", "POST", "quotas/", tok.Access, map[string]any{"name": home, "path": home, "hard_limit": 1}, 200, home},
+ {"quota taken", "POST", "quotas/", tok.Access, map[string]any{"name": home, "path": home, "hard_limit": 1}, 400, "DUPLICATE"},
+ {"quota listed", "GET", "quotas/?name=" + home, tok.Access, nil, 200, `"hard_limit":1`},
+ }
+ for _, c := range cases {
+ if status, out := call(c.method, c.path, c.token, c.body); status != c.status || !strings.Contains(out, c.contains) {
+ t.Errorf("%s: got %d %s, want %d containing %q", c.name, status, out, c.status, c.contains)
+ }
+ }
+ if fi, err := os.Stat(home); err != nil || fi.Mode()&os.ModeSetgid == 0 || fi.Mode().Perm() != 0o750 {
+ t.Fatalf("home mode %v, err %v; want 2750", fi.Mode(), err)
+ }
+}