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>
99 lines
2.9 KiB
Go
99 lines
2.9 KiB
Go
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}})
|
|
}
|