> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Tenant Access Control List の一般的なユースケース向けコードサンプル

> Tenant ACL の一般的なユースケースを実装するための、Management API リクエスト、Auth0 SDK と CLI、Auth0 Terraform provider のコードサンプルです。

## リクエストをブロックする

この Tenant ACL ルールの例では、特定の地理位置情報の国コードからの受信トラフィックをブロックします。

> [tab] Management API
>
> Management API でこの Tenant ACL ルールを作成するには、次の手順に従います。
>
> 1. `create:network_acls` スコープ を指定して、[Management API アクセストークンを取得](/docs/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production)します。
>
> 2. 次の 本文 を指定して、Management API の [アクセス制御リストを作成するエンドポイント](/docs/docs/ja-jp/api/management/v2/network-acls/post-network-acls) を呼び出します。
>
> ```json expandable theme={null}
> {
>   "description": "Example of blocking a request",
>   "active": true,
>   "priority": 2,
>   "rule": {
>     "action": {
>       "block": true
>     },
>     "match": {
>       "geo_country_codes": [
>         "{geoCountryCode}"
>       ]
>     },
>     "scope": "authentication"
>   }
> }{
>   "description": "Example of blocking a request",
>   "active": true,
>   "priority": 2,
>   "rule": {
>     "action": {
>       "block": true
>     },
>     "match": {
>       "geo_country_codes": [
>         "{geoCountryCode}"
>       ]
>     },
>     "scope": "authentication"
>   }
> }
> ```

> [tab] Go SDK
>
> ```go expandable theme={null}
> package main
>
> import (
> 	"context"
> 	"log"
>
> 	"github.com/auth0/go-auth0"
> 	"github.com/auth0/go-auth0/management"
> )
>
> func main() {
> 	mgmt, err := management.New("{yourDomain}", management.WithClientCredentials("{yourClientId}", "{yourClientSecret}"))
> 	if err != nil {
> 		log.Fatal(err)
> 	}
>
> 	networkACL := &management.NetworkACL{
> 		Description: auth0.String("Example of blocking a request"),
> 		Active:      auth0.Bool(true),
> 		Priority:    auth0.Int(2),
> 		Rule: &management.NetworkACLRule{
> 			Action: &management.NetworkACLRuleAction{
> 				Block: auth0.Bool(true),
> 			},
> 			Match: &management.NetworkACLRuleMatch{
> 				GeoCountryCodes: &[]string{"{geoCountryCode}"},
> 			},
> 			Scope: auth0.String("authentication"),
> 		},
> 	}
>
> 	err = mgmt.NetworkACL.Create(context.Background(), networkACL)
> 	if err != nil {
> 		log.Fatal(err)
> 	}
> 	log.Println("Network ACL has been created")
> }
> ```

> [tab] Node SDK
>
> ```js theme={null}
> const createNetworkAclPayload: Management.CreateNetworkAclRequestContent = {
>   description: "Example of blocking a request",
>   active: true,
>   priority: 2,
>   rule: {
>     action: {
>       block: true,
>     },
>     match: {
>       geo_country_codes: ["{geoCountryCode}"],
>     },
>     scope: "authentication",
>   },
> };
>
> const createNetworkAcl = await client.networkAcls.create(createNetworkAclPayload);
> ```

> [tab] Terraform
>
> ```terraform theme={null}
> resource "auth0_network_acl" "example_blocking_request_acl" {
>     description = "Example of blocking a request"
>     active = true
>     priority = 2
>     rule {
>         action {
>             block = true
>         }
>         match {
>             geo_country_codes = ["{geoCountryCode}"]
>         }
>         scope = "authentication"
>     }
> }
> ```

> [tab] Deploy CLI
>
> ```yaml theme={null}
> networkACLs:
>   - description: Example of blocking a request
>     active: true
>     priority: 2
>     rule:
>       action:
>         block: true
>       match:
>         geo_country_codes:
>           - {geoCountryCode}
>       scope: authentication
> ```

> [tab] Auth0 CLI
>
> ```bash wrap theme={null}
> auth0 network-acl create \
>     --description "Example of blocking a request" \
>     --active true \
>     --priority 2 \
>     --rule '{"action":{"block":true},"match":{"geo_country_codes":["{geoCountryCode}"]},"scope":"authentication"}'
> ```

以下はブロックページの例です。

![ブロックページの例](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/tenants/block-page-example.png)

## リクエストを許可する

この Tenant ACL ルールの例では、特定の地理位置情報の国コードからのトラフィックのみを許可します。

