-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support for client secret file. #355
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
Conversation
Do I need to create a feature branch for this PR? |
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.
Hey @pasha-r, thanks for implementing this!
I'm pretty happy with this in general, thought I did leave a couple of comments for potential improvements
Updated the naming: the method is |
if o.ClientSecret == "" && o.ClientSecretFile != "" { | ||
_, err := ioutil.ReadFile(o.ClientSecretFile) | ||
if err != nil { | ||
msgs = append(msgs, "could not read client secret file: "+o.ClientSecretFile) | ||
} | ||
} |
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.
Why do we read the file and do nothing with it? Just to check it's valid?
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.
Yep.
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.
Added one nit, otherwise looking good
Please add a note to the changelog to explain the change and then we can get this merged
Co-Authored-By: Joel Speed <Joel.speed@hotmail.co.uk>
CHANGELOG entry - done. |
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.
LGTM, thanks!
I don't understand the documentation Does this mean I have to manually call this on the oauth2-proxy executable? At the moment I start oauth2-proxy and the secret gets updated while the program is running - oauth2-proxy does not seem to pickup the change automatically?! |
Hi @col-panic could you share your configuration? |
I have a docker compose configuration with the service like this
Now some time after startup of the oauth2-proxy, the key in This is what confuses me in the doc - switching to |
|
I couldn't add the client_secret_file key in my oauth2_proxy.cfg. oauth2_proxy.cfg: |
oidc_issuer_url = "https://login.microsoftonline.com/${tenant_id}/v2.0"
redirect_url = "https://${hostname}"
email_domains = [ "*" ]
upstreams = [ "http://${frontend.name}-service.${namespace}.svc.cluster.local:${frontend.port}" ]
http_address = "0.0.0.0:${oauth2_port}"
provider = "oidc"
client_secret_file: "/mnt/secretstore/client-secret" # This gets an error |
Also somehow get this error: |
Hi @col-panic, first of all, you aren't using our official docker images from quay.io/oauth2-proxy/oauth2-proxy. I have no idea what exactly bitnami is packaging on docker hub. I know they repackage a lot of open source project. I just checked the code. We always read the client secret file when the toke redeeming is happening: Redeem: oauth2-proxy/providers/provider_default.go Lines 45 to 52 in bfd667e
GetClientSecret: oauth2-proxy/providers/provider_data.go Lines 64 to 76 in bfd667e
Unfortunately, the Redeem is only called on the full initial oauth2 flow and not the simple authentication path on subsequent requests. |
All providers should support it. The issue seems to be as described above but I haven't done a deep analysis yet. |
Your last line is wrong. You are using ":" instead of "=". It's a toml file not a yaml file.
|
This looks like you made a mistake in your helm chart values.yaml. Can you share your config? |
Yeah, I tried to explicity set the command together with the config file in my oauth2 deployment. But it didn't work. The spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: "RuntimeDefault"
fsGroup: 101
containers:
- name: oauth2proxy
image: <repo>.azurecr.io/oauth2-proxy/oauth2-proxy:stable
args: ["--config=/etc/oauth2_proxy/oauth2_proxy.cfg", "--client-secret-file='/mnt/secretstore/client-secret'"] |
@tuunit Is the client_secret_file parameter by .cfg config supported for all providers? Should I try changing from oidc provider to azure, or will it not matter? I see that in commit |
Your configuration is wrong:
You have essential tried to use a flag "--config=/etc/oauth2_proxy/oauth2_proxy.cfg" with a parameter of "--client-secret-file=/mnt/secretstore/client-secret". |
The |
@tuunit Thanks for your patience. I get sporadic 403 CSRF error, sometimes adding client-id, client-secret and cookie through environment variable works. Changing to using Could you take a look? apiVersion: apps/v1
kind: Deployment
metadata:
name: app-oauth2-proxy
labels:
app.kubernetes.io/name: app-oauth2-proxy
app.kubernetes.io/created-by: app
app.kubernetes.io/component: frontend-oauth2-proxy
spec:
selector:
matchLabels:
app: app-oauth2-proxy
template:
metadata:
labels:
app: app-oauth2-proxy
app.kubernetes.io/name: app-oauth2-proxy
app.kubernetes.io/created-by: app
app.kubernetes.io/component: frontend-oauth2-proxy
azure.workload.identity/use: "true"
spec:
serviceAccountName: <keyvault_mi>
securityContext:
runAsNonRoot: true
seccompProfile:
type: "RuntimeDefault"
fsGroup: 101
containers:
- name: oauth2proxy
image: <acr>.azurecr.io/oauth2-proxy/oauth2-proxy:v7.5.1
args: ["--config","/etc/oauth2_proxy/oauth2_proxy.cfg"]
# Could comment this in instead, get CSRF error.
# args: ["--config","/etc/oauth2_proxy/oauth2_proxy.cfg","--client-secret-file","/mnt/secretstore/client-secret"]
livenessProbe:
httpGet:
path: /ping
port: 8080
periodSeconds: 3
timeoutSeconds: 1
resources:
limits:
cpu: 500m
memory: 200Mi
requests:
cpu: 200m
memory: 100Mi
ports:
- name: oauth2proxy-pod
containerPort: 8080
volumeMounts:
- name: app-oauth2-proxy-config
mountPath: /etc/oauth2_proxy/
- name: oauth2-proxy-secrets-store
mountPath: /mnt/secretstore
readOnly: true
env:
- name: OAUTH2_PROXY_CLIENT_ID
valueFrom:
secretKeyRef:
name: oauth2-proxy-secrets-store
key: client-id
- name: OAUTH2_PROXY_CLIENT_SECRET # Could comment this out
valueFrom:
secretKeyRef:
name: oauth2-proxy-secrets-store
key: client-secret
- name: OAUTH2_PROXY_COOKIE_SECRET
valueFrom:
secretKeyRef:
name: oauth2-proxy-secrets-store
key: cookie-secret
securityContext:
privileged: false
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
volumes:
- name: app-oauth2-proxy-config
configMap:
name: app-oauth2-proxy
- name: oauth2-proxy-secrets-store
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: app-oauth2-proxy And configmap: apiVersion: v1
kind: ConfigMap
metadata:
name: app-oauth2-proxy
data:
oauth2_proxy.cfg: |
oidc_issuer_url = "https://login.microsoftonline.com/${tenant_id}/v2.0"
redirect_url = "https://${hostname}"
email_domains = [ "*" ]
upstreams = [ "http://app-service.${namespace}.svc.cluster.local:9898" ]
http_address = "0.0.0.0:8080"
provider = "oidc"
# Could add this, get CSRF error if env variables in deployment are not added
# client_secret_file = "/mnt/secretstore/client-secret"
cookie_secure = true
whitelist_domains = ".<domain>.com"
cookie_domains = ".<domain>.com"
cookie_expire = "4h"
cookie_refresh = "2h"
cookie_samesite = "lax"
cookie_name = "__Host-app"
pass_access_token = true
pass_authorization_header = true
skip_provider_button = true
set_authorization_header = true
set_xauthrequest = true
skip_auth_preflight = false
session_store_type = "redis"
redis_connection_url = "redis://redis-master.oauth2-proxy.svc.cluster.local:6379" |
@admincasper you might have actually found a bug then 🤔 I'll have to check the code for the differences in the flow. |
@tuunit The CSRF issue was fixed by removing |
We had a brief discussion about this issue here: #341
Description
Motivation and Context
Some OAuth2 identity management systems rotate client secrets and upload such secrets to running applications as a file in a mounted volume. I would like to be able to read client secret from an in-memory file every time I need to issue a redeem or redeem refresh request.
How Has This Been Tested?
I checked that all existing tests run correctly. I added tests for Options and DataProvider. And checked that Redeem fails if the client secret file is missing.
Checklist: