-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat(cryostat): re-implement basic auth via oauth2-proxy htpasswd config #118
Conversation
49fd8c7
to
8c246a8
Compare
Not sure why it's showing so many conflicts - just try a |
8c84445
to
a795ea7
Compare
Rebase on top of upstream/cryostat3 again please - I just updated that to be up to date with |
Okay, so now that we've figured out how to get it deployable and running again... back to reviewing the important changes from this PR. |
I think with my latest changes this is more or less working. When you open the Next steps for you to tackle, please:
For separate PR(s): |
For example, I created this secret manually: apiVersion: v1
data:
htpasswd: dXNlcjokMnkkMDUkLnAxLzY4b0JXS1gxRmhBdFpPQXJZT29Ob01xc0I0eXVVTlhHT2VTQVRIUHEzZ2VLcUVhWlM=
kind: Secret
metadata:
creationTimestamp: "2024-02-09T17:07:49Z"
name: basicauth
namespace: cryostat3
resourceVersion: "75991"
uid: 16eab9c1-8dd3-4b64-b544-cbb4d52cccba
type: Opaque This is still just $ htpasswd -nbB user pass >> htpasswd
$ htpasswd -nbB atif atifspassword >> htpasswd
$ oc create secret generic basicauth --from-file htpasswd=./htpasswd # no need to use `base64` command if you create from file like this and I applied this patch on top of this branch: diff --git a/charts/cryostat/templates/auth2_proxy.yaml b/charts/cryostat/templates/auth2_proxy.yaml
deleted file mode 100644
index e49b4b1..0000000
--- a/charts/cryostat/templates/auth2_proxy.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
-apiVersion: v1
-kind: Secret
-metadata:
- name: {{ .Release.Name }}-auth-proxy-secret
-data:
- auth_proxy_htpasswd: {{ .Values.authentication.basicAuth.secretName | b64enc | quote }}
diff --git a/charts/cryostat/templates/deployment.yaml b/charts/cryostat/templates/deployment.yaml
index 88536bd..d420158 100644
--- a/charts/cryostat/templates/deployment.yaml
+++ b/charts/cryostat/templates/deployment.yaml
@@ -208,21 +208,22 @@ spec:
value: {{ include "cryostat.cookieSecret" . }}
- name: OAUTH2_PROXY_EMAIL_DOMAINS
value: "*"
+ {{- if .Values.authentication.basicAuth.enabled }}
- name: OAUTH2_PROXY_HTPASSWD_USER_GROUP
value: write
+ - name: OAUTH2_PROXY_HTPASSWD_FILE
+ value: /etc/oauth2_proxy/basicauth/{{ .Values.authentication.basicAuth.filename }}
+ {{- end }}
{{- if not .Values.authentication.basicAuth.enabled }}
- name: OAUTH2_PROXY_SKIP_AUTH_ROUTES
value: ".*"
- {{- end }}
+ {{- end }}
volumeMounts:
- - name: auth-proxy-config
- mountPath: /etc/oauth2_proxy
- readOnly: true
- name: alpha-config
mountPath: /etc/oauth2_proxy/alpha_config
{{- if .Values.authentication.basicAuth.enabled }}
- - name: basic-auth-secret
- mountPath: /etc/oauth2_proxy/basic-auth-secret
+ - name: {{ .Release.Name }}-htpasswd
+ mountPath: /etc/oauth2_proxy/basicauth
readOnly: true
{{- end }}
- name: {{ printf "%s-%s" .Chart.Name "grafana" }}
@@ -291,11 +292,8 @@ spec:
- name: alpha-config
configMap:
name: {{ .Release.Name }}-alpha-config
- - name: auth-proxy-config
- secret:
- secretName: {{ .Release.Name }}-auth-proxy-secret
{{- if .Values.authentication.basicAuth.enabled }}
- - name: basic-auth-secret
+ - name: {{ .Release.Name }}-htpasswd
secret:
secretName: {{ .Values.authentication.basicAuth.secretName }}
{{- end }} With this, I can do: $ helm install cryostat --set pvc.enabled=true --set core.route.enabled=true --set authentication.basicAuth.enabled=false --set authentication.basicAuth.secretName=basicauth --set authentication.basicAuth.filename=htpasswd ./charts/cryostat and get a deployment that has an authproxy set up but which passes all requests without authentication. Simply changing that to $ helm install cryostat --set pvc.enabled=true --set core.route.enabled=true --set authentication.basicAuth.enabled=true --set authentication.basicAuth.secretName=basicauth --set authentication.basicAuth.filename=htpasswd ./charts/cryostat gets me a deployment that uses the Secret I created to perform basic auth on the proxy. |
…er-supplied htpasswd
yes I have done something similar... but runs well on OpenShift |
Are you in the |
Looks good now on my side too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good now, but let's wait for @ebaron to be back and give it a look-over too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks mostly good, but I think there's still the odd bug. When I tested using the default ClusterIP
service type, I didn't get directed to the OAuth login page, but to Cryostat itself.
Here's how I tested:
$ htpasswd -nbB foo bar > /tmp/htpasswd
$ oc create secret generic htpasswd --from-file=htpasswd=/tmp/htpasswd
$ helm install cryostat ./charts/cryostat/ --set authentication.basicAuth.enabled=true,authentication.basicAuth.secretName=htpasswd,authentication.basicAuth.filename=htpasswd
This is the output of the NOTES:
- Tell Cryostat how to serve external traffic:
export POD_NAME=$(kubectl get pods -n helm-test -l "app.kubernetes.io/name=cryostat,app.kubernetes.io/instance=cryostat" --sort-by=.metadata.creationTimestamp -o jsonpath="{.items[-1:].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod -n helm-test $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
export GRAFANA_CONTAINER_PORT=$(kubectl get pod -n helm-test $POD_NAME -o jsonpath="{.spec.containers[1].ports[0].containerPort}")
kubectl -n helm-test set env deploy --containers=cryostat cryostat CRYOSTAT_WEB_HOST=127.0.0.1 CRYOSTAT_EXT_WEB_PORT=8080 GRAFANA_DASHBOARD_URL=http://127.0.0.1:$GRAFANA_CONTAINER_PORT GRAFANA_DASHBOARD_EXT_URL=http://127.0.0.1:8081
- Forward local ports to the application's pod:
export POD_NAME=$(kubectl get pods -n helm-test -l "app.kubernetes.io/name=cryostat,app.kubernetes.io/instance=cryostat" --sort-by=.metadata.creationTimestamp -o jsonpath="{.items[-1:].metadata.name}")
kubectl -n helm-test wait --for=condition=available --timeout=60s deploy/cryostat
kubectl -n helm-test port-forward $POD_NAME 8080:$CONTAINER_PORT 8081:$GRAFANA_CONTAINER_PORT
- Visit the Cryostat application at:
http://127.0.0.1:8080
I think in this case the CONTAINER_PORT
environment variable is wrong. This should point to the oauth-proxy's container port and not Cryostat's container port.
Also, should Cryostat be binding to localhost instead of 0.0.0.0 now?
I'm working on that ClusterIP setup and related things in #122 . I think the Route and ClusterIP setups in that draft are mostly working but I still need to figure out the other options (Ingress etc.) I think I only tested this PR with |
That's a good call, I'll put that change here since it's just a oneliner. The storage container also binds on |
fixes: #116