> [tab] Management API
>
> Management API を使用してこの Tenant ACL ルールを作成するには、次の手順を実行します。
>
> 1. `create:network_acls` スコープを持つ [Management API アクセストークンを取得する](/docs/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production)。
>
> 2. 次のリクエスト本文を指定して、Management API の[アクセス制御リストを作成するエンドポイント](/docs/docs/ja-jp/api/management/v2/network-acls/post-network-acls)を呼び出します。
>
> ```json theme={null}
> {
>   "description": "Example of allowing a request",
>   "active": true,
>   "priority": 2,
>   "rule": {
>     "action": {
>       "allow": true
>     },
>     "match": {
>       "geo_country_codes": [
>         "{geoCountryCode}"
>       ]
>     },
>     "scope": "authentication"
>   }
> }
> ```

> [tab] Go SDK
>
> ```go expandable theme={null}
> package main
>
> import (
> 	"context"
> 	"log"
>
> 	"github.com/auth0/go-auth0"
> 	"github.com/auth0/go-auth0/management"
> )
>
> func main() {
> 	mgmt, err := management.New("{yourDomain}", management.WithClientCredentials("{yourClientId}", "{yourClientSecret}"))
> 	if err != nil {
> 		log.Fatal(err)
> 	}
>
> 	networkACL := &management.NetworkACL{
> 		Description: auth0.String("Example of allowing a request"),
> 		Active:      auth0.Bool(true),
> 		Priority:    auth0.Int(2),
> 		Rule: &management.NetworkACLRule{
> 			Action: &management.NetworkACLRuleAction{
> 				Allow: auth0.Bool(true),
> 			},
> 			Match: &management.NetworkACLRuleMatch{
> 				GeoCountryCodes: &[]string{"{geoCountryCode}"},
> 			},
> 			Scope: auth0.String("authentication"),
> 		},
> 	}
>
> 	err = mgmt.NetworkACL.Create(context.Background(), networkACL)
> 	if err != nil {
> 		log.Fatal(err)
> 	}
> 	log.Println("Network ACL has been created")
> }
> ```

> [tab] Node SDK
>
> ```js theme={null}
> const createNetworkAclPayload: Management.CreateNetworkAclRequestContent = {
>   description: "Example of allowing a request",
>   active: true,
>   priority: 2,
>   rule: {
>     action: {
>       allow: true,
>     },
>     match: {
>       geo_country_codes: ["{geoCountryCode}"],
>     },
>     scope: "authentication",
>   },
> };
>
> const createNetworkAcl = await client.networkAcls.create(createNetworkAclPayload);
> ```

> [tab] Terraform
>
> ```terraform theme={null}
> resource "auth0_network_acl" "example_allowing_request_acl" {
>     description = "Example of allowing a request"
>     active = true
>     priority = 2
>     rule {
>         action {
>             allow = true
>         }
>         match {
>             geo_country_codes = ["{geoCountryCode}"]
>         }
>         scope = "authentication"
>     }
> }
> ```

> [tab] Deploy CLI
>
> ```yaml theme={null}
> networkACLs:
>   - description: Example of allowing a request
>     active: true
>     priority: 2
>     rule:
>       action:
>         allow: true
>       match:
>         geo_country_codes:
>           - {geoCountryCode}
>       scope: authentication
> ```

> [tab] Auth0 CLI
>
> ```bash wrap theme={null}
> auth0 network-acl create \
>     --description "Example of allowing a request" \
>     --active true \
>     --priority 2 \
>     --rule '{"action":{"allow":true},"match":{"geo_country_codes":["{geoCountryCode}"]},"scope":"authentication"}'
> ```

## リクエストをリダイレクトする

この Tenant ACL ルールの例では、特定の地理位置情報の国コードからのすべてのトラフィックをリダイレクトします。

> [tab] Management API
>
> Management API を使用してこの Tenant ACL ルールを作成するには、次の手順に従います。
>
> 1. `create:network_acls` スコープを含む [Management API アクセストークン](/docs/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production) を取得します。
>
> 2. 次の本文で、Management API の[アクセス制御リストを作成するエンドポイント](/docs/docs/ja-jp/api/management/v2/network-acls/post-network-acls)を呼び出します。
>
> ```json theme={null}
> {
>   "description": "Example of redirecting a request",
>   "active": true,
>   "priority": 2,
>   "rule": {
>     "action": {
>       "redirect": true,
>       "redirect_uri": "REDIRECT_URI"
>     },
>     "match": {
>       "geo_country_codes": [
>         "{geoCountryCode}"
>       ]
>     },
>     "scope": "authentication"
>   }
> }
> ```

