|
| 1 | +## Using Azure Entra ID service principals for machine to machine auth with ACS |
| 2 | + |
| 3 | +**Note:** Instructions provided in this guide are provided as-is without warranty or support from Red Hat. |
| 4 | + |
| 5 | +### 1. Create Azure service principal |
| 6 | + |
| 7 | +For this, we can use [the following guide from Microsoft Learn](https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-service-principal-portal?source=recommendations#register-an-application-with-microsoft-entra-id-and-create-a-service-principal). |
| 8 | + |
| 9 | +The only step: “**Register an application with Microsoft Entra ID and create a service principal”** is required. We do not have to add roles for that service principal because it does not have to access any Azure resource. It will be used only for authentication in ACS. |
| 10 | + |
| 11 | +### 2. Setup authentication for created service principal |
| 12 | + |
| 13 | +This is required in order for the service principal to authenticate to Azure. |
| 14 | + |
| 15 | +We can use [the following steps from the same Microsoft Learn page](https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-service-principal-portal?source=recommendations#set-up-authentication). |
| 16 | + |
| 17 | +After authentication setup, we can use the `az` command to log into Azure and retrieve the access token required to do m2m authentication to ACS. |
| 18 | + |
| 19 | +### 3. Login with `az` |
| 20 | + |
| 21 | +This example uses a secret to authenticate (**Option 3** in the “Setup authentication” guide mentioned under step 2.). |
| 22 | + |
| 23 | +``` |
| 24 | +az login --service-principal \ |
| 25 | + --username <service principal Application (client) ID> \ |
| 26 | + --password <created secret Value field> \ |
| 27 | + --tenant <service principal Directory (tenant) ID> \ |
| 28 | + --allow-no-subscriptions |
| 29 | +``` |
| 30 | + |
| 31 | +It is important to use the `--allow-no-subscriptions` flag if the service principal does not have any roles. |
| 32 | + |
| 33 | +**Note:** Logging as a regular user with `az login` would also work. In that case, the difference would be that we need to use `unique_name` or another claim from the token during the configuration of ACS machine access (Step 4\. below) |
| 34 | + |
| 35 | +After this, the command: |
| 36 | + |
| 37 | +``` |
| 38 | +az account list --output yamlc |
| 39 | +``` |
| 40 | + |
| 41 | +Should output account with `user` property. The name of that user should be the service principal ID. |
| 42 | + |
| 43 | +``` |
| 44 | + user: |
| 45 | + name: <service principal Application (client) ID> |
| 46 | + type: servicePrincipal |
| 47 | +``` |
| 48 | + |
| 49 | +### 4. Configure ACS |
| 50 | + |
| 51 | +You can follow [Configuring short-lived access documentation on Red Hat documentation](https://docs.redhat.com/en/documentation/red_hat_advanced_cluster_security_for_kubernetes/4.6/html/operating/managing-user-access#configure-short-lived-access). *Ensure to use documentation from used ACS version.* |
| 52 | + |
| 53 | +Create a **Machine access configuration** - with the following fields: |
| 54 | + |
| 55 | +Issuer: `https://sts.windows.net/<service principal Directory (tenant) ID>/` |
| 56 | + |
| 57 | +Add a rule with: |
| 58 | +Key: `appid` |
| 59 | +Value: `<service principal Application (client) ID>` |
| 60 | + |
| 61 | +**Important:** ACS has to be able to access: `https://sts.windows.net/<service principal Directory (tenant) ID>/.well-known/openid-configuration` |
| 62 | + |
| 63 | +### 5. Test everything |
| 64 | + |
| 65 | +Use the following `roxctl` command: |
| 66 | + |
| 67 | +``` |
| 68 | +roxctl central machine-to-machine exchange \ |
| 69 | + --token="$(az account get-access-token --tenant "<service principal Directory (tenant) ID>" --query "accessToken" --output tsv)" |
| 70 | +``` |
| 71 | + |
| 72 | +*If `--output tsv` does not provide valid token format. There is option to use JSON output and `jq` command to select token from payload.* |
| 73 | + |
| 74 | +After successful login, running: `roxctl central whoami` should output ACS authentication information. And “User name:” in the output should be the same as provided `<service principal Application (client) ID>` in the `az` login command. |
0 commit comments