Git Product home page Git Product logo

mod_authnz_jwt's Introduction

mod_authnz_jwt

Authentication module for Apache httpd with JSON web tokens (JWT).

Build Status

More on JWT : https://jwt.io/

Supported algorithms : HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512

Built-in checks : iss, aud, exp, nbf

Configurable checks : every claims contained in the token (only string and array)

This module is able to deliver JSON web tokens containing all public fields (iss, aud, sub, iat, nbf, exp), and the private field "user". Authentication process is carried out by an authentication provider and specified by the AuthJWTProvider directive.

On the other hand, this module is able to check validity of token based on its signature, and on its public fields. If the token is valid, then the user is authenticated and can be used by an authorization provider with the directive "Require valid-user" to authorize or not the request.

Although this module is able to deliver valid tokens, it may be used to check tokens delivered by a custom application in any language, as long as a secret is shared between the two parts. This feature is possible because token-based authentication is stateless.

Build Requirements

Quick start

Installation using Docker

See Dockerfile

Installation from sources

sudo apt-get install libtool pkg-config autoconf libssl-dev check libjansson-dev
git clone https://github.com/benmcollins/libjwt
cd libjwt
git checkout tags/v1.12.1
autoreconf -i
./configure
make
sudo make install
cd ..
sudo apt-get install apache2 apache2-dev libz-dev
git clone https://github.com/AnthonyDeroche/mod_authnz_jwt
cd mod_authnz_jwt
autoreconf -ivf
./configure
make
sudo make install

Generate EC keys

openssl ecparam -name secp256k1 -genkey -noout -out ec-priv.pem
openssl ec -in ec-priv.pem -pubout -out ec-pub.pem

Generate RSA keys

openssl genpkey -algorithm RSA -out rsa-priv.pem -pkeyopt rsa_keygen_bits:4096
openssl rsa -pubout -in rsa-priv.pem -out rsa-pub.pem

Authentication

The common workflow is to authenticate against a token service using for instance username/password. Then we reuse this token to authenticate our next requests as long as the token remains valid.

Using username/password

You can configure the module to deliver a JWT if your username/password is correct. Use "AuthJWTProvider" to configure which providers will be used to authenticate the user.

Authentication modules are for instance:

The delivered token will contain your username in a field named "user" (See AuthJWTAttributeUsername to override this value) as well as public fields exp, iat, nbf and possibly iss and aud according to the configuration.

A minimal configuration might be:

AuthJWTSignatureAlgorithm HS256
AuthJWTSignatureSharedSecret Q0hBTkdFTUU=
AuthJWTIss example.com
<Location /demo/login>
	SetHandler jwt-login-handler
	AuthJWTProvider file
	AuthUserFile /var/www/jwt.htpasswd
</Location>

Using a JWT

A secured area can be accessed if the provided JWT is valid. JWT must be set in Authorization header. Its value must be "Bearer ".

If the signature is correct and fields are correct, then a secured location can be accessed.

Token must not be expired (exp), not processed too early (nbf), and issuer/audience must match the configuration.

A minimal configuration might be:

AuthJWTSignatureAlgorithm HS256
AuthJWTSignatureSharedSecret Q0hBTkdFTUU=
AuthJWTIss example.com
<Directory /var/www/html/demo/secured/>
	AllowOverride None
	AuthType jwt
	AuthName "private area"
	Require valid-user
</Directory>

Authorization

You can use the directive Require jwt-claim key1=value1 key2=value2. Putting multiple keys/values in the same require results in an OR. You can use RequireAny and RequireAll directives to be more precise in your rules.

In case your key is an array, you can use the directive Require jwt-claim-array key1=value1 to test that "value1" is contained in the array pointed by the key "key1".

Examples:

AuthJWTSignatureAlgorithm HS256
AuthJWTSignatureSharedSecret Q0hBTkdFTUU=
AuthJWTIss example.com
<Directory /var/www/html/demo/secured/>
	AllowOverride None
	AuthType jwt
	AuthName "private area"
	Require jwt-claim user=toto
    Require jwt-claim-array groups=group1
</Directory>

How to get authenticated user in your apps?

If your app is directly hosted by the same Apache than the module, then you can read the environment variable "REMOTE_USER".

If the apache instance on which the module is installed acts as a reverse proxy, then you need to add a header in the request (X-Remote-User for example). We use mod_rewrite to do so. For your information, rewrite rules are interpreted before authentication. That's why why need a "look ahead" variable which will take its final value during the fixup phase.

RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader set X-Remote-User "%{RU}e" env=RU

Configuration examples

This configuration is given for tests purpose. Remember to always use TLS in production.

With HMAC algorithm:

<VirtualHost *:80>
	ServerName example.com
	DocumentRoot /var/www/html/

	# default values
	AuthJWTFormUsername user
	AuthJWTFormPassword password
	AuthJWTAttributeUsername user
	
	AuthJWTSignatureAlgorithm HS256
	AuthJWTSignatureSharedSecret Q0hBTkdFTUU=
	AuthJWTExpDelay 1800
	AuthJWTNbfDelay 0
	AuthJWTIss example.com
	AuthJWTAud demo
	AuthJWTLeeway 10

	<Directory /var/www/html/demo/secured/>
		AllowOverride None
		AuthType jwt
		AuthName "private area"
		Require valid-user
	</Directory>
	
	
	<Location /demo/login>
		SetHandler jwt-login-handler
		AuthJWTProvider file
		AuthUserFile /var/www/jwt.htpasswd
	</Location>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

With EC algorithm:

<VirtualHost *:80>
	ServerName example.com
	DocumentRoot /var/www/html/

	# default values
	AuthJWTFormUsername user
	AuthJWTFormPassword password
	AuthJWTAttributeUsername user
	
	AuthJWTSignatureAlgorithm ES256
	AuthJWTSignaturePublicKeyFile /etc/pki/auth_pub.pem
	AuthJWTSignaturePrivateKeyFile /etc/pki/auth_priv.pem
	AuthJWTExpDelay 1800
	AuthJWTNbfDelay 0
	AuthJWTIss example.com
	AuthJWTAud demo
	AuthJWTLeeway 10

	<Directory /var/www/html/demo/secured/>
		AllowOverride None
		AuthType jwt
		AuthName "private area"
		Require valid-user
	</Directory>
	
	
	<Location /demo/login>
		SetHandler jwt-login-handler
		AuthJWTProvider file
		AuthUserFile /var/www/jwt.htpasswd
	</Location>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

