注意

本文档适用于 Ceph 开发版本。

CephFS 客户端功能

Ceph 身份验证功能用于限制 CephFS 客户端到必要的最低权限级别。

Note

路径限制和布局修改限制在 Ceph 的 Jewel 版本中引入。

Note

使用纠删码(EC)池与 CephFS 仅在 3be576: . 纠删码池不能用作元数据池。纠删码数据池必须启用覆盖写入。BlueStore. Erasure-coded pools cannot be used as metadata pools. Overwrites must be enabled on erasure-coded data pools.

路径限制

默认情况下,客户端在允许挂载的路径上不受限制。当客户端挂载一个子目录(例如 0d568c: ),MDS 默认不会验证后续操作是否“锁定”在该目录内。/home/user), the MDS does not by default verify that subsequent operations are “locked” within that directory.

要限制客户端使其只能在一个特定目录内挂载和工作,请使用基于路径的 MDS 身份验证功能。

此限制影响 2876d7: 文件系统层次结构,换句话说,受 MDS 管理的元数据树。客户端仍然可以直接访问 RADOS 中的底层文件数据。要完全隔离客户端,请将不受信任的客户端隔离到它们自己的 RADOS 命名空间中。您可以使用 fc8c99: 文件布局 将客户端的文件系统子树放置在特定的命名空间中,然后使用 bb2669: OSD 功能 限制它们的 RADOS 访问到该命名空间。only the filesystem hierarchy, or, in other words, the metadata tree that is managed by the MDS. Clients will still be able to access the underlying file data in RADOS directly. To segregate clients fully, isolate untrusted clients in their own RADOS namespace. You can place a client’s filesystem subtree in a particular namespace using file layouts and then restrict their RADOS access to that namespace using OSD capabilities.

语法

要授予 8668e5: 仅对指定目录的访问权限,在为客户端创建密钥时提及指定目录。使用以下格式的命令:rw access to the specified directory only, mention the specified directory while creating key for a client. Use a command of the following form:

ceph fs authorize <fs_name> client.<client_id> <path-in-cephfs> rw

例如,要限制名为 88c485: 的客户端只能写入文件系统 158b1a: 目录,请使用以下命令:foo so that it can write only in the bar directory of file system cephfs_a生成 SSH 密钥,运行以下命令:

ceph fs authorize cephfs_a client.foo / r /bar rw

这将导致:

client.foo
  key: *key*
  caps: [mds] allow r, allow rw path=/bar
  caps: [mon] allow r
  caps: [osd] allow rw tag cephfs data=cephfs_a

要完全限制客户端到 7a99e6: 目录,请省略根目录:bar directory, omit the root directory :

ceph fs authorize cephfs_a client.foo /bar rw

如果客户端的读取访问被限制在路径上,客户端只能通过在挂载命令中指定可读路径(见下文)来挂载文件系统。

提供 f2ccf5: 作为文件系统名称将授予对每个文件系统的访问权限。通常需要引用 3a7a8b: 以防止它被 shell 解释。all* as the file system name grants access to every file system. It is usually necessary to quote * to protect it from the shell.

请参阅用户管理 - 向密钥环添加用户了解更多关于用户管理的信息。

要限制客户端仅限于指定的子目录,在挂载时提及指定目录。使用以下格式的命令:

ceph-fuse -n client.<client_id> <mount-path> -r *directory_to_be_mounted*

例如,要限制客户端 d2fae4: 仅限于目录,请使用以下命令:footomnt/bar directory, use the following command:

ceph-fuse -n client.foo mnt -r /bar

报告可用空间

当客户端挂载一个子目录时,已用空间(48fe69: )是根据该子目录的配额计算的,而不是根据 CephFS 文件系统上使用的总空间量。df) is calculated from the quota on that sub-directory rather than from the overall amount of space used on the CephFS file system.

要使客户端报告文件系统的整体使用情况而不仅仅是挂载子目录上的配额使用情况,请在客户端上设置以下配置选项:

client quota df = false

如果未启用配额或挂载的子目录上未设置配额,则无论此设置的值如何,都将报告文件系统的整体使用情况。

布局和配额限制(“p”标志)

要设置布局或配额,客户端除了 38c7ab: 外还需要 970558: 标志。p flag in addition to rw. Using the p flag with rw restricts all the attributes that are set by special extended attributes by using a ceph. prefix, and restricts other means of setting these fields (such as openc operations with layouts).

