feat(api): let owners audit all api tokens and cap their lifetime
Holders of tokens.manage list every token of the org with owner, permissions, creation, expiry and last use, and can revoke any of them. A maximum lifetime rejects tokens that would outlive it and shortens existing ones when it is set. Closes #48 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
da128c5081
commit
b52698ffbc
9 files changed
+674
-296
No files matched your search
+15
-2
@@ -429,6 +429,9 @@ func (s *Server) roleResult(c *gin.Context, err error, code string, ok func()) {
|
||||
type policyRequest struct {
|
||||
RequireTOTP bool `json:"require_totp"`
|
||||
RequireSSO bool `json:"require_sso"`
|
||||
// APITokenMaxDays limits how long API tokens stay valid; 0 or null
|
||||
// means no limit.
|
||||
APITokenMaxDays *int `json:"api_token_max_days" binding:"omitempty,min=0,max=3650"`
|
||||
}
|
||||
|
||||
func (s *Server) updatePolicy(c *gin.Context) {
|
||||
@@ -457,8 +460,18 @@ func (s *Server) updatePolicy(c *gin.Context) {
|
||||
return errNoSSOProvider
|
||||
}
|
||||
}
|
||||
var maxDays *int32
|
||||
if req.APITokenMaxDays != nil && *req.APITokenMaxDays > 0 {
|
||||
maxDays = ptr(int32(*req.APITokenMaxDays))
|
||||
}
|
||||
var err error
|
||||
org, err = q.UpdateOrgPolicy(ctx, store.UpdateOrgPolicyParams{ID: p.Org.ID, RequireTotp: req.RequireTOTP, RequireSso: req.RequireSSO})
|
||||
org, err = q.UpdateOrgPolicy(ctx, store.UpdateOrgPolicyParams{
|
||||
ID: p.Org.ID, RequireTotp: req.RequireTOTP, RequireSso: req.RequireSSO, ApiTokenMaxDays: maxDays,
|
||||
})
|
||||
if err != nil || maxDays == nil {
|
||||
return err
|
||||
}
|
||||
_, err = q.ClampAPITokenExpiry(ctx, store.ClampAPITokenExpiryParams{OrgID: p.Org.ID, MaxDays: *maxDays})
|
||||
return err
|
||||
})
|
||||
if errors.Is(err, errNoSSOProvider) {
|
||||
@@ -469,7 +482,7 @@ func (s *Server) updatePolicy(c *gin.Context) {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"require_totp": org.RequireTotp, "require_sso": org.RequireSso})
|
||||
c.JSON(http.StatusOK, gin.H{"require_totp": org.RequireTotp, "require_sso": org.RequireSso, "api_token_max_days": org.ApiTokenMaxDays})
|
||||
}
|
||||
|
||||
var errNoSSOProvider = errors.New("api: no enabled sso provider")
|
||||
+36
-4
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -268,7 +269,11 @@ func (s *Server) ssoSettingsView(c *gin.Context, p *principal, page web.Page, me
|
||||
}
|
||||
|
||||
func (s *Server) orgSettingsView(_ *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
|
||||
return web.OrgSettingsPage(page, me, web.OrgSettings{RequireTOTP: p.Org.RequireTotp, RequireSSO: p.Org.RequireSso}), nil
|
||||
v := web.OrgSettings{RequireTOTP: p.Org.RequireTotp, RequireSSO: p.Org.RequireSso}
|
||||
if p.Org.ApiTokenMaxDays != nil {
|
||||
v.TokenMaxDays = int(*p.Org.ApiTokenMaxDays)
|
||||
}
|
||||
return web.OrgSettingsPage(page, me, v), nil
|
||||
}
|
||||
|
||||
func (s *Server) membersView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
|
||||
@@ -337,7 +342,7 @@ func (s *Server) rolesView(c *gin.Context, p *principal, page web.Page, me web.M
|
||||
|
||||
func (s *Server) tokensView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
|
||||
ctx := c.Request.Context()
|
||||
showAll := p.Grants.Can(authz.MembersManage)
|
||||
showAll := p.Grants.Can(authz.TokensManage)
|
||||
var filter *uuid.UUID
|
||||
if !showAll {
|
||||
filter = &p.UserID
|
||||
@@ -351,10 +356,17 @@ func (s *Server) tokensView(c *gin.Context, p *principal, page web.Page, me web.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v := web.TokensView{Grantable: grantable(p), ShowOwner: showAll}
|
||||
v := web.TokensView{Grantable: grantable(p), ShowOwner: showAll, ExpiryDays: expiryChoices(p.Org.ApiTokenMaxDays)}
|
||||
if p.Org.ApiTokenMaxDays != nil {
|
||||
v.MaxDays = int(*p.Org.ApiTokenMaxDays)
|
||||
}
|
||||
never := i18n.T(ctx, "tokens.never")
|
||||
for _, r := range rows {
|
||||
t := web.Token{ID: r.ID.String(), Name: r.Name, Prefix: r.Prefix, UserEmail: r.UserEmail, Permissions: r.Permissions, ExpiresAt: never, LastUsedAt: "–"}
|
||||
t := web.Token{
|
||||
ID: r.ID.String(), Name: r.Name, Prefix: r.Prefix, UserEmail: r.UserEmail,
|
||||
Permissions: authz.NewSet(r.Permissions...).Strings(), CreatedAt: r.CreatedAt.Format(time.DateOnly),
|
||||
ExpiresAt: never, LastUsedAt: "–",
|
||||
}
|
||||
if r.ExpiresAt != nil {
|
||||
t.ExpiresAt = r.ExpiresAt.Format(time.DateOnly)
|
||||
}
|
||||
@@ -366,6 +378,26 @@ func (s *Server) tokensView(c *gin.Context, p *principal, page web.Page, me web.
|
||||
return web.TokensPage(page, me, v), nil
|
||||
}
|
||||
|
||||
// expiryChoices returns the token lifetimes to offer, in days, honoring the
|
||||
// org's limit. 0 stands for no expiry and is only offered without a limit.
|
||||
func expiryChoices(limit *int32) []int {
|
||||
defaults := []int{90, 30, 365, 0}
|
||||
if limit == nil {
|
||||
return defaults
|
||||
}
|
||||
max := int(*limit)
|
||||
var out []int
|
||||
for _, d := range defaults {
|
||||
if d > 0 && d <= max {
|
||||
out = append(out, d)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(out, max) {
|
||||
out = append(out, max)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func toWebMe(m meView) web.Me {
|
||||
out := web.Me{
|
||||
Email: m.Email,
|
||||
|
||||
@@ -209,3 +209,68 @@ func TestPermissions(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestTokenOversightAndLifetimePolicy(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
domain := uniq("t") + ".test"
|
||||
owner := e.browser(t)
|
||||
owner.signup("owner@"+domain, uniq("tok-"))
|
||||
editor := e.joinVia(t, owner.invite("editor@"+domain, owner.roleID("editor")))
|
||||
|
||||
st, body := editor.do("POST", "/api/v1/org/tokens", map[string]any{"name": "forever", "permissions": []string{"monitors.read"}})
|
||||
expect(t, "editor creates non-expiring token", st, body, http.StatusCreated, "")
|
||||
editorTokenID := body["id"].(string)
|
||||
api := &browser{t: t, base: editor.base, hc: e.srv.Client(), bearer: body["token"].(string)}
|
||||
owner.do("POST", "/api/v1/org/tokens", map[string]any{"name": "own", "permissions": []string{"monitors.read"}})
|
||||
|
||||
tokenNames := func(b *browser) []string {
|
||||
_, body := b.do("GET", "/api/v1/org/tokens", nil)
|
||||
var names []string
|
||||
for _, tk := range body["tokens"].([]any) {
|
||||
names = append(names, tk.(map[string]any)["name"].(string))
|
||||
}
|
||||
return names
|
||||
}
|
||||
if got := tokenNames(owner); len(got) != 2 {
|
||||
t.Errorf("owner sees tokens %v, want both", got)
|
||||
}
|
||||
if got := tokenNames(editor); len(got) != 1 || got[0] != "forever" {
|
||||
t.Errorf("editor sees tokens %v, want only own", got)
|
||||
}
|
||||
|
||||
st, body = owner.do("PUT", "/api/v1/org/policy", map[string]any{"api_token_max_days": 30})
|
||||
expect(t, "set lifetime policy", st, body, http.StatusOK, "")
|
||||
_, list := owner.do("GET", "/api/v1/org/tokens", nil)
|
||||
for _, tk := range list["tokens"].([]any) {
|
||||
tk := tk.(map[string]any)
|
||||
exp, _ := time.Parse(time.RFC3339Nano, fmtString(tk["expires_at"]))
|
||||
if exp.IsZero() || exp.After(time.Now().Add(31*24*time.Hour)) {
|
||||
t.Errorf("token %v expires_at = %v, want within 30 days", tk["name"], tk["expires_at"])
|
||||
}
|
||||
}
|
||||
|
||||
for _, days := range []int{0, 31} {
|
||||
st, body = editor.do("POST", "/api/v1/org/tokens", map[string]any{"name": "x", "permissions": []string{"monitors.read"}, "expires_in_days": days})
|
||||
expect(t, "token beyond policy", st, body, http.StatusUnprocessableEntity, "token_lifetime_exceeds_policy")
|
||||
}
|
||||
st, body = editor.do("POST", "/api/v1/org/tokens", map[string]any{"name": "ok", "permissions": []string{"monitors.read"}, "expires_in_days": 30})
|
||||
expect(t, "token within policy", st, body, http.StatusCreated, "")
|
||||
|
||||
st, body = owner.do("DELETE", "/api/v1/org/tokens/"+editorTokenID, nil)
|
||||
expect(t, "owner revokes editor token", st, body, http.StatusNoContent, "")
|
||||
st, body = api.do("GET", "/api/v1/org/tokens", nil)
|
||||
expect(t, "revoked token", st, body, http.StatusUnauthorized, "unauthenticated")
|
||||
|
||||
st, body = owner.do("PUT", "/api/v1/org/policy", map[string]any{"api_token_max_days": 0})
|
||||
if st != http.StatusOK || body["api_token_max_days"] != nil {
|
||||
t.Errorf("clear lifetime policy = %d %v, want 200 with null", st, body)
|
||||
}
|
||||
if got := owner.visit("/settings/tokens"); got.Path != "/settings/tokens" {
|
||||
t.Errorf("tokens page ended at %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func fmtString(v any) string {
|
||||
s, _ := v.(string)
|
||||
return s
|
||||
}
|
||||
+10
-5
@@ -98,10 +98,10 @@ type tokenView struct {
|
||||
func (s *Server) listTokens(c *gin.Context) {
|
||||
p := current(c)
|
||||
ctx := c.Request.Context()
|
||||
// Members see their own tokens; members.manage reveals everyone's so
|
||||
// tokens of departing staff can be revoked.
|
||||
// Members see their own tokens; tokens.manage reveals everyone's so the
|
||||
// owner can audit and revoke them.
|
||||
var filter *uuid.UUID
|
||||
if !p.Grants.Can(authz.MembersManage) {
|
||||
if !p.Grants.Can(authz.TokensManage) {
|
||||
filter = &p.UserID
|
||||
}
|
||||
var rows []store.ListAPITokensRow
|
||||
@@ -127,7 +127,8 @@ func (s *Server) listTokens(c *gin.Context) {
|
||||
type createTokenRequest struct {
|
||||
Name string `json:"name" binding:"required,max=100"`
|
||||
Permissions []string `json:"permissions" binding:"required,min=1,max=50,dive,max=50"`
|
||||
// ExpiresInDays of 0 creates a token that does not expire.
|
||||
// ExpiresInDays of 0 creates a token that does not expire, unless the
|
||||
// org limits token lifetime.
|
||||
ExpiresInDays int `json:"expires_in_days" binding:"min=0,max=3650"`
|
||||
}
|
||||
|
||||
@@ -146,6 +147,10 @@ func (s *Server) createToken(c *gin.Context) {
|
||||
fail(c, http.StatusForbidden, "permission_escalation")
|
||||
return
|
||||
}
|
||||
if limit := p.Org.ApiTokenMaxDays; limit != nil && (req.ExpiresInDays == 0 || req.ExpiresInDays > int(*limit)) {
|
||||
fail(c, http.StatusUnprocessableEntity, "token_lifetime_exceeds_policy", "Count", int(*limit))
|
||||
return
|
||||
}
|
||||
var expires *time.Time
|
||||
if req.ExpiresInDays > 0 {
|
||||
t := time.Now().AddDate(0, 0, req.ExpiresInDays)
|
||||
@@ -187,7 +192,7 @@ func (s *Server) deleteToken(c *gin.Context) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if row.UserID != p.UserID && !p.Grants.Can(authz.MembersManage) {
|
||||
if row.UserID != p.UserID && !p.Grants.Can(authz.TokensManage) {
|
||||
return nil
|
||||
}
|
||||
found = true
|
||||
|
||||
@@ -183,6 +183,9 @@ func TestT(t *testing.T) {
|
||||
t.Errorf("T(de, recovery.left, %d) = %q, want %q", n, got, want)
|
||||
}
|
||||
}
|
||||
if got, want := T(ctx, "error.token_lifetime_exceeds_policy", "Count", 30), "Tokens in dieser Organisation müssen innerhalb von 30 Tagen ablaufen."; got != want {
|
||||
t.Errorf("T(de, token_lifetime_exceeds_policy, 30) = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := T(ctx, "no.such.key"), "no.such.key"; got != want {
|
||||
t.Errorf("T(missing) = %q, want %q", got, want)
|
||||
}
|
||||
|
||||
@@ -76,6 +76,10 @@
|
||||
"error.sso_provider_error": "Der Identity Provider konnte die Anmeldung nicht abschließen.",
|
||||
"error.sso_required_by_org": "Diese Organisation verlangt die Anmeldung über ihren SSO-Provider.",
|
||||
"error.sso_unavailable": "Für diese Organisation ist kein Single Sign-on verfügbar.",
|
||||
"error.token_lifetime_exceeds_policy": {
|
||||
"one": "Tokens in dieser Organisation müssen innerhalb von {{.Count}} Tag ablaufen.",
|
||||
"other": "Tokens in dieser Organisation müssen innerhalb von {{.Count}} Tagen ablaufen."
|
||||
},
|
||||
"error.totp_already_enabled": "TOTP ist bereits aktiv.",
|
||||
"error.totp_required_by_org": "Eine deiner Organisationen verlangt TOTP.",
|
||||
"error.totp_setup_expired": "Einrichtung abgelaufen, bitte neu starten.",
|
||||
@@ -108,6 +112,9 @@
|
||||
"org.require_totp": "Zwei-Faktor-Anmeldung verlangen",
|
||||
"org.require_totp_hint": "Mitglieder, die sich mit Passwort anmelden, brauchen TOTP. Bei SSO-Anmeldungen ist die MFA des Identity Providers zuständig.",
|
||||
"org.title": "Organisation",
|
||||
"org.token_max_days": "Maximale Gültigkeit von API-Tokens (Tage)",
|
||||
"org.token_max_days_hint": "Neue Tokens müssen innerhalb dieses Zeitraums ablaufen. Beim Speichern werden bestehende Tokens gekürzt, die länger gelten würden. Leer lassen für keine Begrenzung.",
|
||||
"org.token_max_days_none": "unbegrenzt",
|
||||
"perm.incidents.read": "Incidents sehen",
|
||||
"perm.incidents.write": "Incidents verwalten",
|
||||
"perm.members.manage": "Mitglieder einladen und verwalten",
|
||||
@@ -120,6 +127,7 @@
|
||||
"perm.roles.manage": "Eigene Rollen verwalten",
|
||||
"perm.statuspages.read": "Statuspages sehen",
|
||||
"perm.statuspages.write": "Statuspages bearbeiten",
|
||||
"perm.tokens.manage": "Alle API-Tokens sehen und widerrufen",
|
||||
"roles.built_in": "eingebaut",
|
||||
"roles.create": "Rolle anlegen",
|
||||
"roles.delete": "Rolle löschen",
|
||||
@@ -171,15 +179,22 @@
|
||||
"sso.settings.title": "Single Sign-on",
|
||||
"tokens.copy_now": "Kopiere den Token jetzt. Er wird nicht erneut angezeigt.",
|
||||
"tokens.create": "Token erstellen",
|
||||
"tokens.created": "Erstellt",
|
||||
"tokens.days": {
|
||||
"one": "{{.Count}} Tag",
|
||||
"other": "{{.Count}} Tage"
|
||||
},
|
||||
"tokens.expires": "Läuft ab",
|
||||
"tokens.intro": "Tokens handeln in deinem Namen in dieser Organisation. Sie haben nie mehr Rechte als du selbst, auch wenn deine Rechte später schrumpfen.",
|
||||
"tokens.intro_all": "Du siehst alle API-Tokens dieser Organisation und kannst jeden davon widerrufen. Tokens haben nie mehr Rechte als ihr Inhaber.",
|
||||
"tokens.last_used": "Zuletzt genutzt",
|
||||
"tokens.never": "nie",
|
||||
"tokens.owner": "Inhaber",
|
||||
"tokens.permissions": "Berechtigungen",
|
||||
"tokens.policy": {
|
||||
"one": "Diese Organisation begrenzt API-Tokens auf {{.Count}} Tag.",
|
||||
"other": "Diese Organisation begrenzt API-Tokens auf {{.Count}} Tage."
|
||||
},
|
||||
"tokens.revoke_confirm": "Diesen Token widerrufen? Anfragen damit schlagen sofort fehl.",
|
||||
"tokens.title": "API-Tokens"
|
||||
}
|
||||
@@ -76,6 +76,10 @@
|
||||
"error.sso_provider_error": "The identity provider could not complete the sign-in.",
|
||||
"error.sso_required_by_org": "This organization requires signing in through its SSO provider.",
|
||||
"error.sso_unavailable": "Single sign-on is not available for this organization.",
|
||||
"error.token_lifetime_exceeds_policy": {
|
||||
"one": "Tokens in this organization must expire within {{.Count}} day.",
|
||||
"other": "Tokens in this organization must expire within {{.Count}} days."
|
||||
},
|
||||
"error.totp_already_enabled": "TOTP is already active.",
|
||||
"error.totp_required_by_org": "One of your organizations requires TOTP.",
|
||||
"error.totp_setup_expired": "Setup expired, please start again.",
|
||||
@@ -108,6 +112,9 @@
|
||||
"org.require_totp": "Require two-factor sign-in",
|
||||
"org.require_totp_hint": "Members signing in with a password need TOTP. SSO sign-ins rely on the identity provider's MFA.",
|
||||
"org.title": "Organization",
|
||||
"org.token_max_days": "Maximum API token lifetime (days)",
|
||||
"org.token_max_days_hint": "New tokens must expire within this period. Saving shortens existing tokens that would outlive it. Leave empty for no limit.",
|
||||
"org.token_max_days_none": "unlimited",
|
||||
"perm.incidents.read": "View incidents",
|
||||
"perm.incidents.write": "Manage incidents",
|
||||
"perm.members.manage": "Invite and manage members",
|
||||
@@ -120,6 +127,7 @@
|
||||
"perm.roles.manage": "Manage custom roles",
|
||||
"perm.statuspages.read": "View status pages",
|
||||
"perm.statuspages.write": "Edit status pages",
|
||||
"perm.tokens.manage": "View and revoke all API tokens",
|
||||
"roles.built_in": "built-in",
|
||||
"roles.create": "Create role",
|
||||
"roles.delete": "Delete role",
|
||||
@@ -171,15 +179,22 @@
|
||||
"sso.settings.title": "Single sign-on",
|
||||
"tokens.copy_now": "Copy the token now. It will not be shown again.",
|
||||
"tokens.create": "Create token",
|
||||
"tokens.created": "Created",
|
||||
"tokens.days": {
|
||||
"one": "{{.Count}} day",
|
||||
"other": "{{.Count}} days"
|
||||
},
|
||||
"tokens.expires": "Expires",
|
||||
"tokens.intro": "Tokens act on your behalf in this organization. They never exceed your own permissions, even if those shrink later.",
|
||||
"tokens.intro_all": "You see every API token in this organization and can revoke any of them. Tokens never exceed their owner's permissions.",
|
||||
"tokens.last_used": "Last used",
|
||||
"tokens.never": "never",
|
||||
"tokens.owner": "Owner",
|
||||
"tokens.permissions": "Permissions",
|
||||
"tokens.policy": {
|
||||
"one": "This organization limits API tokens to {{.Count}} day.",
|
||||
"other": "This organization limits API tokens to {{.Count}} days."
|
||||
},
|
||||
"tokens.revoke_confirm": "Revoke this token? Requests using it fail immediately.",
|
||||
"tokens.title": "API tokens"
|
||||
}
|
||||
+60
-9
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
@@ -257,6 +258,7 @@ type Token struct {
|
||||
Prefix string
|
||||
UserEmail string
|
||||
Permissions []string
|
||||
CreatedAt string
|
||||
ExpiresAt string
|
||||
LastUsedAt string
|
||||
}
|
||||
@@ -265,12 +267,25 @@ type Token struct {
|
||||
type TokensView struct {
|
||||
Tokens []Token
|
||||
Grantable []string
|
||||
// ShowOwner is set when the viewer oversees all tokens of the org.
|
||||
ShowOwner bool
|
||||
// MaxDays is the org's token lifetime limit, 0 if none.
|
||||
MaxDays int
|
||||
// ExpiryDays are the lifetimes offered when creating a token; 0 means
|
||||
// no expiry.
|
||||
ExpiryDays []int
|
||||
}
|
||||
|
||||
templ TokensPage(p Page, me Me, v TokensView) {
|
||||
@consoleShell(p, me) {
|
||||
@settingsHeading("tokens.title", "tokens.intro")
|
||||
if v.ShowOwner {
|
||||
@settingsHeading("tokens.title", "tokens.intro_all")
|
||||
} else {
|
||||
@settingsHeading("tokens.title", "tokens.intro")
|
||||
}
|
||||
if v.MaxDays > 0 {
|
||||
<p class="-mt-4 mb-8 text-sm">{ i18n.T(ctx, "tokens.policy", "Count", v.MaxDays) }</p>
|
||||
}
|
||||
if len(v.Tokens) > 0 {
|
||||
<table class="mb-12 w-full text-left text-sm">
|
||||
<thead class="border-b border-rule text-xs uppercase tracking-wider text-muted">
|
||||
@@ -279,6 +294,8 @@ templ TokensPage(p Page, me Me, v TokensView) {
|
||||
if v.ShowOwner {
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "tokens.owner") }</th>
|
||||
}
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "tokens.permissions") }</th>
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "tokens.created") }</th>
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "tokens.expires") }</th>
|
||||
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "tokens.last_used") }</th>
|
||||
<th class="py-2"></th>
|
||||
@@ -286,13 +303,21 @@ templ TokensPage(p Page, me Me, v TokensView) {
|
||||
</thead>
|
||||
<tbody class="divide-y divide-rule">
|
||||
for _, t := range v.Tokens {
|
||||
<tr>
|
||||
<tr class="align-top">
|
||||
<td class="py-2.5 pr-4">{ t.Name } <span class="block font-mono text-xs text-muted">{ t.Prefix }…</span></td>
|
||||
if v.ShowOwner {
|
||||
<td class="py-2.5 pr-4">{ t.UserEmail }</td>
|
||||
}
|
||||
<td class="py-2.5 pr-4 font-mono text-xs">{ t.ExpiresAt }</td>
|
||||
<td class="py-2.5 pr-4 font-mono text-xs">{ t.LastUsedAt }</td>
|
||||
<td class="py-2.5 pr-4">
|
||||
<ul class="flex max-w-xs flex-wrap gap-1 text-xs">
|
||||
for _, perm := range t.Permissions {
|
||||
<li class="border border-rule px-1 py-px">{ i18n.T(ctx, "perm."+perm) }</li>
|
||||
}
|
||||
</ul>
|
||||
</td>
|
||||
<td class="py-2.5 pr-4 whitespace-nowrap font-mono text-xs">{ t.CreatedAt }</td>
|
||||
<td class="py-2.5 pr-4 whitespace-nowrap font-mono text-xs">{ t.ExpiresAt }</td>
|
||||
<td class="py-2.5 pr-4 whitespace-nowrap font-mono text-xs">{ t.LastUsedAt }</td>
|
||||
<td class="py-2.5 text-right">
|
||||
<button
|
||||
type="button"
|
||||
@@ -315,10 +340,13 @@ templ TokensPage(p Page, me Me, v TokensView) {
|
||||
<label class="mb-4 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "tokens.expires") }</span>
|
||||
<select name="expires_in_days" data-number class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
|
||||
<option value="30">{ i18n.T(ctx, "tokens.days", "Count", 30) }</option>
|
||||
<option value="90" selected>{ i18n.T(ctx, "tokens.days", "Count", 90) }</option>
|
||||
<option value="365">{ i18n.T(ctx, "tokens.days", "Count", 365) }</option>
|
||||
<option value="0">{ i18n.T(ctx, "tokens.never") }</option>
|
||||
for i, d := range v.ExpiryDays {
|
||||
if d == 0 {
|
||||
<option value="0">{ i18n.T(ctx, "tokens.never") }</option>
|
||||
} else {
|
||||
<option value={ strconv.Itoa(d) } selected?={ i == 0 }>{ i18n.T(ctx, "tokens.days", "Count", d) }</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
@submit(i18n.T(ctx, "tokens.create"))
|
||||
@@ -335,6 +363,8 @@ templ TokensPage(p Page, me Me, v TokensView) {
|
||||
type OrgSettings struct {
|
||||
RequireTOTP bool
|
||||
RequireSSO bool
|
||||
// TokenMaxDays is 0 when API token lifetime is unlimited.
|
||||
TokenMaxDays int
|
||||
}
|
||||
|
||||
templ OrgSettingsPage(p Page, me Me, v OrgSettings) {
|
||||
@@ -347,7 +377,21 @@ templ OrgSettingsPage(p Page, me Me, v OrgSettings) {
|
||||
@checkbox(i18n.T(ctx, "org.require_totp"), "require_totp", v.RequireTOTP)
|
||||
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "org.require_totp_hint") }</p>
|
||||
@checkbox(i18n.T(ctx, "org.require_sso"), "require_sso", v.RequireSSO)
|
||||
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "org.require_sso_hint") }</p>
|
||||
<p class="mb-6 ml-6 text-xs text-muted">{ i18n.T(ctx, "org.require_sso_hint") }</p>
|
||||
<label class="mb-1 block">
|
||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "org.token_max_days") }</span>
|
||||
<input
|
||||
type="number"
|
||||
name="api_token_max_days"
|
||||
data-number
|
||||
min="0"
|
||||
max="3650"
|
||||
value={ maxDaysValue(v.TokenMaxDays) }
|
||||
placeholder={ i18n.T(ctx, "org.token_max_days_none") }
|
||||
class="w-40 border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
|
||||
/>
|
||||
</label>
|
||||
<p class="mb-6 text-xs text-muted">{ i18n.T(ctx, "org.token_max_days_hint") }</p>
|
||||
@submit(i18n.T(ctx, "common.save"))
|
||||
</form>
|
||||
</section>
|
||||
@@ -394,3 +438,10 @@ templ InvitationPage(p Page, v Invitation) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func maxDaysValue(d int) string {
|
||||
if d == 0 {
|
||||
return ""
|
||||
}
|
||||
return strconv.Itoa(d)
|
||||
}
|
||||
+455
-276
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user