Skip to content

Commit 8deae73

Browse files
authored
aa
1 parent 609bc24 commit 8deae73

File tree

2 files changed

+19
-56
lines changed

2 files changed

+19
-56
lines changed

articles/azure-signalr/signalr-howto-config-application-firewall.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Client Connection Count Rules restrict concurrent client connections. When a cli
6565
# [Portal](#tab/Portal)
6666
To use Application Firewall, navigate to the SignalR **Application Firewall** blade on the Azure portal and click **Add** to add a rule.
6767

68-
![Screenshot of creating replica for Azure SignalR on Portal.](./media/signalr-howto-config-application-firewall/signalr-add-application-firewall-rule.png "Add rule")
68+
![Screenshot of adding application firewall rules for Azure SignalR on Portal.](./media/signalr-howto-config-application-firewall/signalr-add-application-firewall-rule.png "Add rule")
6969

7070
# [Bicep](#tab/Bicep)
7171

@@ -101,7 +101,7 @@ resource signalr 'Microsoft.SignalRService/signalr@2024-04-01-preview' = {
101101
type: 'ThrottleByJwtCustomClaimRule'
102102
maxCount: 100
103103
claimName: 'paidUser'
104-
}
104+
}
105105
]
106106
}
107107
}

articles/azure-web-pubsub/howto-config-application-firewall.md

Lines changed: 17 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
title: SignalR Application Firewall (Preview)
3-
description: An introduction about why and how to setup Application Firewall for Azure SignalR service
2+
title: Web PubSub Application Firewall (Preview)
3+
description: An introduction about why and how to setup Application Firewall for Azure Web PubSub service
44
author: biqian
5-
ms.service: signalr
5+
ms.service: azure-web-pubsub
66
ms.custom: devx-track-azurecli
77
ms.topic: how-to
88
ms.date: 07/10/2024
99
ms.author: biqian
1010
---
11-
# Application Firewall for Azure SignalR Service
11+
# Application Firewall for Azure Web PubSub Service
1212

1313
The Application Firewall provides sophisticated control over client connections in a distributed system. Before diving into its functionality and setup, let's clarify what the Application Firewall does not do:
1414

@@ -21,12 +21,11 @@ The Application Firewall consists of various rule lists. Currently, there is a r
2121

2222
This guideline is divided into three parts:
2323
1. Introduction to different application firewall rules.
24-
2. Instructions on configuring the rules using the Portal or Bicep on the SignalR service side.
24+
2. Instructions on configuring the rules using the Portal or Bicep on the Web PubSub service side.
2525
3. Steps to configure the token on the server side.
2626

