Skip to content

Commit a0e7e35

Browse files
committed
Configure python SimpleView access for public domains
ref: https://issues.redhat.com/browse/PULP-1065
1 parent 1ae68a8 commit a0e7e35

File tree

6 files changed

+605
-6
lines changed

6 files changed

+605
-6
lines changed

.tekton/pulp-deploy-and-test.yaml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,153 @@ spec:
781781
# Run pulp_npm functional tests
782782
cmd_prefix bash -c "HOME=/tmp/home PYTHONPATH=/tmp/home/.local/lib/python3.11/site-packages/ XDG_CONFIG_HOME=/tmp/home/.config API_PROTOCOL=http API_HOST=pulp-api API_PORT=8000 ADMIN_USERNAME=admin ADMIN_PASSWORD=$PASSWORD /tmp/home/.local/bin/pytest -o cache_dir=/tmp/home/.cache/pytest_cache -v -r sx --color=yes --pyargs pulp_npm.tests.functional -k 'test_pull_through_install' --junitxml=/tmp/home/junit-pulp-serial.xml" || debug_and_fail
783783
784+
- name: pulp-service-functional-tests
785+
when:
786+
- input: '$(tasks.test-metadata.results.test-event-type)'
787+
operator: in
788+
values: ["pull_request"]
789+
runAfter:
790+
- install-bindings
791+
params:
792+
- name: BONFIRE_IMAGE
793+
value: "$(params.BONFIRE_IMAGE)"
794+
- name: NS
795+
value: "$(tasks.reserve-namespace.results.NS)"
796+
- name: EPHEMERAL_ENV_PROVIDER_SECRET
797+
value: "$(params.EPHEMERAL_ENV_PROVIDER_SECRET)"
798+
taskSpec:
799+
params:
800+
- name: BONFIRE_IMAGE
801+
type: string
802+
description: The container Bonfire image to use for the tekton tasks
803+
default: quay.io/redhat-user-workloads/hcc-devprod-tenant/hcc-cicd-tools/cicd-tools:834176766e3f911ffa24bfacff59dd15126e4b3a
804+
- name: EPHEMERAL_ENV_PROVIDER_SECRET
805+
type: string
806+
default: ephemeral-env-provider
807+
- name: NS
808+
type: string
809+
description: Namespace name to deploy the application to
810+
steps:
811+
- name: functional-tests
812+
image: "$(params.BONFIRE_IMAGE)"
813+
env:
814+
- name: OC_LOGIN_TOKEN
815+
valueFrom:
816+
secretKeyRef:
817+
name: $(params.EPHEMERAL_ENV_PROVIDER_SECRET)
818+
key: token
819+
- name: OC_LOGIN_SERVER
820+
valueFrom:
821+
secretKeyRef:
822+
name: $(params.EPHEMERAL_ENV_PROVIDER_SECRET)
823+
key: url
824+
- name: NS
825+
value: $(params.NS)
826+
script: |
827+
set -ex
828+
829+
login.sh
830+
831+
if [ -n "$NS" ]; then
832+
oc_wrapper project $NS
833+
else
834+
export NS=$(oc_wrapper project | grep -oE 'ephemeral-......')
835+
fi
836+
echo "Namespace is $NS"
837+
838+
PASSWORD=$(oc_wrapper extract secret/pulp-admin-password --to=-)
839+
840+
POD=$(oc_wrapper get pod | grep -oE "pulp-api\S*")
841+
echo $POD
842+
oc_wrapper get pod $POD -o yaml | grep memory:
843+
844+
oc_wrapper get clowdenvironment env-$(oc_wrapper project | grep -oE 'ephemeral-......') -o yaml
845+
846+
oc_wrapper get clowdapp pulp -o yaml
847+
848+
### Adapted from ./.github/workflows/scripts/utils.sh
849+
# Run a command
850+
cmd_prefix() {
851+
oc_wrapper exec -c pulp-api deployment/pulp-api -- "$@"
852+
}
853+
854+
# Run a command, and pass STDIN
855+
cmd_stdin_prefix() {
856+
oc_wrapper exec -c pulp-api -i deployment/pulp-api -- "$@"
857+
}
858+
### END Adapted from ./.github/workflows/scripts/utils.sh
859+
860+
debug_and_fail() {
861+
oc_wrapper logs $(oc_wrapper get pod | grep -oE "pulp-content\S*")
862+
oc_wrapper logs $(oc_wrapper get pod | grep -oE "pulp-api\S*")
863+
echo "CURL OUTPUT"
864+
curl https://env-${NS}.apps.crc-eph.r9lp.p1.openshiftapps.com/api/pulp-content/default/
865+
echo "ROUTES"
866+
oc_wrapper get route
867+
exit 1
868+
}
869+
870+
cmd_prefix bash -c "HOME=/tmp/home pip3 install pytest\<8"
871+
cmd_prefix bash -c "HOME=/tmp/home pip3 install pulp-smash@git+https://github.com/pulp/pulp-smash.git@2ded6671e0f32c51e70681467199e8a195f7f5fe"
872+
873+
cmd_prefix mkdir -p /tmp/home/.config/pulp_smash
874+
cat << EOF >> pulp-smash.json
875+
{
876+
"pulp": {
877+
"auth": [
878+
"admin",
879+
"password"
880+
],
881+
"selinux enabled": false,
882+
"version": "3"
883+
},
884+
"hosts": [
885+
{
886+
"hostname": "pulp-api",
887+
"roles": {
888+
"api": {
889+
"port": 8000,
890+
"scheme": "http",
891+
"service": "nginx"
892+
},
893+
"content": {
894+
"port": 8000,
895+
"scheme": "https",
896+
"service": "pulp-content"
897+
},
898+
"pulp resource manager": {},
899+
"pulp workers": {},
900+
"redis": {},
901+
"shell": {
902+
"transport": "local"
903+
}
904+
}
905+
}
906+
]
907+
}
908+
EOF
909+
sed "s#password#${PASSWORD}#g" pulp-smash.json > pulp-smash.customized.json
910+
sed -i "s/pulp-content/env-${NS}.apps.crc-eph.r9lp.p1.openshiftapps.com/g" pulp-smash.customized.json
911+
912+
echo "PULP-SMASH CONFIG:"
913+
cat pulp-smash.customized.json
914+
915+
curl -o functest_requirements.txt https://raw.githubusercontent.com/pulp/pulp_rpm/main/functest_requirements.txt
916+
curl -o unittest_requirements.txt https://raw.githubusercontent.com/pulp/pulp_rpm/main/unittest_requirements.txt
917+
918+
### Adapted from ./.github/workflows/scripts/script.sh
919+
cat unittest_requirements.txt | cmd_stdin_prefix bash -c "cat > /tmp/unittest_requirements.txt"
920+
cat functest_requirements.txt | cmd_stdin_prefix bash -c "cat > /tmp/functest_requirements.txt"
921+
cat pulp-smash.customized.json | cmd_stdin_prefix bash -c "cat > /tmp/home/.config/pulp_smash/settings.json"
922+
cmd_prefix bash -c "HOME=/tmp/home pip3 install -r /tmp/unittest_requirements.txt -r /tmp/functest_requirements.txt"
923+
# Because we pass the path to pytest -o cache_dir=/tmp/home/.cache/pytest_cache, pulpcore-manager must be in the same dir
924+
cmd_prefix bash -c "ln -s /usr/local/lib/pulp/bin/pulpcore-manager /tmp/home/.local/bin/pulpcore-manager || /bin/true"
925+
echo "CURL OUTPUT"
926+
curl https://env-${NS}.apps.crc-eph.r9lp.p1.openshiftapps.com/api/pulp-content/default/
927+
echo "ROUTES"
928+
oc_wrapper get route
929+
set +e
930+
784931
# Run pulp_service functional tests
785932
cmd_prefix bash -c "HOME=/tmp/home PYTHONPATH=/tmp/home/.local/lib/python3.11/site-packages/ XDG_CONFIG_HOME=/tmp/home/.config API_PROTOCOL=http API_HOST=pulp-api API_PORT=8000 ADMIN_USERNAME=admin ADMIN_PASSWORD=$PASSWORD /tmp/home/.local/bin/pytest -o cache_dir=/tmp/home/.cache/pytest_cache -v -r sx --color=yes --pyargs pulp_service.tests.functional -m 'not parallel' --junitxml=/tmp/home/junit-pulp-serial.xml" || debug_and_fail
786933
@@ -800,6 +947,7 @@ spec:
800947
value: "$(params.SNAPSHOT)"
801948
runAfter:
802949
- pulp-functional-tests
950+
- pulp-service-functional-tests
803951
taskSpec:
804952
params:
805953
- name: BONFIRE_IMAGE

