This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 49fa6b11e fix(rmqctl): align config directory read and write 
permissions (#6952)
49fa6b11e is described below

commit 49fa6b11ea4a2eee54ccfffaea8908251b03ba1d
Author: aias00 <[email protected]>
AuthorDate: Fri Nov 27 12:06:37 2026 +0800

    fix(rmqctl): align config directory read and write permissions (#6952)
---
 docs/ai-agent-architecture.md                      |  4 ++
 .../config/permissions_policy_unix_test.go         | 75 ++++++++++++++++++++++
 rmqctl/internal/config/permissions_unix.go         | 12 +++-
 3 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/docs/ai-agent-architecture.md b/docs/ai-agent-architecture.md
index 40e9d8322..60aba8c2e 100644
--- a/docs/ai-agent-architecture.md
+++ b/docs/ai-agent-architecture.md
@@ -101,6 +101,10 @@ stdio 桥最多转发 64 个在途调用;满载时暂停读取后续输入,
 | **mcp.json 不需要 `env` 块** | 在 claude 进程环境里导出的变量被 rmqctl 子进程继承(MCP stdio 
server 继承 agent 环境) | 少写一处配置;但 yaml 里的 `env:NAME` 引用名必须与实际导出的变量名一致 |
 | **`--strict-mcp-config` 必需** | — | 否则 claude 还会加载 `~/.claude.json` 与 user 
scope 的 MCP server,在容器里是不可控暴露面 |
 
+Unix 配置权限:配置文件权限不得宽于 `0600`;其直接父目录不得允许组或其他用户写入。新目录以 `0700` 创建,已有 `0750` / 
`0755` 目录可用于读取和写入,CLI 不修改已有目录权限。Windows 保留用户配置目录继承的 ACL 策略。
+
+Unix config permissions: files must be no wider than `0600`; the immediate 
parent directory must not be group- or other-writable. New directories are 
created as `0700`. Existing `0750` / `0755` directories support both reads and 
writes without having their modes changed. Windows retains its inherited 
user-profile ACL policy.
+
 delta 实测分布(run1 + run2):`thinking_delta` 67、`text_delta` 80、`input_json_delta` 
10、
 `signature_delta` 4。`signature_delta` 是密码学签名,**永不渲染、永不落库**。`thinking_delta` 的存在
 就是「思维链」需求能真实满足的依据——它来自模型,不是 prompt 改写。
diff --git a/rmqctl/internal/config/permissions_policy_unix_test.go 
b/rmqctl/internal/config/permissions_policy_unix_test.go
new file mode 100644
index 000000000..3fd906dc9
--- /dev/null
+++ b/rmqctl/internal/config/permissions_policy_unix_test.go
@@ -0,0 +1,75 @@
+//go:build !windows
+
+/*
+ * 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.
+ */
+package config
+
+import (
+       "fmt"
+       "os"
+       "path/filepath"
+       "strings"
+       "testing"
+)
+
+func TestConfigRoundTripInNonWritableSharedDirectories(t *testing.T) {
+       for _, mode := range []os.FileMode{0o700, 0o750, 0o755} {
+               t.Run(fmt.Sprintf("%04o", mode), func(t *testing.T) {
+                       directory := t.TempDir()
+                       if err := os.Chmod(directory, mode); err != nil {
+                               t.Fatal(err)
+                       }
+                       path := filepath.Join(directory, "config.yaml")
+                       store := NewStore()
+                       if err := store.Save(path, EmptyConfig()); err != nil {
+                               t.Fatal(err)
+                       }
+                       if _, err := store.Load(path); err != nil {
+                               t.Fatal(err)
+                       }
+                       info, err := os.Stat(directory)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       if info.Mode().Perm() != mode {
+                               t.Fatalf("operator directory permissions 
changed: %04o", info.Mode().Perm())
+                       }
+                       file, err := os.Stat(path)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       if file.Mode().Perm() != 0o600 {
+                               t.Fatalf("file permissions = %04o", 
file.Mode().Perm())
+                       }
+               })
+       }
+}
+
+func TestConfigRejectsGroupOrOtherWritableParentsOnReadsAndWrites(t 
*testing.T) {
+       for _, mode := range []os.FileMode{0o770, 0o777} {
+               t.Run(fmt.Sprintf("%04o", mode), func(t *testing.T) {
+                       directory := t.TempDir()
+                       if err := os.Chmod(directory, 0o700); err != nil {
+                               t.Fatal(err)
+                       }
+                       path := filepath.Join(directory, "config.yaml")
+                       store := NewStore()
+                       if err := store.Save(path, EmptyConfig()); err != nil {
+                               t.Fatal(err)
+                       }
+                       if err := os.Chmod(directory, mode); err != nil {
+                               t.Fatal(err)
+                       }
+                       if _, err := store.Load(path); err == nil || 
!strings.Contains(err.Error(), "must not be writable by group or others") {
+                               t.Fatalf("Load error = %v", err)
+                       }
+                       if err := store.Save(path, EmptyConfig()); err == nil 
|| !strings.Contains(err.Error(), "must not be writable by group or others") {
+                               t.Fatalf("Save error = %v", err)
+                       }
+               })
+       }
+}
diff --git a/rmqctl/internal/config/permissions_unix.go 
b/rmqctl/internal/config/permissions_unix.go
index 4b38e5ee4..c0f91e4b0 100644
--- a/rmqctl/internal/config/permissions_unix.go
+++ b/rmqctl/internal/config/permissions_unix.go
@@ -21,12 +21,17 @@ package config
 import (
        "fmt"
        "os"
+       "path/filepath"
 )
 
 func ensureConfigDirectory(path string) error {
        if err := os.MkdirAll(path, 0o700); err != nil {
                return err
        }
+       return checkConfigDirectory(path)
+}
+
+func checkConfigDirectory(path string) error {
        info, err := os.Stat(path)
        if err != nil {
                return fmt.Errorf("inspect config directory: %w", err)
@@ -34,8 +39,8 @@ func ensureConfigDirectory(path string) error {
        if !info.IsDir() {
                return fmt.Errorf("config parent is not a directory: %s", path)
        }
-       if info.Mode().Perm() != 0o700 {
-               return fmt.Errorf("config directory %s must have permissions 
0700 (found %04o)",
+       if info.Mode().Perm()&0o022 != 0 {
+               return fmt.Errorf("config directory %s must not be writable by 
group or others (found %04o)",
                        path, info.Mode().Perm())
        }
        return nil
@@ -46,6 +51,9 @@ func secureConfigFile(path string) error {
 }
 
 func checkFilePermissions(path string) error {
+       if err := checkConfigDirectory(filepath.Dir(path)); err != nil {
+               return err
+       }
        info, err := os.Stat(path)
        if err != nil {
                return fmt.Errorf("inspect config file: %w", err)

Reply via email to