Skip to content

Commit b4cb016

Browse files
authored
Add Azure m2m auth with ACS (#114)
1 parent 5fca467 commit b4cb016

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

Readme.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
Welcome to the StackRox contributions repository. This repository stores a variety of configuration files, scripts, and samples related to the deployment and use of the [StackRox Kubernetes security platform](https://www.stackrox.io) and [Red Hat Advanced Cluster Security](https://www.redhat.com/en/technologies/cloud-computing/openshift/advanced-cluster-security-kubernetes).
44

5-
All code in this repo is provided as-is without warranty or support from Red Hat.
5+
All code in this repo is provided as-is without warranty or support from Red Hat.
66

77
Join the #stackrox channel on [CNCF Slack](https://cncf.slack.com/) for community discussion and support.
88

9-
We'd love your feedback! Please take care with any of the configurations in this repo before applying using these in your environment.
9+
We'd love your feedback! Please take care with any of the configurations in this repo before applying using these in your environment.
1010

1111
## What's in this Repository
12-
* `ci/` samples for using StackRox *roxctl* command-line tool in CI/CD pipelines
12+
* `ci/` samples for using StackRox *roxctl* command-line tool in CI/CD pipelines
1313
* `ingress/` configurations for StackRox under popular Kubernetes ingress controllers
1414
* `completions/` shell auto-completions for roxctl
1515
* `util-scripts/` scripts using Stackrox API or roxctl for popular tasks (export to csv,...)
16+
* `guides/` instructions on how to configure ACS or integrate it with 3rd party services
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)