【问题标题】:Running HashiCorp Vault in root-less docker container在无根 docker 容器中运行 HashiCorp Vault
【发布时间】:2021-10-02 05:09:39
【问题描述】:

我正在尝试在 Ubuntu 20.2 上使用无根 docker 在容器中运行 Vault。但是,我不断收到以下错误:

vault    | Error initializing core: Failed to lock memory: cannot allocate memory
vault    |
vault    | This usually means that the mlock syscall is not available.

使用具有 root 权限的 docker 运行容器时不会出现该问题。

有没有办法在不禁用 mlock 并因此破坏 vault 安全性的情况下为无 root 的 docker 提供 mlock 权限?

docker-compose.yml:

version: "3"
services:
  vault:
    image: "hashicorp/vault:1.8.0-rc2"
    user: "root"
    container_name: vault
    restart: on-failure:10
    volumes:
      - ./config:/vault/config:rw
      - ./file:/vault/file:rw
    ports:
      - 8200:8200
    cap_add:
      - IPC_LOCK
    environment:
      - VAULT_ADDR=http://0.0.0.0:8200
    command: vault server -config=/vault/config

config.hcl:

storage "file" {
  path    = "/vault/file"
}

listener "tcp" {
  address     = "0.0.0.0:8200"
  tls_disable = "true"
}

api_addr = "http://127.0.0.1:8200"
ui = true

【问题讨论】:

    标签: docker ubuntu hashicorp-vault


    【解决方案1】:

    来自the documentation:

    On Linux, Vault may fail to start with the following error:
    
    Error initializing core: Failed to lock memory: cannot allocate memory
    
    This usually means that the mlock syscall is not available.
    Vault uses mlock to prevent memory from being swapped to
    disk. This requires root privileges as well as a machine
    that supports mlock. Please enable mlock on your system or
    disable Vault from using it. To disable Vault from using it,
    set the `disable_mlock` configuration option in your configuration
    file.
    

    尝试将disable_mlock = true 添加到您的config.hcl 文件中,如下所示:

    ...
    api_addr = "http://127.0.0.1:8200"
    ui = true
    disable_mlock = true
    

    【讨论】:

    • 这显然使脚本运行但破坏了安全性。我正在寻找不会绕过安全性的东西。
    • 这里有一篇关于这个主题的博客文章medium.com/@thejasongerard/…
    猜你喜欢
    • 2017-03-15
    • 2021-05-07
    • 2021-05-17
    • 2020-01-29
    • 2020-02-29
    • 2018-10-05
    • 2019-06-03
    • 2020-08-27
    • 2017-01-20
    相关资源
    最近更新 更多