With Cookie:

<VirtualHost *:80>
	ServerName example.com
	DocumentRoot /var/www/html/

	# default values
	AuthJWTFormUsername user
	AuthJWTFormPassword password
	AuthJWTAttributeUsername user

	AuthJWTSignatureAlgorithm HS256
	AuthJWTSignatureSharedSecret Q0hBTkdFTUU=
	AuthJWTExpDelay 1800
	AuthJWTNbfDelay 0
	AuthJWTIss example.com
	AuthJWTAud demo
	AuthJWTLeeway 10

    AuthJWTDeliveryType Cookie

	<Directory /var/www/html/demo/secured/>
		AllowOverride None
		AuthType jwt-cookie
		AuthName "private area"
		Require valid-user
	</Directory>


	<Location /demo/login>
		SetHandler jwt-login-handler
		AuthJWTProvider file
		AuthUserFile /var/www/jwt.htpasswd
	</Location>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Documentation

Directives

AuthType
  • Description: Authentication type to allow. jwt and jwt-bearer will allow only the Authorization header. jwt-cookie allows only Cookie usage. jwt-both accepts Authorization header and cookie. Cookie value will be ignored if Authorization header is set.
  • Context: directory
  • Possibles values: jwt, jwt-bearer, jwt-cookie, jwt-both
AuthJWTProvider
  • Description: Authentication providers used
  • Context: directory
AuthJWTSignatureAlgorithm
  • Description: The algorithm to use to sign tokens
  • Context: server config, directory
  • Default: HS256
  • Possibles values: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512
  • Mandatory: yes
AuthJWTSignatureSharedSecret
  • Description: The secret to use to sign tokens with HMACs. It must be base64 encoded.
  • Context: server config, directory
  • Mandatory: no
AuthJWTSignaturePublicKeyFile
  • Description: The file path of public key used with either RSA or EC algorithms.
  • Context: server config, directory
  • Mandatory: no
AuthJWTSignaturePrivateKeyFile
  • Description: The file path of private key used with either RSA or EC algorithms.
  • Context: server config, directory
  • Mandatory: no
AuthJWTIss
  • Description: The issuer of delivered tokens
  • Context: server config, directory
  • Mandatory: no
AuthJWTAud
  • Description: The audience of delivered tokens
  • Context: server config, directory
  • Mandatory: no
AuthJWTExpDelay
  • Description: The time delay in seconds after which delivered tokens are considered invalid
  • Context: server config, directory
  • Default: 1800
  • Mandatory: no
AuthJWTNbfDelay
  • Description: The time delay in seconds before which delivered tokens must not be processed
  • Context: server config, directory
  • Default: 0
  • Mandatory: no
AuthJWTLeeway
  • Description: The leeway to account for clock skew in token validation process
  • Context: server config, directory
  • Default: 0
  • Mandatory: no
AuthJWTFormUsername
  • Description: The name of the field containing the username in authentication process
  • Context: server config, directory
  • Default: user
  • Mandatory: no
AuthJWTFormPassword
  • Description: The name of the field containing the password in authentication process
  • Context: server config, directory
  • Default: password
  • Mandatory: no
AuthJWTAttributeUsername
  • Description: The name of the attribute containing the username in the token (used for authorization as well as token generation)
  • Context: server config, directory
  • Default: user
  • Mandatory: no
AuthJWTDeliveryType
  • Description: Type of token delivery JSON or Cookie (case-sensitive)
  • Context: server config, directory
  • Default: JSON
  • Possibles values: JSON, Cookie
  • Mandatory: no
AuthJWTTokenName
  • Description: Token name to use when using JSON delivery
  • Context: server config, directory
  • Default: token
  • Mandatory: no
AuthJWTCookieName
  • Description: Cookie name to use when using cookie delivery
  • Context: server config, directory
  • Default: AuthToken
  • Mandatory: no
AuthJWTCookieAttr
  • Description: Semi-colon separated attributes for cookie when using cookie delivery
  • Context: server config, directory
  • Default: Secure;HttpOnly;SameSite
  • Mandatory: no
AuthJWTRemoveCookie
  • Description: Remove cookie from the headers, and thus keep it private from the backend
  • Context: server config, directory
  • Default: 1
  • Mandatory: no

mod_authnz_jwt's People

Contributors

alyptik avatar anthonyderoche avatar bmerry avatar brycehemme avatar ecki avatar eflanagan0 avatar ghetolay avatar jbloggz avatar jeremyjpj0916 avatar jesseestum avatar nikosft avatar weh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mod_authnz_jwt's Issues

Cannot load mod_authnz_jwt.so... libjwt.so.0: cannot open shared object file

Debian jessie, Apache/2.4.10.

Error after installation:

apache2: Cannot load /usr/lib/apache2/modules/mod_authnz_jwt.so into server: libjwt.so.0: cannot open shared object file: No such file or directory

ldd:

ldd /usr/lib/apache2/modules/mod_authnz_jwt.so
libjwt.so.0 => not found

Fix:

cp /usr/local/lib/libjwt.* /lib/x86_64-linux-gnu/

ldd:

ldd /usr/lib/apache2/modules/mod_authnz_jwt.so
libjwt.so.0 => /usr/local/lib/libjwt.so.0

Symmetric encryption signature keys are handled as null-terminated C-strings

Signature keys (e.g., the ones specified in httpd.conf with AuthJWTSignatureSharedSecret) are assumed to be null-terminated C-strings. This is a problem if the signature key contains a null byte as part of it, which is entirely legal and not uncommon for encryption keys.

This could be fixed by using functions like strncpy instead of strcpy and passing around the length of the keys.

Centos issues with mod_authnz_jwt