deploy/clowdapp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ parameters:
11751175
value: "@merge ['django.contrib.auth.backends.RemoteUserBackend','pulp_service.app.authentication.RHSamlAuthentication']"
11761176
- name: PULP_REST_FRAMEWORK__DEFAULT_AUTHENTICATION_CLASSES
11771177
description: The default authentication classes for Pulp.
1178-
value: "['pulp_service.app.authentication.RHServiceAccountCertAuthentication','pulpcore.app.authentication.JSONHeaderRemoteAuthentication','rest_framework.authentication.BasicAuthentication','rest_framework.authentication.SessionAuthentication']"
1178+
value: "['pulp_service.app.authentication.RHServiceAccountCertAuthentication','pulpcore.app.authentication.JSONHeaderRemoteAuthentication','rest_framework.authentication.BasicAuthentication','rest_framework.authentication.SessionAuthentication','pulp_service.app.authentication.RHEntitlementCertAuthentication']"
11791179
- name: PULP_REST_FRAMEWORK__DEFAULT_PERMISSION_CLASSES
11801180
description: The default permission classes for the REST API
11811181
value: "['pulp_service.app.authorization.DomainBasedPermission']"
Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
From d2578a51b604d478fae11c20fb7bb8da022bf7ce Mon Sep 17 00:00:00 2001
1+
From 6632cb10ac66d70091b4b42ec0469b963fdcc32d Mon Sep 17 00:00:00 2001
22
From: Yasen <[email protected]>
33
Date: Fri, 8 Aug 2025 15:44:15 +0200
4-
Subject: [PATCH] Add auth override to pulp-python SimpleView
4+
Subject: [PATCH 1/2] Add auth override to pulp-python SimpleView
55

