Skip to content

Commit 65bb400

Browse files
bretambroseBret Ambrose
and
Bret Ambrose
authored
Cleanup custom auth samples, improve associated sample readmes (#529)
* Cleanup custom auth samples, improve associated sample readmes --------- Co-authored-by: Bret Ambrose <[email protected]>
1 parent ed5a186 commit 65bb400

8 files changed

+23
-59
lines changed

.github/workflows/ci_run_custom_authorizer_connect_cfg.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
"name": "--endpoint",
99
"secret": "ci/endpoint"
1010
},
11-
{
12-
"name": "--signing_region",
13-
"data": "us-east-1"
14-
},
1511
{
1612
"name": "--custom_auth_authorizer_name",
1713
"secret": "ci/CustomAuthorizer/name"

.github/workflows/ci_run_mqtt5_custom_authorizer_cfg.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@
1515
{
1616
"name": "--custom_auth_password",
1717
"secret": "ci/CustomAuthorizer/password"
18-
},
19-
{
20-
"name": "--cert",
21-
"secret": "ci/mqtt5/us/mqtt5_thing/cert",
22-
"filename": "tmp_certificate.pem"
23-
},
24-
{
25-
"name": "--key",
26-
"secret": "ci/mqtt5/us/mqtt5_thing/key",
27-
"filename": "tmp_key.pem"
2818
}
2919
]
3020
}

.github/workflows/ci_run_mqtt5_custom_authorizer_websockets_cfg.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
{
2020
"name": "--use_websockets",
2121
"data": "true"
22-
},
23-
{
24-
"name": "--signing_region",
25-
"data": "us-east-1"
2622
}
2723
]
2824
}