Can't locate API module structure `authnz_jwt_module' in file /etc/httpd/modules/mod_authnz_jwt.so: /usr/lib64/httpd/modules/mod_authnz_jwt.so: undefined symbol: authnz_jwt_module.

support nested claims

some oidc providers like for example https://github.com/dexidp/dex produce jwt's with claim fields nested.

For example:

{
  "iss": "..."
  "federated_claims": {
    "connector_id": "ldap",
    "user_id": "userid"
  }
}

As far as I can tell this module does not support these claims for e.g. Require jwt-claim or AuthJWTAttributeUsername

Would it make sense to add support for these type of claims in this module?
E.g. via federated_claims.user_ud

AuthJWTProvider ldap with Require ldap-group

We are currently using LDAP Basic Auth with group checking in a reverse proxy setup, which we'd like to switch to a JWT cookie setup, but are running into problems.

We are successful using the file auth provider, posting the credentials to the login-handler, receiving the JWT cookie in return.
But when we switch to AuthJWTProvider ldap, we are unable to use the "Require ldap-group" directive in the login configuration. Is this currently not supported?
Even better would be the possibility to check groups on each individual secured path, so you'd be able to have different requirements for each, but I assume that would require the assigned groups to be stored in the cookie and then checked on access, and I don't think that's possible.

    AuthJWTFormUsername user
    AuthJWTFormPassword password
    AuthJWTAttributeUsername user
    AuthJWTSignatureAlgorithm HS256
    AuthJWTSignatureSharedSecret sikrit
    AuthJWTCookieName ProxyJWT
    AuthJWTExpDelay 1800
    AuthJWTNbfDelay 0
    AuthJWTIss demo.company.com
    AuthJWTAud demo
    AuthJWTLeeway 10

    AuthJWTDeliveryType Cookie
    AuthJWTCookieAttr "Secure; HttpOnly; SameSite=Strict; Path=/"

    <Directory /var/www/html/demo/secured/>
        AllowOverride None
        AuthType jwt-cookie
        AuthName "jwt private area"
        Require valid-user
    </Directory>

    <Location /demo/login>
        SetHandler jwt-login-handler
        AuthJWTProvider ldap
        AuthLDAPURL    "ldap://ldaphost:389/ou=People,dc=company,dc=com?uid,cn,mail?sub?(objectClass=*)"
        AuthLDAPBindDN "cn=admin,dc=company,dc=com"
        AuthLDAPGroupAttribute "memberUid"
        AuthLDAPGroupAttributeIsDN off
        AuthLDAPBindPassword "anotherSikrit"
        AuthLDAPRemoteUserAttribute "uid"
        Require ldap-group cn=mygroup,ou=Group,dc=company,dc=com
    </Location>

Cognito integration

We are utilizing Apache HTTP server as a gateway in AWS for APIs and front-end web code in S3 buckets. We currently use mod_auth_mellon for authentication and pass user information in headers back to our API's when a client successfully authenticates.

We are looking to switch to AWS Cognito for authentication utilizing JWT.

I have been experimenting with your module. On it's own, I can utilize JWT to grant access to protected URI's. When I attempt to utilize it with Cognito, I am running into errors.

Steps used to recreate:

  1. Harvest jwks.json for our specific user pool in Cognito.
    https://cognito-idp.us-east-1.amazonaws.com//.well-known/jwks.json
    I pull the one public key from it that our JWT tokens are signed with.
  2. Run that public key through the following process: Convert it to pem: https://runkit.com/npm/jwk-to-pem
  3. Trim out all unnecessary info from pem: openssl rsa -inform pem -in FILEPATH.pem -pubin -pubout -RSAPublicKey_in

When I put the JWT token I have and the fully processed pem into the debugger on https://jwt.io, the signature validates correctly. However, when I throw them into Apache utilizing mod_authz_jwt, I get an invalid token and/or invalid signature error.

The problem is 2-fold, Cognito exposes 2 keys through the jwks.json and this module claims invalid token/signature when converting one of the keys for static use. Can you modify this module so I can pass it the URL for the jwks.json file and have the module harvest and covert those keys?

User is not getting validated, though user exist in htpasswd file

Hi,

Thanks for your module.

I am trying to use your module for authentication. But when I try to post user and password to url. Its returning unauthenticated.

I am using same configuration from example
`<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/requests.log combined

# default values
#AuthJWTFormUsername user
#AuthJWTFormPassword password
#AuthJWTAttributeUsername user

AuthJWTSignatureAlgorithm HS256
AuthJWTExpDelay 1800
AuthJWTNbfDelay 0
#AuthJWTIss example.com
#AuthJWTAud demo
#AuthJWTLeeway 10

  AuthJWTSignatureSharedSecret secret
  AllowOverride none

LogLevel auth_jwt:debug
RewriteEngine On

<Directory /var/www/example.com/public_html/demo/secured/>
	

    AuthType jwt
    AuthName "private area"
    Require valid-user
</Directory>


<Location /login>
	
    SetHandler jwt-login-handler
    AuthJWTProvider file ldap
    AuthUserFile /var/www/example.com/jwt.htpasswd

</Location>

`

Could you please help me out, why its not getting validated

Added header not working

Hi,

I have a scenario where I can't send the token as a header (javascript window.location).

It would be great if the module coudl fallback to a token cookie or query param.

I tried using mod_rewrite add an Authorization RequestHeader from a query param, but it looks like it's too late, because the error log always shows "auth_jwt authn: missing Authorization header" even when I explicitely add the Authorization header with mod_rewrite.

Could you either natively support falling back to reading token from cookie and/or query param when header not present (a lot of other jwt handlers do that)

