-
Notifications
You must be signed in to change notification settings - Fork 2k
Migrate access control example to documentation website #6572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
23d2617
Migrate access control example to documentation website
ADubhlaoich e8dda9a
Merge branch 'main' into docs/example-migration
ADubhlaoich fabb850
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 03da540
Update Markdown heading for linter compliance
ADubhlaoich c1070a8
Merge branch 'docs/example-migration' of github.com:nginxinc/kubernet…
ADubhlaoich 969ddf2
Merge branch 'main' into docs/example-migration
ADubhlaoich 91387ef
Merge branch 'main' into docs/example-migration
ADubhlaoich 56ca0c4
Merge branch 'main' into docs/example-migration
ADubhlaoich 1db65ae
Merge branch 'main' into docs/example-migration
ADubhlaoich 866d847
Merge branch 'main' into docs/example-migration
ADubhlaoich a09099d
Merge branch 'main' into docs/example-migration
ADubhlaoich a8f7c41
Merge branch 'main' into docs/example-migration
ADubhlaoich d74164c
Apply suggestions from code review
ADubhlaoich f4484fe
Update formatting
ADubhlaoich a502e04
Merge branch 'main' into docs/example-migration
ADubhlaoich d66dc22
Merge branch 'main' into docs/example-migration
ADubhlaoich 8d90d1a
Merge branch 'main' into docs/example-migration
ADubhlaoich 692716c
Merge branch 'main' into docs/example-migration
ADubhlaoich d52a8f1
Merge branch 'main' into docs/example-migration
ADubhlaoich b1dbd5b
Merge branch 'main' into docs/example-migration
ADubhlaoich 49b41ad
Merge branch 'main' into docs/example-migration
vepatel e836299
Merge branch 'main' into docs/example-migration
vepatel 1754688
Merge branch 'main' into docs/example-migration
jjngx aed5fbd
Merge branch 'main' into docs/example-migration
ADubhlaoich 0825f18
Update document to shift the subject focus the Policy object
ADubhlaoich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,3 @@ | ||
# Access Control | ||
# Deploy an Access Control policy | ||
|
||
In this example, we deploy a web application; configure load balancing for it via a VirtualServer; and apply access | ||
control policies to deny and allow traffic from a specific subnet. | ||
|
||
## Prerequisites | ||
|
||
1. Follow the [installation](https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/) | ||
instructions to deploy the Ingress Controller. | ||
1. Save the public IP address of the Ingress Controller into a shell variable: | ||
|
||
```console | ||
IC_IP=XXX.YYY.ZZZ.III | ||
``` | ||
|
||
1. Save the HTTP port of the Ingress Controller into a shell variable: | ||
|
||
```console | ||
IC_HTTP_PORT=<port number> | ||
``` | ||
|
||
## Step 1 - Deploy a Web Application | ||
|
||
Create the application deployment and service: | ||
|
||
```console | ||
kubectl apply -f webapp.yaml | ||
``` | ||
|
||
## Step 2 - Deploy an Access Control Policy | ||
|
||
In this step, we create a policy with the name `webapp-policy` that denies requests from clients with an IP that belongs | ||
to the subnet `10.0.0.0/8`. This is the subnet that our test client in Steps 4 and 6 will belong to. Make sure to change | ||
the `deny` field of the `access-control-policy-deny.yaml` according to your environment (use the subnet of your | ||
machine). | ||
|
||
Create the policy: | ||
|
||
```console | ||
kubectl apply -f access-control-policy-deny.yaml | ||
``` | ||
|
||
## Step 3 - Configure Load Balancing | ||
|
||
Create a VirtualServer resource for the web application: | ||
|
||
```console | ||
kubectl apply -f virtual-server.yaml | ||
``` | ||
|
||
Note that the VirtualServer references the policy `webapp-policy` created in Step 2. | ||
|
||
## Step 4 - Test the Configuration | ||
|
||
Let's access the application: | ||
|
||
```console | ||
curl --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT | ||
``` | ||
|
||
```text | ||
<html> | ||
<head><title>403 Forbidden</title></head> | ||
<body> | ||
<center><h1>403 Forbidden</h1></center> | ||
</body> | ||
</html> | ||
``` | ||
|
||
We got a 403 response from NGINX, which means that our policy successfully blocked our request. | ||
|
||
## Step 5 - Update the Policy | ||
|
||
In this step, we update the policy to allow requests from clients from the subnet `10.0.0.0/8`. Make sure to change the | ||
`allow` field of the `access-control-policy-allow.yaml` according to your environment. | ||
|
||
Update the policy: | ||
|
||
```console | ||
kubectl apply -f access-control-policy-allow.yaml | ||
``` | ||
|
||
## Step 6 - Test the Configuration | ||
|
||
Let's access the application again: | ||
|
||
```console | ||
curl --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT | ||
``` | ||
|
||
```text | ||
Server address: 10.64.0.13:8080 | ||
Server name: webapp-5cbbc7bd78-wf85w | ||
``` | ||
|
||
In contrast with Step 4, we got a 200 response, which means that our updated policy successfully allowed our request. | ||
This is the example code used in the [Deploy an Access Control policy](https://docs.nginx.com/nginx-ingress-controller/configuration/access-control/) documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
--- | ||
title: Deploy an Access Control policy | ||
weight: 900 | ||
toc: true | ||
docs: DOCS-000 | ||
--- | ||
|
||
This topic describes how to apply and update an Access Control policy with F5 NGINX Ingress Controller. | ||
j1m-ryan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
It demonstrates this using an example application and a [VirtualServer custom resource]({{< ref "/configuration/virtualserver-and-virtualserverroute-resources.md" >}}) | ||
|
||
--- | ||
|
||
## Before you begin | ||
|
||
You should have a [working NGINX Ingress Controller]({{< ref "/installation/installing-nic/installation-with-helm.md" >}}) instance. | ||
|
||
For ease of use in shell commands, set two shell variables: | ||
|
||
1. The public IP address for your NGINX Ingress Controller instance. | ||
|
||
```shell | ||
IC_IP=<ip-address> | ||
``` | ||
|
||
2. The HTTP port of the same instance | ||
ADubhlaoich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```shell | ||
IC_HTTP_PORT=<port number> | ||
``` | ||
|
||
--- | ||
|
||
## Deploy the example application | ||
|
||
Create the file *webapp.yaml* with the following contents: | ||
|
||
{{< ghcode "https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/refs/heads/main/examples/custom-resources/access-control/webapp.yaml" >}} | ||
|
||
Apply it using *kubectl*: | ||
ADubhlaoich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```shell | ||
kubectl apply -f webapp.yaml | ||
``` | ||
|
||
--- | ||
|
||
## Deploy an Access Control policy | ||
ADubhlaoich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Create a file named *access-control-policy-deny.yaml*. The highlighted *deny* field will be used by the example application, and should be changed to the subnet of your machine. | ||
|
||
{{< ghcode "https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/refs/heads/main/examples/custom-resources/access-control/access-control-policy-deny.yaml" "hl_lines=7-8" >}} | ||
|
||
Apply the policy: | ||
|
||
```shell | ||
kubectl apply -f access-control-policy-deny.yaml | ||
``` | ||
|
||
--- | ||
|
||
## Configure load balancing | ||
|
||
Create a file named *virtual-server.yaml* for the VirtualServer resource. The *policies* field references the example application. | ||
ADubhlaoich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{{< ghcode "https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/refs/heads/main/examples/custom-resources/access-control/virtual-server.yaml" "hl_lines=7-8" >}} | ||
|
||
Apply the policy: | ||
|
||
```shell | ||
kubectl apply -f virtual-server.yaml | ||
``` | ||
|
||
--- | ||
|
||
## Test the example application | ||
|
||
Use *curl* to attempt to access the application: | ||
|
||
```shell | ||
curl --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT | ||
``` | ||
```text | ||
<html> | ||
<head><title>403 Forbidden</title></head> | ||
<body> | ||
<center><h1>403 Forbidden</h1></center> | ||
</body> | ||
</html> | ||
``` | ||
|
||
The *403* response is expected, successfully blocking your machine. | ||
|
||
--- | ||
|
||
## Update the policy | ||
ADubhlaoich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Create a new policy with the file *access-control-policy-allow.yaml*, updating the *allow* field to the subnet of your machine. | ||
|
||
{{< ghcode "https://raw.githubusercontent.com/nginxinc/kubernetes-ingress/refs/heads/main/examples/custom-resources/access-control/access-control-policy-allow.yaml" "hl_lines=7-8" >}} | ||
|
||
Apply the policy: | ||
|
||
```shell | ||
kubectl apply -f access-control-policy-allow.yaml | ||
``` | ||
|
||
---- | ||
|
||
## Verify the policy update | ||
|
||
Attempt to access the application again: | ||
|
||
```shell | ||
curl --resolve webapp.example.com:$IC_HTTP_PORT:$IC_IP http://webapp.example.com:$IC_HTTP_PORT | ||
``` | ||
```text | ||
Server address: 10.64.0.13:8080 | ||
Server name: webapp-5cbbc7bd78-wf85w | ||
``` | ||
|
||
The successful response demonstrates that the policy has been updated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
site/content/configuration/virtualserver-and-virtualserverroute-resources.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.