2.23.7.3. Authorization header
A request includes an app_id and app_key in an authorization header. If there is at least one or two values outputted at the end, then you can assign the app_key.
The resolution here assigns the app_key if there is one or two outputted at the end.
The authorization header specifies a value with the type of authorization and its value is encoded as Base64. This means you can split the value by a space character, take the second output and then split it again using a colon (:) as the separator. For example, if you use this format app_id:app_key, the header looks like the following example for credential:
aladdin:opensesame: Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
You must use lower case header field names as shown in the following example:
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: <threescale_wasm_plugin_name>
spec:
# ...
services:
# ...
credentials:
app_id:
- header:
keys:
- authorization
ops:
- split:
separator: " "
max: 2
- length:
min: 2
- drop:
head: 1
- base64_urlsafe
- split:
max: 2
app_key:
- header:
keys:
- app_key
# ...
The previous example use case looks at the headers for an authorization:
-
It takes its string value and split it by a space, checking that it generates at least two values of a
credential-type and thecredentialitself, then dropping thecredential-type. It then decodes the second value containing the data it needs, and splits it by using a colon (:) character to have an operations stack including first the
app_id, then theapp_key, if it exists.-
If
app_keydoes not exist in the authorization header then its specific sources are checked, for example, the header with the keyapp_keyin this case.
-
If
-
To add extra conditions to
credentials, allowBasicauthorizations, whereapp_idis eitheraladdinoradmin, or anyapp_idbeing at least 8 characters in length. app_keymust contain a value and have a minimum of 64 characters as shown in the following example:apiVersion: extensions.istio.io/v1alpha1 kind: WasmPlugin metadata: name: <threescale_wasm_plugin_name> spec: # ... services: # ... credentials: app_id: - header: keys: - authorization ops: - split: separator: " " max: 2 - length: min: 2 - reverse - glob: - Basic - drop: tail: 1 - base64_urlsafe - split: max: 2 - test: if: length: min: 2 then: - strlen: max: 63 - or: - strlen: min: 1 - drop: tail: 1 - assert: - and: - reverse - or: - strlen: min: 8 - glob: - aladdin - admin # ...-
After picking up the
authorizationheader value, you get aBasiccredential-type by reversing the stack so that the type is placed on top. -
Run a glob match on it. When it validates, and the credential is decoded and split, you get the
app_idat the bottom of the stack, and potentially theapp_keyat the top. Run a
test:if there are two values in the stack, meaning anapp_keywas acquired.-
Ensure the string length is between 1 and 63, including
app_idandapp_key. If the key’s length is zero, drop it and continue as if no key exists. If there was only anapp_idand noapp_key, the missing else branch indicates a successful test and evaluation continues.
-
Ensure the string length is between 1 and 63, including
The last operation, assert, indicates that no side-effects make it into the stack. You can then modify the stack:
Reverse the stack to have the
app_idat the top.-
Whether or not an
app_keyis present, reversing the stack ensuresapp_idis at the top.
-
Whether or not an
Use
andto preserve the contents of the stack across tests.Then use one of the following possibilities:
-
Make sure
app_idhas a string length of at least 8. -
Make sure
app_idmatches eitheraladdinoradmin.
-
Make sure