容器里的治理进程以固定非 root 用户运行,agent 原先只接受与自身同 uid 的连接, socket 挂进容器后一律被拒(peer uid is not allowed)。新增 --allow-peer-uid, 默认仍只允许同 uid,放行清单只能由部署参数给出,避免"挂上就能连"。
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
// agent. File mode 0600 already limits connect() to that uid; the credential
|
||||
// check makes the boundary explicit and fails closed if the socket is ever
|
||||
// reached another way (bind mount into a container with a different uid).
|
||||
func peerAllowed(conn net.Conn) error {
|
||||
func peerAllowed(conn net.Conn, allowed map[uint32]bool) error {
|
||||
unixConn, ok := conn.(*net.UnixConn)
|
||||
if !ok {
|
||||
return errors.New("unsupported transport")
|
||||
@@ -30,7 +30,9 @@ func peerAllowed(conn net.Conn) error {
|
||||
if controlErr != nil || credential == nil {
|
||||
return errors.New("peer credentials unavailable")
|
||||
}
|
||||
if credential.Uid != uint32(os.Geteuid()) {
|
||||
// 默认只允许与 agent 同 uid 的连接;显式声明过的 uid(例如容器里的
|
||||
// 固定运行用户)才放行。放行清单来自部署参数,不是"任何人"。
|
||||
if credential.Uid != uint32(os.Geteuid()) && !allowed[credential.Uid] {
|
||||
return errors.New("peer uid is not allowed")
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user