Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs Ubuntu Upgrade #415

Merged
33 commits merged into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
68b159c
feat: remove cove proxy
Mar 10, 2023
2df32fe
feat: update docs server to ubuntu 22
Mar 10, 2023
5327a25
fix: set userdir permissions
Mar 10, 2023
bc240ef
feat: proxy elasticsearch requests via apache
Mar 10, 2023
9ce62f4
docs: record ocp07 host
Mar 10, 2023
f9676c1
feat: update rkhunter for ubuntu 22
Mar 13, 2023
394cd65
docs: update elasticsearch path
Mar 13, 2023
9ff0ef7
refactor: remove jinja newlines
Mar 13, 2023
6ad46e0
feat: remove legacy proxy settings
Mar 13, 2023
f4ce9c5
feat: add search ES path
Mar 13, 2023
ab480d8
feat: remove local specific access
Mar 13, 2023
158814c
fix: new apt-key location on ubuntu 22
Mar 13, 2023
e336664
feat: configure ES for proxied connections
Mar 17, 2023
e451533
feat: elasticsearch version 8
Mar 17, 2023
481db4c
Update salt/elasticsearch/init.sls
Mar 17, 2023
9b208d5
Update salt/elasticsearch/init.sls
Mar 17, 2023
230ee67
feat: use new ES endpoint
Mar 21, 2023
0a74147
feat: remove cors configuration
Mar 21, 2023
ee7f96f
feat: Config readonlyrest access via pillar
Mar 21, 2023
02fcab9
feat: simplify and configure for ES 8
Mar 21, 2023
f4f9fab
Update pillar/docs.sls
Mar 21, 2023
d8aa3a7
feat: Add ocpadmin ror user
Mar 21, 2023
afaf371
Update salt/elasticsearch/files/config/readonlyrest-docs.yml
Apr 6, 2023
6179526
Update salt/docs/init.sls
Apr 6, 2023
884dde0
docs: remove public access
Apr 6, 2023
15020ca
refactor: clear readonlyrest permission names
Apr 6, 2023
e8699f5
feat: remove elasticsearch public access
Apr 6, 2023
9748344
docs: add readonly rest configuration guide
Apr 6, 2023
d2a3e1d
feat: remove legacy elasticsearch variables
Apr 6, 2023
99e924c
docs: Restore ReadOnlyREST section
jpmckinney Apr 6, 2023
c7e5a12
feat: set web dir permissions
Apr 13, 2023
4d5f352
feat: remove admin_ips variable
Apr 13, 2023
ab9b891
docs: Explain why Apache (and world) needs access to user directory
jpmckinney Apr 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deploy-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ if [ "$RELEASE" != "true" ]; then

# Index the build directory.
ocdsindex sphinx build/ https://standard.open-contracting.org/"$PREFIX""$PATH_PREFIX""$REF"/ > documents.json
ocdsindex index https://standard.open-contracting.org:9200 documents.json
ocdsindex index https://standard.open-contracting.org/search documents.json
if [ "$REF" == "$VERSION" ]; then
ocdsindex sphinx build/ https://standard.open-contracting.org/"$PREFIX""$PATH_PREFIX"latest/ > documents.json
ocdsindex index https://standard.open-contracting.org:9200 documents.json
ocdsindex index https://standard.open-contracting.org/search documents.json
fi

if [ "$PRODUCTION" == "true" ]; then
Expand Down
1 change: 0 additions & 1 deletion docs/deploy/create_server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ For Django application servers:
For OCDS documentation servers:

#. Copy the ``/home/ocds-docs/web`` directory
#. Update the IP addresses in the ``pillar/cove.sls`` file, and deploy the ``cove-*`` services

For Redmine servers:

Expand Down
78 changes: 1 addition & 77 deletions docs/develop/update/elasticsearch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,82 +46,6 @@ Set swappiness value
vm:
swappiness: 1

Enable public access
jpmckinney marked this conversation as resolved.
Show resolved Hide resolved
--------------------

As stated by Elasticsearch, `"Do not expose Elasticsearch directly to users." <https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-security.html>`__ For the OCDS documentation, we use the `ReadOnlyREST <https://readonlyrest.com>`__ plugin to control access.

#. Add the ``elasticsearch.plugins.readonlyrest`` state file to your service's target in the ``salt/top.sls`` file.
jpmckinney marked this conversation as resolved.
Show resolved Hide resolved

#. Allow anyone to access Elasticsearch. Add to your service's Pillar file:

.. code-block:: yaml

elasticsearch:
public_access: True

#. Allow cross-origin HTTP requests (optional). Add to your service's Pillar file, for example:

.. code-block:: yaml
:emphasize-lines: 2

elasticsearch:
allowed_origins: https://standard.open-contracting.org

#. Configure ReadOnlyREST SSL certificates in your service's Pillar file. If :doc:`Apache<apache>` and Elasticsearch serve content from the same domain, you can reuse the certificates acquired by the ``mod_md`` module. For example:

.. code-block:: yaml

elasticsearch:
plugins:
readonlyrest:
certificate_key_file: /etc/apache2/md/domains/standard.open-contracting.org/privkey.pem
certificate_file: /etc/apache2/md/domains/standard.open-contracting.org/pubcert.pem

If reusing certificates, configure the ``mod_md`` module to restart Elasticsearch after renewing certificates:

.. code-block:: yaml
:emphasize-lines: 2-4

apache:
modules:
mod_md:
MDNotifyCmd: /opt/restart-elasticsearch.sh

#. Add users for public searches and for admin actions. Add to your service's *private* Pillar file, replacing ``AUTH_KEY_SHA512`` with the output of ``echo -n 'USERNAME:PASSWORD' | shasum -a 512`` (replacing ``USERNAME`` and ``PASSWORD`` with a strong password each time):

.. code-block:: yaml
:emphasize-lines: 4-10

elasticsearch:
plugins:
readonlyrest:
users:
- auth_key_sha512: AUTH_KEY_SHA512
username: public
groups:
- public
- auth_key_sha512: AUTH_KEY_SHA512
username: manage
groups:
- manage

#. :doc:`Deploy the service<../../deploy/deploy>`

#. Test the public user, replacing ``PASSWORD``. For example, for the ``standard.open-contracting.org`` domain:

.. code-block:: bash

curl -u 'public:PASSWORD' https://standard.open-contracting.org:9200/ocdsindex_en/_search \
-H 'Content-Type: application/json' \
-d '{"query": {"term": {"base_url": "https://standard.open-contracting.org/staging/1.1-dev/"}}}'

#. Test the admin user, replacing ``PASSWORD``. For example, for the ``standard.open-contracting.org`` domain:

.. code-block:: bash

curl -u 'manage:PASSWORD' https://standard.open-contracting.org:9200/_cat/indices

Troubleshoot
~~~~~~~~~~~~

