Skip to content

Commit d29d56e

Browse files
committed
Allow to specify the type of remote authentication
When configuring remote authentication (by the reverse proxy), one should be able to augment the openAPI security specification accordingly. fixes pulp#5437
1 parent 3955039 commit d29d56e

File tree

11 files changed

+57
-61
lines changed

11 files changed

+57
-61
lines changed

.github/template_gitref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2021.08.26-337-g7c7a09a
1+
2021.08.26-338-g2237db8

.github/workflows/scripts/before_script.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ tail -v -n +1 .ci/ansible/Containerfile
3636
cmd_prefix bash -c "echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/nopasswd"
3737
cmd_prefix bash -c "usermod -a -G wheel pulp"
3838

39-
SCENARIOS=("pulp" "performance" "azure" "gcp" "s3" "generate-bindings" "lowerbounds")
40-
if [[ " ${SCENARIOS[*]} " =~ " ${TEST} " ]]; then
41-
# Many functional tests require these
42-
cmd_prefix dnf install -yq lsof which
43-
fi
44-
4539
if [[ "${REDIS_DISABLED:-false}" == true ]]; then
4640
cmd_prefix bash -c "s6-rc -d change redis"
4741
echo "The Redis service was disabled for $TEST"

.github/workflows/scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ if [ "$TEST" = "azure" ]; then
126126
- ./azurite:/etc/pulp\
127127
command: "azurite-blob --blobHost 0.0.0.0 --cert /etc/pulp/azcert.pem --key /etc/pulp/azkey.pem"' vars/main.yaml
128128
sed -i -e '$a azure_test: true\
129-
pulp_scenario_settings: {"domain_enabled": true}\
129+
pulp_scenario_settings: {"domain_enabled": true, "rest_framework__default_authentication_classes": "@merge pulpcore.app.authentication.PulpRemoteUserAuthentication"}\
130130
pulp_scenario_env: {"otel_bsp_max_export_batch_size": 1, "otel_bsp_max_queue_size": 1, "otel_exporter_otlp_endpoint": "http://localhost:4318", "otel_exporter_otlp_protocol": "http/protobuf", "otel_metric_export_interval": 800, "pulp_otel_enabled": "true"}\
131131
' vars/main.yaml
132132
fi

CHANGES/.TEMPLATE.rst

Lines changed: 0 additions & 47 deletions
This file was deleted.

CHANGES/5437.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add ability to configure the openapi schema for remote user authentication via `REMOTE_USER_OPENAPI_SECURITY_SCHEME`.
2+
It defaults to "mutualTLS" for cert based authentication.

pulpcore/app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
TMPFILE_PROTECTION_TIME = 0
265265

266266
REMOTE_USER_ENVIRON_NAME = "REMOTE_USER"
267+
REMOTE_USER_OPENAPI_SECURITY_SCHEME = {"type": "mutualTLS"}
267268

268269
AUTHENTICATION_JSON_HEADER = ""
269270
AUTHENTICATION_JSON_HEADER_JQ_FILTER = ""

pulpcore/openapi/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,14 @@ def get_schema(self, request=None, public=False):
521521
return normalize_result_object(result)
522522

523523

524+
class PulpRemoteUserAuthenticationScheme(OpenApiAuthenticationExtension):
525+
target_class = "pulpcore.app.authentication.PulpRemoteUserAuthentication"
526+
name = "RemoteUserAuthentication"
527+
528+
def get_security_definition(self, auto_schema):
529+
return settings.REMOTE_USER_OPENAPI_SECURITY_SCHEME
530+
531+
524532
class JSONHeaderRemoteAuthenticationScheme(OpenApiAuthenticationExtension):
525533
target_class = "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
526534
name = "json_header_remote_authentication"

pulpcore/tests/functional/api/test_auth.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515

1616
@pytest.mark.parallel
17+
@pytest.mark.skipif(
18+
"rest_framework.authentication.BasicAuthentication"
19+
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
20+
reason="Test can't run unless BasicAuthentication is enabled",
21+
)
1722
def test_base_auth_success(pulpcore_bindings, pulp_admin_user):
1823
"""Perform HTTP basic authentication with valid credentials.
1924
@@ -27,6 +32,11 @@ def test_base_auth_success(pulpcore_bindings, pulp_admin_user):
2732

2833

2934
@pytest.mark.parallel
35+
@pytest.mark.skipif(
36+
"rest_framework.authentication.BasicAuthentication"
37+
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
38+
reason="Test can't run unless BasicAuthentication is enabled",
39+
)
3040
def test_base_auth_failure(pulpcore_bindings, invalid_user):
3141
"""Perform HTTP basic authentication with invalid credentials.
3242
@@ -44,6 +54,11 @@ def test_base_auth_failure(pulpcore_bindings, invalid_user):
4454

4555

