Ошибка HTTP 403 с readthedocs.org и Apache? - PullRequest
0 голосов
/ 27 июня 2019

после установки ReadTheDocs согласно документам все работало нормально. Но после переключения на Apache задачи сборки как-то не выполняются, так как они получают ошибки HTTP 403 от собственного API, когда я использую кнопку «Тест» в GitLab для проверки интеграции:

[27/Jun/2019 10:39:25] readthedocs.core.views.hooks:29[26594]: INFO (Version build) Building smelt:latest
[27/Jun/2019 10:39:25] urllib3.connectionpool:206[26594]: DEBUG Starting new HTTP connection (1): 10.162.187.224:80
[27/Jun/2019 10:39:25] urllib3.connectionpool:396[26594]: DEBUG http://10.162.187.224:80 "GET /api/v2/version/2/ HTTP/1.1" 200 460
[27/Jun/2019 10:39:25] urllib3.connectionpool:396[26594]: DEBUG http://10.162.187.224:80 "GET /api/v2/build/19/ HTTP/1.1" 200 386
[27/Jun/2019 10:39:25] urllib3.connectionpool:396[26594]: DEBUG http://10.162.187.224:80 "PUT /api/v2/build/19/ HTTP/1.1" 403 58
[27/Jun/2019 10:39:25] readthedocs.doc_builder.environments:757[26594]: ERROR Unable to update build: id=19
Traceback (most recent call last):
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 753, in update_build
    api_v2.build(self.build['id']).put(self.build)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 175, in put
    resp = self._request("PUT", data=data, files=files, params=kwargs)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 101, in _request
    raise exception_class("Client Error %s: %s" % (resp.status_code, url), response=resp, content=resp.content)