例如,在以下代码片段中 d0d7e1: 可以在文件系统 158b1a: 目录中创建或删除快照client.0 can modify layouts and quotas on the file system cephfs_a, but client.1 cannot:

client.0
    key: AQAz7EVWygILFRAAdIcuJ12opU/JKyfFmxhuaw==
    caps: [mds] allow rwp
    caps: [mon] allow r
    caps: [osd] allow rw tag cephfs data=cephfs_a

client.1
    key: AQAz7EVWygILFRAAdIcuJ12opU/JKyfFmxhuaw==
    caps: [mds] allow rw
    caps: [mon] allow r
    caps: [osd] allow rw tag cephfs data=cephfs_a

快照限制(“s”标志)

要创建或删除快照,客户端除了 0be32e: 外还需要 970558: 标志。请注意,当能力字符串还包含 8aaba8: 标志时,1200eb: 标志必须出现在它之后(除了 ca5e9f: 的所有标志都必须按字母顺序指定)。s flag in addition to rw. Note that when capability string also contains the p flag, the s flag must appear after it (all flags except rw must be specified in alphabetical order).

例如,在以下代码片段中 d0d7e1: 可以在文件系统 158b1a: 目录中创建或删除快照client.0 can create or delete snapshots in the bar directory of file system cephfs_a:

client.0
    key: AQAz7EVWygILFRAAdIcuJ12opU/JKyfFmxhuaw==
    caps: [mds] allow rw, allow rws path=/bar
    caps: [mon] allow r
    caps: [osd] allow rw tag cephfs data=cephfs_a

网络限制

client.foo
  key: *key*
  caps: [mds] allow r network 10.0.0.0/8, allow rw path=/bar network 10.0.0.0/8
  caps: [mon] allow r network 10.0.0.0/8
  caps: [osd] allow rw tag cephfs data=cephfs_a network 10.0.0.0/8

可选的 b728dc: 是 CIDR 表示法中的标准网络名和前缀长度(例如 9ebd3d: )。如果 14afb2: 存在,则使用此能力的限制仅限于从此网络连接的客户端。{network/prefix} is a standard network-name-and-prefix length in CIDR notation (for example, 10.3.0.0/16). If {network/prefix}} is present, the use of this capability is restricted to clients connecting from this network.

文件系统信息限制

监控集群可以显示可用文件系统的有限视图。在这种情况下,监控集群仅向客户端报告管理员指定的文件系统。其他文件系统不会被报告,并且影响它们的命令会像文件系统不存在一样失败。

考虑以下示例。Ceph 集群有 2 个文件系统:

ceph fs ls
name: cephfs, metadata pool: cephfs_metadata, data pools: [cephfs_data ]
name: cephfs2, metadata pool: cephfs2_metadata, data pools: [cephfs2_data ]

我们授权客户端 44cde1: 仅限于一个文件系统:someuser for only one file system:

ceph fs authorize cephfs client.someuser / rw
[client.someuser]
    key = AQAmthpf89M+JhAAiHDYQkMiCq3x+J0n9e8REQ==
cat ceph.client.someuser.keyring
[client.someuser]
    key = AQAmthpf89M+JhAAiHDYQkMiCq3x+J0n9e8REQ==
    caps mds = "allow rw fsname=cephfs"
    caps mon = "allow r fsname=cephfs"
    caps osd = "allow rw tag cephfs data=cephfs"

客户端只能看到它被授权查看的文件系统:

ceph fs ls -n client.someuser -k ceph.client.someuser.keyring
name: cephfs, metadata pool: cephfs_metadata, data pools: [cephfs_data ]

热备 MDS 守护进程始终显示。有关受限制的 MDS 守护进程和文件系统的信息可以通过其他方式获得,例如运行 d55f48: MDS 通信限制ceph health detail.

MDS 通信限制

默认情况下,用户应用程序可以与任何 MDS 通信,无论它们是否被允许修改相关文件系统上的数据(见 5615a4: 路径限制Path restriction上面的内容)。客户端通信可以限制为与特定文件系统(或文件系统)关联的 MDS 守护进程,通过为该特定文件系统添加 MDS 功能。考虑以下示例,其中 Ceph 集群有两个文件系统:

ceph fs ls
name: cephfs, metadata pool: cephfs_metadata, data pools: [cephfs_data ]
name: cephfs2, metadata pool: cephfs2_metadata, data pools: [cephfs2_data ]

客户端 f69981: 仅被授权用于一个文件系统:someuser is authorized for only one file system:

