Slurm's shared files and users: one path everywhere, accounts as Linux users
CI / test (push) Failing after 7m1s

slurm.shared mounts the site's NFS export, has an llmgw node export the path
over NFS to the Slurm machines alone (2049 in the firewall), or looks for a
file system the site mounts. slurm.users "llmgw" makes each active account a
Linux user on every Slurm machine: login from its e-mail, a UID from 200000
kept in slurm_users and never reused, its home on the shared path, its SSH
keys from the portal's Profile (or ctl slurm users keys) read by sshd from
/etc/llmgw/ssh-keys. server init --slurm chooses /shared from the first
machine and llmgw's users; --slurm-shared and --slurm-users change that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-11-12 21:34:34 +01:00
1 parent b9d20e7bba
commit d8ce573bdb
45 files changed
+2505 -79

No files matched your search

+10
View File
@@ -17,6 +17,7 @@ import (
"gitea.mynodes.xyz/ilker/llmgw/internal/account"
"gitea.mynodes.xyz/ilker/llmgw/internal/audit"
"gitea.mynodes.xyz/ilker/llmgw/internal/clientip"
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
"gitea.mynodes.xyz/ilker/llmgw/internal/guard"
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
"gitea.mynodes.xyz/ilker/llmgw/internal/vscodeext"
@@ -151,6 +152,10 @@ type AccountPages struct {
resets account.ResetStore
mailer Mailer
publicURL string
// slurmKeys and slurmSettings offer the Slurm cluster's login; see
// SetSlurm.
slurmKeys SlurmKeys
slurmSettings func() config.SlurmSettings
}
// ServedModels supplies the names the profile page's example should use.
@@ -207,6 +212,7 @@ func (p *AccountPages) Register(mux *http.ServeMux) {
mux.HandleFunc("POST /profile/keys/{id}/revoke", p.selfAudited(p.revokeKey))
mux.HandleFunc("POST /profile/password", p.selfAudited(p.changePassword))
mux.HandleFunc("POST /profile/licences", p.selfAudited(p.setLicences))
mux.HandleFunc("POST /profile/ssh-keys", p.selfAudited(p.setSlurmKeys))
mux.HandleFunc("POST /profile/connect", p.selfAudited(p.connect))
mux.HandleFunc("GET /setup/{tool}", p.setupScript)
mux.HandleFunc("GET /setup/vscode/"+vscodeext.FileName, p.vsix)
@@ -415,6 +421,9 @@ type profileData struct {
Licences *LicenceChoices
LicencesSaved bool
LicenceError string
// Slurm is the person's login to the Slurm cluster and its SSH keys;
// nil unless llmgw makes the cluster's users.
Slurm *slurmView
PasswordChanged bool
PasswordError string
@@ -558,6 +567,7 @@ func (p *AccountPages) render(w http.ResponseWriter, r *http.Request,
d.Keys = keys
p.fillPlaces(r.Context(), langOf(r), user, &d)
p.fillLicences(r.Context(), user.ID, &d)
p.fillSlurm(r.Context(), user, &d)
render(w, r, "profile", d)
}
+9 -1
View File
@@ -188,5 +188,13 @@
"reset.bad": "This link does not work: it was used already, it expired, or a newer one was sent.",
"reset.err.mismatch": "the two passwords are not the same",
"reset.mail.subject": "Set a new password for llmgw",
"reset.mail.body": "Hello %s,\n\nA link to set a new password for your llmgw account was asked for:\n\n%s\n\nIt works once, for %d minutes. If you did not ask for it, ignore this message: your password stays as it is.\n"
"reset.mail.body": "Hello %s,\n\nA link to set a new password for your llmgw account was asked for:\n\n%s\n\nIt works once, for %d minutes. If you did not ask for it, ignore this message: your password stays as it is.\n",
"profile.slurm": "Slurm: login and SSH keys",
"profile.slurm.saved": "Your keys are kept; every machine of the Slurm cluster has them within a minute.",
"profile.slurm.intro": "You are %s (UID %d) on every machine of the Slurm cluster, your home %s. Log in to the controller with one of the keys below and submit jobs there.",
"profile.slurm.keys": "SSH public keys, one a line (as ~/.ssh/id_ed25519.pub)",
"profile.slurm.save": "Save keys",
"profile.slurm.note": "Only the public key: the private one never leaves your computer. An empty box takes every key away.",
"profile.slurm.err_keys": "Not kept: %s.",
"profile.slurm.placeholder": "ssh-ed25519 AAAA… you@laptop"
}
+9 -1
View File
@@ -188,5 +188,13 @@
"reset.bad": "Bu bağlantı çalışmıyor: daha önce kullanılmış, süresi dolmuş ya da daha yenisi gönderilmiş.",
"reset.err.mismatch": "iki şifre aynı değil",
"reset.mail.subject": "llmgw için yeni şifre belirleyin",
"reset.mail.body": "Merhaba %s,\n\nllmgw hesabınız için yeni şifre belirleme bağlantısı istendi:\n\n%s\n\nBir kez ve %d dakika boyunca geçerli. Siz istemediyseniz bu mesajı dikkate almayın: şifreniz değişmez.\n"
"reset.mail.body": "Merhaba %s,\n\nllmgw hesabınız için yeni şifre belirleme bağlantısı istendi:\n\n%s\n\nBir kez ve %d dakika boyunca geçerli. Siz istemediyseniz bu mesajı dikkate almayın: şifreniz değişmez.\n",
"profile.slurm": "Slurm: giriş ve SSH anahtarları",
"profile.slurm.saved": "Anahtarlarınız kaydedildi; Slurm cluster'ının her makinesine bir dakika içinde ulaşır.",
"profile.slurm.intro": "Slurm cluster'ının her makinesinde %s (UID %d) olarak varsınız, ev dizininiz %s. Aşağıdaki anahtarlardan biriyle kontrolcüye bağlanıp işlerinizi oradan gönderin.",
"profile.slurm.keys": "SSH açık anahtarları, satır başına bir tane (~/.ssh/id_ed25519.pub gibi)",
"profile.slurm.save": "Anahtarları kaydet",
"profile.slurm.note": "Yalnızca açık anahtar: gizli anahtar bilgisayarınızdan hiç çıkmaz. Kutuyu boşaltmak bütün anahtarları kaldırır.",
"profile.slurm.err_keys": "Kaydedilmedi: %s.",
"profile.slurm.placeholder": "ssh-ed25519 AAAA… siz@dizüstü"
}
+98
View File
@@ -0,0 +1,98 @@
package web
import (
"context"
"net/http"
"strings"
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
"gitea.mynodes.xyz/ilker/llmgw/internal/slurm"
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
)
// SlurmKeys keeps the SSH keys a person logs in to the Slurm cluster with.
type SlurmKeys interface {
SlurmUserByID(ctx context.Context, userID string) (store.SlurmUser, error)
SetSlurmSSHKeys(ctx context.Context, userID string, keys []string) error
}
// SetSlurm has the profile page offer the Slurm cluster's login and SSH
// keys while settings say llmgw makes its users.
func (p *AccountPages) SetSlurm(keys SlurmKeys, settings func() config.SlurmSettings) {
p.slurmKeys, p.slurmSettings = keys, settings
}
// slurmView is the profile's Slurm part.
type slurmView struct {
Login string
UID int
Home string
// Host is where jobs are submitted: the controller.
Host string
Keys string
Saved bool
Error string
}
// slurmOn is the settings, and whether the page offers the part.
func (p *AccountPages) slurmOn() (config.SlurmSettings, bool) {
if p.slurmKeys == nil || p.slurmSettings == nil {
return config.SlurmSettings{}, false
}
s := p.slurmSettings()
return s, s.Enabled && s.Users == config.UsersLlmgw
}
// fillSlurm puts the person's Slurm login in d, keeping what d says of a
// save.
func (p *AccountPages) fillSlurm(ctx context.Context, user store.User, d *profileData) {
set, on := p.slurmOn()
if !on || !user.CanSignIn() {
return
}
u, err := p.slurmKeys.SlurmUserByID(ctx, user.ID)
if err != nil {
p.log.Error("could not read a person's Slurm login", "user", user.ID, "err", err)
return
}
v := &slurmView{Login: u.Login, UID: u.UID, Home: set.HomeDir(u.Login), Host: set.Controller,
Keys: strings.Join(u.SSHKeys, "\n")}
if d.Slurm != nil {
v.Saved, v.Error = d.Slurm.Saved, d.Slurm.Error
if v.Error != "" {
v.Keys = d.Slurm.Keys
}
}
d.Slurm = v
}
func (p *AccountPages) setSlurmKeys(w http.ResponseWriter, r *http.Request) {
noStore(w)
sess, user, ok := p.session(r)
if !ok {
http.Redirect(w, r, "/login", http.StatusSeeOther)
return
}
if _, on := p.slurmOn(); !on {
http.NotFound(w, r)
return
}
if !p.accounts.CheckCSRF(sess, r.FormValue("csrf")) {
badForm(w, r)
return
}
l := langOf(r)
text := r.FormValue("keys")
keys, err := slurm.ParseSSHKeys(text)
if err != nil {
p.render(w, r, sess, user, profileData{Slurm: &slurmView{Keys: text, Error: l.T("profile.slurm.err_keys", err.Error())}})
return
}
if err := p.slurmKeys.SetSlurmSSHKeys(r.Context(), user.ID, keys); err != nil {
p.log.Error("could not keep a person's SSH keys", "user", user.ID, "err", err)
p.render(w, r, sess, user, profileData{Slurm: &slurmView{Keys: text, Error: l.T("profile.err.try_again")}})
return
}
p.log.Info("a user changed their SSH keys for Slurm", "user", user.ID, "keys", len(keys))
p.render(w, r, sess, user, profileData{Slurm: &slurmView{Saved: true}})
}
+74
View File
@@ -0,0 +1,74 @@
package web
import (
"log/slog"
"net/http"
"net/http/httptest"
"net/url"
"path/filepath"
"strings"
"testing"
"time"
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
)
func TestTheProfileKeepsAPersonsSSHKeysForSlurm(t *testing.T) {
ctx := t.Context()
st, err := store.OpenSQLite(ctx, filepath.Join(t.TempDir(), "s.db"))
if err != nil {
t.Fatal(err)
}
defer st.Close()
ayse := store.User{ID: "usr-a", Email: "ayse@llmt.test", Name: "Ayşe", State: store.UserActive, CreatedAt: time.Now()}
if err := st.CreateUser(ctx, ayse); err != nil {
t.Fatal(err)
}
set := config.SlurmSettings{Enabled: true, Controller: "llmt-1", Users: config.UsersLlmgw,
Shared: config.SharedStorage{Path: "/shared", Server: "llmt-1"}}
p := NewAccountPages(fakeAccounts{user: ayse}, st, nil, "v0", slog.New(slog.DiscardHandler))
p.SetSlurm(st, func() config.SlurmSettings { return set })
mux := http.NewServeMux()
p.Register(mux)
do := func(form url.Values) (int, string) {
req := httptest.NewRequest(http.MethodGet, "/profile", nil)
if form != nil {
form.Set("csrf", "tok")
req = httptest.NewRequest(http.MethodPost, "/profile/ssh-keys", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
req.AddCookie(&http.Cookie{Name: SessionCookie, Value: "good"})
req.AddCookie(&http.Cookie{Name: csrfCookie, Value: "tok"})
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
return rec.Code, rec.Body.String()
}
_, page := do(nil)
for _, want := range []string{`action="/profile/ssh-keys"`, "ssh ayse@llmt-1", "UID 200000", "/shared/home/ayse"} {
if !strings.Contains(page, want) {
t.Errorf("the page lacks %q", want)
}
}
key := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILq3vMdLAKlaDdxwrSgCtP/j/qrF4nzxNBNGuJmK5vxh ayse@laptop"
_, saved := do(url.Values{"keys": {key + "\n"}})
u, _ := st.SlurmUserByID(ctx, ayse.ID)
if len(u.SSHKeys) != 1 || u.SSHKeys[0] != key || !strings.Contains(saved, "within a minute") {
t.Fatalf("kept %v", u.SSHKeys)
}
_, bad := do(url.Values{"keys": {"not a key"}})
if !strings.Contains(bad, "Not kept") || !strings.Contains(bad, "not a key</textarea>") {
t.Error("a bad key was not refused, or the box lost what was typed")
}
if u, _ := st.SlurmUserByID(ctx, ayse.ID); len(u.SSHKeys) != 1 {
t.Error("a refused form changed the keys")
}
// Off: neither the part nor the form.
set.Users = ""
if _, page := do(nil); strings.Contains(page, "ssh-keys") {
t.Error("offered with slurm.users off")
}
if code, _ := do(url.Values{"keys": {key}}); code != http.StatusNotFound {
t.Errorf("posted with slurm.users off: %d", code)
}
}
+15
View File
@@ -232,6 +232,21 @@ document.addEventListener("click", (e) => {
<p class="note">{{t "profile.licences.note"}}</p>
{{end}}
{{with .Slurm}}
<h2 id="slurm">{{t "profile.slurm"}}</h2>
{{if .Saved}}<p>{{t "profile.slurm.saved"}}</p>{{end}}
{{if .Error}}<p class="error">{{.Error}}</p>{{end}}
{{if .Login}}<p class="note">{{t "profile.slurm.intro" .Login .UID .Home}}</p>
<pre><code>ssh {{.Login}}@{{.Host}}
sbatch job.sh</code></pre>{{end}}
<form method="post" action="/profile/ssh-keys" class="narrow">
<input type="hidden" name="csrf" value="{{$.CSRF}}">
<label>{{t "profile.slurm.keys"}}<textarea name="keys" rows="4" spellcheck="false" autocomplete="off" placeholder="{{t "profile.slurm.placeholder"}}">{{.Keys}}</textarea></label>
<button type="submit">{{t "profile.slurm.save"}}</button>
</form>
<p class="note">{{t "profile.slurm.note"}}</p>
{{end}}
<h2>{{t "profile.password"}}</h2>
{{if .PasswordChanged}}<p>{{t "profile.password_changed"}}</p>{{end}}
{{if .PasswordError}}<p class="error">{{.PasswordError}}</p>{{end}}