> [tab] Go SDK
>
> ```go expandable theme={null}
> package main
>
> import (
> 	"context"
> 	"log"
>
> 	"github.com/auth0/go-auth0"
> 	"github.com/auth0/go-auth0/management"
> )
>
> func main() {
> 	mgmt, err := management.New("{yourDomain}", management.WithClientCredentials("{yourClientId}", "{yourClientSecret}"))
> 	if err != nil {
> 		log.Fatal(err)
> 	}
>
> 	networkACL := &management.NetworkACL{
> 		Description: auth0.String("Example of redirecting a request"),
> 		Active:      auth0.Bool(true),
> 		Priority:    auth0.Int(2),
> 		Rule: &management.NetworkACLRule{
> 			Action: &management.NetworkACLRuleAction{
> 				Redirect: auth0.Bool(true),
> 				RedirectURI: auth0.String("REDIRECT_URI"),
> 			},
> 			Match: &management.NetworkACLRuleMatch{
> 				GeoCountryCodes: &[]string{"{geoCountryCode}"},
> 			},
> 			Scope: auth0.String("authentication"),
> 		},
> 	}
>
> 	err = mgmt.NetworkACL.Create(context.Background(), networkACL)
> 	if err != nil {
> 		log.Fatal(err)
> 	}
> 	log.Println("Network ACL has been created")
> }
> ```

> [tab] Node SDK
>
> ```js theme={null}
> const createNetworkAclPayload: Management.CreateNetworkAclRequestContent = {
>   description: "Example of a complex comparison",
>   active: true,
>   priority: 1,
>   rule: {
>     action: {
>       block: true,
>     },
>     match: {
>       geo_country_codes: ["{geoCountryCode}"],
>     },
>     not_match: {
>       geo_subdivision_codes: ["{geoSubdivisionCode}"],
>     },
>     scope: "authentication",
>   },
> };
>
> const createNetworkAcl = await client.networkAcls.create(createNetworkAclPayload);
> ```

> [tab] Terraform
>
> ```terraform theme={null}
> resource "auth0_network_acl" "example_complex_comparison_acl" {
>     description = "Example of a complex comparison"
>     active = true
>     priority = 1
>     rule {
>         action {
>             block = true
>         }
>         match {
>             geo_country_codes = ["{geoCountryCode}"]
>         }
>         not_match {
>             geo_subdivision_codes = ["{geoSubdivisionCode}"]
>         }
>         scope = "authentication"
>     }
> }
> ```

> [tab] Deploy CLI
>
> ```yaml theme={null}
> networkACLs:
>   - description: Example of a complex comparison
>     active: true
>     priority: 1
>     rule:
>       action:
>         block: true
>       match:
>         geo_country_codes:
>           - {geoCountryCode}
>       not_match:
>         geo_subdivision_codes:
>           - {geoSubdivisionCode}
>       scope: authentication
> ```

> [tab] Auth0 CLI
>
> ```bash wrap theme={null}
> auth0 network-acl create \
>     --description "Example of a complex comparison"
>     --active true \
>     --priority 1 \
>     --rule '{"action":{"block":true},"match":{"geo_country_codes":["{geoCountryCode}"]},"not_match":{"geo_subdivision_codes":["{geoSubdivisionCode}"]},"scope":"authentication"}'
> ```

## 複雑な比較

1 つの Tenant ACL ルール内で `match` 演算子と `not_match` 演算子を組み合わせることで、きめ細かなアクセス制御ポリシーを適用できます。

この Tenant ACL ルールの例では、`geo_country_code` シグナルと `geo_subdivision_code` シグナルを評価し、特定の国からのすべてのトラフィックを、その国の特定の州、地域、または県からのトラフィックを除いてブロックします。

> [tab] Management API
>
> Management API を使用してこの Tenant ACL ルールを作成するには、次の手順に従います。
>
> 1. `create:network_acls` スコープを持つ [Management API アクセストークンを取得](/docs/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production) します。
>
> 2. 次の本文を指定して、Management API の[アクセス制御リストを作成するエンドポイント](/docs/docs/ja-jp/api/management/v2/network-acls/post-network-acls)を呼び出します。
>
> ```json theme={null}
> {
>   "description": "Example of a complex comparison",
>   "active": true,
>   "priority": 1,
>   "rule": {
>     "action": {
>       "block": true
>     },
>     "match": {
>       "geo_country_codes": [
>         "{geoCountryCode}"
>       ]
>     },
>     "not_match": {
>       "geo_subdivision_codes": [
>         "{geoSubdivisionCode}"
>       ]
>     },
>     "scope": "authentication"
>   }
> }
> ```

