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 CSRF & CORS problems #1477

Merged
merged 7 commits into from
Sep 3, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ spec:
key: {{ .Values.secrets.servicePsql.key.databasePassword }}
- name: PUBLIC_GROUP_NAME
value: {{ .Values.application.publicGroupName }}
- name: ALLOWED_HOSTS
value: {{ .Values.application.allowedHosts | quote }}
- name: CSRF_TRUSTED_ORIGINS
value: {{ .Values.application.trustedOrigins | quote }}
- name: CORS_ALLOWED_ORIGIN_REGEXES
value: {{ .Values.application.corsOrigins | quote }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
3 changes: 3 additions & 0 deletions charts/qiskit-serverless/charts/gateway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ application:
iqpQcon:
url: "https://api-qcon.quantum.ibm.com/api"
publicGroupName: "ibm-q/open/main"
allowedHosts: "*"
trustedOrigins: "http://localhost"
corsOrigins: "http://localhost"

cos:
claimName: gateway-claim
Expand Down
14 changes: 14 additions & 0 deletions gateway/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,20 @@
# SECURITY WARNING: don't run with debug turned on in production!
LOG_LEVEL = "DEBUG" if int(os.environ.get("DEBUG", 1)) else "INFO"

# It must be a full url without protocol: mydomain.com
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "*").split(",")

# It must be a full url: https://mydomain.com
CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS", "http://localhost").split(
","
)

# It must be a regex compatible: ^https://\w+\.example\.com$
CORS_ALLOWED_ORIGIN_REGEXES = os.environ.get(
"CORS_ALLOWED_ORIGIN_REGEXES", "http://localhost"
).split(",")
CORS_ALLOWED_ORIGIN_REGEXES = [rf"{pattern}" for pattern in CORS_ALLOWED_ORIGIN_REGEXES]

# allow connections from any kubernetes pod within the cluster
# k8s pods are given an IP on the private 10. network, and 10.0.0.0/8
# includes all 10. IPs.
Expand All @@ -64,9 +76,11 @@
"api",
"psycopg2",
"drf_yasg",
"corsheaders",
]

MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"csp.middleware.CSPMiddleware",
"allow_cidr.middleware.AllowCIDRMiddleware",
"django_prometheus.middleware.PrometheusBeforeMiddleware",
Expand Down
1 change: 1 addition & 0 deletions gateway/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ drf-yasg>=1.21.7, <2
sqlparse>=0.5.0, <1
qiskit-ibm-runtime>=0.27.0
tzdata>=2024.1
django-cors-headers>=4.4.0, <5