66
---
77
pulp_python/app/pypi/views.py | 2 ++
88
1 file changed, 2 insertions(+)
99

1010
diff --git a/pulp_python/app/pypi/views.py b/pulp_python/app/pypi/views.py
11-
index 79033d4..0e8a747 100644
11+
index b7808a9..3f44390 100644
1212
--- a/pulp_python/app/pypi/views.py
1313
+++ b/pulp_python/app/pypi/views.py
14-
@@ -220,6 +220,8 @@ class SimpleView(PackageUploadMixin, ViewSet):
14+
@@ -255,6 +255,8 @@ class SimpleView(PackageUploadMixin, ViewSet):
1515
"""View for the PyPI simple API."""
1616

1717
endpoint_name = "simple"
@@ -21,4 +21,41 @@ index 79033d4..0e8a747 100644
2121
"statements": [
2222
{
2323
--
24-
2.50.1
24+
2.46.2
25+
26+
27+
From 88bb3da0ef0a8ac1c0a51188bd31a7f72f2eb96e Mon Sep 17 00:00:00 2001
28+
From: git-hyagi <[email protected]>
29+
Date: Wed, 7 Jan 2026 14:21:13 -0300
30+
Subject: [PATCH 2/2] Add PublicDomainPermission to SimpleView
31+
permission_classes
32+
33+
---
34+
pulp_python/app/pypi/views.py | 4 ++--
35+
1 file changed, 2 insertions(+), 2 deletions(-)
36+
37+
diff --git a/pulp_python/app/pypi/views.py b/pulp_python/app/pypi/views.py
38+
index 3f44390..cf0f596 100644
39+
--- a/pulp_python/app/pypi/views.py
40+
+++ b/pulp_python/app/pypi/views.py
41+
@@ -54,6 +54,7 @@ from pulp_python.app.utils import (
42+
)
43+
44+
from pulp_python.app import tasks
45+
+from pulp_service.app.authorization import DomainBasedPermission, PublicDomainPermission
46+
47+
log = logging.getLogger(__name__)
48+
49+
@@ -255,8 +256,7 @@ class SimpleView(PackageUploadMixin, ViewSet):
50+
"""View for the PyPI simple API."""
51+
52+
endpoint_name = "simple"
53+
- authentication_classes = []
54+
- permission_classes = []
55+
+ permission_classes = [PublicDomainPermission|DomainBasedPermission]
56+
DEFAULT_ACCESS_POLICY = {
57+
"statements": [
58+
{
59+
--
60+
2.46.2
61+

pulp_service/pulp_service/app/authorization.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.db.models import Q
55
import json
66
import jq
7+
from pulpcore.plugin.models import Domain
78
from pulpcore.plugin.util import extract_pk, get_domain_pk
89
from pulp_service.app.models import DomainOrg
910
from rest_framework.permissions import BasePermission
@@ -117,3 +118,26 @@ def get_org_id(self, decoded_header_content):
117118
return org_id_json_path.input_value(header_value).first()
118119
except json.JSONDecodeError:
119120
return
121+
122+
123+
class PublicDomainPermission(BasePermission):
124+
"""
125+
A Permission Class that grants permission to Domains with public- prefix
126+
"""
127+
128+
def has_permission(self, request, view):
129+
# Only allow GET requests
130+
if request.method != "GET":
131+
return False
132+
133+
try:
134+
domain_pk = get_domain_pk()
135+
domain = Domain.objects.get(pk=domain_pk)
136+
if domain.name.startswith("public-"):
137+
return True
138+
except Exception:
139+
# If we can't get the domain, deny access
140+
return False
141+
142+
# Not a public domain
143+
return False

pulp_service/pulp_service/tests/functional/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,34 @@ def _gen_group(name=None):
4040
pulpcore_bindings.GroupsApi, {"name": name}
4141
)
4242
return _gen_group
43+
44+
45+
@pytest.fixture()
46+
def cleanup_auth_headers(request, pulpcore_bindings):
47+
"""
48+
Automatically clean up x-rh-identity headers before each test.
49+
50+
This prevents authentication headers from leaking between tests
51+
and affecting other test results.
52+
"""
53+
# Clean up after the test runs
54+
if hasattr(pulpcore_bindings, "DomainsApi"):
55+
pulpcore_bindings.DomainsApi.api_client.default_headers.pop("x-rh-identity", None)
56+
57+
# Try to clean up file_bindings if it was used in the test
58+
if "file_bindings" in request.fixturenames:
59+
file_bindings = request.getfixturevalue("file_bindings")
60+
if hasattr(file_bindings, "RepositoriesFileApi"):
61+
file_bindings.RepositoriesFileApi.api_client.default_headers.pop("x-rh-identity", None)
62+
63+
# Try to clean up python_bindings if it was used in the test
64+
if "python_bindings" in request.fixturenames:
65+
python_bindings = request.getfixturevalue("python_bindings")
66+
if hasattr(python_bindings, "RepositoriesPythonApi"):
67+
python_bindings.RepositoriesPythonApi.api_client.default_headers.pop(
68+
"x-rh-identity", None
69+
)
70+
if hasattr(python_bindings, "DistributionsPypiApi"):
71+
python_bindings.DistributionsPypiApi.api_client.default_headers.pop(
72+
"x-rh-identity", None
73+
)

0 commit comments

Comments
 (0)