solr-operator icon indicating copy to clipboard operation
solr-operator copied to clipboard

elegant way to enable cross origin resource sharing?

Open tzelch opened this issue 3 years ago • 3 comments

Hi guys,

First of all thanks for everybody working on this operator, it was quite easy to use even for a Solr noob like me :)

I need to access my solr cloud from an angular Application and am running into cross origin errors. The easiest way to enable cross origin resource sharing seems to be to edit the web.xml / webdefault.xml: http://laurenthinoul.com/how-to-enable-cors-in-solr/

On a regular deployment directly in Docker or on a VM this is easily done, but using Kubernetes and the operator it seems there is no easy way to do this and I might have to build a custom solr image.

Figured I asked if somebody else is running the operator and found an elegant solution to enable CORS?

Thanks in advance, Thomas

tzelch avatar Dec 29 '22 20:12 tzelch

I have not done this, but you might be able to use a custom volume in the Solr container and overwrite the web.xml / webdefault.xml.

The option you want to look at is SolrCloud.Spec.customSolrKubeOptions.podOptions.volumes

HoustonPutman avatar Jan 03 '23 18:01 HoustonPutman

For anyone interested in a guide.

  1. Create a custom web.xml

    • Get the default web.xml from solr's repository or from your container at /opt/solr-9.7.0/server/solr-webapp/webapp/WEB-INF/web.xml ( make sure to put the correct version )
    • follow https://laurenthinoul.com/how-to-enable-cors-in-solr/ to do the required changes
  2. Create a ConfigMap that contains the new web.xml file. You can do this by running the following command:

kubectl create configmap custom-web-xml --from-file=web.xml={{path/to/your/web.xml on machine running kubectl}}
  1. Attach a volume to solr containers

In SolrCloud resource file, create a new volume under SolrCloud.spec.customSolrKubeOptions.podOptions.volumes as follows:

# specs: https://apache.github.io/solr-operator/docs/solr-cloud/solr-cloud-crd.html
apiVersion: solr.apache.org/v1beta1
kind: SolrCloud
metadata:
  name: search-cluster
spec:
  # <new config>
  customSolrKubeOptions:
    podOptions:
      # override /opt/solr-9.7.0/server/solr-webapp/webapp/WEB-INF/web.xml with custom web.xml to enable CORS
      volumes:
        - name: custom-web-xml-volume
          source:
            configMap:
              name: custom-web-xml
              items:
                - key: web.xml
                  path: web.xml
          defaultContainerMount:
            name: custom-web-xml-volume
            mountPath: /opt/solr-9.7.0/server/solr-webapp/webapp/WEB-INF/web.xml # ! match solr version
            subPath: web.xml
            readOnly: true
  # </new config>
  # rest of the file ....
  replicas: 2
  solrJavaMem: -Xms512M -Xmx1G
  solrImage:
    tag: 9.7.0
  1. Apply changes
  2. Verify

get one of your pods' names, and verify that it has the new xml file:

kubectl exec -it <solr-pod-name> -- cat /opt/solr-9.7.0/server/solr-webapp/webapp/WEB-INF/web.xml

ibraheemalayan avatar Feb 23 '25 14:02 ibraheemalayan

We really need a better way to support CORS than hacking web.xml. We need some environment or solr.xml or something settings!

epugh avatar Feb 23 '25 14:02 epugh