Apache에서 nginx로 인증 헤더를 전달할 때 발생하는 이상한 문제 - 진행 요청에서 비어 있지 않은 헤더(se_custid/ein)를 찾을 수 없습니다.

Apache에서 nginx로 인증 헤더를 전달할 때 발생하는 이상한 문제 - 진행 요청에서 비어 있지 않은 헤더(se_custid/ein)를 찾을 수 없습니다.

아래 설명된 설정에서 Apache는 필수 헤더를 nginx 또는 nginx로 전달할 수 없는 반면 초기 요청 전달은 전체 URL이 아니라 상대 경로만 전달하는 것 같습니다.

여기서의 아이디어는 nginx에서 호스팅되는 애플리케이션에 대한 요청이 Azure ADFS에 의해 인증되도록 하는 것입니다. 이것이 작동하려면 아파치가 모든 인증 요청에 대해 프록시 역할을 합니다. Apache는 mod_auth_openidc를 사용하고 인증되지 않은 요청을 Azure ADFS에 전달합니다. 아래를 참조하세요.

Nginx -> Apache:6000-> Azure ADFS -> Apache:6000 -> Nginx

사용자가 Azure ADFS에 의해 올바르게 인증되는 동안 Nginx:80으로 다시 리디렉션되지만 앱으로 인해 브라우저에 "계속 요청에서 비어 있지 않은 헤더(se_custid/ein)를 찾을 수 없습니다."라는 이상한 오류가 표시됩니다.

Apache 로그에 두 가지 오류가 더 있습니다.

[auth_openidc:error] [pid 26485] [client SERVERIP:35888] oidc_clean_expired_state_cookies: 상태가 만료되었습니다.

nginx에 특정 오류가 기록되지 않았습니다.

여기서 질문은 인증 후 사용자가 앱을 올바르게 사용할 수 있도록 apache에서 nginx로 올바른 헤더를 전달하는 방법입니다. 아니면 아래 구성이 충분하거나 더 많은 설정이 필요합니까?

아파치 설정 부분

<Location /ourapp>
   AuthType openid-connect
   Require valid-user
</Location>

LoadModule auth_openidc_module modules/mod_auth_openidc.so
OIDCProviderMetadataURL https://login.microsoftonline.com/XXXX_XXX-xxx-XXXXXX/v2.0/.well-known/openid-configuration
OIDCClientID XXXXXXXXXXXXXXX
OIDCClientSecret XXXXXXXXXX
OIDCRedirectURI https://forever-authcheck.tire1network.com:6000/ourapp 
OIDCCryptoPassphrase XXXXXXXXXXXX
OIDCScope "openid email profile"
#OIDCRemoteUserClaim email
OIDCProviderAuthorizationEndpoint https://login.microsoftonline.com/XXXX_XXX-xxx-XXXXXX/oauth2/v2.0/authorize
OIDCProviderTokenEndpoint https://login.microsoftonline.com/XXXX_XXX-xxx-XXXXXX/oauth2/v2.0/token
#OIDCPKCEMethod S256

OIDCPassIDTokenAs claims
OIDCCookiePath /
OIDCCookieDomain forever-authcheck.tire1network.com
OIDCCookie APP-OIDC-SESSION
OIDCCookieHTTPOnly On
OIDCSessionInactivityTimeout 600
OIDCSessionMaxDuration 36006

<VirtualHost *:6000>

    ProxyPreserveHost On
    ErrorLog  /var/log/httpd/voidcerror.log
    LogLevel debug
    ServerName forever-authcheck.tire1network.com

    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header always set Access-Control-Max-Age "1000"
    Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
    
    ProxyPreserveHost On
    Header set ein %{OIDC_CLAIM_EIN}e
    ProxyPass /ourapp/ forever-authcheck.tire1network.com/in/
    ProxyPassReverse /ourapp/ forever-authcheck.tire1network.com/in/
    ProxyPreserveHost On
    ServerName  forever-authcheck.tire1network.com
    
    SSLEngine on
    SSLCertificateFile "/etc/pki/outcert/Certificate.pem"
    SSLCertificateKeyFile "/etc/pki/outcert/CertificateKey.pem"
    SSLCertificateChainFile "/etc/pki/outcert/CertificateChain.p12"
</VirtualHost>



nginx 구성 부분

nginx:80


location /ourapp/ {
  proxy_ssl_server_name on;
  proxy_pass https://forever-authcheck.tire1network.com:6000;
  proxy_set_header se-journey "direct";
  proxy_set_header  Host $host;
  proxy_set_header  X-Real-IP $remote_addr;
  proxy_set_header  X-Forwarded-For $remote_addr;
  proxy_set_header  X-Forwarded-Host $remote_addr;
  proxy_redirect default;
  

  proxy_ssl_certificate     /etc/pki/outcert/Certificate.pem;
  proxy_ssl_certificate_key /etc/pki/outcert/CertificateKey.pem;
  proxy_ssl_verify       off;
}









답변1

좋습니다. 이해를 돕기 위해 약간의 작업을 수행하고 더 많은 로그를 이해하기 위해 또 다른 임시 설정을 배포했습니다.

현재 이해하고 있는 사용자 요청 -> Nginx:443/ourapp -> Apache:6000 -> Azure ADFS ->는 다음과 같습니다.Azure는 브라우저에 URL을 반환합니다. ->브라우저는 반환된 URL을 요청합니다.

로그를 자세히 살펴보면 무슨 일이 일어나고 있는지 명확했고, 더 나아가 이를 이해하는 데 도움이 되었습니다.

포트와 올바른 호스트로 올바른 헤더를 보내도록 ngnix를 조정한 후,

proxy_set_header X-Forwarded-Port "443";

proxy_set_header X-Forwarded-Host "forever-authcheck.tire1network.com";

그 결과 apache 및 mod_auth_openidc에 의해 Original_url에 대한 올바른 쿠키 설정이 이루어졌습니다.

이제 리디렉션이 올바르게 작동하고 클레임이 NGINX와 앱에 도달합니다.

관련 정보