简体   繁体   English

Nginx开源是否支持OpenID和JWT

[英]Does Nginx open source support OpenID and JWT

I have a basic Nginx docker image, acting as a reverse-proxy, that currently uses basic authentication sitting in front of my application server.我有一个基本的 Nginx docker 图像,充当反向代理,目前使用位于我的应用程序服务器前面的基本身份验证。 I'm looking for a way to integrate it with our SSO solution in development that uses JWT, but all of the documentation says it requires Nginx+.我正在寻找一种方法将它与我们使用 JWT 的开发中的 SSO 解决方案集成,但所有文档都说它需要 Nginx+。 So, is it possible to do JWT validation inside of open-sourced Nginx, or do I need the paid version?那么,是否可以在开源 Nginx 内部进行 JWT 验证,还是我需要付费版本?

Sure, there are open source codes, which you can use and customize for your case ( example ).当然,有开源代码,您可以根据自己的情况使用和自定义(示例)。

IMHO there are better implementations, which you can use as an "auth proxy" in front of your application.恕我直言,有更好的实现,您可以将其用作应用程序前面的“身份验证代理”。 My favorite is keycloak-gatekeeper (you can use it with any OpenID IdP, not only with the Keycloak), which can provide authentication, authorization, token encryption, refresh token implementation, small footprint, ...我最喜欢的是keycloak-gatekeeper (您可以将它与任何 OpenID IdP 一起使用,而不仅仅是与 Keycloak 一起使用),它可以提供身份验证、授权、令牌加密、刷新令牌实现、占用空间小、......

There's also lua-resty-openidc : https://github.com/zmartzone/lua-resty-openidc还有lua-resty-openidchttps : //github.com/zmartzone/lua-resty-openidc

lua-resty-openidc is a library for NGINX implementing the OpenID Connect Relying Party (RP) and/or the OAuth 2.0 Resource Server (RS) functionality. lua-resty-openidc 是 NGINX 的库,用于实现 OpenID 连接依赖方 (RP) 和/或 OAuth 2.0 资源服务器 (RS) 功能。

When used as an OpenID Connect Relying Party it authenticates users against an OpenID Connect Provider using OpenID Connect Discovery and the Basic Client Profile (ie the Authorization Code flow).当用作 OpenID Connect 依赖方时,它使用 OpenID Connect 发现和基本客户端配置文件(即授权代码流)根据 OpenID Connect 提供者对用户进行身份验证。 When used as an OAuth 2.0 Resource Server it can validate OAuth 2.0 Bearer Access Tokens against an Authorization Server or, in case a JSON Web Token is used for an Access Token, verification can happen against a pre-configured secret/key .当用作 OAuth 2.0 资源服务器时,它可以根据授权服务器验证 OAuth 2.0 承载访问令牌,或者,如果 JSON Web 令牌用于访问令牌,则可以根据预先配置的密钥/密钥进行验证。

Given that you have a configuration set up without authentication, I found this and got it to work: https://hub.docker.com/r/tomsmithokta/nginx-oss-okta which is entirely based on the lua-resty-openidc as mentioned above.鉴于您在没有身份验证的情况下设置了配置,我找到了它并使其工作: https : lua-resty-openidc完全基于lua-resty-openidc正如刚才提到的。 The fact that it was already built was helpful for me though.不过,它已经建成的事实对我很有帮助。

First configure your Okta app in the Okta web GUI then fill in the proper fields that are not commented out in the NGINX example conf.首先在 Okta Web GUI 中配置您的 Okta 应用程序,然后填写在 NGINX 示例配置中未注释掉的正确字段。 The only caveat is to uncomment the redirect_uri and fill that in but instead comment out or remove the redirect_uri_path which is a deprecated field.唯一需要注意的是取消对 redirect_uri 的注释并填写它,而是注释掉或删除 redirect_uri_path,这是一个不推荐使用的字段。 All the other things in the config are parameters you can play with or just accept them as is.配置中的所有其他内容都是您可以使用的参数,也可以按原样接受它们。

By default it passes you onto a headers page but if you adjust the proxy_pass field you should be able to pass it to your app.默认情况下,它会将您传递到标题页面,但如果您调整 proxy_pass 字段,您应该能够将其传递给您的应用程序。

based on this gist https://gist.github.com/abbaspour/af8dff3b297b0fcc6ba7c625c2d7c0a3基于这个要点https://gist.github.com/abbaspour/af8dff3b297b0fcc6ba7c625c2d7c0a3

here's how I did it in a dockerfile ( based on buster-slim )这是我在 dockerfile 中的做法(基于 buster-slim )

FROM python:3.9-slim as base

FROM base as builder

ENV LANG en_GB.UTF-8 \
    LANGUAGE en_GB.UTF-8 \
    PYTHONUNBUFFERED=True \
    PYTHONIOENCODING=UTF-8

RUN apt-get update \
    && apt-get install --no-install-recommends --no-install-suggests -y \
    build-essential  \
    patch \
    git \
    wget \
    libssl-dev \
    libjwt-dev \
    libjansson-dev \
    libpcre3-dev \
    zlib1g-dev \
    && wget https://nginx.org/download/nginx-1.18.0.tar.gz \
    && tar -zxvf nginx-1.18.0.tar.gz \
    && git clone https://github.com/TeslaGov/ngx-http-auth-jwt-module \
    && cd nginx-1.18.0  \
    && ./configure --add-module=../ngx-http-auth-jwt-module \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-ld-opt="-L/usr/local/opt/openssl/lib" \
    --with-cc-opt="-I/usr/local/opt/openssl/include" \
    && make


FROM base

COPY --from=builder /nginx-1.18.0/objs/nginx /usr/sbin/nginx
COPY --from=builder /nginx-1.18.0/conf /usr/local/nginx/conf

ENV LANG en_GB.UTF-8 \
    LANGUAGE en_GB.UTF-8 \
    PYTHONUNBUFFERED=True \
    PYTHONIOENCODING=UTF-8

RUN apt-get update && \
    apt-get install --no-install-recommends --no-install-suggests -y \
    libssl-dev \
    libjwt-dev \
    libjansson-dev \
    libpcre3-dev \
    zlib1g-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM