travisghansen / external-auth-server

easy auth for reverse proxies
MIT License
330 stars 44 forks source link

Environment variables #180

Open gfrankliu opened 1 year ago

gfrankliu commented 1 year ago

The docker example in the README mentions bunch of environment variables.

docker run -d --name eas -p 8080:8080 \
-e EAS_CONFIG_TOKEN_SIGN_SECRET="foo" \
-e EAS_CONFIG_TOKEN_ENCRYPT_SECRET="bar" \
-e EAS_ISSUER_SIGN_SECRET="super secret" \
-e EAS_ISSUER_ENCRYPT_SECRET="blah" \
-e EAS_COOKIE_SIGN_SECRET="hello world" \
-e EAS_COOKIE_ENCRYPT_SECRET="something" \
-e EAS_SESSION_ENCRYPT_SECRET="baz" \
-e EAS_CONFIG_TOKEN_STORES='{}' \
-e EAS_LOG_LEVEL="info" \
-e EAS_PORT=8080 \
travisghansen/external-auth-server

Is there a doc explaining those? I assume some of them are used only by some plugins. So if I don't use those plugins, I could just not set, or give some dummy values.

travisghansen commented 1 year ago

Good point. I didn’t realize those never got documented properly.

The CONFIG_ are required for everything. The issuer/cookie/session stuff is currently only for oauth/oidc use. Having said that, the deployment checks for the env vars at startup to ensure the service is fully functional as it has no knowledge of config tokens at startup.

gfrankliu commented 1 year ago

What's the different use for SIGN_SECRET and ENCRYPT_SECRET? Do we need both for everything? eg: oauth2-proxy only uses a single --cookie-secret to encrypt/decrypt cookies.

travisghansen commented 1 year ago

Here's the breakdown:

oauth2-proxy is a very different approach to the same problem and has far few features. It's limitations are one of the prime reasons I wrote this. In order to keep everything nice and secure and to handle/offload a bunch of features client-side to a mostly stateless service required a lot of signing and encrypting and using different keys for the different attack vectors to keep the blast radius low should something be compromised :)

gfrankliu commented 1 year ago

Thanks for keeping security in mind! Have you tried enabling the github dependabot for this repo? It can find if any dependent packages in package.json or yarn.lock, with versions that have vulnerabilities.

gfrankliu commented 1 year ago

In one of my m2m use case, I use jwt plugin and all requests will come with jwt header:

eas:
  plugins:
    - type: jwt
      header_name: my-jwt-header
      config:
        secret: https://www.provider1.com/public_key-jwk.json
        options:
          audience: /special/audience/for/me
          issuer: https://www.provider1.com

In this case, I guess there are no cookie, sign/encrypt secrets needed, so I can just set those env variables to dummy values?

travisghansen commented 1 year ago

Yeah, but you should not need a new deployment per app if that concept was not clear. It's designed to have a single installation to handle many many configs/apps.

gfrankliu commented 1 year ago

That makes sense. One additional question regarding the jwt config:

      config:
        secret: https://www.provider1.com/public_key-jwk.json

Is this key cached? If so, for how long? Is this configurable. I see there is "expiresIn" option in this doc but not sure if that is related to this key caching. The provider may update/rotate this key, though infrequent, which will cause jwt validation failure. Will you re-retrieve the key and try again in that case, or will you always re-retrieve this file and update in-memory cache at some pre-defined internal?

travisghansen commented 1 year ago

Sorry, been super busy. So the key is cached yes and it's based on the header sent by the provider. In short it will 'just work'.

gfrankliu commented 1 year ago

I checked the key from iap :

curl -I https://www.gstatic.com/iap/verify/public_key-jwk
HTTP/2 200 
accept-ranges: bytes
content-security-policy: require-trusted-types-for 'script'; report-uri https://csp.withgoogle.com/csp/cloud-gatekeeper-team
cross-origin-resource-policy: cross-origin
cross-origin-opener-policy: same-origin; report-to="cloud-gatekeeper-team"
report-to: {"group":"cloud-gatekeeper-team","max_age":2592000,"endpoints":[{"url":"https://csp.withgoogle.com/csp/report-to/cloud-gatekeeper-team"}]}
content-length: 1352
x-content-type-options: nosniff
server: sffe
x-xss-protection: 0
date: Fri, 28 Jul 2023 15:06:26 GMT
expires: Fri, 28 Jul 2023 15:56:26 GMT
cache-control: public, max-age=3000
last-modified: Fri, 28 Jul 2023 13:40:55 GMT
content-type: application/json
vary: Accept-Encoding
age: 1023
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

Does this mean you will cache it for max-age=3000 or until expires: Fri, 28 Jul 2023 15:56:26 GMT ?

travisghansen commented 1 year ago

https://github.com/auth0/node-jwks-rsa/blob/master/EXAMPLES.md#caching

I want to say that doc has changed from what it was the last time I looked at it so it may be slightly different. The documented behavior there (which may not be the same version currently imported into the app) seems to indicated a static value defaulting to 10m. I was under the impression the older versions were using one of those 2 headers but don't recall which.

gfrankliu commented 1 year ago

Yeah, but you should not need a new deployment per app if that concept was not clear. It's designed to have a single installation to handle many many configs/apps.

My understanding is each request to the nginx ingress will trigger a call to external-auth-server. I plan to have one external-auth-server installation for each Kubernetes cluster (nginx ingress) where clusters are scattered across the world, so that auth traffic are local within the cluster. Having all clusters passing every request to a central external-auth-server installation may not be optimal. That's why I am hoping to see oauth plugin supports redirect_uri with uri only without base dns name. The base dns name could be retrieved to $host header if not provided in the redirect_uri config.

travisghansen commented 1 year ago

Yeah fair enough. The context of that comment was more about multiple apps within a single cluster.

I can look into making the value of that property a handlebars template.