长期支持版本

    社区创新版本

      safeguard 使用手册

      配置

      safeguard 的配置文件是一个YAML格式的文件,包含了key: value 或者 key: [value list] 的键值对。

      配置选项

      ConfigTypeDescription
      networkListRule for network restrictions.
      filesListRule for file access restrictions.
      processListRule for process restrictions.
      mountListRule for mount restrictions.
      dns_proxyListDNS Proxy configurations
      logList containing the following sub-keys:
    • format: [json|text]
    • output: <path>
    • max_size:: Maximum size to rotate (MB). Default: 100MB
    • max_age: Period for which logs are kept. Default: 365
    • labels: Key / Value to be added to the log.
    • Log configuration.

      network

      ConfigTypeDescription
      enableEnum with the following possible values: true, falseWhether to enable restrictions or not. Default is true.
      modeEnum with the following possible values: monitor, blockIf monitor is specified, events are only logged. If block is specified, network access is blocked.
      targetEnum with the following possible values: host, containerSelecting host applies the restriction to the host-wide. Selecting container will apply the restriction only to containers.
      cidrList containing the following sub-keys:
    • allow: [cidr list]
    • deny: [cidr list]
    • Allow or Deny CIDRs.
      domainList containing the following sub-keys:
    • allow: [domain list]
    • deny: [domain list]
    • Allow or Deny Domains.
      commandList containing the following sub-keys:
    • allow: [command list]
    • deny: [command list]
    • Allow or Deny commands.
      uidList containing the following sub-keys:
    • allow: [uid list]
    • deny: [uid list]
    • Allow or Deny uids.
      gidList containing the following sub-keys:
    • allow: [gid list]
    • deny: [gid list]
    • Allow or Deny gids.

      示例

      Allow all network connections

      Allows all network communications and monitors their connections.

      network:
        mode: monitor
        target: host
        cidr:
          allow: ['0.0.0.0/0']
      

      Block specify Private Networks

      Block access to 192.168.1.1/24 and 10.0.1.1/24.

      network:
        mode: block
        target: host
        cidr:
          allow: ['0.0.0.0/0']
          deny:
            - 192.168.1.1/24
            - 10.0.1.1/24
      

      Block Metadata service API

      Block access to the public cloud Metadata Service. This is a mitigation measure against SSRF, etc.

      network:
        mode: block
        target: host
        cidr:
          allow: ['0.0.0.0/0']
          deny:
            - 169.254.169.254/32
      

      Block connections to the specified domain

      Block connections to example.com. safeguard periodically looks up IP addresses, so it keeps up with IP address changes.

      network:
        mode: block
        target: host
        cidr:
          allow: ['0.0.0.0/0']
        domain:
          deny:
            - example.com
      

      Block network connections of containers

      Allow communication from the host, but block communication from the containers.

      network:
        mode: block
        target: container
        cidr:
          allow: ['0.0.0.0/0']
        domain:
          deny:
          - example.com
      

      !!! example

      vagrant@ubuntu-impish:~$ curl -I https://example.com
      HTTP/2 200
      
      vagrant@ubuntu-impish:~$ sudo docker run --rm -it curlimages/curl https://example.com
      curl: (7) Couldn't connect to server
      

      Block all connections from curl

      network:
        mode: monitor
        target: container
        cidr:
          allow: ['0.0.0.0/0']
        command:
          deny: ['curl']
      

      !!! example

      vagrant@ubuntu-impish:~$ curl -I https://example.com
      curl: (6) Could not resolve host: example.com
      
      vagrant@ubuntu-impish:~$ wget https://example.com -O /dev/null
      --2022-03-09 14:45:11--  http://example.com/
      Resolving example.com (example.com)... 93.184.216.34
      Connecting to example.com (example.com)|93.184.216.34|:80... connected.
      HTTP request sent, awaiting response... 200 OK
      Length: 1256 (1.2K) [text/html]
      Saving to: ‘/dev/null’
      
      /dev/null               100%[============================>]   1.23K  --.-KB/s    in 0s
      
      2022-03-09 14:45:12 (70.1 MB/s) - ‘/dev/null’ saved [1256/1256]
      

      Block all connections by users with UID 1000

      Setting that blocks all network access for UID 1000 user, but does not apply restrictions to UID 0 (root).

      network:
        mode: monitor
        target: container
        cidr:
          allow: ['0.0.0.0/0']
        uid:
          allow: [0]
          deny: [1000]
      

      !!! example

      vagrant@ubuntu-impish:~$ id
      uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant)
      
      vagrant@ubuntu-impish:~$ curl -I https://example.com
      curl: (6) Could not resolve host: example.com
      
      vagrant@ubuntu-impish:~$ sudo curl -I https://example.com
      HTTP/2 200
      

      files

      Linux Kernel >= 5.13 is required to use this option.

      ConfigTypeDescription
      enableEnum with the following possible values: true, falseWhether to enable restrictions or not. Default is true.
      modeEnum with the following possible values: monitor, blockIf monitor is specified, events are only logged. If block is specified, network access is blocked.
      targetEnum with the following possible values: host, containerSelecting host applies the restriction to the host-wide. Selecting container will apply the restriction only to containers.
      allowA list of allow file paths
      denyA list of allow file paths

      示例

      Allow access to all files

      file:
        mode: monitor
        target: host
        allow:
          - /
      

      Block access to /etc/passwd

      file:
        mode: block
        target: host
        allow:
          - /
        deny:
          - /etc/passwd
      

      Block all access to the /root/.ssh directory

      file:
        mode: block
        target: host
        allow:
          - /
        deny:
          - /root/.ssh
      

      Block access to the /proc/sys directory in the container

      file:
        mode: block
        target: container
        allow:
          - /
        deny:
          - /proc/sys
      

      !!! example

      root@ubuntu-impish:/# ls /proc/sys
      abi  debug  dev  fs  kernel  net  user  vm
      
      root@ubuntu-impish:/# docker run --privileged --rm -it ubuntu:latest bash
      root@9cf961922b00:/# ls /proc/sys
      ls: cannot open directory '/proc/sys': Operation not permitted
      

      Block escapes from Privileged Container

      file:
        mode: block
        target: container
        allow:
          - /
        deny:
          - /proc/sysrq-trigger
          - /sys/kernel
          - /proc/sys/kernel
      

      !!! example

      root@ubuntu-impish:/# docker run --privileged --rm -it ubuntu:latest bash
      root@e3b2ffe5b284:/# echo c > /proc/sysrq-trigger
      bash: /proc/sysrq-trigger: Operation not permitted
      
      root@e3b2ffe5b284:/# echo '/path/to/evil' > /sys/kernel/uevent_helper
      bash: /sys/kernel/uevent_helper: Operation not permitted
      
      root@e3b2ffe5b284:/# echo '|/path/to/evil' > /proc/sys/kernel/core_pattern
      bash: /proc/sys/kernel/core_pattern: Operation not permitted
      

      process

      ConfigTypeDescription
      enableEnum with the following possible values: true, falseWhether to enable restrictions or not. Default is true.
      modeEnum with the following possible values: monitorIf monitor is specified, events are only logged.
      targetEnum with the following possible values: host, containerSelecting host applies the restriction to the host-wide. Selecting container will apply the restriction only to containers.

      示例

      mount:
        mode: monitor
        target: host
      

      mount

      ConfigTypeDescription
      enableEnum with the following possible values: true, falseWhether to enable restrictions or not. Default is true.
      modeEnum with the following possible values: monitor, blockIf monitor is specified, events are only logged. If block is specified, access is blocked.
      targetEnum with the following possible values: host, containerSelecting host applies the restriction to the host-wide. Selecting container will apply the restriction only to containers.
      denyA list of allow mount paths

      示例

      Block mount /var/run/docker.sock to container

      mount:
        mode: block
        target: host
        deny:
          - /var/run/docker.sock
      

      文档捉虫

      “有虫”文档片段

      问题描述

      提交类型 issue

      有点复杂...

      找人问问吧。

      PR

      小问题,全程线上修改...

      一键搞定!

      问题类型
      规范和低错类

      ● 错别字或拼写错误;标点符号使用错误;

      ● 链接错误、空单元格、格式错误;

      ● 英文中包含中文字符;

      ● 界面和描述不一致,但不影响操作;

      ● 表述不通顺,但不影响理解;

      ● 版本号不匹配:如软件包名称、界面版本号;

      易用性

      ● 关键步骤错误或缺失,无法指导用户完成任务;

      ● 缺少必要的前提条件、注意事项等;

      ● 图形、表格、文字等晦涩难懂;

      ● 逻辑不清晰,该分类、分项、分步骤的没有给出;

      正确性

      ● 技术原理、功能、规格等描述和软件不一致,存在错误;

      ● 原理图、架构图等存在错误;

      ● 命令、命令参数等错误;

      ● 代码片段错误;

      ● 命令无法完成对应功能;

      ● 界面错误,无法指导操作;

      风险提示

      ● 对重要数据或系统存在风险的操作,缺少安全提示;

      内容合规

      ● 违反法律法规,涉及政治、领土主权等敏感词;

      ● 内容侵权;

      您对文档的总体满意度

      非常不满意
      非常满意
      提交
      根据您的反馈,会自动生成issue模板。您只需点击按钮,创建issue即可。
      文档捉虫
      编组 3备份