Or, give me some clue as to how to add a header using mod_rewrite so that your module can see it, maybe I am not doing it right. I tried putting in the virtualhost and inside directory, but neither seem to work :(

thanks!

PassPhrase

Hi
I try to use your extension for Single auth
My app actually create token Like that :

{
  "alg": "RS256"
}{
  "username": "alborq",
  "exp": 1488785031,
  "iat": 1488781431
}

i hope it's ok, but my problem is somewhere else.
I generate Key like that :

$ openssl genrsa -out var/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in var/jwt/private.pem -out var/jwt/public.pem

Add i add key pass phrase

I try to configure my Vhost like that :

        AuthJWTSignatureAlgorithm RS256
        AuthJWTSignaturePublicKeyFile var/jwt/public.pem  # Path is Ok, i just trucate it
        AuthJWTSignaturePrivateKeyFile var/jwt/private.pem # Path is Ok, i just trucate it

        <Location />
                AuthType jwt
                AuthName "private area"
                Require valid-user
        </Location>

But how can i pass my key pass phrase for .pem ?

Thanks for reply !
Alborq.

Question - authorization user per folder

Hi,

Is it possible to implement authorization in the following way:

  • Every user has his own folder
  • User is allowed to access only his folder
  • We will need to add users and folders not changing the apache config file
  • The folder name with be same as the username

Thnx,
Istvan

Run tests permission issue

In stock Debian it appears there may be a permissions issue with the openssl commands in debian_tests.sh under certain conditions. The generated keys are written to the newly created directory under /opt. The new directory inherits permissions from the parent which is set to rwxr-x-r-x. So, the user must be root to write to the directory. I suspect the same is true for Redhat. Adding sudo to the commands should fix the issue and also allow it to remain working.

Do you mind if I submit a pull request for this?

Decoding process has failed, token is either malformed or signature is invalid

I guess this error is still alive. I have the following config:

AuthJWTSignatureAlgorithm RS256
AuthJWTSignaturePublicKeyFile /etc/pki/auth_pub.pem
AuthJWTSignaturePrivateKeyFile /etc/pki/auth_priv.pem

<Location "/test/">
AllowOverride None
AuthType jwt-bearer
AuthName "private area"
Require valid-user

in jwt.io the token will be accepted. token is not expired and after nbf.

OS: Rocky Linux 8

Valid tokens stop being accepted

It occured twice in the last days that I issued a token which was valid and accepted by the server, and from the next day on it says "Decoding process has failed, token is either malformed or signature is invalid". Testing the tokens with other tools, they are still valid (expiring in one year).
I would like to know if anybody could think of an idea, how this could be theoretically possible. There were no changes made on the server.

How do I forward to another page after login?

When using cookie, I have a login html page with a username/password form, with the submit going to the configured login handler Location in apache "/authenticate". When I click the form's SUBMIT it works just fine to authenticate, but I don't see a way of forwarding anywhere, such as a returnURL or the secured page. Is there a directive I should be using, what's the correct approach given the context of this plugin?

Any help is greatly appreaciated.

AuthJWTLeeway causes crash

Hey,
thanks for mod!

If in this config remove AuthJWTLeeway 10, auth fails with crash:
[Mon Dec 12 22:22:29.898372 2016] [core:notice] [pid 19793] AH00052: child pid 20078 exit signal Segmentation fault (11)

<VirtualHost *:80>
    ServerName testjwt.local
    DocumentRoot /var/www/testjwt/
    
    AuthJWTExpDelay 1800
    AuthJWTIss testjwt.local
    AuthJWTAud tests
    AuthJWTLeeway 10

    LogLevel auth_jwt:debug
    RewriteEngine On

    Alias "/hmac_secured" "/var/www/testjwt"
    Alias "/rsa_secured" "/var/www/testjwt"
    Alias "/ec_secured" "/var/www/testjwt"

    <Directory /var/www/testjwt/>
        AllowOverride None
        Options -Indexes
        Require all granted
    </Directory>

    <Location "/hmac_secured">
        AuthJWTSignatureSharedSecret secret
        AllowOverride None
        Options -Indexes
        AuthType jwt
        AuthName "private area"
        Require valid-user
    </Location>

    <Location "/jwt_login">
	AuthJWTSignatureAlgorithm HS256
	AuthJWTSignatureSharedSecret secret
        SetHandler jwt-login-handler
        AuthJWTProvider file
        AuthUserFile /var/www/jwt.htpasswd
    </Location>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Using tokens from external sources

We are already issuing JWT tokens for access to our API but would like to start protecting some semi-static websites (including images/static files) with the same auth scheme. We are imagining:

  1. User goes to HTML/JS login page that sends credentials to our existing API which returns a JWT token
  2. We somehow inform the browser (basic auth?, cookie, local storage) that we have a token
  3. Now the browser automatically sends the Authorization header or cookie with each requests & mod_authnz_jwt validates

Is there a way I can coerce the browser to send custom Authorization headers?

I believe I am interested in what is happening here: #28

Example config?

Do you have any example apache config you could add to the docs?

Installation does not work on OpenSuse Leap 15.2 / 15.3 because of apache module naming glitch

OpenSuSe uses it's own logic for module naming where the module name in the sysconfig variable ($APACHE_MODULES) has to match the installed apache module file under /usr/lib64/apache2/.

Module name is "auth_jwt", therefore apache module file has to be mod_auth_jwt.so.
Currently the file name is "mod_authnz_jwt.so" which leads to the effect that OpenSUSE does not add the module to the loadmodule.conf file generated at starting time of apache.

A simple rename of the apache module file from mod_authnz_jwt.so" to "mod_auth_jwt.so" solved the problem for us.

Module accepts any issuer and expiration

Installing the newest version from source and using e.g. the minimal configuration from the readme, the module accepts just any value given as AuthJWTIss and does not mind the expiration time. Access is only denied if the token is completely wrong.

Supported version of mod_authnz_jwt

Hi Team,

I would like to reach out and ask if there is a version of mod_authnz_jwt that would be supported by your team for any issues/customizations ?

A little guidance if you may, generating and passing along a JWT?

@AnthonyDeroche I see you support HS256 symmetric jwt. My use case is that I need to generate a token from a key(the jwt iss or issuer) + secret with a proper exp(say valid 15 minutes into the future or whatever) and then add that token as an Authorization: Bearer <jwt_token> Header OR if that is not available then to do like query parameter ?jwt= before I proxy. Does your lib expose any kind of environment variable or something I can reference in a conf file to access a token this module generates, and then attach it as a Bearer token header when Apache reverse proxies? Also curious if you have thought to add any cache logic so that same token can be referenced without taking a hit on cpu/crypto every tx request so the cache lives the life of the token?(not a big deal if not really, I don't expect the traffic to be so hard hitting that the extra crypto will kill me)

Thanks in advance if you have any insights, an example conf would be helpful as I am super new to httpd(I usually use nginx)!
-Jeremy

Question - Is it possible to get the values of the claims so these can be fwd'ed as headers?

Hello

It does not look like it is possible but then I am not much of an Apache HTTPD person and not very experienced in reading module documentation.

Context - A JWT token is received containing claims that need to be 'converted' to headers so that downstream services can stay unaware of the JWT token details

Is it possible to extract claim values from the jwt token? Idea is to add the values to request headers when fwd'ing the request?

Tx!

Peter

Erreneously complains: Decoding process has failed, token is either malformed or signature is invalid

The module is installed on apache2 cantos and following the configuration being used

RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader set X-Remote-User "%{RU}e" env=RU

  AuthJWTSignatureSharedSecret "BASE 64 encoded secret"
  AuthJWTSignatureAlgorithm HS256
  AuthJWTIss <set to servername of this config file>
  AuthJWTAttributeUsername user
  <Location />
    AllowOverride None
    AuthType jwt-bearer
    AuthName "private area"
    Require valid-user
  </Location>

The token being generated elsewhere in a python

         iat = datetime.datetime.utcnow()
        exp = iat + datetime.timedelta(hours=8, minutes=0, seconds=0)
        payload = {'exp': exp, 'iat': iat,
                   'sub': user, 'user': user['username']}
        return jwt.encode(
            payload, 'same base 64 encoded SECRET_KEY', algorithm='HS256')

We have only setup mod_authnz_jwt to verify the token. Currently the module is detecting the presence of header token and also us using secret key setup to decode but keeps complaining with following logs

[Thu Jun 17 17:20:53.823078 2021] [auth_jwt:error] AH55512: Decoding process has failed, token is either malformed or signature is invalid

But decoding succeed without issue when tried through following python code without issue

try:
    payload = jwt.decode(
        auth_token, 'same base 64 encoded SECRET_KEY', algorithms='HS256')
    return payload['user']
except jwt.ExpiredSignatureError:
    raise RestException(RestException.TOKEN_EXPIRED)
except jwt.InvalidTokenError:
    raise RestException(RestException.TOKEN_INVALID)

Can you please as something seems to be broken at decoding process or library being used to decode in mod_authnz_jwt? Its seems to be almost there. Please help with our setup?

Check Content-Type

Module should not deliver token if the content-type of posted data is not www-application/x-www-form-urlencoded

We are able to generate the token but not able to set the required environment variables with data stored in DB. Used AuthJWTProvider dbd technique

Code Snippet:
<Location /gettoken>
SetHandler jwt-login-handler
AuthJWTProvider dbd
AuthDBDUserPWQuery "SELECT password, cn as SSL_CLIENT_S_DN_CN, ou as SSL_CLIENT_S_DN_OU, o as SSL_CLIENT_S_DN_O from dbo.USER_CERT_VIEW where userName = %s" --> as user name is not passing along with URL, not sure whether this query will help us to set required ENV variables

Tried to set the username explicitly with the below code. (Note: Sent user name as query param)
<Location /gettoken>
SetHandler jwt-login-handler
AuthJWTProvider dbd
Rewriteengine On
RewriteCond %{QUERY_STRING} ^(?:.&)?username=(.)$
RewriteRule ^ - [env=username:%1]
Header set TokenH %{username}e
AuthDBDUserPWQuery "SELECT password, cn as SSL_CLIENT_S_DN_CN, ou as SSL_CLIENT_S_DN_OU, o as SSL_CLIENT_S_DN_O from dbo.USER_CERT_VIEW where userName = %{username}e"

Getting error with above query. Could you please suggest me on the usage of query in case of AuthJWTProvider dbd as i didn't get any example to refer.
Declaimer: I doesn't have prior knowledge on Apache HttpD server.

Error on libssl.so.1.1 with httpd:2.4.58 image

I have an error when i use an image rebuilding with your dockerfile (thanks to that) with httpd:2.4.58 image.

root@apache-6657f4499c-nmz6h:/usr/local/apache2# httpd -t httpd: Syntax error on line 66 of /usr/local/apache2/conf/httpd.conf: Syntax error on line 21 of /usr/local/apache2/conf/modules.d/1.authentification.conf: Cannot load modules/mod_authnz_jwt.so into server: libssl.so.1.1: cannot open shared object file: No such file or directory root@apache-6657f4499c-nmz6h:/usr/local/apache2#

Is there any operation i miss ?

Using with Docker

I'm trying to use this in docker, and trying to configure my docker-compose file, I'm struggling finding all the files I need. One by one I am finding the binaries, but I'm stuck trying to get libjwt.so. Do you have any instructions on how to extract the needed files for something like docker where I need to distribute the files?

Random invalid signature check

Hi,

I have an issue with mod_authnz_jwt.
When using a JWT to authenticate, mod_authnz_jwt randomly answers :

  • 200 OK
  • 401 Unauthorized

for any apparent reason.

The JWT we are using for test :
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0ZG9tYWluLmNvbSIsImlhdCI6MTUyMTY1NDgwMSwiZXhwIjoxNTUzMTkwODEwLCJhdWQiOiJ3d3cuZXhhbXBsZS5jb20iLCJzdWIiOiJ0ZXN0QGV4YW1wbGUuY29tIiwidXNlciI6ImFkbWluIn0.g6lHZQbv7H9dD3CXZpw3zZ7zfO4bTuGs3BI6mWndAeE
Secret is test

Sended to our test server with this curl command :
curl -X GET -k -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0ZG9tYWluLmNvbSIsImlhdCI6MTUyMTY1NDgwMSwiZXhwIjoxNTUzMTkwODEwLCJhdWQiOiJ3d3cuZXhhbXBsZS5jb20iLCJzdWIiOiJ0ZXN0QGV4YW1wbGUuY29tIiwidXNlciI6ImFkbWluIn0.g6lHZQbv7H9dD3CXZpw3zZ7zfO4bTuGs3BI6mWndAeE' -i 'https://testdomain.com'

We sometimes receive 200 OK answer
Apache logs :

[Thu Mar 22 10:15:40.702067 2018] [auth_jwt:debug] [pid 334] mod_authnz_jwt.c(975): [client 217.108.243.20:13728] AH55405: auth_jwt authn: checking signature and fields correctness...
[Thu Mar 22 10:15:40.702334 2018] [auth_jwt:debug] [pid 334] mod_authnz_jwt.c(980): [client 217.108.243.20:13728] AH55406: auth_jwt authn: signature is correct
[Thu Mar 22 10:15:40.702352 2018] [auth_jwt:debug] [pid 334] mod_authnz_jwt.c(983): [client 217.108.243.20:13728] AH55405: auth_jwt authn: algorithm found is HS256

And sometimes 401 Unauthorized a few seconds later
Apache logs :

[Thu Mar 22 10:15:37.096715 2018] [auth_jwt:debug] [pid 334] mod_authnz_jwt.c(975): [client 217.108.243.20:13728] AH55405: auth_jwt authn: checking signature and fields correctness...
[Thu Mar 22 10:15:37.096913 2018] [auth_jwt:error] [pid 334] [client 217.108.243.20:13728] AH55512: Decoding process has failed, token is either malformed or signature is invalid

Token and request method are strictly the same. Do you have any idea why the token is sometimes decoded and sometimes rejected as invalid/malformed ?

Thanks

Duplicate requests and Index not working

I followed instructions on a fresh test box, and everything works great. Then when I tried to move it to production, I'm having some serious trouble! I've got it to the point where if I put:

https://myurl.com/subdir/index.php

It works, but if I just put:

https://myurl.com/subdir/

I get a 401 Unauthorized error.

The modules between the boxes are similar, the one where it's not working:
authz_core (enabled by maintainer script)
mpm_prefork (enabled by maintainer script)
deflate (enabled by maintainer script)
php7.0 (enabled by maintainer script)
autoindex (enabled by maintainer script)
alias (enabled by maintainer script)
mime (enabled by maintainer script)
headers (enabled by site administrator)
auth_basic (enabled by site administrator)
authz_user (enabled by maintainer script)
access_compat (enabled by maintainer script)
setenvif (enabled by maintainer script)
ssl (enabled by site administrator)
dir (enabled by maintainer script)
socache_shmcb (enabled by site administrator)
status (enabled by maintainer script)
rewrite (enabled by site administrator)
filter (enabled by maintainer script)
authz_groupfile (enabled by site administrator)
negotiation (enabled by maintainer script)
authz_host (enabled by maintainer script)
auth_jwt (enabled by site administrator)
authn_core (enabled by maintainer script)
env (enabled by maintainer script)
authn_file (enabled by maintainer script)

The modules where everything works fine, has:
access_compat (enabled by maintainer script)
ssl (enabled by site administrator)
setenvif (enabled by maintainer script)
autoindex (enabled by maintainer script)
socache_shmcb (enabled by site administrator)
env (enabled by maintainer script)
mpm_event (enabled by maintainer script)
auth_jwt (enabled by site administrator)
dir (enabled by maintainer script)
auth_basic (enabled by maintainer script)
alias (enabled by maintainer script)
authn_file (enabled by maintainer script)
filter (enabled by maintainer script)
deflate (enabled by maintainer script)
authz_host (enabled by maintainer script)
status (enabled by maintainer script)
mime (enabled by maintainer script)
authz_core (enabled by maintainer script)
authz_user (enabled by maintainer script)
reqtimeout (enabled by maintainer script)
negotiation (enabled by maintainer script)
authn_core (enabled by maintainer script)

The default-ssl.conf looks like this on both:

<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/845782569bd11d43.crt
SSLCertificateKeyFile /etc/ssl/private/mysite.key
SSLCACertificatePath /etc/ssl/certs/
<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars

<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars

AuthJWTFormUsername user
AuthJWTFormPassword password
AuthJWTAttributeUsername user
AuthJWTExpDelay 1800
AuthJWTNbfDelay 0
AuthJWTLeeway 10
AuthJWTSignatureSharedSecret 23md093jd8j3
AuthJWTIss ustaclubs.com
AuthJWTDeliveryType Cookie
AuthJWTCookieName AuthToken
<Location /authenticate>
SetHandler jwt-login-handler
AuthJWTProvider file
AuthUserFile /var/www/passwd/passwords
AuthGroupFile /var/www/passwd/groups


I am using .htaccess in a directory for access, this example is in /var/www/html/meets/meet_532
AuthType jwt-cookie
AuthName myauthname
AuthUserFile /var/www/passwd/passwords
AuthGroupFile /var/www/passwd/groups
Require group meet532

My User file:
myusername:$apr1$xO3YBihC$n.tALxCJ3QOsdfdsfKjyC/

My Group File:
meet532: myusername

My apache2.conf directory setup:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
DirectoryIndex index.php

My security.conf directory setup:
<Directory /var/www/html/meets>
AllowOverride all
DirectoryIndex index.php

What I find is strange, is I see duplicates in the error log and I go. I've been studing the code, and it looks like things maybe are getting mixed up:
[Tue Apr 12 04:28:12.778674 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1083): [client 24.14.160.70:34742] AH55400: auth_jwt: checking authentication with token...
[Tue Apr 12 04:28:12.778680 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1099): [client 24.14.160.70:34742] AH55400: auth_jwt: authSubType -cookie
[Tue Apr 12 04:28:12.778682 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1108): [client 24.14.160.70:34742] AH55400: auth_jwt: delivery_type 4
[Tue Apr 12 04:28:12.778705 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1170): [client 24.14.160.70:34742] AH55405: auth_jwt authn: checking signature and fields correctness...
[Tue Apr 12 04:28:12.778762 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1175): [client 24.14.160.70:34742] AH55406: auth_jwt authn: signature is correct
[Tue Apr 12 04:28:12.778765 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1178): [client 24.14.160.70:34742] AH55405: auth_jwt authn: algorithm found is HS256
[Tue Apr 12 04:28:12.778833 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1083): [client 24.14.160.70:34742] AH55400: auth_jwt: checking authentication with token...
[Tue Apr 12 04:28:12.778836 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1099): [client 24.14.160.70:34742] AH55400: auth_jwt: authSubType -cookie
[Tue Apr 12 04:28:12.778838 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1108): [client 24.14.160.70:34742] AH55400: auth_jwt: delivery_type 4
[Tue Apr 12 04:28:12.778844 2022] [auth_jwt:error] [pid 18237] [client 24.14.160.70:34742] AH55409: auth_jwt authn: missing authorization cookie

Like I said, if I put /index.php it loads, but if no index.php it gives me a 401:
Unauthorized
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Apache/2.4.18 (Ubuntu) Server at ustaclubs.com Port 443

I know it's authenticating, because if I put the wrong password, it doesn't work and errors out during authenticate.

See below, on the following log, I can see that first it says ok, then it says denied for the group and the user:

[Tue Apr 12 04:28:12.778652 2022] [authz_core:debug] [pid 18237] mod_authz_core.c(809): [client 24.14.160.70:34742] AH01626: authorization result of Require group meet532: denied (no authenticated user yet)
[Tue Apr 12 04:28:12.778663 2022] [authz_core:debug] [pid 18237] mod_authz_core.c(809): [client 24.14.160.70:34742] AH01626: authorization result of : denied (no authenticated user yet)
[Tue Apr 12 04:28:12.778674 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1083): [client 24.14.160.70:34742] AH55400: auth_jwt: checking authentication with token...
[Tue Apr 12 04:28:12.778680 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1099): [client 24.14.160.70:34742] AH55400: auth_jwt: authSubType -cookie
[Tue Apr 12 04:28:12.778682 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1108): [client 24.14.160.70:34742] AH55400: auth_jwt: delivery_type 4
[Tue Apr 12 04:28:12.778705 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1170): [client 24.14.160.70:34742] AH55405: auth_jwt authn: checking signature and fields correctness...
[Tue Apr 12 04:28:12.778762 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1175): [client 24.14.160.70:34742] AH55406: auth_jwt authn: signature is correct
[Tue Apr 12 04:28:12.778765 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1178): [client 24.14.160.70:34742] AH55405: auth_jwt authn: algorithm found is HS256
[Tue Apr 12 04:28:12.778792 2022] [authz_core:debug] [pid 18237] mod_authz_core.c(809): [client 24.14.160.70:34742] AH01626: authorization result of Require group meet532: granted
[Tue Apr 12 04:28:12.778794 2022] [authz_core:debug] [pid 18237] mod_authz_core.c(809): [client 24.14.160.70:34742] AH01626: authorization result of : granted
[Tue Apr 12 04:28:12.778828 2022] [authz_core:debug] [pid 18237] mod_authz_core.c(809): [client 24.14.160.70:34742] AH01626: authorization result of Require group meet532: denied (no authenticated user yet)
[Tue Apr 12 04:28:12.778830 2022] [authz_core:debug] [pid 18237] mod_authz_core.c(809): [client 24.14.160.70:34742] AH01626: authorization result of : denied (no authenticated user yet)
[Tue Apr 12 04:28:12.778833 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1083): [client 24.14.160.70:34742] AH55400: auth_jwt: checking authentication with token...
[Tue Apr 12 04:28:12.778836 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1099): [client 24.14.160.70:34742] AH55400: auth_jwt: authSubType -cookie
[Tue Apr 12 04:28:12.778838 2022] [auth_jwt:debug] [pid 18237] mod_authnz_jwt.c(1108): [client 24.14.160.70:34742] AH55400: auth_jwt: delivery_type 4
[Tue Apr 12 04:28:12.778844 2022] [auth_jwt:error] [pid 18237] [client 24.14.160.70:34742] AH55409: auth_jwt authn: missing authorization cookie

Notice at the bottom it complaints about missing the authorization cookie, but in the log above it, it found it and granted the group.

If anyone can help me, I'd be greatly appreciative, I've been staring at the source and tracing for days now.

I've modified some parts of the log such as the IP address and a couple of directories, so if you see a small difference go ahead and call it out, but it may just be something I forgot to update. I tried to be concise and provide all of the information possible.

Thank you!
Dan Chase

How to implement in docker

I'm trying to use this in docker, and trying to configure my docker-compose file, I'm struggling finding all the files I need. One by one I am finding the binaries, but I'm stuck trying to get libjwt.so. Do you have any instructions on how to extract the needed files for something like docker where I need to distribute the files?

Incorrect call to ap_log_rerror()

If you make a request to a protected page but don't provide a token (through either the Authorization header or cookie), you get errors like the following in the logs;
[Fri Mar 05 21:52:36.960160 2021] [auth_jwt:error] [pid 9213:tid 140084577822464] [client 127.0.0.1:41868] AH55404:
So the error description is missing.

A check of the code shows the issue is caused y an incorrect call to ap_log_rerror():
1126: ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, logCode, logStr);

This should instead be:
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "%s%s", logCode, logStr);

