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

Fix Ceryx crash when no certificate settings exist #66

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python:
- 3.6

env:
- DOCKER_COMPOSE_VERSION=1.23.2 COMPOSE_FILE=docker-compose.yml:docker-compose.override.yml:docker-compose.test.yml
- DOCKER_COMPOSE_VERSION=1.23.2 COMPOSE_FILE=docker-compose.yml:docker-compose.override.yml:docker-compose.test.yml CERYX_DISABLE_LETS_ENCRYPT=true

install:
- pip install --upgrade --ignore-installed docker-compose==${DOCKER_COMPOSE_VERSION}
Expand Down
3 changes: 3 additions & 0 deletions ceryx/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ COPY . ./
ENV CERYX_DEBUG true
ENV CERYX_DISABLE_LETS_ENCRYPT true

COPY --from=sourcelair/ceryx:latest /etc/ceryx/ssl/default.key /etc/ceryx/ssl/default.key
COPY --from=sourcelair/ceryx:latest /etc/ceryx/ssl/default.crt /etc/ceryx/ssl/default.crt

CMD ["pytest", "tests/"]
1 change: 1 addition & 0 deletions ceryx/nginx/conf/nginx.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ user www-data www-data;
worker_processes 1;
pid /run/nginx.pid;

env CERYX_DISABLE_LETS_ENCRYPT;
env CERYX_REDIS_PREFIX;
env CERYX_REDIS_HOST;
env CERYX_REDIS_PASSWORD;
Expand Down
2 changes: 1 addition & 1 deletion ceryx/nginx/lualib/certificate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end

local host_certificates = certificates.getCertificatesForHost(host)

if certificates ~= nil then
if host_certificates ~= nil then
-- Convert data from PEM to DER
local certificate_der, certificate_der_err = ssl.cert_pem_to_der(host_certificates["certificate"])
if not certificate_der or certificate_der_err then
Expand Down
4 changes: 2 additions & 2 deletions ceryx/nginx/lualib/ceryx/certificates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ function getCertificatesForHost(host)
local certificate_path, certificate_err = redisClient:hget(certificates_redis_key, "certificate_path")
local key_path, key_err = redisClient:hget(certificates_redis_key, "key_path")

if certificate_path == nil then
if certificate_path == ngx.null then
ngx.log(ngx.ERR, "Could not retrieve SSL certificate path for " .. host .. " from Redis: " .. (certificate_err or "N/A"))
return nil
end

if key_path == nil then
if key_path == ngx.null then
ngx.log(ngx.ERR, "Could not retrieve SSL key path for " .. host .. " from Redis: " .. (key_err or "N/A"))
return nil
end
Expand Down
2 changes: 1 addition & 1 deletion ceryx/tests/client/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def init_poolmanager(
self.poolmanager = CeryxTestsPoolManager(
num_pools=connections, maxsize=maxsize, block=block, strict=True,
**pool_kwargs,
)
)
11 changes: 11 additions & 0 deletions ceryx/tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ def test_custom_certificate(self):
self.redis.hset(self.redis_settings_key, "key_path", key_path)

self.client.get(f"https://{self.host}/", verify=certificate_path)

def test_fallback_certificate(self):
"""
Ensure that Ceryx uses the fallback certificate if a route gets accessed
via HTTPS with no configured certificate or automatic Let's Encrypt
certificates enabled.
"""
try:
response = self.client.get(f"https://ghost.ceryx.test/", verify="/etc/ceryx/ssl/default.crt")
except Exception as e:
assert "sni-support-required-for-valid-ssl" in str(e)