solr - 基本身份验证

问题描述

(新手问题提醒!) 我正在尝试在此 doc 之后在 SOLR 8.3(docker 容器:FROM solr:8.3)上设置基本身份验证:

添加了/var/solr/data/security.json:

{
"authentication":{ 
   "blockUnkNown": true,"class":"solr.BasicAuthPlugin","credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekcfAJXr1GGfLtRUXhgrF8c="},"realm":"My Solr users","forwardCredentials": false 
},"authorization":{
   "class":"solr.RuleBasedAuthorizationPlugin","permissions":[{"name":"security-edit","role":"admin"}],"user-role":{"solr":"admin"} 
}}

当我尝试更改管理员密码时:

curl --user solr:SolrRocks http://10.x.x.x:8983/solr/admin/authentication -H 'Content-type:application/json' -d '{"set-user": {"solr" : "MynewsuperSecurePass" }}'

我收到错误

  "responseHeader":{
    "status":400,"QTime":1},"error":{
    "Metadata":[
      "error-class","org.apache.solr.common.solrException","root-error-class","org.apache.solr.common.solrException"],"msg":"No authentication plugin configured","code":400}}

解决方法

我发现只有在容器中运行 solr 时才会出现这种行为。基本上 security.json 文件必须放在容器构建时。 所以我添加到Dockerfile:

FROM solr:8.3
ENV SOLR_USER="solr" \
    SOLR_GROUP="solr"
USER root
COPY --chown=solr:solr security/security.json /var/solr/data/security.json
USER $SOLR_USER

此后,新构建的容器的行为如文档中所述。