slumber.exceptions.HttpClientError: Client Error 403: http://10.162.187.224:80/api/v2/build/19/
[27/Jun/2019 10:39:25] readthedocs.projects.tasks:617[26594]: INFO (Build) [smelt:latest] Updating docs from VCS
[27/Jun/2019 10:39:25] readthedocs.projects.tasks:137[26594]: INFO (Build) [smelt:latest] Checking out version latest: master
[27/Jun/2019 10:39:25] readthedocs.doc_builder.environments:142[26594]: INFO Running: 'git remote set-url origin https://gitlab.suse.de/l3ms/smelt.git' [/opt/readthedocs/readthedocs.org/user_builds/smelt/checkouts/latest]
[27/Jun/2019 10:39:25] urllib3.connectionpool:396[26594]: DEBUG http://10.162.187.224:80 "POST /api/v2/command/ HTTP/1.1" 403 58
[27/Jun/2019 10:39:25] readthedocs.projects.tasks:635[26594]: ERROR An unhandled exception was raised during VCS syncing
Traceback (most recent call last):
  File "/opt/readthedocs/readthedocs.org/readthedocs/projects/tasks.py", line 621, in setup_vcs
    self.sync_repo()
  File "/opt/readthedocs/readthedocs.org/readthedocs/projects/tasks.py", line 141, in sync_repo
    version_repo.update()
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/backends/git.py", line 57, in update
    self.set_remote_url(self.repo_url)
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/backends/git.py", line 51, in set_remote_url
    return self.run('git', 'remote', 'set-url', 'origin', url)
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/base.py", line 99, in run
    build_cmd = self.environment.run(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 631, in run
    return super().run(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 418, in run
    return self.run_command_class(cls=self.command_class, cmd=cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 637, in run_command_class
    return super().run_command_class(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 465, in run_command_class
    self.record_command(build_cmd)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 625, in record_command
    command.save()
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 292, in save
    resp = api_v2.command.post(data)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 167, in post
    resp = self._request("POST", data=data, files=files, params=kwargs)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 101, in _request
    raise exception_class("Client Error %s: %s" % (resp.status_code, url), response=resp, content=resp.content)
slumber.exceptions.HttpClientError: Client Error 403: http://10.162.187.224:80/api/v2/command/
[27/Jun/2019 10:39:25] readthedocs.vcs_support.utils:129[26594]: DEBUG Lock (smelt): Releasing
[27/Jun/2019 10:39:25] readthedocs.doc_builder.environments:618[26594]: ERROR (Build) [smelt:latest] Client Error 403: http://10.162.187.224:80/api/v2/command/
Traceback (most recent call last):
  File "/opt/readthedocs/readthedocs.org/readthedocs/projects/tasks.py", line 440, in run_setup
    self.setup_vcs()
  File "/opt/readthedocs/readthedocs.org/readthedocs/projects/tasks.py", line 621, in setup_vcs
    self.sync_repo()
  File "/opt/readthedocs/readthedocs.org/readthedocs/projects/tasks.py", line 141, in sync_repo
    version_repo.update()
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/backends/git.py", line 57, in update
    self.set_remote_url(self.repo_url)
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/backends/git.py", line 51, in set_remote_url
    return self.run('git', 'remote', 'set-url', 'origin', url)
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/base.py", line 99, in run
    build_cmd = self.environment.run(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 631, in run
    return super().run(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 418, in run
    return self.run_command_class(cls=self.command_class, cmd=cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 637, in run_command_class
    return super().run_command_class(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 465, in run_command_class
    self.record_command(build_cmd)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 625, in record_command
    command.save()
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 292, in save
    resp = api_v2.command.post(data)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 167, in post
    resp = self._request("POST", data=data, files=files, params=kwargs)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 101, in _request
    raise exception_class("Client Error %s: %s" % (resp.status_code, url), response=resp, content=resp.content)
slumber.exceptions.HttpClientError: Client Error 403: http://10.162.187.224:80/api/v2/command/
[27/Jun/2019 10:39:25] readthedocs.doc_builder.environments:726[26594]: ERROR Build failed with unhandled exception: Client Error 403: http://10.162.187.224:80/api/v2/command/
[27/Jun/2019 10:39:25] urllib3.connectionpool:396[26594]: DEBUG http://10.162.187.224:80 "PUT /api/v2/build/19/ HTTP/1.1" 403 58
[27/Jun/2019 10:39:25] readthedocs.doc_builder.environments:757[26594]: ERROR Unable to update build: id=19
Traceback (most recent call last):
  File "/opt/readthedocs/readthedocs.org/readthedocs/projects/tasks.py", line 440, in run_setup
    self.setup_vcs()
  File "/opt/readthedocs/readthedocs.org/readthedocs/projects/tasks.py", line 621, in setup_vcs
    self.sync_repo()
  File "/opt/readthedocs/readthedocs.org/readthedocs/projects/tasks.py", line 141, in sync_repo
    version_repo.update()
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/backends/git.py", line 57, in update
    self.set_remote_url(self.repo_url)
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/backends/git.py", line 51, in set_remote_url
    return self.run('git', 'remote', 'set-url', 'origin', url)
  File "/opt/readthedocs/readthedocs.org/readthedocs/vcs_support/base.py", line 99, in run
    build_cmd = self.environment.run(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 631, in run
    return super().run(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 418, in run
    return self.run_command_class(cls=self.command_class, cmd=cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 637, in run_command_class
    return super().run_command_class(*cmd, **kwargs)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 465, in run_command_class
    self.record_command(build_cmd)
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 625, in record_command
    command.save()
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 292, in save
    resp = api_v2.command.post(data)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 167, in post
    resp = self._request("POST", data=data, files=files, params=kwargs)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 101, in _request
    raise exception_class("Client Error %s: %s" % (resp.status_code, url), response=resp, content=resp.content)
slumber.exceptions.HttpClientError: Client Error 403: http://10.162.187.224:80/api/v2/command/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 753, in update_build
    api_v2.build(self.build['id']).put(self.build)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 175, in put
    resp = self._request("PUT", data=data, files=files, params=kwargs)
  File "/opt/readthedocs/lib/python3.6/site-packages/slumber/__init__.py", line 101, in _request
    raise exception_class("Client Error %s: %s" % (resp.status_code, url), response=resp, content=resp.content)
slumber.exceptions.HttpClientError: Client Error 403: http://10.162.187.224:80/api/v2/build/19/
[27/Jun/2019 10:39:25] readthedocs.doc_builder.environments:574[26594]: INFO (Build) [smelt:latest] Build finished
[27/Jun/2019 10:39:25] readthedocs.projects.tasks:465[26594]: INFO (Build) [smelt:latest] Failing build because of setup failure: There was a problem with Read the Docs while building your documentation. Please try again later. However, if this problem persists, please report this to us with your build id (19).
[27/Jun/2019 10:39:25] celery.app.trace:124[26594]: INFO Task readthedocs.projects.tasks.send_notifications[a1bda137-30b7-436b-ba57-fba9b194b156] succeeded in 0.009141267000813968s: None
[27/Jun/2019 10:39:25] urllib3.connectionpool:396[26594]: DEBUG http://10.162.187.224:80 "GET /api/v2/version/2/ HTTP/1.1" 200 460

Некоторый контекст:

  • Сервер Ubuntu 18.04 (образ облака) с установленными PostgreSQL и Apache
  • Использование python3.6 для приложения WSGI
  • Локальный IP ВМ: 44.13.0.113
  • Внешне доступный IP ВМ: 10.162.187.224

local_settings

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'readthedocs',
        'USER': 'readthedocs',
        'PASSWORD': 'readthedodcs',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

DEFAULT_FROM_EMAIL = "from.me@example.com"

PRODUCTION_DOMAIN = "10.162.187.224:80"

SLUMBER_USERNAME = "itsme"
SLUMBER_PASSWORD = "********"
SLUMBER_API_HOST = 'http://10.162.187.224:80'
PUBLIC_API_URL = 'http://10.162.187.224:80'

Конфигурация Apache vhost:

<VirtualHost *:80>
        ServerName 10.162.187.224
        ServerAlias 44.13.0.113
        ServerAdmin ahasenkopf@suse.de

        WSGIDaemonProcess rtd python-path=/opt/readthedocs/readthedocs.org python-home=/opt/readthedocs
        WSGIProcessGroup rtd
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptAlias / /opt/readthedocs/readthedocs.org/readthedocs/wsgi.py

        Alias /static/ /opt/readthedocs/readthedocs.org/static/

        <Directory "/opt/readthedocs">
                Require all granted
        </Directory>
        <Directory "/opt/readthedocs/readthedocs.org/static">
                Require all granted
        </Directory>

        <Location "/api">
                AuthType Basic
                AuthName "API auth"
                Require all granted
                AuthBasicProvider wsgi
                WSGIAuthUserScript /opt/readthedocs/readthedocs.org/readthedocs/wsgi.py
        </Location>

        ErrorLog /var/log/apache2/error_rtd.log
        LogLevel warn
        CustomLog /var/log/apache2/access_rtd.log combined

</VirtualHost>

Я попробовал также конфиг без тега Location. Без разницы.

Я почти уверен, что мне не хватает только одной маленькой детали конфигурации, касающейся аутентификации ...

...