[Feature] cookie

Would it be viable to add an option for the cookie variant ?

We would need to set a cookie (name configurable) at login and during access check for it instead of the Authorization header.

[Feature] Add extra claim field

Would it be possible to add extra claim field and value when issuing JWT token in configuration?

Like giving each user a role to specify its privilege.

Just a question about /login

I'm using Ubuntu Server 20.04 and just installed mod_authnz_jwt from source...so far so good, I used the configuration example and recreated the same folder /var/www/html/demo/login and /var/www/html/demo/secured.

I have generated a jwt.htpasswd with a single user for testing, so far I get the Unauthorized warning on /var/www/html/demo/secured, but when I try to access /var/www/html/demo/login it shows the warning:

Method Not Allowed
The requested method GET is not allowed for this URL

Am I doing something wrong? Or do I need an extra step?

Kind regards,
carekaPT

Memory leaks when using module

Hello!

Using this module for a high-traffic web application, I've observed that the server gradually runs out of memory due to ever-increasing httpd worker process memory usage.

I've reproduced the issue with a very basic configuration, please see attached Dockerfile, it builds the module, enables JWT token auth, starts httpd and runs ab to generate requests.

Sample output of build:

 ---> Running in 99174bd2f0d0
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.5. Set the 'ServerName' directive globally to suppress this message
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  3.5  0.0   2392   752 ?        Ss   16:51   0:00 /bin/sh -c httpd && sleep 3 && ps aux && ab -q -n 1000000 -c 50 http://localhost/ >/dev/null && ps aux
root           7  0.0  0.0  11832  4016 ?        Ss   16:51   0:00 httpd
daemon         9  0.0  0.0 2002932 12252 ?       Sl   16:51   0:00 httpd
daemon        10  0.0  0.0 2002932 12252 ?       Sl   16:51   0:00 httpd
daemon        11  0.0  0.0 2002932 12252 ?       Sl   16:51   0:00 httpd
root          93  0.0  0.0   7644  2800 ?        R    16:51   0:00 ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.4  0.0   2392   752 ?        Ss   16:51   0:00 /bin/sh -c httpd && sleep 3 && ps aux && ab -q -n 1000000 -c 50 http://localhost/ >/dev/null && ps aux
root           7  0.0  0.0  11832  4016 ?        Ss   16:51   0:00 httpd
daemon         9 60.0  1.0 3067060 542372 ?      Sl   16:51   0:18 httpd
daemon        10  113  2.1 4144172 1082132 ?     Sl   16:51   0:34 httpd
daemon        11  108  2.1 4069540 1044720 ?     Sl   16:51   0:32 httpd
daemon        95  165  2.7 4735308 1378620 ?     Sl   16:51   0:42 httpd
root         123  0.0  0.0   7644  2724 ?        R    16:51   0:00 ps aux