> [tab] Go SDK
>
> ```go expandable theme={null}
> package main
>
> import (
> 	"context"
> 	"log"
>
> 	"github.com/auth0/go-auth0"
> 	"github.com/auth0/go-auth0/management"
> )
>
> func main() {
> 	mgmt, err := management.New("{yourDomain}", management.WithClientCredentials("{yourClientId}", "{yourClientSecret}"))
> 	if err != nil {
> 		log.Fatal(err)
> 	}
>
> 	networkACL := &management.NetworkACL{
> 		Description: auth0.String("Example of a complex comparison"),
> 		Active:      auth0.Bool(true),
> 		Priority:    auth0.Int(1),
> 		Rule: &management.NetworkACLRule{
> 			Action: &management.NetworkACLRuleAction{
> 				Block: auth0.Bool(true),
> 			},
> 			Match: &management.NetworkACLRuleMatch{
> 				GeoCountryCodes: &[]string{"{geoCountryCode}"},
> 			},
> 			NotMatch: &management.NetworkACLRuleMatch{
> 				GeoSubdivisionCodes: &[]string{"{geoSubdivisionCode}"},
> 			},
> 			Scope: auth0.String("authentication"),
> 		},
> 	}
>
> 	err = mgmt.NetworkACL.Create(context.Background(), networkACL)
> 	if err != nil {
> 		log.Fatal(err)
> 	}
> 	log.Println("Network ACL has been created")
> }
> ```

> [tab] Node SDK
>
> ```js theme={null}
> const createNetworkAclPayload: Management.CreateNetworkAclRequestContent = {
>   description: "Example of a complex comparison",
>   active: true,
>   priority: 1,
>   rule: {
>     action: {
>       block: true,
>     },
>     match: {
>       geo_country_codes: ["{geoCountryCode}"],
>     },
>     not_match: {
>       geo_subdivision_codes: ["{geoSubdivisionCode}"],
>     },
>     scope: "authentication",
>   },
> };
>
> const createNetworkAcl = await client.networkAcls.create(createNetworkAclPayload);
> ```

> [tab] Terraform
>
> ```terraform theme={null}
> resource "auth0_network_acl" "example_complex_comparison_acl" {
>     description = "Example of a complex comparison"
>     active = true
>     priority = 1
>     rule {
>         action {
>             block = true
>         }
>         match {
>             geo_country_codes = ["{geoCountryCode}"]
>         }
>         not_match {
>             geo_subdivision_codes = ["{geoSubdivisionCode}"]
>         }
>         scope = "authentication"
>     }
> }
> ```

> [tab] Deploy CLI
>
> ```yaml theme={null}
> networkACLs:
>   - description: Example of a complex comparison
>     active: true
>     priority: 1
>     rule:
>       action:
>         block: true
>       match:
>         geo_country_codes:
>           - {geoCountryCode}
>       not_match:
>         geo_subdivision_codes:
>           - {geoSubdivisionCode}
>       scope: authentication
> ```

> [tab] Auth0 CLI
>
> ```bash wrap theme={null}
> auth0 network-acl create \
>     --description "Example of a complex comparison" \
>     --active true \
>     --priority 1 \
>     --rule '{"action":{"block":true},"match":{"geo_country_codes":["{geoCountryCode}"]},"not_match":{"geo_subdivision_codes":["{geoSubdivisionCode}"]},"scope":"authentication"}'
> ```

## 特定のインフラストラクチャを経由するようにトラフィックを制限する

`hostnames` と `connecting_ipv4_cidrs` のシグナルを組み合わせることで、リバースプロキシや VPN など、承認済みのインフラストラクチャを経由するリクエストだけをテナントにルーティングできます。

この Tenant ACL ルールの例では、Auth0 エッジに直接接続する特定の IP アドレス群から送信されたリクエスト以外について、正規ドメインおよびカスタムドメインへのアクセスをブロックします。これにより、ユーザーがパブリックインターネットからテナントのホスト名に直接アクセスして、セキュリティ制御を回避することを防げます。

> [tab] Management API
>
> Management API を使用してこの Tenant ACL ルールを作成するには、次の手順を実行します。
>
> 1. `create:network_acls` スコープを指定して、[Management API アクセストークンを取得します](/docs/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production)。
>
> 2. 次の本文を指定して、Management API の[アクセス制御リストを作成するエンドポイント](/docs/docs/ja-jp/api/management/v2/network-acls/post-network-acls)を呼び出します。
>
> ```json theme={null}
> {
>   "description": "Restrict access to specific proxy IPs for custom and canonical domains",
>   "active": true,
>   "priority": 10,
>   "rule": {
>     "action": {
>       "block": true
>     },
>     "match": {
>        "hostnames": ["auth.example.com", "my-tenant.us.auth0.com"] 
>     },
>     "not_match": {
>       "connecting_ipv4_cidrs": [
>         "192.0.2.0/24",
>         "203.0.113.5/32"
>       ]
>     },
>     "scope": "tenant"
>   }
> }
>
> ```
