Docker本地仓库tls漏洞:TLS版本过低

问题描述:TLSv1.0/1.1 is enabled and the server supports at least one cipher.

解决方案1(失败):

按照docker官方文档的描述,可以通过在docker本地仓库的配置文件config.xml中设定允许使用的tls最低版本。

官方文档参考链接:Configuring a registry | Docker Documentation

step1:创建config.xml文件,挂载到docker容器中

vim /etc/docker/registry/config.xml

version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
  tls:
    minimumtls: tls1.2
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3

step2:创建docker-compose.yml

vim docker-compose.yml

version: '3'
services:
  registry:
    image: registry:2.7.1
    volumes:
      - /mnt/local_reg:/var/lib/registry
      - /etc/docker/local_reg/auth:/auth
      - /etc/docker/local_reg/certs:/certs
      - /etc/docker/local_reg/config.yml:/etc/docker/registry/config.yml
    restart: always
    ports:
      - 5000:5000
    environment:
      - REGISTRY_STORAGE_DELETE_ENABLED=true
...(略)

如上所示,已经严格按照官网描述设置了minimumtls: tls1.2,但是实测无效。。。

遂改变思路,打算使用nginx代理来实现限制tls版本。

解决方案2(成功):

官方文档参考链接:Authenticate proxy with nginx | Docker Documentation

step1:创建auth/nginx.conf文件

vim auth/nginx.conf

events {
    worker_connections  1024;
}

http {

  upstream docker-registry {
    server registry:5000;
  }

  ## Set a variable to help us decide if we need to add the
  ## 'Docker-Distribution-Api-Version' header.
  ## The registry always sets this header.
  ## In the case of nginx performing auth, the header is unset
  ## since nginx is auth-ing before proxying.
  map $upstream_http_docker_distribution_api_version $docker_distribution_api_version {
    '' 'registry/2.0';
  }

  server {
    listen 443 ssl;
    server_name myregistrydomain.com;

    # SSL
    ssl_certificate /etc/nginx/conf.d/domain.crt;
    ssl_certificate_key /etc/nginx/conf.d/domain.key;

    # Recommendations from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;

    # disable any limits to avoid HTTP 413 for large image uploads
    client_max_body_size 0;

    # required to avoid HTTP 411: see Issue #1486 (https://github.com/moby/moby/issues/1486)
    chunked_transfer_encoding on;

    location /v2/ {
      # Do not allow connections from docker 1.5 and earlier
      # docker pre-1.6.0 did not properly set the user agent on ping, catch "Go *" user agents
      if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) {
        return 404;
      }

      # To add basic authentication to v2 use auth_basic setting.
      auth_basic "Registry realm";
      auth_basic_user_file /etc/nginx/conf.d/nginx.htpasswd;

      ## If $docker_distribution_api_version is empty, the header is not added.
      ## See the map directive above where this variable is defined.
      add_header 'Docker-Distribution-Api-Version' $docker_distribution_api_version always;

      proxy_pass                          http://docker-registry;
      proxy_set_header  Host              $http_host;   # required for docker client's sake
      proxy_set_header  X-Real-IP         $remote_addr; # pass on real client's IP
      proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
      proxy_set_header  X-Forwarded-Proto $scheme;
      proxy_read_timeout                  900;
    }
  }
}

注)此处需要改动:

ssl_protocols TLSv1.1 TLSv1.2;修改为ssl_protocols TLSv1.2; //这里表示只允许TLSv1.2的访问

step2:创建docker-compose.yml

nginx:
  image: "nginx:alpine"
  ports:
    - 5043:443
  links:
    - registry:registry
  volumes:
    - ./auth:/etc/nginx/conf.d
    - ./auth/nginx.conf:/etc/nginx/nginx.conf:ro

registry:
  image: registry:2
  volumes:
    - ./data:/var/lib/registry

注)domain.crt,domain.key以及nginx.htpasswd的生成过程已省略,且这三个文件的路径均为./auth。参考另一篇博客Linux环境创建Docker本地仓库

Tips:

使用如下命令验证某版本的SSL或者TLS是否可用:

openssl s_client -connect 【ip或域名】:【端口号】 -tls1
openssl s_client -connect 【ip或域名】:【端口号】 -tls1_1
openssl s_client -connect 【ip或域名】:【端口号】 -tls1_2
openssl s_client -connect 【ip或域名】:【端口号】 -ssl1
openssl s_client -connect 【ip或域名】:【端口号】 -ssl2
openssl s_client -connect 【ip或域名】:【端口号】 -ssl3

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值