As you can see, after 1M requests, RSS column adds up to almost 4GiB.
If Require valid-user is commented out, this does not happen.

[HELP] Always getting: Token is malformed or signature is invalid

I tried the minimal configuration for just securing a folder on my apache2 webserver.
I am always getting:

Bildschirmfoto 2019-06-18 um 00 42 37

I tried both http and https.

I set the Authorization Header like "Bearer eylskdvnsdlns...." and give apache the private key and here's my apache2 config:

<VirtualHost *:443>
	ServerName sub.domain.com

	ServerAdmin [email protected]
	DocumentRoot /var/www/test

	AuthJWTSignatureAlgorithm HS512
	AuthJWTSignatureSharedSecret r9yfFB8Bf......RKBv

	<Directory /var/www/test/secured/>
		AllowOverride None
		AuthType jwt
		AuthName "private"
		Require valid-user
	</Directory>
	...
</VirtualHost>

Please help me, I don't know why apache can't decode my json webtoken. on JWT.io it's valid if I enter my secret private key.

kind regads.
Rebar

Sent from my Pixel 2 XL using FastHub

Typo in Readme

Generate RSA keys
openssl genpkey -algorit RSA -out rsa-priv.pem -pkeyopt rsa_keygen_bits:4096

should be:
openssl genpkey -algorithm RSA -out rsa-priv.pem -pkeyopt rsa_keygen_bits:4096