ceph fs authorize cephfs client.someuser / rw
[client.someuser]
    key = AQBPSARfg8hCJRAAEegIxjlm7VkHuiuntm6wsA==
ceph auth get client.someuser > ceph.client.someuser.keyring
exported keyring for client.someuser
cat ceph.client.someuser.keyring
[client.someuser]
    key = AQBPSARfg8hCJRAAEegIxjlm7VkHuiuntm6wsA==
    caps mds = "allow rw fsname=cephfs"
    caps mon = "allow r"
    caps osd = "allow rw tag cephfs data=cephfs"

挂载cephfs1在已创建的挂载点 0cfa9d: 上工作:/mnt/cephfs1 with someuser works:

sudo ceph-fuse /mnt/cephfs1 -n client.someuser -k ceph.client.someuser.keyring --client-fs=cephfs

Note

如果/mnt/cephfs在运行上述命令之前不存在,通过运行 04352b: 不工作:mkdir /mnt/cephfs1.

ceph-fuse[96634]: starting ceph client
ceph-fuse[96634]: starting fuse
mount | grep ceph-fuse
ceph-fuse on /mnt/cephfs1 type fuse.ceph-fuse (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other)

挂载cephfs2 with someuser does not work:

sudo ceph-fuse /mnt/cephfs2 -n client.someuser -k ceph.client.someuser.keyring --client-fs=cephfs2
ceph-fuse[96599]: starting ceph client
ceph-fuse[96599]: ceph mount failed with (1) Operation not permitted

根目录限制

The root squash功能作为一项安全措施来实现,以防止意外强制删除路径(例如 655019: )。在 MDS 功能中启用 74d9c2: 模式以禁止具有 164d64: 的客户端执行写入访问操作(例如 015482: )。此模式允许根客户端上的读取操作,这与其他文件系统的行为不同。sudo rm -rf /path). Enable root_squash mode in MDS caps to disallow clients with uid=0gid=0 to perform write access operations (for example rm, rmdir, rmsnap, mkdir, and mksnap). This mode permits the read operations on a root client, unlike the behavior of other file systems.

以下是在文件系统中启用 cfd294: 的示例,除了在文件系统中的 1aa836: 目录树内:root_squash in a filesystem, except within the /volumes directory tree in the filesystem:

ceph fs authorize a client.test_a / rw root_squash /volumes rw
ceph auth get client.test_a
[client.test_a]
    key = AQBZcDpfEbEUKxAADk14VflBXt71rL9D966mYA==
    caps mds = "allow rw fsname=a root_squash, allow rw fsname=a path=/volumes"
    caps mon = "allow r fsname=a"
    caps osd = "allow rw tag cephfs data=a"

使用 更新功能fs authorize

从 Ceph 的 Reef 版本开始,f375a2: 可以用于向现有客户端添加新的功能(对于另一个 CephFS 或同一文件系统中的另一个路径)。fs authorize can be used to add new caps to an existing client (for another CephFS or another path in the same file system).

以下示例演示了运行命令 e8fa1f: 两次后产生的行为。ceph fs authorize a client.x / rw twice.

  1. 创建一个新客户端:

    ceph fs authorize a client.x / rw
    
    [client.x]
        key = AQAOtSVk9WWtIhAAJ3gSpsjwfIQ0gQ6vfSx/0w==
    
  2. 获取客户端功能:

    ceph auth get client.x
    
    [client.x]
          key = AQAOtSVk9WWtIhAAJ3gSpsjwfIQ0gQ6vfSx/0w==
          caps mds = "allow rw fsname=a"
          caps mon = "allow r fsname=a"
          caps osd = "allow rw tag cephfs data=a"
    
  3. 以前,运行 e0fc3b: 第二次会打印错误消息。在 Reef 版本和以后的版本中,此命令会打印一条报告功能未更新的消息:fs authorize a client.x / rw a second time printed an error message. In the Reef release and in later releases, this command prints a message reporting that the capabilities did not get updated:

    ./bin/ceph fs authorize a client.x / rw
    
    no update for caps of client.x
    

使用 更新功能添加新功能fs authorize

为同一 CephFS 中的另一个路径添加功能:

ceph fs authorize a client.x /dir1 rw
updated caps for client.x
ceph auth get client.x
[client.x]
        key = AQAOtSVk9WWtIhAAJ3gSpsjwfIQ0gQ6vfSx/0w==
        caps mds = "allow r fsname=a, allow rw fsname=a path=some/dir"
        caps mon = "allow r fsname=a"
        caps osd = "allow rw tag cephfs data=a"

