Skip to content

Instantly share code, notes, and snippets.

@nickumia-reisys
Last active May 20, 2022 15:37
Show Gist options
  • Save nickumia-reisys/18544d2c6aad4160293bda1fec6ead7f to your computer and use it in GitHub Desktop.
Save nickumia-reisys/18544d2c6aad4160293bda1fec6ead7f to your computer and use it in GitHub Desktop.
Local Solr Server with Auth

Build the docker image,

docker build -t solr-auth .

Run an instance,

docker run --rm -p 8983:8983 --name solr-test solr-auth:latest

See solr started at http://localhost:8983

Add a new user,

curl --user solr:SolrRocks http://localhost:8984/solr/admin/authentication -H 'Content-type:application/json' -d '{"set-user": {"tom":"TomIsCool", "harry":"HarrysSecret"}}'

Default admin user:pass is solr:SolrRocks.

Create new users/manage auth following official docs.

FROM solr:8.11-slim
ADD security.json $SOLR_HOME
{
"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"}
}}
#!/bin/bash
mkdir -p /tmp/ckan_config
# add solr authentication
cat <<SOLRAUTH > /var/solr/data/security.json
{
"authentication":{
"blockUnknown": true,
"class":"solr.BasicAuthPlugin",
"credentials":{"catalog":"rJzrn+HooKn79Q+cfysdGKmMhJbtj0Q1bTokFud6f9o= eKuBUjAoBIkJAMYZxJU6HOKSchTAce+DoQrY5Vewu7I="},
"realm":"data.gov users",
"forwardCredentials": false
},
"authorization":{
"class":"solr.RuleBasedAuthorizationPlugin",
"permissions":[{"name":"security-edit",
"role":"admin"}],
"user-role":{"catalog":"admin"}
}}
SOLRAUTH
# add solr config files for ckan 2.9
wget -O /tmp/ckan_config/schema.xml https://raw.githubusercontent.com/GSA/catalog.data.gov/main/ckan/setup/solr/managed-schema
wget -O /tmp/ckan_config/protwords.txt https://raw.githubusercontent.com/GSA/catalog.data.gov/main/ckan/setup/solr/protwords.txt
wget -O /tmp/ckan_config/solrconfig.xml https://raw.githubusercontent.com/GSA/catalog.data.gov/main/ckan/setup/solr/solrconfig.xml
wget -O /tmp/ckan_config/stopwords.txt https://raw.githubusercontent.com/GSA/catalog.data.gov/main/ckan/setup/solr/stopwords.txt
wget -O /tmp/ckan_config/synonyms.txt https://raw.githubusercontent.com/GSA/catalog.data.gov/main/ckan/setup/solr/synonyms.txt
# group user solr:solr is 8983:8983 in solr docker image
chown -R 8983:8983 /var/solr/data/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment