Skip to content

Commit db29a62

Browse files
authored
docs: principal ID and rules in readme (#222)
## Issue There wasn't much guidance on how to specify the correct `principalId` in the spec for RBAC rule. Azure is complex when it comes to this. There are four GUIDs users see in the Azure Portal, where three of them are unique to each Entra ID identify they create. We need to guide them. ## Description Clarifies how principalID works in the docs. This includes the docstring generated by kubebuilder and some additions to the readme that go into detail about it, including screenshots. Because there is now a readme section on each rule in detail, there is a part where it describes the community gallery image rule too. But there isn't much to say about that rule right now. Also removes some unneeded `MaxLength` annotations (because they aren't used in other kubebuilder validations where long strings are problematic). Note that unlike in the PR #219, the `ActionStr` type and its `MaxLength` annotation must remain. This is because the RBAC rule forbids wildcards in specified permissions and kubebuilder validation here validates this, which is a type of kubebuilder validation where long strings are problematic. We need `ActionStr` because we need to place the `MaxLength` annotation on the list of actions in a way where it is applied to each string in a slice of strings, and this is the recommended way to do that right now. --------- Signed-off-by: Matt Welke <matt.welke@spectrocloud.com>
1 parent 57205c6 commit db29a62

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,34 @@ Each `AzureValidator` CR is (re)-processed every two minutes to continuously ens
2020

2121
See the [samples](https://github.com/validator-labs/validator-plugin-azure/tree/main/config/samples) directory for example `AzureValidator` configurations. Some samples require you to add data to the rules configured in them such as the Azure subscription to use.
2222

23+
### Rules
24+
25+
#### RBAC rule
26+
27+
This rule compares the Azure RBAC permissions associated with a [security principal](https://learn.microsoft.com/en-us/azure/role-based-access-control/overview#security-principal) against an expected permission set.
28+
29+
It checks if an Azure security principal (e.g., users, service principals) has the required Azure RBAC permissions. In Azure RBAC, permissions are applied to principals by a role assignment being created that links a role (which can be a BuiltInRole or a CustomRole) to the principal at a particular scope. API operations at that scope or lower (e.g. operations against a subscription or against a resource group within the subscription) are permitted but operations outside of that scope are not.
30+
31+
Validation is successful if the principal has the necessary permissions, either from one role assignment or a combination of role assignments.
32+
33+
The list of permissions defined in the spec cannot have an action or data action with a wildcard. However, the roles that provide the permissions (via role assignments) may have wildcards in their actions and data actions.
34+
35+
Note that you must use the correct ID when configuring the `principalId` in the spec for the principal. For a service principal, this is the "application object ID" found in the Azure portal under Entra ID > application registration > managed application page > "object ID". Note that this is different from the tenant ID, client ID, and object ID of the application registration.
36+
37+
Service principal example:
38+
39+
![3](https://github.com/user-attachments/assets/59b54214-10f6-4c7c-9ec5-eeeadfada35e)
40+
41+
![4](https://github.com/user-attachments/assets/560acda5-2515-4c87-a1e3-1f400492f4ad)
42+
43+
See [azurevalidator-rbac-one-permission-set-all-actions-permitted-by-one-role.yaml](config/samples/azurevalidator-rbac-one-permission-set-all-actions-permitted-by-one-role.yaml`) for an example rule spec.
44+
45+
#### Community image gallery rule
46+
47+
This rule verifies that images in [community image galleries](https://learn.microsoft.com/en-us/azure/virtual-machines/share-gallery-community) exist.
48+
49+
See [azurevalidator-communitygalleryimages-one-image.yaml](config/samples/azurevalidator-communitygalleryimages-one-image.yaml) for an example rule spec.
50+
2351
## Authn & Authz
2452

2553
Authentication details for the Azure validator controller are provided within each `AzureValidator` custom resource. Azure authentication can be configured either implicitly or explicitly:

api/v1alpha1/azurevalidator_types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ type RBACRule struct {
5353
//+kubebuilder:validation:XValidation:message="Each permission set must have Actions, DataActions, or both defined",rule="self.all(item, size(item.actions) > 0 || size(item.dataActions) > 0)"
5454
Permissions []PermissionSet `json:"permissionSets" yaml:"permissionSets"`
5555
// The principal being validated. This can be any type of principal - Device, ForeignGroup,
56-
// Group, ServicePrincipal, or User.
56+
// Group, ServicePrincipal, or User. If using a service principal, this is the "application
57+
// object ID". In the Azure portal, this can be found by navigating to Entra ID, selecting the
58+
// application registration of the service principal, navigating from that page to the managed
59+
// application page, and copying the "object ID". This ID is different from the tenant ID,
60+
// client ID, and object ID of the application registration.
5761
PrincipalID string `json:"principalId" yaml:"principalId"`
5862
}
5963

@@ -77,10 +81,8 @@ type CommunityGalleryImageRule struct {
7781
// CommunityGallery is a community gallery in a particular location.
7882
type CommunityGallery struct {
7983
// Location is the location of the community gallery (e.g. "westus").
80-
// +kubebuilder:validation:MaxLength=50
8184
Location string `json:"location" yaml:"location"`
8285
// Name is the name of the community gallery.
83-
// +kubebuilder:validation:MaxLength=200
8486
Name string `json:"name" yaml:"name"`
8587
}
8688

chart/validator-plugin-azure/crds/validation.spectrocloud.labs_azurevalidators.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ spec:
7272
location:
7373
description: Location is the location of the community gallery
7474
(e.g. "westus").
75-
maxLength: 50
7675
type: string
7776
name:
7877
description: Name is the name of the community gallery.
79-
maxLength: 200
8078
type: string
8179
required:
8280
- location
@@ -183,7 +181,11 @@ spec:
183181
principalId:
184182
description: |-
185183
The principal being validated. This can be any type of principal - Device, ForeignGroup,
186-
Group, ServicePrincipal, or User.
184+
Group, ServicePrincipal, or User. If using a service principal, this is the "application
185+
object ID". In the Azure portal, this can be found by navigating to Entra ID, selecting the
186+
application registration of the service principal, navigating from that page to the managed
187+
application page, and copying the "object ID". This ID is different from the tenant ID,
188+
client ID, and object ID of the application registration.
187189
type: string
188190
required:
189191
- name

config/crd/bases/validation.spectrocloud.labs_azurevalidators.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ spec:
7272
location:
7373
description: Location is the location of the community gallery
7474
(e.g. "westus").
75-
maxLength: 50
7675
type: string
7776
name:
7877
description: Name is the name of the community gallery.
79-
maxLength: 200
8078
type: string
8179
required:
8280
- location
@@ -183,7 +181,11 @@ spec:
183181
principalId:
184182
description: |-
185183
The principal being validated. This can be any type of principal - Device, ForeignGroup,
186-
Group, ServicePrincipal, or User.
184+
Group, ServicePrincipal, or User. If using a service principal, this is the "application
185+
object ID". In the Azure portal, this can be found by navigating to Entra ID, selecting the
186+
application registration of the service principal, navigating from that page to the managed
187+
application page, and copying the "object ID". This ID is different from the tenant ID,
188+
client ID, and object ID of the application registration.
187189
type: string
188190
required:
189191
- name

0 commit comments

Comments
 (0)