Invalid command 'AuthJWTDeliveryType'

Hi guys,

I am some having some issue with setting this part of my apache config? I am I missing something from apache set up.

"Invalid command 'AuthJWTDeliveryType', perhaps misspelled or defined by a module not included in the server configuration"

Whitelisting UI resources (Help needed)

We are hosting a web application on Apache 2, which contains both secured resources and login handler under the same document root. The JWT token is generated by the login handler and will be passed to all subsequent UI request. Is there any configuration to whitelist few resources to by pass validation of JWT token as Login handler related UI resources won't be getting JWT token.

Missing Authorization header even though one is set

Hi Anthony,

I am trying to integrate your module into an Apache 2.4 server on Centos 7 running in a Docker container. This is to meet a requirement for the client to supply a valid JWT before allowing proxying of a request through Apache to a destination API.

The client supplies a header named X-Custom-Auth-Header (this is constrained by other components and the header name cannot be changed to be more standard); my idea is to turn it into an Authorization: Bearer ... header so that mod_authnz_jwt can validate the token before granting the access request.

Here is the configuration in the virtual host that contains the proxy:


RequestHeader set Authorization "Bearer %{X-Custom-Auth-Header}e"

<IfModule auth_jwt_module>
	AuthJWTSignatureAlgorithm HS512
	AuthJWTSignatureSharedSecret xxxx
