Skip to content

Commit d0de07c

Browse files
committed
docs(azure): better security granuality concerning external dns service principal
1 parent b7fb7ec commit d0de07c

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

docs/tutorials/azure.md

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,18 @@ The `resourceGroup` is the Resource Group created in a previous step.
6161
The `aadClientID` and `aaClientSecret` are assoiated with the Service Principal, that you need to create next.
6262

6363
### Creating service principal
64-
A Service Principal with a minimum access level of contribute to the resource group containing the Azure DNS zone(s) is necessary for ExternalDNS to be able to edit DNS records. This is an Azure CLI example on how to query the Azure API for the information required for the Resource Group and DNS zone you would have already created in previous steps.
64+
A Service Principal with a minimum access level of `contributor` to the DNS zone(s) and `reader` to the resource group containing the Azure DNS zone(s) is necessary for ExternalDNS to be able to edit DNS records. However, other more permissive access levels will work too (e.g. `contributor` to the resource group or the whole subscription).
6565

66+
This is an Azure CLI example on how to query the Azure API for the information required for the Resource Group and DNS zone you would have already created in previous steps.
67+
68+
``` bash
69+
> az login
6670
```
67-
>az login
68-
...
69-
# find the relevant subscription and set the az context. id = subscriptionId value in the azure.json.
70-
>az account list
71+
72+
Find the relevant subscription and make sure it is selected (the same subscriptionId should be set into azure.json)
73+
74+
``` bash
75+
> az account list
7176
{
7277
"cloudName": "AzureCloud",
7378
"id": "<subscriptionId GUID>",
@@ -79,22 +84,48 @@ A Service Principal with a minimum access level of contribute to the resource gr
7984
"name": "name",
8085
"type": "user"
8186
}
82-
>az account set -s id
87+
88+
# select the subscription
89+
> az account set -s <subscriptionId GUID>
8390
...
84-
>az group show --name externaldns
91+
```
92+
Create the service principal
93+
94+
``` bash
95+
> az ad sp create-for-rbac -n ExternalDnsServicePrincipal
96+
{
97+
"appId": "appId GUID", <-- aadClientId value
98+
...
99+
"password": "password", <-- aadClientSecret value
100+
"tenant": "AzureAD Tenant Id" <-- tenantId value
101+
}
102+
```
103+
104+
Assign the rights for the service principal
105+
106+
```
107+
# find out the resource ids of the resource group where the dns zone is deployed, and the dns zone itself
108+
> az group show --name externaldns
85109
{
86110
"id": "/subscriptions/id/resourceGroups/externaldns",
87111
...
88112
}
89113

90-
# use the id from the previous step in the scopes argument
91-
>az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/id/resourceGroups/externaldns" -n ExternalDnsServicePrincipal
114+
> az network dns zone show --name example.com -g externaldns
92115
{
93-
"appId": "appId GUID", <-- aadClientId value
116+
"id": "/subscriptions/.../resourceGroups/externaldns/providers/Microsoft.Network/dnszones/example.com",
94117
...
95-
"password": "password", <-- aadClientSecret value
96-
"tenant": "AzureAD Tenant Id" <-- tenantId value
97118
}
119+
```
120+
```
121+
# assign the rights to the created service principal, using the resource ids from previous step
122+
123+
# 1. as a reader to the resource group
124+
> az role assignment create --role "Reader" --assignee <appId GUID> --scope <resource group resource id>
125+
126+
# 2. as a contributor to DNS Zone itself
127+
> az role assignment create --role "Contributor" --assignee <appId GUID> --scope <dns zone resource id>
128+
98129
```
99130
100131
Now you can create a file named 'azure.json' with values gathered above and with the structure of the example above. Use this file to create a Kubernetes secret:

0 commit comments

Comments
 (0)