Skip to content

Commit 65964a4

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Allow options to disable user ssh keys configuration from the interface on app.ini (go-gitea#29447) Inline the `css-variables-parser` dependency (go-gitea#29571)
2 parents ad08bad + 8e12ba3 commit 65964a4

File tree

10 files changed

+63
-47
lines changed

10 files changed

+63
-47
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,8 +1480,9 @@ LEVEL = Info
14801480
;;
14811481
;; Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
14821482
;DEFAULT_EMAIL_NOTIFICATIONS = enabled
1483-
;; Disabled features for users, could be "deletion","manage_gpg_keys" more features can be disabled in future
1483+
;; Disabled features for users, could be "deletion", "manage_ssh_keys","manage_gpg_keys" more features can be disabled in future
14841484
;; - deletion: a user cannot delete their own account
1485+
;; - manage_ssh_keys: a user cannot configure ssh keys
14851486
;; - manage_gpg_keys: a user cannot configure gpg keys
14861487
;USER_DISABLED_FEATURES =
14871488

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,10 @@ And the following unique queues:
518518

519519
- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**: Default configuration for email notifications for users (user configurable). Options: enabled, onmention, disabled
520520
- `DISABLE_REGULAR_ORG_CREATION`: **false**: Disallow regular (non-admin) users from creating organizations.
521-
- `USER_DISABLED_FEATURES`: **_empty_** Disabled features for users, could be `deletion`, `manage_gpg_keys` and more features can be added in future.
521+
- `USER_DISABLED_FEATURES`: **_empty_** Disabled features for users, could be `deletion`, `manage_ssh_keys`, `manage_gpg_keys` and more features can be added in future.
522522
- `deletion`: User cannot delete their own account.
523-
- `manage_gpg_keys`: User cannot configure gpg keys
523+
- `manage_ssh_keys`: User cannot configure ssh keys.
524+
- `manage_gpg_keys`: User cannot configure gpg keys.
524525

525526
## Security (`security`)
526527

docs/content/administration/config-cheat-sheet.zh-cn.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,10 @@ Gitea 创建以下非唯一队列:
497497

498498
- `DEFAULT_EMAIL_NOTIFICATIONS`: **enabled**:用户电子邮件通知的默认配置(用户可配置)。选项:enabled、onmention、disabled
499499
- `DISABLE_REGULAR_ORG_CREATION`: **false**:禁止普通(非管理员)用户创建组织。
500-
- `USER_DISABLED_FEATURES`:**_empty_** 禁用的用户特性,当前允许为空或者 `deletion``manage_gpg_keys` 未来可以增加更多设置。
500+
- `USER_DISABLED_FEATURES`:**_empty_** 禁用的用户特性,当前允许为空或者 `deletion``manage_ssh_keys``manage_gpg_keys` 未来可以增加更多设置。
501501
- `deletion`: 用户不能通过界面或者API删除他自己。
502-
- `manage_gpg_keys`: 用户不能配置 GPG 密钥
502+
- `manage_ssh_keys`: 用户不能通过界面或者API配置SSH Keys。
503+
- `manage_gpg_keys`: 用户不能配置 GPG 密钥。
503504

504505
## 安全性 (`security`)
505506

modules/setting/admin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ func loadAdminFrom(rootCfg ConfigProvider) {
2121

2222
const (
2323
UserFeatureDeletion = "deletion"
24+
UserFeatureManageSSHKeys = "manage_ssh_keys"
2425
UserFeatureManageGPGKeys = "manage_gpg_keys"
2526
)

package-lock.json

Lines changed: 0 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"chartjs-plugin-zoom": "2.0.1",
2424
"clippie": "4.0.7",
2525
"css-loader": "6.10.0",
26-
"css-variables-parser": "1.0.1",
2726
"dayjs": "1.11.10",
2827
"dropzone": "6.0.0-beta.2",
2928
"easymde": "2.18.0",

routers/api/v1/user/key.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package user
55

66
import (
77
std_ctx "context"
8+
"fmt"
89
"net/http"
910

1011
asymkey_model "code.gitea.io/gitea/models/asymkey"
@@ -198,6 +199,11 @@ func GetPublicKey(ctx *context.APIContext) {
198199

199200
// CreateUserPublicKey creates new public key to given user by ID.
200201
func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid int64) {
202+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageSSHKeys) {
203+
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
204+
return
205+
}
206+
201207
content, err := asymkey_model.CheckPublicKeyString(form.Key)
202208
if err != nil {
203209
repo.HandleCheckKeyStringError(ctx, err)
@@ -263,6 +269,11 @@ func DeletePublicKey(ctx *context.APIContext) {
263269
// "404":
264270
// "$ref": "#/responses/notFound"
265271

272+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageSSHKeys) {
273+
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
274+
return
275+
}
276+
266277
id := ctx.ParamsInt64(":id")
267278
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id)
268279
if err != nil {

routers/web/user/setting/keys.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ func KeysPost(ctx *context.Context) {
159159
ctx.Flash.Success(ctx.Tr("settings.verify_gpg_key_success", keyID))
160160
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
161161
case "ssh":
162+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageSSHKeys) {
163+
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
164+
return
165+
}
166+
162167
content, err := asymkey_model.CheckPublicKeyString(form.Content)
163168
if err != nil {
164169
if db.IsErrSSHDisabled(err) {
@@ -198,6 +203,11 @@ func KeysPost(ctx *context.Context) {
198203
ctx.Flash.Success(ctx.Tr("settings.add_key_success", form.Title))
199204
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
200205
case "verify_ssh":
206+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageSSHKeys) {
207+
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
208+
return
209+
}
210+
201211
token := asymkey_model.VerificationToken(ctx.Doer, 1)
202212
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
203213

@@ -240,6 +250,11 @@ func DeleteKey(ctx *context.Context) {
240250
ctx.Flash.Success(ctx.Tr("settings.gpg_key_deletion_success"))
241251
}
242252
case "ssh":
253+
if setting.Admin.UserDisabledFeatures.Contains(setting.UserFeatureManageSSHKeys) {
254+
ctx.NotFound("Not Found", fmt.Errorf("ssh keys setting is not allowed to be visited"))
255+
return
256+
}
257+
243258
keyID := ctx.FormInt64("id")
244259
external, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, keyID)
245260
if err != nil {
@@ -318,4 +333,5 @@ func loadKeysData(ctx *context.Context) {
318333

319334
ctx.Data["VerifyingID"] = ctx.FormString("verify_gpg")
320335
ctx.Data["VerifyingFingerprint"] = ctx.FormString("verify_ssh")
336+
ctx.Data["UserDisabledFeatures"] = &setting.Admin.UserDisabledFeatures
321337
}

tailwind.config.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
import {readFileSync} from 'node:fs';
22
import {env} from 'node:process';
3-
import {parse} from 'css-variables-parser';
3+
import {parse} from 'postcss';
44

55
const isProduction = env.NODE_ENV !== 'development';
66

7+
function extractRootVars(css) {
8+
const root = parse(css);
9+
const vars = new Set();
10+
root.walkRules((rule) => {
11+
if (rule.selector !== ':root') return;
12+
rule.each((decl) => {
13+
if (decl.value && decl.prop.startsWith('--')) {
14+
vars.add(decl.prop.substring(2));
15+
}
16+
});
17+
});
18+
return Array.from(vars);
19+
}
20+
21+
const vars = extractRootVars([
22+
readFileSync(new URL('web_src/css/themes/theme-gitea-light.css', import.meta.url), 'utf8'),
23+
readFileSync(new URL('web_src/css/themes/theme-gitea-dark.css', import.meta.url), 'utf8'),
24+
].join('\n'));
25+
726
export default {
827
prefix: 'tw-',
928
important: true, // the frameworks are mixed together, so tailwind needs to override other framework's styles
@@ -23,15 +42,10 @@ export default {
2342
theme: {
2443
colors: {
2544
// make `tw-bg-red` etc work with our CSS variables
26-
...Object.fromEntries(
27-
Object.keys(parse([
28-
readFileSync(new URL('web_src/css/themes/theme-gitea-light.css', import.meta.url), 'utf8'),
29-
readFileSync(new URL('web_src/css/themes/theme-gitea-dark.css', import.meta.url), 'utf8'),
30-
].join('\n'), {})).filter((prop) => prop.startsWith('color-')).map((prop) => {
31-
const color = prop.substring(6);
32-
return [color, `var(--color-${color})`];
33-
})
34-
),
45+
...Object.fromEntries(vars.filter((prop) => prop.startsWith('color-')).map((prop) => {
46+
const color = prop.substring(6);
47+
return [color, `var(--color-${color})`];
48+
})),
3549
inherit: 'inherit',
3650
current: 'currentcolor',
3751
transparent: 'transparent',

templates/user/settings/keys.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{template "user/settings/layout_head" (dict "ctxData" . "pageClass" "user settings sshkeys")}}
22
<div class="user-setting-content">
3-
{{template "user/settings/keys_ssh" .}}
3+
{{if not ($.UserDisabledFeatures.Contains "manage_ssh_keys")}}
4+
{{template "user/settings/keys_ssh" .}}
5+
{{end}}
46
{{template "user/settings/keys_principal" .}}
57
{{if not ($.UserDisabledFeatures.Contains "manage_gpg_keys")}}
68
{{template "user/settings/keys_gpg" .}}

0 commit comments

Comments
 (0)