codebuild/samples/custom-auth-linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ AUTH_NAME=$(aws secretsmanager get-secret-value --secret-id "ci/CustomAuthorizer
1212
AUTH_PASSWORD=$(aws secretsmanager get-secret-value --secret-id "ci/CustomAuthorizer/password" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
1313

1414
echo "Custom Authorizer test"
15-
python3 custom_authorizer_connect.py --endpoint $ENDPOINT --custom_auth_authorizer_name $AUTH_NAME --custom_auth_password $AUTH_PASSWORD --signing_region us-east-1
15+
python3 custom_authorizer_connect.py --endpoint $ENDPOINT --custom_auth_authorizer_name $AUTH_NAME --custom_auth_password $AUTH_PASSWORD
1616

1717
popd

samples/custom_authorizer_connect.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,18 @@ Note that in a real application, you may want to avoid the use of wildcards in y
3737

3838
# How to run
3939

40+
**Note** The sample also allows passing arguments to specify additional data your custom authorizer may need. The snippet below assumes that the custom authorizer does not need these additional parameters, but in the general case, you will almost always need some of them depending on the authorizer's configuration and the associated Lambda function's internals.
41+
* `--custom_auth_username` - opaque string value passed to the authorizer via an MQTT Connect packet. The authorizer's Lambda can check this value from the event JSON value it receives as input: `event.protocolData.mqtt.username`
42+
* `--custom_auth_password` - opaque binary value passed to the authorizer via an MQTT Connect packet. The authorizer's Lambda can check this value from the event JSON value it receives as input: `event.protocolData.mqtt.password`
43+
* `--custom_auth_token_key_name` - (Signed authorizers only) The query string parameter name that the token value should be bound to in the MQTT Connect packet.
44+
* `--custom_auth_token_value` - (Signed authorizers only) An arbitrary value chosen by the user. The user must also submit a digital signature of this value using the private key associated with the authorizer.
45+
* `--custom_auth_authorizer_signature` - (Signed authorizers only) a digital signature of the value of the `--custom_auth_token_value` parameter using the private key associated with the authorizer. The binary signature value must be base64 encoded and then URI encoded; the SDK will not do this for you.
46+
47+
## MQTT over TCP with TLS
48+
4049
To run the Custom Authorizer connect sample from the `samples` folder, use the following command:
4150

4251
``` sh
43-
# For Windows: replace 'python3' with 'python' and '/' with '\'
52+
# For Windows: replace 'python3' with 'python'
4453
python3 custom_authorizer_connect.py --endpoint <endpoint> --custom_auth_authorizer_name <authorizer name>
4554
```
46-
47-
**Note** The sample also allows passing additional arguments (`--custom_auth_username`, `--custom_auth_password`, and `custom_auth_authorizer_signature`) to fullfil the additional data your custom authorizer may need. The examples above assume that the custom authorizer does not need these additional parameters.

samples/mqtt5_custom_authorizer_connect.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,27 @@ Note that in a real application, you may want to avoid the use of wildcards in y
4141

4242
# How to run
4343

44-
### Direct MQTT via mTLS
44+
**Note** The sample also allows passing arguments to specify additional data your custom authorizer may need. The snippets below assume that the custom authorizer does not need these additional parameters, but in the general case, you will almost always need some of them depending on the authorizer's configuration and the associated Lambda function's internals.
45+
* `--custom_auth_username` - opaque string value passed to the authorizer via an MQTT Connect packet. The authorizer's Lambda can check this value from the event JSON value it receives as input: `event.protocolData.mqtt.username`
46+
* `--custom_auth_password` - opaque binary value passed to the authorizer via an MQTT Connect packet. The authorizer's Lambda can check this value from the event JSON value it receives as input: `event.protocolData.mqtt.password`
47+
* `--custom_auth_token_key_name` - (Signed authorizers only) The query string parameter name that the token value should be bound to in the MQTT Connect packet.
48+
* `--custom_auth_token_value` - (Signed authorizers only) An arbitrary value chosen by the user. The user must also submit a digital signature of this value using the private key associated with the authorizer.
49+
* `--custom_auth_authorizer_signature` - (Signed authorizers only) a digital signature of the value of the `--custom_auth_token_value` parameter using the private key associated with the authorizer. The binary signature value must be base64 encoded and then URI encoded; the SDK will not do this for you.
4550

46-
To run the MQTT5 Custom Authorizer connect sample from the `samples` folder using mTLS, use the following command:
51+
## MQTT over TCP with TLS
4752

48-
``` sh
49-
# For Windows: replace 'python3' with 'python' and '/' with '\'
50-
python3 mqtt5_custom_authorizer_connect.py --endpoint <endpoint> --cert <path to certificate> --key <path to private key> --custom_auth_authorizer_name <authorizer name>
51-
```
52-
53-
You can also pass a Certificate Authority file (CA) if your certificate and key combination requires it:
53+
To run the MQTT5 Custom Authorizer connect sample from the `samples` folder using TCP, use the following command:
5454

5555
``` sh
56-
# For Windows: replace 'python3' with 'python' and '/' with '\'
57-
python3 mqtt5_custom_authorizer_connect.py --endpoint <endpoint> --cert <path to certificate> --key <path to private key> --custom_auth_authorizer_name <authorizer name> --ca_file <path to CA file>
56+
# For Windows: replace 'python3' with 'python'
57+
python3 mqtt5_custom_authorizer_connect.py --endpoint <endpoint> --custom_auth_authorizer_name <authorizer name>
5858
```
5959

60-
**Note** The sample also allows passing additional arguments (`--custom_auth_username`, `--custom_auth_password`, and `custom_auth_authorizer_signature`) to fullfil the additional data your custom authorizer may need. The examples above assume that the custom authorizer does not need these additional parameters.
61-
62-
63-
## Websockets
60+
## MQTT over Websockets with TLS
6461

6562
To run the MQTT5 Custom Authorizer connect sample from the `samples` folder using Websockets, use the following command:
6663

6764
``` sh
68-
# For Windows: replace 'python3' with 'python' and '/' with '\'
65+
# For Windows: replace 'python3' with 'python'
6966
python3 mqtt5_custom_authorizer_connect.py --endpoint <endpoint> --use_websockets "true" --custom_auth_authorizer_name <authorizer name>
7067
```
71-
72-
**Note** The sample also allows passing additional arguments (`--custom_auth_username`, `--custom_auth_password`, and `custom_auth_authorizer_signature`) to fullfil the additional data your custom authorizer may need. The examples above assume that the custom authorizer does not need these additional parameters.

samples/mqtt5_custom_authorizer_connect.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ def on_lifecycle_connection_success(lifecycle_connect_success_data: mqtt5.Lifecy
3737
client = mqtt5_client_builder.direct_with_custom_authorizer(
3838
endpoint=cmdData.input_endpoint,
3939
ca_filepath=cmdData.input_ca,
40-
cert_filepath=cmdData.input_cert,
41-
pri_key_filepath=cmdData.input_key,
4240
auth_username=cmdData.input_custom_auth_username,
4341
auth_authorizer_name=cmdData.input_custom_authorizer_name,
4442
auth_authorizer_signature=cmdData.input_custom_authorizer_signature,
@@ -51,7 +49,6 @@ def on_lifecycle_connection_success(lifecycle_connect_success_data: mqtt5.Lifecy
5149
else:
5250
client = mqtt5_client_builder.websockets_with_custom_authorizer(
5351
endpoint=cmdData.input_endpoint,
54-
region=cmdData.input_signing_region,
5552
auth_username=cmdData.input_custom_auth_username,
5653
auth_authorizer_name=cmdData.input_custom_authorizer_name,
5754
auth_authorizer_signature=cmdData.input_custom_authorizer_signature,

samples/utils/command_line_utils.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -405,20 +405,13 @@ def parse_sample_input_custom_authorizer_connect():
405405
cmdUtils.add_common_mqtt_commands()
406406
cmdUtils.add_common_logging_commands()
407407
cmdUtils.add_common_custom_authorizer_commands()
408-
cmdUtils.register_command(CommandLineUtils.m_cmd_signing_region, "<str>",
409-
"The signing region used for the websocket signer",
410-
False, str)
411-
cmdUtils.register_command(CommandLineUtils.m_cmd_region, "<str>",
412-
"The signing region used for the websocket signer",
413-
False, str)
414408
cmdUtils.register_command(CommandLineUtils.m_cmd_client_id, "<str>",
415409
"Client ID to use for MQTT connection (optional, default='test-*').",
416410
default="test-" + str(uuid4()))
417411
cmdUtils.get_args()
418412

419413
cmdData = CommandLineUtils.CmdData()
420414
cmdData.input_endpoint = cmdUtils.get_command_required(CommandLineUtils.m_cmd_endpoint)
421-
cmdData.input_signing_region = cmdUtils.get_command_required(CommandLineUtils.m_cmd_signing_region, CommandLineUtils.m_cmd_region)
422415
cmdData.input_custom_authorizer_name = cmdUtils.get_command(CommandLineUtils.m_cmd_custom_auth_authorizer_name)
423416
cmdData.input_custom_authorizer_signature = cmdUtils.get_command(CommandLineUtils.m_cmd_custom_auth_authorizer_signature)
424417
cmdData.input_custom_auth_password = cmdUtils.get_command(CommandLineUtils.m_cmd_custom_auth_password)
@@ -488,13 +481,6 @@ def parse_sample_input_mqtt5_custom_authorizer_connect():
488481
cmdUtils = CommandLineUtils(
489482
"Custom Authorizer Connect - Make a MQTT5 Client connection using a custom authorizer.")
490483
cmdUtils.add_common_mqtt_commands()
491-
cmdUtils.register_command(CommandLineUtils.m_cmd_key_file, "<path>",
492-
"Path to your key in PEM format.", False, str)
493-
cmdUtils.register_command(CommandLineUtils.m_cmd_cert_file, "<path>",
494-
"Path to your client certificate in PEM format.", False, str)
495-
cmdUtils.register_command(CommandLineUtils.m_cmd_signing_region, "<str>",
496-
"The signing region used for the websocket signer",
497-
False, str)
498484
cmdUtils.add_common_logging_commands()
499485
cmdUtils.add_common_custom_authorizer_commands()
500486
cmdUtils.register_command(CommandLineUtils.m_cmd_client_id, "<str>",
@@ -505,9 +491,6 @@ def parse_sample_input_mqtt5_custom_authorizer_connect():
505491

506492
cmdData = CommandLineUtils.CmdData()
507493
cmdData.input_endpoint = cmdUtils.get_command_required(CommandLineUtils.m_cmd_endpoint)
508-
cmdData.input_signing_region = cmdUtils.get_command(CommandLineUtils.m_cmd_signing_region, None)
509-
cmdData.input_cert = cmdUtils.get_command(CommandLineUtils.m_cmd_cert_file, None)
510-
cmdData.input_key = cmdUtils.get_command(CommandLineUtils.m_cmd_key_file, None)
511494
cmdData.input_ca = cmdUtils.get_command(CommandLineUtils.m_cmd_ca_file, None)
512495
cmdData.input_custom_authorizer_name = cmdUtils.get_command(CommandLineUtils.m_cmd_custom_auth_authorizer_name)
513496
cmdData.input_custom_authorizer_signature = cmdUtils.get_command(CommandLineUtils.m_cmd_custom_auth_authorizer_signature)

0 commit comments

Comments
 (0)