4656
@pytest.mark.parallel
57+
@pytest.mark.skipif(
58+
"rest_framework.authentication.BasicAuthentication"
59+
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
60+
reason="Test can't run unless BasicAuthentication is enabled",
61+
)
4762
def test_base_auth_required(pulpcore_bindings, anonymous_user):
4863
"""Perform HTTP basic authentication with no credentials.
4964
@@ -63,7 +78,7 @@ def test_base_auth_required(pulpcore_bindings, anonymous_user):
6378
@pytest.mark.parallel
6479
@pytest.mark.skipif(
6580
"django.contrib.auth.backends.RemoteUserBackend" not in settings.AUTHENTICATION_BACKENDS
66-
and "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
81+
or "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
6782
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
6883
reason="Test can't run unless RemoteUserBackend and JSONHeaderRemoteAuthentication are enabled",
6984
)
@@ -86,7 +101,7 @@ def test_jq_header_remote_auth(pulpcore_bindings, anonymous_user):
86101
@pytest.mark.parallel
87102
@pytest.mark.skipif(
88103
"django.contrib.auth.backends.RemoteUserBackend" not in settings.AUTHENTICATION_BACKENDS
89-
and "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
104+
or "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
90105
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
91106
reason="Test can't run unless RemoteUserBackend and JSONHeaderRemoteAuthentication are enabled",
92107
)
@@ -115,7 +130,7 @@ def test_jq_header_remote_auth_denied_by_wrong_header(pulpcore_bindings, anonymo
115130
@pytest.mark.parallel
116131
@pytest.mark.skipif(
117132
"django.contrib.auth.backends.RemoteUserBackend" not in settings.AUTHENTICATION_BACKENDS
118-
and "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
133+
or "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
119134
not in settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"],
120135
reason="Test can't run unless RemoteUserBackend and JSONHeaderRemoteAuthentication are enabled",
121136
)

pulpcore/tests/functional/api/test_openapi_schema.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,26 @@ def test_no_dup_operation_ids(pulp_openapi_schema):
8888
assert len(dup_ids) == 0, f"Duplicate operationIds found: {dup_ids}"
8989

9090

91+
@pytest.mark.parallel
92+
def test_remote_user_auth_security_scheme(pulp_settings, pulp_openapi_schema):
93+
if (
94+
"pulpcore.app.authentication.PulpRemoteUserAuthentication"
95+
not in pulp_settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"]
96+
):
97+
pytest.skip("Test can't run unless PulpRemoteUserAuthentication is enabled.")
98+
99+
expected_security_scheme = pulp_settings.REMOTE_USER_OPENAPI_SECURITY_SCHEME
100+
security_schemes = pulp_openapi_schema["components"]["securitySchemes"]
101+
102+
assert security_schemes["remote_user_authentication"] == expected_security_scheme
103+
104+
91105
@pytest.mark.parallel
92106
def test_external_auth_on_security_scheme(pulp_settings, pulp_openapi_schema):
93107
if (
94108
"django.contrib.auth.backends.RemoteUserBackend"
95109
not in pulp_settings.AUTHENTICATION_BACKENDS
96-
and "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
110+
or "pulpcore.app.authentication.JSONHeaderRemoteAuthentication"
97111
not in pulp_settings.REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"]
98112
):
99113
pytest.skip(

staging_docs/admin/learn/settings.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ Defaults to `30` seconds.
272272

273273
### REMOTE_USER_ENVIRON_NAME
274274

275-
The name of the WSGI environment variable to read for `webserver authentication
276-
<webserver-authentication>`.
275+
The name of the WSGI environment variable to read for `webserver authentication <webserver-authentication>`.
276+
It is only used with the `PulpRemoteUserAuthentication` authentication class.
277277

278278
!!! warning
279279
Configuring this has serious security implications. See the [Django warning at the end of this
@@ -283,6 +283,14 @@ Defaults to `'REMOTE_USER'`.
283283

284284

285285

286+
### REMOTE_USER_OPENAPI_SECURITY_SCHEME
287+
288+
A JSON object representing the security scheme advertised for the `PulpRemoteUserAuthentication` authentication class.
289+
290+
Defaults to `{"type": "mutualTLS"}`, which represents x509 certificate based authentication.
291+
292+
293+
286294
### ALLOWED_IMPORT_PATHS
287295

288296
One or more real filesystem paths that Remotes with filesystem paths can import from. For example

template_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pulp_settings:
7171
upload_protection_time: 10
7272
pulp_settings_azure:
7373
domain_enabled: true
74+
rest_framework__default_authentication_classes: '@merge pulpcore.app.authentication.PulpRemoteUserAuthentication'
7475
pulp_settings_gcp: null
7576
pulp_settings_s3:
7677
authentication_backends: '@merge django.contrib.auth.backends.RemoteUserBackend'

0 commit comments

Comments
 (0)