2727
## Prerequisites
28-
29-
* An Azure SignalR Service in [Premium tier](https://azure.microsoft.com/pricing/details/signalr-service/).
28+
* A Web PubSub resource in [premium tier](https://azure.microsoft.com/pricing/details/web-pubsub/).
3029

3130
## Client Connection Count Rules
3231
Client Connection Count Rules restrict concurrent client connections. When a client attempts to establish a new connection, the rules are checked **sequentially**. If any rule is violated, the connection is rejected with a status code 429.
@@ -45,37 +44,29 @@ Client Connection Count Rules restrict concurrent client connections. When a cli
4544
**Note:** It's not guaranteed by default that tokens generated by the SDK are different each time. Though each token contaisn a timestamp, this timestamp might be the same if vast tokens are generated within seconds. To avoid identical tokens, insert a random claim into the token claims. Refer to [Configure access token](#configure-access-token).
4645

4746

48-
#### ThrottleByJwtCustomClaimRule
49-
50-
More advancedly, connections could be grouped into different groups according to custom claim. Connections with the same claim will be aggregated to do the check. For example, you could add a *ThrottleByJwtCustomClaimRule* to allow 5 concurrent connections for those with custom claim key "freeUser".
51-
52-
**Key point**: The rule applies to all claims with a certain claim name. The connection count aggregation is on the same claim (including claim name and claim value). The *ThrottleByUserIdRule* is a special case of this rule, applying to all connections with the userIdentity claim.
53-
54-
55-
5647
### Best Practice
5748
#### Avoid using too aggressive maxCount
5849

59-
Client connections may close without completing the tcp handshake. SignalR service can't detect those "half-closed" connections immediately. The connection is taken as active until the heartbeart failure. Therefore, aggressive throttling strategies might unexpectedly throttle clients. A smoother approach is to **leave some buffer** for the connection count, for example: double the *maxCount*.
50+
Client connections may close without completing the tcp handshake. Web PubSub service can't detect those "half-closed" connections immediately. The connection is taken as active until the heartbeart failure. Therefore, aggressive throttling strategies might unexpectedly throttle clients. A smoother approach is to **leave some buffer** for the connection count, for example: double the *maxCount*.
6051

6152

6253

6354
## Setup Application Firewall
6455

6556
# [Portal](#tab/Portal)
66-
To use Application Firewall, navigate to the SignalR **Application Firewall** blade on the Azure portal and click **Add** to add a rule.
57+
To use Application Firewall, navigate to the Web PubSub **Application Firewall** blade on the Azure portal and click **Add** to add a rule.
6758

68-
![Screenshot of creating replica for Azure SignalR on Portal.](./media/signalr-howto-config-application-firewall/add-application-firewall-rule.png "Add rule")
59+
![Screenshot of adding application firewall rules for Azure Web PubSub on Portal.](./media/howto-config-application-firewall/add-application-firewall-rule.png "Add rule")
6960

7061
# [Bicep](#tab/Bicep)
7162

7263
Use Visual Studio Code or your favorite editor to create a file with the following content and name it main.bicep:
7364

7465
```bicep
75-
@description('The name for your SignalR service')
66+
@description('The name for your Web PubSub service')
7667
param resourceName string = 'contoso'
7768
78-
resource signalr 'Microsoft.SignalRService/signalr@2024-04-01-preview' = {
69+
resource webpubsub 'Microsoft.SignalRService/webpubsub@2024-04-01-preview' = {
7970
name: resourceName
8071
properties: {
8172
applicationFirewall:{
@@ -90,18 +81,6 @@ resource signalr 'Microsoft.SignalRService/signalr@2024-04-01-preview' = {
9081
type: 'ThrottleByJwtSignatureRule'
9182
maxCount: 10
9283
}
93-
{
94-
// This rule will be skipped if no freeUser claim is set
95-
type: 'ThrottleByJwtCustomClaimRule'
96-
maxCount: 10
97-
claimName: 'freeUser'
98-
}
99-
{
100-
// This rule will be skipped if no paidUser claim is set
101-
type: 'ThrottleByJwtCustomClaimRule'
102-
maxCount: 100
103-
claimName: 'paidUser'
104-
}
10584
]
10685
}
10786
}
@@ -119,33 +98,17 @@ Deploy the Bicep file using Azure CLI
11998

12099

121100
## Configure access token
122-
The application firewall rules only take effect when the access token contains the corresponding claim. A rule will be **skipped** if the connection does not have the corresponding claim.
123101

124-
Below is an example to add userId or custom claim in the access token in **Default Mode**:
102+
The application firewall rules only take effect when the access token contains the corresponding claim. A rule will be **skipped** if the connection does not have the corresponding claim. *userId" and *roles* are currently supported claims in the SDK.
103+
104+
Below is an example to add userId and insert a unique placeholder in the access token:
125105

126106
```cs
127-
services.AddSignalR().AddAzureSignalR(options =>
128-
{
129-
// Add necessary claims according to your rules.
130-
options.ClaimsProvider = context => new[]
131-
{
132-
// Add UserId: Used in ThrottleByUserIdRule
133-
new Claim(ClaimTypes.NameIdentifier, context.Request.Query["username"]),
134-
135-
// Add unique claim: Ensure uniqueness when using ThrottleByJwtSignatureRule.
136-
// The token name is not important. You could change it as you like.
137-
new Claim("uniqueToken", Guid.NewGuid().ToString()),
138-
139-
// Cutom claim: Used in ThrottleByJwtCustomClaimRule
140-
new Claim("<Custom Claim Name>", "<Custom Claim Value>"),
141-
// Custom claim example
142-
new Claim("freeUser", context.Request.Query["username"]),
143-
};
144-
});
107+
// The GUID role wont have any effect. But it esures this token's uniqueness when using rule ThrottleByJwtSignatureRule.
108+
var url = service.GetClientAccessUri((userId: "user1" , roles: new string[] { "webpubsub.joinLeaveGroup.group1", Guid.NewGuid().ToString()});
145109
```
146-
The logic for **Serverless Mode** is similar.
147110

148-
For more details, refer to [Client negotiation](signalr-concept-client-negotiation.md#What-can-you-do-during-negotiation) .
111+
For more details, refer to [Client negotiation](howto-generate-client-access-url.md#generate-from-service-sdk) .
149112

150113

151114

0 commit comments

Comments
 (0)