Skip to content

Commit c1b9321

Browse files
committed
Add key file path, minor name change
1 parent d81405c commit c1b9321

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

Dockerfile

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,9 @@ RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.n
1515
yum -y install pcre-devel pcre zlib-devel openssl-devel wget cmake check-devel check && \
1616
yum -y install nginx-$NGINX_VERSION
1717

18-
# for compiling for rh-nginx110
19-
# RUN yum -y install libxml2 libxslt libxml2-devel libxslt-devel gd gd-devel perl-ExtUtils-Embed
20-
2118
# for compiling for epel7
2219
RUN yum -y install libxml2 libxslt libxml2-devel libxslt-devel gd gd-devel perl-ExtUtils-Embed geoip geoip-devel google-perftools google-perftools-devel
2320

24-
# Jansson requires new cmake
25-
# RUN yum -y install cmake3 && \
26-
# alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake 10 \
27-
# --slave /usr/local/bin/ctest ctest /usr/bin/ctest \
28-
# --slave /usr/local/bin/cpack cpack /usr/bin/cpack \
29-
# --slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake \
30-
# --family cmake && \
31-
# alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 20 \
32-
# --slave /usr/local/bin/ctest ctest /usr/bin/ctest3 \
33-
# --slave /usr/local/bin/cpack cpack /usr/bin/cpack3 \
34-
# --slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 \
35-
# --family cmake
36-
3721
RUN mkdir -p /root/dl
3822
WORKDIR /root/dl
3923

@@ -91,13 +75,6 @@ RUN wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz && \
9175

9276
# Get nginx ready to run
9377
COPY resources/nginx.conf /etc/nginx/nginx.conf
94-
COPY resources/test-jwt-nginx.conf /etc/nginx/conf.d/test-jwt-nginx.conf
95-
# RUN rm -rf /usr/share/nginx/html
96-
# RUN cp -r /root/dl/nginx/html /usr/share/nginx
97-
# RUN cp -r /usr/share/nginx/html /usr/share/nginx/secure
98-
# RUN cp -r /usr/share/nginx/html /usr/share/nginx/secure-rs256
99-
# RUN cp -r /usr/share/nginx/html /usr/share/nginx/secure-auth-header
100-
# RUN cp -r /usr/share/nginx/html /usr/share/nginx/secure-no-redirect
10178

10279
ENTRYPOINT ["/usr/sbin/nginx"]
10380

resources/test-jwt-nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jwIDAQAB
4848
auth_jwt_enabled on;
4949
auth_jwt_validation_type AUTHORIZATION;
5050
auth_jwt_algorithm RS256;
51-
auth_jwt_filekey on;
51+
auth_jwt_use_keyfile on;
5252
root /usr/share/nginx;
5353
index index.html index.htm;
5454
}

src/ngx_http_auth_jwt_module.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ typedef struct {
2929
ngx_flag_t auth_jwt_redirect;
3030
ngx_str_t auth_jwt_validation_type;
3131
ngx_str_t auth_jwt_algorithm;
32-
ngx_flag_t auth_jwt_filekey;
32+
ngx_flag_t auth_jwt_use_keyfile;
33+
ngx_str_t auth_jwt_keyfile_path;
3334
ngx_flag_t auth_jwt_validate_email;
3435

3536
} ngx_http_auth_jwt_loc_conf_t;
@@ -63,11 +64,18 @@ static ngx_command_t ngx_http_auth_jwt_commands[] = {
6364
offsetof(ngx_http_auth_jwt_loc_conf_t, auth_jwt_enabled),
6465
NULL },
6566

66-
{ ngx_string("auth_jwt_filekey"),
67+
{ ngx_string("auth_jwt_use_keyfile"),
6768
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
6869
ngx_conf_set_flag_slot,
6970
NGX_HTTP_LOC_CONF_OFFSET,
70-
offsetof(ngx_http_auth_jwt_loc_conf_t, auth_jwt_filekey),
71+
offsetof(ngx_http_auth_jwt_loc_conf_t, auth_jwt_use_keyfile),
72+
NULL },
73+
74+
{ ngx_string("auth_jwt_keyfile_path"),
75+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
76+
ngx_conf_set_str_slot,
77+
NGX_HTTP_LOC_CONF_OFFSET,
78+
offsetof(ngx_http_auth_jwt_loc_conf_t, auth_jwt_keyfile_path),
7179
NULL },
7280

7381
{ ngx_string("auth_jwt_redirect"),
@@ -190,9 +198,9 @@ static ngx_int_t ngx_http_auth_jwt_handler(ngx_http_request_t *r)
190198
{
191199
// in this case, 'Binary' is a misnomer, as it is the public key string itself
192200
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "failed to find a jwt");
193-
if (jwtcf->auth_jwt_filekey == 1)
201+
if (jwtcf->auth_jwt_use_keyfile == 1)
194202
{
195-
FILE *file = fopen(KEY_FILE_PATH, "rb");
203+
FILE *file = fopen((const char*)jwtcf->auth_jwt_keyfile_path.data, "rb");
196204

197205
// Check if file exists or is correctly opened
198206
if (file == NULL)
@@ -423,7 +431,7 @@ ngx_http_auth_jwt_create_loc_conf(ngx_conf_t *cf)
423431
conf->auth_jwt_enabled = (ngx_flag_t) -1;
424432
conf->auth_jwt_redirect = (ngx_flag_t) -1;
425433
conf->auth_jwt_validate_email = (ngx_flag_t) -1;
426-
conf->auth_jwt_filekey = (ngx_flag_t) -1;
434+
conf->auth_jwt_use_keyfile = (ngx_flag_t) -1;
427435

428436
ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "Created Location Configuration");
429437

@@ -441,6 +449,7 @@ ngx_http_auth_jwt_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
441449
ngx_conf_merge_str_value(conf->auth_jwt_key, prev->auth_jwt_key, "");
442450
ngx_conf_merge_str_value(conf->auth_jwt_validation_type, prev->auth_jwt_validation_type, "");
443451
ngx_conf_merge_str_value(conf->auth_jwt_algorithm, prev->auth_jwt_algorithm, "HS256");
452+
ngx_conf_merge_str_value(conf->auth_jwt_keyfile_path, prev->auth_jwt_keyfile_path, KEY_FILE_PATH);
444453
ngx_conf_merge_off_value(conf->auth_jwt_validate_email, prev->auth_jwt_validate_email, 1);
445454

446455
if (conf->auth_jwt_enabled == ((ngx_flag_t) -1))
@@ -453,9 +462,9 @@ ngx_http_auth_jwt_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
453462
conf->auth_jwt_redirect = (prev->auth_jwt_redirect == ((ngx_flag_t) -1)) ? 0 : prev->auth_jwt_redirect;
454463
}
455464

456-
if (conf->auth_jwt_filekey == ((ngx_flag_t) -1))
465+
if (conf->auth_jwt_use_keyfile == ((ngx_flag_t) -1))
457466
{
458-
conf->auth_jwt_filekey = (prev->auth_jwt_filekey == ((ngx_flag_t) -1)) ? 0 : prev->auth_jwt_filekey;
467+
conf->auth_jwt_use_keyfile = (prev->auth_jwt_use_keyfile == ((ngx_flag_t) -1)) ? 0 : prev->auth_jwt_use_keyfile;
459468
}
460469

461470
return NGX_CONF_OK;

0 commit comments

Comments
 (0)