@@ -20,6 +20,7 @@ typedef struct {
20
20
ngx_str_t access_key ;
21
21
ngx_str_t secret ;
22
22
ngx_str_t s3_bucket ;
23
+ ngx_str_t chop_prefix ;
23
24
} ngx_http_aws_auth_conf_t ;
24
25
25
26
@@ -44,6 +45,13 @@ static ngx_command_t ngx_http_aws_auth_commands[] = {
44
45
NGX_HTTP_LOC_CONF_OFFSET ,
45
46
offsetof(ngx_http_aws_auth_conf_t , s3_bucket ),
46
47
NULL },
48
+
49
+ { ngx_string ("chop_prefix" ),
50
+ NGX_HTTP_SRV_CONF |NGX_HTTP_LOC_CONF |NGX_CONF_TAKE1 ,
51
+ ngx_conf_set_str_slot ,
52
+ NGX_HTTP_LOC_CONF_OFFSET ,
53
+ offsetof(ngx_http_aws_auth_conf_t , chop_prefix ),
54
+ NULL },
47
55
48
56
ngx_null_command
49
57
};
@@ -101,6 +109,7 @@ ngx_http_aws_auth_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
101
109
102
110
ngx_conf_merge_str_value (conf -> access_key , prev -> access_key , "" );
103
111
ngx_conf_merge_str_value (conf -> secret , prev -> secret , "" );
112
+ ngx_conf_merge_str_value (conf -> chop_prefix , prev -> chop_prefix , "" );
104
113
105
114
return NGX_CONF_OK ;
106
115
}
@@ -113,12 +122,34 @@ ngx_http_aws_auth_variable_s3(ngx_http_request_t *r, ngx_http_variable_value_t *
113
122
int t ;
114
123
unsigned int md_len ;
115
124
unsigned char md [EVP_MAX_MD_SIZE ];
116
-
117
125
aws_conf = ngx_http_get_module_loc_conf (r , ngx_http_aws_auth_module );
118
-
126
+
127
+
128
+ /*
129
+ * This Block of code added to deal with paths that are not on the root -
130
+ * that is, via proxy_pass that are being redirected and the base part of
131
+ * the proxy url needs to be taken off the beginning of the URI in order
132
+ * to sign it correctly.
133
+ */
134
+ u_char * uri = ngx_palloc (r -> pool , r -> uri .len );
135
+ ngx_sprintf (uri ,"%V" ,& r -> uri );
136
+ if (ngx_strcmp (aws_conf -> chop_prefix .data , "" )) {
137
+ if (!ngx_strncmp (r -> uri .data , aws_conf -> chop_prefix .data , aws_conf -> chop_prefix .len )) {
138
+ uri += aws_conf -> chop_prefix .len ;
139
+ ngx_log_error (NGX_LOG_DEBUG , r -> connection -> log , 0 ,
140
+ "chop_prefix '%V' chopped from URI" ,& aws_conf -> chop_prefix );
141
+ } else {
142
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
143
+ "chop_prefix '%V' NOT in URI" ,& aws_conf -> chop_prefix );
144
+ }
145
+ }
146
+
119
147
u_char * str_to_sign = ngx_palloc (r -> pool , r -> uri .len + aws_conf -> s3_bucket .len + 200 );
120
- ngx_sprintf (str_to_sign , "GET\n\n\n\nx-amz-date:%V\n/%V%V" ,
121
- & ngx_cached_http_time , & aws_conf -> s3_bucket , & r -> uri );
148
+ ngx_sprintf (str_to_sign , "GET\n\n\n\nx-amz-date:%V\n/%V%s" ,
149
+ & ngx_cached_http_time , & aws_conf -> s3_bucket ,uri );
150
+
151
+
152
+
122
153
123
154
if (evp_md == NULL )
124
155
{
0 commit comments