Expand Down Expand Up @@ -152,7 +76,7 @@ You will see a message like (newlines are added for readability):
MET:HEAD,
PTH:/ocdsindex_en,
CNT:<N/A>,
HDR:Accept=*/*, Authorization=<OMITTED>, Host=standard.open-contracting.org:9200, User-Agent=curl/7.64.1, content-length=0,
HDR:Accept=*/*, Authorization=<OMITTED>, Host=standard.open-contracting.org, User-Agent=curl/7.64.1, content-length=0,
HIS:
[Allow localhost->
RULES:[hosts->false],
Expand Down
10 changes: 5 additions & 5 deletions docs/maintain/elasticsearch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ List indices:

.. code-block:: bash

curl -n https://standard.open-contracting.org:9200/_cat/indices
curl -n https://standard.open-contracting.org/search/_cat/indices

List base URLs in a given index, for example:

.. code-block:: bash

curl -n -X GET 'https://standard.open-contracting.org:9200/ocdsindex_en/_search?size=0&pretty' \
curl -n -X GET 'https://standard.open-contracting.org/search/ocdsindex_en/_search?size=0&pretty' \
-H 'Content-Type: application/json' \
-d '{"aggs": {"base_urls": {"terms": {"field": "base_url", "size": 10000}}}}'

Delete documents matching a base URL:

.. code-block:: bash

curl -n -X POST 'https://standard.open-contracting.org:9200/ocdsindex_en/_delete_by_query' \
curl -n -X POST 'https://standard.open-contracting.org/search/ocdsindex_en/_delete_by_query' \
-H 'Content-Type: application/json' \
-d '{"query": {"term": {"base_url": "https://standard.open-contracting.org/staging/1.1-dev/"}}}'

Expire documents using `OCDS Index <https://github.com/open-contracting/ocds-index>`__:

.. code-block:: bash

ocdsindex expire https://standard.open-contracting.org:9200 --exclude-file=ocdsindex-exclude.txt
ocdsindex expire https://standard.open-contracting.org/search --exclude-file=ocdsindex-exclude.txt

Search documents in a given index matching a base URL, for example:

.. code-block:: bash

curl -n -X GET 'https://standard.open-contracting.org:9200/ocdsindex_en/_search?size=10000' \
curl -n -X GET 'https://standard.open-contracting.org/search/ocdsindex_en/_search?size=10000' \
-H 'Content-Type: application/json' \
-d '{"query": {"term": {"base_url": "https://standard.open-contracting.org/staging/1.1-dev/"}}}'

Expand Down
3 changes: 0 additions & 3 deletions pillar/cove.sls
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ python_apps:
VALIDATION_ERROR_LOCATIONS_LENGTH: 100
apache:
configuration: django
context:
docs_ipv4: 5.28.62.151
docs_ipv6: 2001:41c9:1:41c::151
uwsgi:
configuration: django
harakiri: 1800 # 30 min
Expand Down
15 changes: 10 additions & 5 deletions pillar/docs.sls
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
network:
host_id: ocp19
ipv4: 178.79.135.174
#ipv6: 2001:db8::19
This conversation was marked as resolved.
Show resolved Hide resolved
networkd:
template: linode
gateway4: 178.79.135.1

ssh:
docs:
# Public key for salt/private/keys/docs_ci
Expand All @@ -17,14 +25,11 @@ apache:
servername: standard.open-contracting.org

elasticsearch:
public_access: True
# Allow OCDS documentation and GitHub Actions.
allowed_origins: "*"
# This is to inform the installation of ReadOnlyREST – not to control the version of Elasticsearch to install.
version: 7.17.9
version: 8.6.2
plugins:
readonlyrest:
version: 1.47.0_es7.17.9
version: 1.47.0_es8.6.2
configuration: docs
certificate_key_file: /etc/elasticsearch/ssl/standard.open-contracting.org/privkey.pem
certificate_file: /etc/elasticsearch/ssl/standard.open-contracting.org/pubcert.pem
3 changes: 3 additions & 0 deletions pillar/docs_maintenance.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ maintenance:
patching: manual
rkhunter_customisation: |
ALLOWHIDDENDIR=/etc/.java
ALLOW_SSH_ROOT_USER=yes
RTKT_FILE_WHITELIST=/usr/lib/x86_64-linux-gnu/libkeyutils.so.1.9
USER_FILEPROP_FILES_DIRS=/usr/lib/x86_64-linux-gnu/libkeyutils.so.1.9
3 changes: 2 additions & 1 deletion salt-config/roster
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cove-oc4ids: ocp17.open-contracting.org
cove-ocds: ocp18.open-contracting.org
docs: ocp07.open-contracting.org
docs: ocp19.open-contracting.org
kingfisher-process: ocp04.open-contracting.org
kingfisher-replica: ocp05.open-contracting.org
prometheus: ocp03.open-contracting.org
Expand All @@ -16,6 +16,7 @@ registry:
# ocp01 was cove-oc4ids on Ubuntu 18
# ocp02 was cove-ocds on Ubuntu 18
# ocp06 was covid19-dev
# ocp07 was docs on Ubuntu 18
# ocp08 was redash.open-contracting.org on Ubuntu 18
# ocp09 was toucan.open-contracting.org
# ocp10 was archive.kingfisher.open-contracting.org
Expand Down
22 changes: 10 additions & 12 deletions salt/apache/files/sites/docs.conf.include
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# vi: ft=apache

{# The paths should be in decreasing order of specificity to generate the correct order of precedence. #}
{%
{#- The paths should be in decreasing order of specificity to generate the correct order of precedence. #}
{%-
set options = {
'/profiles/eforms': {
'versions': ['latest'],
Expand Down Expand Up @@ -37,10 +37,10 @@
}
%}

{# Matches all root paths. #}
{% set pattern = '(profiles/[^/]+/|infrastructure/)?' %}
{#- Matches all root paths. #}
{%- set pattern = '(profiles/[^/]+/|infrastructure/)?' %}

{% set documentroot = '/home/ocds-docs/web' %}
{%- set documentroot = '/home/ocds-docs/web' %}

DocumentRoot {{ documentroot }}
RewriteMap unescape int:unescape
Expand Down Expand Up @@ -76,13 +76,6 @@ SetEnv BANNER /includes/banner_live.html
SetEnv BANNER /includes/banner_staging_profiles_ppp.html
</Location>

# Needed to proxy to SSL servers.
SSLProxyEngine on
# ProxyPreserveHost was on but we need it to be Off, as it makes adding SSL much easier.
ProxyPreserveHost Off
# With a keepalive, we had problems with headers being interpreted as the start of the response.
SetEnv proxy-nokeepalive 1

# Remember: The Directory directive applies only to static files, not to proxied or redirected paths.
<Directory {{ documentroot }}>
Require all granted
Expand Down Expand Up @@ -347,3 +340,8 @@ RedirectMatch ^/infrastructure/review/(.*)$ https://review-oc4ids.standard.open-
# The backreferences are the root, version and language.
RewriteRule ^{{ documentroot }}/staging/{{ pattern }}([^/]*) https://standard.open-contracting.org/staging/$1$2/${unescape:%1}/? [R]
</LocationMatch>

####################
# ElasticSearch
####################
ProxyPassMatch "^/search/(.*)?" http://localhost:9200/$1
5 changes: 0 additions & 5 deletions salt/apache/includes/cove.include.jinja
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
ErrorDocument 500 "<h2>Sorry, something went wrong.</h2> <p>Sometimes this happens because the input file is too big - maybe try again with a smaller sample.</p><p>Please file a <a href=\"https://github.com/open-contracting/cove-ocds/issues/new\">GitHub issue</a> or email <a href=\"mailto:[email protected]\">[email protected]</a> if this problem persists.</p>"

RemoteIPHeader X-Forwarded-For
# Trust docs reverse proxy.
RemoteIPTrustedProxy {{ docs_ipv4 }}
RemoteIPTrustedProxy {{ docs_ipv6 }}
8 changes: 8 additions & 0 deletions salt/docs/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ include:
- apache.modules.rewrite

{% set user = 'ocds-docs' %}
{% set userdir = '/home/' + user %}
{{ create_user(user, authorized_keys=pillar.ssh.docs) }}

allow Apache access to {{ userdir }}:
file.directory:
- name: {{ userdir }}
This conversation was marked as resolved.
Show resolved Hide resolved
- mode: 755
- require:
- user: {{ user }}_user_exists

# Needed to create a ZIP file of the schema and codelists.
# https://ocdsdeploy.readthedocs.io/en/latest/deploy/docs.html#copy-the-schema-and-zip-file-into-place
zip:
Expand Down
20 changes: 14 additions & 6 deletions salt/elasticsearch/files/config/readonlyrest-docs.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
readonlyrest:
# https://github.com/beshu-tech/readonlyrest-docs/blob/master/kibana.md#loading-settings-order-of-precedence
force_load_from_file: True
ssl:
server_certificate_key_file: {{ pillar.elasticsearch.plugins.readonlyrest.certificate_key_file }}
server_certificate_file: {{ pillar.elasticsearch.plugins.readonlyrest.certificate_file }}
# https://github.com/beshu-tech/readonlyrest-docs/blob/master/actionstrings/action_strings_es7.10.1.txt
access_control_rules:
- name: Allow localhost
hosts:
- localhost
- name: Allow the ocpadmin group to administrate Elasticsearch
groups:
- ocpadmin
x_forwarded_for:
- "127.0.0.0/8"
- "{{ pillar.network.ipv4 }}"
{%- if "ipv6" in pillar.network %}
- "{{ pillar.network.ipv6 }}"
{%- endif %}
This conversation was marked as resolved.
Show resolved Hide resolved
{%- for ip in pillar.elasticsearch.get("admin_ips", []) %}
- "{{ ip }}"
{%- endfor %}
- name: Allow the public group to search indices created by OCDS Index
groups:
- public
Expand All @@ -18,6 +24,7 @@ readonlyrest:
must_involve_indices: True
actions:
- indices:data/read/search
x_forwarded_for: ["0.0.0.0/0"]
- name: Allow the manage group to manage indices created by OCDS Index
groups:
- manage
Expand All @@ -31,4 +38,5 @@ readonlyrest:
- indices:data/write/bulk
- indices:data/write/delete/byquery
- indices:monitor/settings/get
x_forwarded_for: ["0.0.0.0/0"]
users: {{ pillar.elasticsearch.plugins.readonlyrest.users|yaml }}
3 changes: 0 additions & 3 deletions salt/elasticsearch/files/restart-elasticsearch.sh

This file was deleted.

1 change: 0 additions & 1 deletion salt/elasticsearch/files/sudoers.d/restart-elasticsearch

This file was deleted.

Loading