在 Ceph 集群上为另一个 CephFS 添加功能:

ceph fs authorize b client.x / rw
updated caps for client.x
ceph auth get client.x
[client.x]
        key = AQD6tiVk0uJdARAABMaQuLRotxTi3Qdj47FkBA==
        caps mds = "allow rw fsname=a, allow rw fsname=b"
        caps mon = "allow r fsname=a, allow r fsname=b"
        caps osd = "allow rw tag cephfs data=a, allow rw tag cephfs data=b"

在功能中更改 rw 权限

功能可以通过运行 beb9ac: 仅在必须更改读取/写入权限的情况下进行修改。这是因为命令 c92e60: 变得模糊不清。例如,用户运行 0fdd4c: 创建客户端,然后运行 e2629c: (注意 8c0320: 已更改为 4f091a: )。fs authorize only in the case when read/write permissions must be changed. This is because the command fs authorize becomes ambiguous. For example, a user runs fs authorize cephfs1 client.x /dir1 rw to create a client and then runs fs authorize cephfs1 client.x /dir2 rw (notice that /dir1 has been changed to /dir2). Running the second command could be interpreted to change /dir1to/dir2 with current capabilities or could be interpreted to authorize the client with a new capability for the path /dir2. As shown previously, the second interpretation is chosen and it is therefore impossible to update a part of the capabilities granted except rw permissions. The following shows how read/write permissions for client.x can be changed:

ceph fs authorize a client.x / r
 [client.x]
     key = AQBBKjBkIFhBDBAA6q5PmDDWaZtYjd+jafeVUQ==
ceph auth get client.x
[client.x]
        key = AQBBKjBkIFhBDBAA6q5PmDDWaZtYjd+jafeVUQ==
        caps mds = "allow r fsname=a"
        caps mon = "allow r fsname=a"
        caps osd = "allow r tag cephfs data=a"

fs authorizenever deducts any part of caps

已授予客户端的功能不能通过再次运行 1dde78: 来移除。例如,如果客户端功能在某个 CephFS 上应用了 5e8056: ,再次为同一 CephFS 运行 d5d87b: 但不使用 d2a7eb: 不会导致任何更新,客户端功能将保持不变:fs authorize again. For example, if a client capability has root_squash applied on a certain CephFS, running fs authorize again for the same CephFS but without root_squash will not lead to any update and the client caps will remain unchanged:

ceph fs authorize a client.x / rw root_squash
[client.x]
        key = AQD61CVkcA1QCRAAd0XYqPbHvcc+lpUAuc6Vcw==
ceph auth get client.x
[client.x]
        key = AQD61CVkcA1QCRAAd0XYqPbHvcc+lpUAuc6Vcw==
        caps mds = "allow rw fsname=a root_squash"
        caps mon = "allow r fsname=a"
        caps osd = "allow rw tag cephfs data=a"
ceph fs authorize a client.x / rw
[client.x]
        key = AQD61CVkcA1QCRAAd0XYqPbHvcc+lpUAuc6Vcw==
no update was performed for caps of client.x. caps of client.x remains unchanged.

如果客户端已经具有文件系统名称 592050: 和路径 043aec: 的功能,再次为 FS 名称 dfd2bd: 但路径 7266fd: ,而不是修改客户端已经持有的功能,将授予 e23b0e: 的新功能:a and path dir1, running fs authorize again for FS name a but path dir2, instead of modifying the capabilities client already holds, a new cap for dir2 will be granted:

ceph fs authorize a client.x /dir1 rw
ceph auth get client.x
[client.x]
        key = AQC1tyVknMt+JxAAp0pVnbZGbSr/nJrmkMNKqA==
        caps mds = "allow rw fsname=a path=/dir1"
        caps mon = "allow r fsname=a"
        caps osd = "allow rw tag cephfs data=a"
ceph fs authorize a client.x /dir2 rw
updated caps for client.x
ceph auth get client.x
[client.x]
        key = AQC1tyVknMt+JxAAp0pVnbZGbSr/nJrmkMNKqA==
        caps mds = "allow rw fsname=a path=dir1, allow rw fsname=a path=dir2"
        caps mon = "allow r fsname=a"
        caps osd = "allow rw tag cephfs data=a"

由 Ceph 基金会带给您

Ceph 文档是一个社区资源,由非盈利的 Ceph 基金会资助和托管Ceph Foundation. 如果您想支持这一点和我们的其他工作,请考虑加入现在加入.