23
23
* <pre>
24
24
* readonlyrest:
25
25
* enable: true
26
+ * auth_key: secretAuthKey // this can bypasses all other rules and allows for operation if matched
26
27
* allow_localhost: true
27
28
* whitelist: [192.168.1.144]
28
29
* forbidden_uri_re: .*bar_me_pls.*
@@ -57,6 +58,13 @@ public ReadonlyRestAction(final Settings settings, Client client, RestController
57
58
58
59
@ Override
59
60
public void process (RestRequest request , RestChannel channel , RestFilterChain filterChain ) {
61
+ if (isAuthorisedToBypassACL (request , conf )) {
62
+ logger .debug ("Auth ok, will bypass filters" );
63
+ ok (request , filterChain , channel );
64
+ return ;
65
+ } else {
66
+ logger .debug ("Cannot bypass filters via Authorization" );
67
+ }
60
68
ACLRequest aclReq = new ACLRequest (request , channel );
61
69
String reason = acl .check (aclReq );
62
70
if (reason == null ){
@@ -73,6 +81,21 @@ public void process(RestRequest request, RestChannel channel, RestFilterChain fi
73
81
}
74
82
});
75
83
}
84
+
85
+ protected boolean isAuthorisedToBypassACL (RestRequest request , ConfigurationHelper conf ) {
86
+ logger .debug ("Auth key: {}" , conf .authKeyBase64 );
87
+ if (conf .authKeyBase64 == null ) {
88
+ return false ;
89
+ }
90
+ String authVal = request .header ("Authorization" );
91
+ logger .debug ("Auth header: {}" , authVal );
92
+ if (authVal == null ) {
93
+ return false ;
94
+ }
95
+ String val = authVal .replace ("Basic " , "" ).trim ();
96
+ return val .equals (conf .authKeyBase64 );
97
+ }
98
+
76
99
public void ok (RestRequest request , RestFilterChain filterChain , RestChannel channel ){
77
100
filterChain .continueProcessing (request , channel );
78
101
}
0 commit comments