說明
registry v1沒有提供認(rèn)證,鑒權(quán)的功能,需要自己通過類似nginx的反向代理來做簡單的認(rèn)證鑒權(quán)
registry v2提供了認(rèn)證、鑒權(quán)的接口,但是需要自己實現(xiàn)認(rèn)證鑒權(quán)的功能,或者是對接第三方的認(rèn)證鑒權(quán)
鑒于此,對接第三方的認(rèn)證鑒權(quán)是比較合適的選擇,而業(yè)界使用比較多的registry認(rèn)證鑒權(quán)是cesanta/docker_auth
現(xiàn)在基于docker_auth來搭建docker registry
- 二進(jìn)制形式安裝
- 下載編譯
registry
git clone https://github.com/docker/distribution.git
cd distribution/cmd/registry
go build
- 編輯配置文件
cp sample.yml conf.yml
配置文件如下
version: 0.1
log:
fields:
service: registry
level: debug
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
tls:
certificate: /path/to/registry/registry.crt
key: /path/to/registry/registry.key
auth:
token:
realm: "https://docker_auth.ip:5001/auth"
service: "Docker registry"
issuer: "Acme auth server"
rootcertbundle: /path/to/docker_auth/server-cert.pem
- 注意:證書要提前規(guī)劃化好
- http 模塊的證書,是需要放到
docker deamon配置的信任證書的地方,一般是/etc/docker/cert.d/registry_xx_dome/registry.crt這樣在執(zhí)行docker login等命令是,就可以建立tls連接了- auth token 處的證書,是為了
registry與auth建立tls連接用的- 由于
docker deamon與registry交互式,registry會把auth地址返回回來,讓docker deamon去申請授權(quán),所以docker deamon會直接與auth進(jìn)行交互,而建立tls連接時,需要認(rèn)證簽名auth證書的證書,
此時需要把,centos環(huán)境下,需要把注意是,該證書的簽發(fā)證書放到/etc/pki/ca-trust/source/anchors/下
然后執(zhí)行update-ca-trust systemctl restart docker
- heath 模塊配置去掉,負(fù)責(zé),
docker deamon與registry交互,會出發(fā)registry進(jìn)行heath check導(dǎo)致失敗- log 日志級別設(shè)置成
debug會打印比較詳盡的日志
- 啟動
registry
nohup ./registry serve config.yml &
- 下載編譯
docker_auth
git clone https://github.com/cesanta/docker_auth.git
cd auth_server
govendor sync
#添加兩個常量到main.go中
go build
添加的兩個常量是
const ( Version = "xx" BuildId = "xx" )
- docker_auth 配置
注意證書配對
- 啟動
docker_auth
nohup ./auth_server ../examples/simple.yml &
7.測試略