</IfModule>

<LocationMatch "/gosomewhere">
	ProxyPass https://api.somewhere.com
	ProxyPassReverse https://api.somewhere.com
	RequestHeader set X-APIKey yyyy
	<IfModule auth_jwt_module>
		AllowOverride None
		AuthType jwt
		AuthName "private area"
		AuthJWTAttributeUsername username
		Require valid-user
	</IfModule>
</LocationMatch>

The error I get in the Apache logs is :

[authz_core:debug] mod_authz_core.c(818):  AH01626: authorization result of <RequireAny>: denied (no authenticated user yet)
[auth_jwt:debug] mod_authnz_jwt.c(1056):  AH55400: auth_jwt: checking authentication with token...
[auth_jwt:debug] mod_authnz_jwt.c(1072): AH55400: auth_jwt: authSubType
[auth_jwt:debug] mod_authnz_jwt.c(1081):  AH55400: auth_jwt: delivery_type 2
[auth_jwt:debug] mod_authnz_jwt.c(1094):  AH55402: auth_jwt authn: reading Authorization header...
[auth_jwt:error] AH55404: auth_jwt authn: missing Authorization header, responding with WWW-Authenticate header...

It seems that it is erroring at a stage before the RequestHeader set Authorization ... line. Is it possible to work around this, and if so, please can you advise what I need to do in order to get the Authorization header to be detected by mod_authnz_jwt?

Thank you.

Simon Payne

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.