Skip to content

Commit 51b7ecd

Browse files
authored
Merge pull request #2 from upbound/group-member-fixes
Add dynamic references and fix group membership issues in Microsoft Graph function
2 parents 02c8dab + 95a083f commit 51b7ecd

26 files changed

+2746
-99
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,13 @@ spec:
189189
|-------|------|-------------|
190190
| `queryType` | string | Required. Type of query to perform. Valid values: `UserValidation`, `GroupMembership`, `GroupObjectIDs`, `ServicePrincipalDetails` |
191191
| `users` | []string | List of user principal names (email IDs) for user validation |
192+
| `usersRef` | string | Reference to resolve a list of user names from `spec`, `status` or `context` (e.g., `spec.userAccess.emails`) |
192193
| `group` | string | Single group name for group membership queries |
194+
| `groupRef` | string | Reference to resolve a single group name from `spec`, `status` or `context` (e.g., `spec.groupConfig.name`) |
193195
| `groups` | []string | List of group names for group object ID queries |
196+
| `groupsRef` | string | Reference to resolve a list of group names from `spec`, `status` or `context` (e.g., `spec.groupConfig.names`) |
194197
| `servicePrincipals` | []string | List of service principal names |
198+
| `servicePrincipalsRef` | string | Reference to resolve a list of service principal names from `spec`, `status` or `context` (e.g., `spec.servicePrincipalConfig.names`) |
195199
| `target` | string | Required. Where to store the query results. Can be `status.<field>` or `context.<field>` |
196200
| `skipQueryWhenTargetHasData` | bool | Optional. When true, will skip the query if the target already has data |
197201

@@ -213,6 +217,50 @@ target: "context.results"
213217
target: "context.[apiextensions.crossplane.io/environment].results"
214218
```
215219

220+
## Using Reference Fields
221+
222+
You can reference values from XR spec, status, or context instead of hardcoding them:
223+
224+
### Using groupRef from spec
225+
226+
```yaml
227+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
228+
kind: Input
229+
queryType: GroupMembership
230+
groupRef: "spec.groupConfig.name" # Get group name from XR spec
231+
target: "status.groupMembers"
232+
```
233+
234+
### Using groupsRef from spec
235+
236+
```yaml
237+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
238+
kind: Input
239+
queryType: GroupObjectIDs
240+
groupsRef: "spec.groupConfig.names" # Get group names from XR spec
241+
target: "status.groupObjectIDs"
242+
```
243+
244+
### Using usersRef from spec
245+
246+
```yaml
247+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
248+
kind: Input
249+
queryType: UserValidation
250+
usersRef: "spec.userAccess.emails" # Get user emails from XR spec
251+
target: "status.validatedUsers"
252+
```
253+
254+
### Using servicePrincipalsRef from spec
255+
256+
```yaml
257+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
258+
kind: Input
259+
queryType: ServicePrincipalDetails
260+
servicePrincipalsRef: "spec.servicePrincipalConfig.names" # Get service principal names from XR spec
261+
target: "status.servicePrincipals"
262+
```
263+
216264
## References
217265

218266
- [Microsoft Graph API Overview](https://learn.microsoft.com/en-us/graph/api/overview?view=graph-rest-1.0)

example/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ Validate if specified Azure AD users exist:
4242
crossplane render xr.yaml user-validation-example.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
4343
```
4444

45+
Dynamic `usersRef` variations:
46+
47+
```shell
48+
crossplane render xr.yaml user-validation-example-status-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
49+
```
50+
51+
```shell
52+
crossplane render xr.yaml user-validation-example-context-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc --extra-resources=envconfig.yaml
53+
```
54+
55+
```shell
56+
crossplane render xr.yaml user-validation-example-spec-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
57+
```
58+
4559
### 2. Group Membership
4660

4761
Get all members of a specified Azure AD group:
@@ -50,6 +64,20 @@ Get all members of a specified Azure AD group:
5064
crossplane render xr.yaml group-membership-example.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
5165
```
5266

67+
Dynamic `groupRef` variations:
68+
69+
```shell
70+
crossplane render xr.yaml group-membership-example-status-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
71+
```
72+
73+
```shell
74+
crossplane render xr.yaml group-membership-example-context-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc --extra-resources=envconfig.yaml
75+
```
76+
77+
```shell
78+
crossplane render xr.yaml group-membership-example-spec-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
79+
```
80+
5381
### 3. Group Object IDs
5482

5583
Get object IDs for specified Azure AD groups:
@@ -58,10 +86,38 @@ Get object IDs for specified Azure AD groups:
5886
crossplane render xr.yaml group-objectids-example.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
5987
```
6088

89+
Dynamic `groupsRef` variations:
90+
91+
```shell
92+
crossplane render xr.yaml group-objectids-example-status-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
93+
```
94+
95+
```shell
96+
crossplane render xr.yaml group-objectids-example-context-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc --extra-resources=envconfig.yaml
97+
```
98+
99+
```shell
100+
crossplane render xr.yaml group-objectids-example-spec-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
101+
```
102+
61103
### 4. Service Principal Details
62104

63105
Get details of specified service principals:
64106

65107
```shell
66108
crossplane render xr.yaml service-principal-example.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
67109
```
110+
111+
Dynamic `servicePrinicpalsRef` variations:
112+
113+
```shell
114+
crossplane render xr.yaml service-principal-example-status-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
115+
```
116+
117+
```shell
118+
crossplane render xr.yaml service-principal-example-context-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc --extra-resources=envconfig.yaml
119+
```
120+
121+
```shell
122+
crossplane render xr.yaml service-principal-example-spec-ref.yaml functions.yaml --function-credentials=./secrets/azure-creds.yaml -rc
123+
```

example/definition.yaml

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,64 @@ spec:
2323
queryResourceType:
2424
description: resource type for az resource query construction
2525
type: string
26+
groupConfig:
27+
description: Configuration for group references
28+
type: object
29+
properties:
30+
name:
31+
description: Name of a single group to reference with groupRef
32+
type: string
33+
names:
34+
description: List of group names to reference with groupsRef
35+
type: array
36+
items:
37+
type: string
38+
userAccess:
39+
description: Configuration for user references
40+
type: object
41+
properties:
42+
emails:
43+
description: List of user emails to reference with usersRef
44+
type: array
45+
items:
46+
type: string
47+
servicePrincipalConfig:
48+
description: Configuration for service principal references
49+
type: object
50+
properties:
51+
names:
52+
description: List of service principal names to reference with servicePrincipalsRef
53+
type: array
54+
items:
55+
type: string
2656
status:
2757
description: XRStatus defines the observed state of XR.
2858
type: object
2959
properties:
30-
azResourceGraphQueryResult:
31-
description: Freeform field containing query results from function-azresourcegraph
60+
groupMembers:
61+
description: Freeform field containing query results from function-msgraph
62+
type: array
63+
items:
64+
type: object
65+
x-kubernetes-preserve-unknown-fields: true
66+
validatedUsers:
67+
description: Freeform field containing query results from function-msgraph
68+
type: array
69+
items:
70+
type: object
71+
x-kubernetes-preserve-unknown-fields: true
72+
groupObjectIDs:
73+
description: Freeform field containing query results from function-msgraph
74+
type: array
75+
items:
76+
type: object
77+
x-kubernetes-preserve-unknown-fields: true
78+
servicePrincipals:
79+
description: Freeform field containing query results from function-msgraph
3280
type: array
3381
items:
3482
type: object
3583
x-kubernetes-preserve-unknown-fields: true
36-
azResourceGraphQuery:
37-
description: Freeform field containing query results from function-azresourcegraph
38-
type: string
3984
required:
4085
- spec
4186
type: object

example/envconfig.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: apiextensions.crossplane.io/v1alpha1
2+
kind: EnvironmentConfig
3+
metadata:
4+
name: example-config
5+
data:
6+
group:
7+
name: test-fn-msgraph
8+
groups:
9+
- test-fn-msgraph
10+
users:
11+
12+
servicePrincipalNames:
13+
- yury-upbound-oidc-provider

example/functions.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ metadata:
88
render.crossplane.io/runtime: Development
99
spec:
1010
package: xpkg.upbound.io/upbound/function-msgraph:v0.1.0
11+
---
12+
apiVersion: pkg.crossplane.io/v1beta1
13+
kind: Function
14+
metadata:
15+
name: crossplane-contrib-function-environment-configs
16+
spec:
17+
package: xpkg.upbound.io/crossplane-contrib/function-environment-configs:v0.2.0
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: Composition
3+
metadata:
4+
name: group-membership-example-context-ref
5+
spec:
6+
compositeTypeRef:
7+
apiVersion: example.crossplane.io/v1
8+
kind: XR
9+
mode: Pipeline
10+
pipeline:
11+
- step: environmentConfigs
12+
functionRef:
13+
name: crossplane-contrib-function-environment-configs
14+
input:
15+
apiVersion: environmentconfigs.fn.crossplane.io/v1beta1
16+
kind: Input
17+
spec:
18+
environmentConfigs:
19+
- type: Reference
20+
ref:
21+
name: example-config
22+
- step: get-group-members
23+
functionRef:
24+
name: function-msgraph
25+
input:
26+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
27+
kind: Input
28+
queryType: GroupMembership
29+
groupRef: context.[apiextensions.crossplane.io/environment].group.name
30+
# The function will automatically select standard fields:
31+
# - id, displayName, mail, userPrincipalName, appId, description
32+
target: "status.groupMembers"
33+
skipQueryWhenTargetHasData: true
34+
credentials:
35+
- name: azure-creds
36+
source: Secret
37+
secretRef:
38+
namespace: upbound-system
39+
name: azure-account-creds
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: Composition
3+
metadata:
4+
name: group-membership-example-spec-ref
5+
annotations:
6+
# Important: This function requires an Azure AD app registration with Microsoft Graph API permissions:
7+
# - Group.Read.All
8+
# - Directory.Read.All
9+
# - User.Read.All (if groups contain users)
10+
# - Application.Read.All (if groups contain service principals)
11+
spec:
12+
compositeTypeRef:
13+
apiVersion: example.crossplane.io/v1
14+
kind: XR
15+
mode: Pipeline
16+
pipeline:
17+
- step: get-group-members
18+
functionRef:
19+
name: function-msgraph
20+
input:
21+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
22+
kind: Input
23+
queryType: GroupMembership
24+
# Using spec reference to get group name
25+
groupRef: "spec.groupConfig.name"
26+
# The function will automatically select standard fields:
27+
# - id, displayName, mail, userPrincipalName, appId, description
28+
target: "status.groupMembers"
29+
skipQueryWhenTargetHasData: true
30+
credentials:
31+
- name: azure-creds
32+
source: Secret
33+
secretRef:
34+
namespace: upbound-system
35+
name: azure-account-creds
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: Composition
3+
metadata:
4+
name: group-membership-example-status-ref
5+
spec:
6+
compositeTypeRef:
7+
apiVersion: example.crossplane.io/v1
8+
kind: XR
9+
mode: Pipeline
10+
pipeline:
11+
- step: get-group-members
12+
functionRef:
13+
name: function-msgraph
14+
input:
15+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
16+
kind: Input
17+
queryType: GroupMembership
18+
groupRef: status.group.name
19+
# The function will automatically select standard fields:
20+
# - id, displayName, mail, userPrincipalName, appId, description
21+
target: "status.groupMembers"
22+
skipQueryWhenTargetHasData: true
23+
credentials:
24+
- name: azure-creds
25+
source: Secret
26+
secretRef:
27+
namespace: upbound-system
28+
name: azure-account-creds

example/group-membership-example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
apiVersion: msgraph.fn.crossplane.io/v1alpha1
2222
kind: Input
2323
queryType: GroupMembership
24-
group: "All Company"
24+
group: test-fn-msgraph
2525
# The function will automatically select standard fields:
2626
# - id, displayName, mail, userPrincipalName, appId, description
2727
target: "status.groupMembers"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: Composition
3+
metadata:
4+
name: group-objectids-example-context-ref
5+
spec:
6+
compositeTypeRef:
7+
apiVersion: example.crossplane.io/v1
8+
kind: XR
9+
mode: Pipeline
10+
pipeline:
11+
- step: environmentConfigs
12+
functionRef:
13+
name: crossplane-contrib-function-environment-configs
14+
input:
15+
apiVersion: environmentconfigs.fn.crossplane.io/v1beta1
16+
kind: Input
17+
spec:
18+
environmentConfigs:
19+
- type: Reference
20+
ref:
21+
name: example-config
22+
- step: get-group-objectids
23+
functionRef:
24+
name: function-msgraph
25+
input:
26+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
27+
kind: Input
28+
queryType: GroupObjectIDs
29+
groupsRef: context.[apiextensions.crossplane.io/environment].groups
30+
target: "status.groupObjectIDs"
31+
skipQueryWhenTargetHasData: true
32+
credentials:
33+
- name: azure-creds
34+
source: Secret
35+
secretRef:
36+
namespace: upbound-system
37+
name: azure-account-creds

0 commit comments

Comments
 (0)