From 9231dc78d03193e03e09457677dd5da0bc2f804e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=A4sser?= Date: Tue, 24 Nov 2026 14:42:05 +0100 Subject: [PATCH 1/3] e2e: add up test --e2e harness (Azure workload identity via Upbound OIDC) Queries the e2e app's own service principal (ServicePrincipalDetails) with AzureWorkloadIdentityCredentials, exchanging the function pod's Upbound OIDC token. Needs Microsoft Graph Application.Read.All with admin consent on the solutions-e2e-function Entra app. --- .gitignore | 4 ++ e2e/README.md | 78 +++++++++++++++++++++++++++++ e2e/apis/xqueries/composition.yaml | 36 +++++++++++++ e2e/apis/xqueries/definition.yaml | 28 +++++++++++ e2e/functions/.gitkeep | 0 e2e/tests/e2etest-queries/test.yaml | 57 +++++++++++++++++++++ e2e/upbound.yaml | 25 +++++++++ 7 files changed, 228 insertions(+) create mode 100644 e2e/README.md create mode 100644 e2e/apis/xqueries/composition.yaml create mode 100644 e2e/apis/xqueries/definition.yaml create mode 100644 e2e/functions/.gitkeep create mode 100644 e2e/tests/e2etest-queries/test.yaml create mode 100644 e2e/upbound.yaml diff --git a/.gitignore b/.gitignore index 3b735ec..29ee186 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ # Go workspace file go.work + +# up project build artifacts and generated model cache for the e2e harness +e2e/_output/ +e2e/.up/ diff --git a/e2e/README.md b/e2e/README.md new file mode 100644 index 0000000..f9e7d14 --- /dev/null +++ b/e2e/README.md @@ -0,0 +1,78 @@ +# function-msgraph end-to-end tests + +This directory is a small Upbound project used only to run **real** end-to-end +tests for `function-msgraph`: `up test run tests/* --e2e` installs it on a +throwaway control plane, together with the function built from the pull request, +and checks that the function answers a live Microsoft Graph query. It is never +published to production. + +## Layout + +``` +e2e/ +├── upbound.yaml # test configuration; depends on the function under test (pinned by CI) +├── apis/xqueries/ # XRD + Composition that call the function +├── functions/.gitkeep # must exist for `up` +└── tests/ + └── e2etest-queries/ + └── test.yaml # E2ETest: default DRC audience + identity Secret, applies an XQuery, waits for Ready +``` + +The query reads the details of the e2e app's own service principal +(`ServicePrincipalDetails` for `solutions-e2e-function`). It reads no user or group +data and changes nothing. Any sign-in or query error (including a missing Graph +permission) makes the function return a fatal result, so the XR never becomes +`Ready` and the test fails. A service principal that isn't found gives an empty +result, not an error; the test queries the app's own principal, which always +exists. + +## Credentials (no Azure secrets in CI) + +The function signs in with Azure workload identity, using the Upbound OIDC token +of its own pod: + +- `test.yaml` patches the control plane's `default` `DeploymentRuntimeConfig` with + `proidc.cloud-spaces.upbound.io/audience: api://AzureADTokenExchange`. Upbound + then mounts a token for that audience at + `/var/run/secrets/upbound.io/provider/token` (function pods too). +- `test.yaml` also creates the `azure-e2e-identity` Secret the Composition passes + to the function. It holds only non-secret values: the Entra app (client) ID, the + tenant ID and the token path. + +### Entra setup + +App registration `solutions-e2e-function` (client ID +`b7b332bc-677c-4bae-a3ba-0aa7e6b2f24a`), shared with the function-azresourcegraph +e2e test. For this test it needs the Microsoft Graph application permission +**`Application.Read.All`** with admin consent, and a federated credential: + +| Field | Value | +|----------|-------| +| Issuer | `https://proidc.upbound.io` | +| Audience | `api://AzureADTokenExchange` | +| Subject | `mcp:solutions/function-msgraph-e2e-wrapper-uptest-e2e-msgraph:function:solutions-function-msgraph` | + +Entra matches the subject exactly. It is `mcp:/:function:`: +`up test` names the control plane `-uptest-`, and a function +installed as a dependency is named `-`. Renaming the project, the test +or the org changes the subject, and the federated credential must follow. + +## Two repos, one function + +The function dev build is pushed to `solutions/` and the wrapper project to +**`solutions/-e2e-wrapper`**. They must be separate: Crossplane's package +lock keys dependency-graph nodes by source repo, so a project and a function +sharing one repo collide (`node ... already exists`). The `-e2e-wrapper` +repo is granted to the e2e robot in `solutions-gitops-prod`. + +## What runs in CI + +On a pull request labelled `run-e2e-tests`, `.github/workflows/e2e.yaml` (synced +from `upbound/sa-up`): + +1. builds the function package from the PR head and pushes it to `solutions/` + at a dev tag, +2. pins that tag in `upbound.yaml` (`@FUNCTION_VERSION@`), +3. switches to the e2e Spaces control plane group, and +4. runs `up test run tests/* --e2e`, pushing the wrapper project to + `solutions/-e2e-wrapper`. diff --git a/e2e/apis/xqueries/composition.yaml b/e2e/apis/xqueries/composition.yaml new file mode 100644 index 0000000..8c4b5c7 --- /dev/null +++ b/e2e/apis/xqueries/composition.yaml @@ -0,0 +1,36 @@ +# One read-only Microsoft Graph query: the details of the e2e app's own service +# principal (needs Application.Read.All, no user data). The function signs in +# with Azure workload identity, exchanging the Upbound OIDC token for an Entra +# token. Any sign-in or query error (for example a missing Graph permission) is +# fatal, so the XR never goes Ready. +apiVersion: apiextensions.crossplane.io/v1 +kind: Composition +metadata: + name: xqueries.e2e.msgraph.upbound.io +spec: + compositeTypeRef: + apiVersion: e2e.msgraph.upbound.io/v1alpha1 + kind: XQuery + mode: Pipeline + pipeline: + - step: service-principal + functionRef: + name: solutions-function-msgraph + input: + apiVersion: msgraph.fn.crossplane.io/v1alpha1 + kind: Input + identity: + type: AzureWorkloadIdentityCredentials + queryType: ServicePrincipalDetails + servicePrincipals: + - solutions-e2e-function + target: status.servicePrincipals + credentials: + - name: azure-creds + source: Secret + secretRef: + namespace: crossplane-system + name: azure-e2e-identity + - step: auto-ready + functionRef: + name: crossplane-contrib-function-auto-ready diff --git a/e2e/apis/xqueries/definition.yaml b/e2e/apis/xqueries/definition.yaml new file mode 100644 index 0000000..9a51a10 --- /dev/null +++ b/e2e/apis/xqueries/definition.yaml @@ -0,0 +1,28 @@ +apiVersion: apiextensions.crossplane.io/v1 +kind: CompositeResourceDefinition +metadata: + name: xqueries.e2e.msgraph.upbound.io +spec: + group: e2e.msgraph.upbound.io + scope: Namespaced + names: + kind: XQuery + plural: xqueries + versions: + - name: v1alpha1 + served: true + referenceable: true + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + status: + type: object + properties: + servicePrincipals: + type: array + items: + type: object + x-kubernetes-preserve-unknown-fields: true diff --git a/e2e/functions/.gitkeep b/e2e/functions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/e2e/tests/e2etest-queries/test.yaml b/e2e/tests/e2etest-queries/test.yaml new file mode 100644 index 0000000..b7c29d7 --- /dev/null +++ b/e2e/tests/e2etest-queries/test.yaml @@ -0,0 +1,57 @@ +# End-to-end test for function-msgraph. `up test run tests/* --e2e` spins +# up a throwaway Spaces control plane, installs this project (the XRD and +# Composition in apis/, plus the function under test as a dependency), creates the +# XR and waits for it to go Ready. A failed sign-in or query makes the function +# return fatal, the XR never goes Ready, and the test fails. +apiVersion: meta.dev.upbound.io/v1alpha1 +kind: E2ETest +metadata: + name: e2e-msgraph +spec: + crossplane: + autoUpgrade: + channel: Rapid + defaultConditions: + - Ready + initResources: + # Patch the control plane's default DeploymentRuntimeConfig before the + # functions install, so every function pod gets an Upbound OIDC token with + # the Entra token-exchange audience, mounted at + # /var/run/secrets/upbound.io/provider/token (function pods too). Spaces + # policy only allows the audience annotation here. + - apiVersion: pkg.crossplane.io/v1beta1 + kind: DeploymentRuntimeConfig + metadata: + name: default + spec: + deploymentTemplate: + spec: + selector: {} + template: + metadata: + annotations: + proidc.cloud-spaces.upbound.io/audience: api://AzureADTokenExchange + # Workload identity settings for the function. Nothing here is secret: the + # Entra app and tenant IDs, and the path of the Upbound OIDC token. + - apiVersion: v1 + kind: Secret + metadata: + name: azure-e2e-identity + namespace: crossplane-system + type: Opaque + stringData: + credentials: | + { + "clientId": "b7b332bc-677c-4bae-a3ba-0aa7e6b2f24a", + "tenantId": "b9925bc4-8383-4c37-b9d2-fa456d1bb1c7", + "federatedTokenFile": "/var/run/secrets/upbound.io/provider/token" + } + manifests: + - apiVersion: e2e.msgraph.upbound.io/v1alpha1 + kind: XQuery + metadata: + name: e2e-query + namespace: default + spec: {} + skipDelete: false + timeoutSeconds: 900 diff --git a/e2e/upbound.yaml b/e2e/upbound.yaml new file mode 100644 index 0000000..74539e3 --- /dev/null +++ b/e2e/upbound.yaml @@ -0,0 +1,25 @@ +apiVersion: meta.dev.upbound.io/v2alpha1 +kind: Project +metadata: + name: function-msgraph-e2e-wrapper +spec: + # CI rewrites @FUNCTION_VERSION@ to the dev tag it just built and pushed from + # the pull request, so the configuration installs that build as a dependency. + dependsOn: + - apiVersion: pkg.crossplane.io/v1 + kind: Function + package: xpkg.upbound.io/solutions/function-msgraph + version: '@FUNCTION_VERSION@' + - apiVersion: pkg.crossplane.io/v1 + kind: Function + package: xpkg.upbound.io/crossplane-contrib/function-auto-ready + version: '>=v0.0.0' + description: | + Test configuration that runs function-msgraph in end-to-end tests: an XRD and + a Composition that call the function, installed on a throwaway control plane + by `up test run tests/* --e2e`. Never published to production. + license: Apache-2.0 + maintainer: Upbound + readme: | + See e2e/README.md. + repository: xpkg.upbound.io/solutions/function-msgraph-e2e-wrapper From 1875724f23f2ce773b9e5858ecff18499842973d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=A4sser?= Date: Tue, 24 Nov 2026 17:32:16 +0100 Subject: [PATCH 2/3] e2e: no Graph permission needed; fail on an empty result A service principal can read its own details without any Graph permission, so the e2e app needs no admin consent (CI e2e passed without it, and the XR status held the real service principal). The XRD now requires at least one entry in status.servicePrincipals, so a lookup that finds nothing fails the test instead of passing (verified with a nonexistent name). --- e2e/README.md | 11 +++++++---- e2e/apis/xqueries/composition.yaml | 7 ++++--- e2e/apis/xqueries/definition.yaml | 3 +++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/e2e/README.md b/e2e/README.md index f9e7d14..efa61ad 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -23,8 +23,9 @@ The query reads the details of the e2e app's own service principal data and changes nothing. Any sign-in or query error (including a missing Graph permission) makes the function return a fatal result, so the XR never becomes `Ready` and the test fails. A service principal that isn't found gives an empty -result, not an error; the test queries the app's own principal, which always -exists. +result, not an error, so the XRD requires at least one entry in +`status.servicePrincipals`: an empty result is rejected and the XR never becomes +`Ready` either. (Checked: querying a name that doesn't exist fails the test.) ## Credentials (no Azure secrets in CI) @@ -43,8 +44,10 @@ of its own pod: App registration `solutions-e2e-function` (client ID `b7b332bc-677c-4bae-a3ba-0aa7e6b2f24a`), shared with the function-azresourcegraph -e2e test. For this test it needs the Microsoft Graph application permission -**`Application.Read.All`** with admin consent, and a federated credential: +e2e test. It needs **no Microsoft Graph permission**: a service principal can +read its own application and service principal details without one (see +"Permissions for specific scenarios" on Microsoft's *List servicePrincipals* +page). It only needs a federated credential: | Field | Value | |----------|-------| diff --git a/e2e/apis/xqueries/composition.yaml b/e2e/apis/xqueries/composition.yaml index 8c4b5c7..afd5e9d 100644 --- a/e2e/apis/xqueries/composition.yaml +++ b/e2e/apis/xqueries/composition.yaml @@ -1,8 +1,9 @@ # One read-only Microsoft Graph query: the details of the e2e app's own service -# principal (needs Application.Read.All, no user data). The function signs in +# principal. A service principal can read its own details without any Graph +# permission, so the app needs no admin consent. No user data. The function signs in # with Azure workload identity, exchanging the Upbound OIDC token for an Entra -# token. Any sign-in or query error (for example a missing Graph permission) is -# fatal, so the XR never goes Ready. +# token. Any sign-in or query error is fatal, and an empty result fails the +# XRD's minItems, so in both cases the XR never goes Ready. apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: diff --git a/e2e/apis/xqueries/definition.yaml b/e2e/apis/xqueries/definition.yaml index 9a51a10..efd63d8 100644 --- a/e2e/apis/xqueries/definition.yaml +++ b/e2e/apis/xqueries/definition.yaml @@ -22,7 +22,10 @@ spec: type: object properties: servicePrincipals: + # At least one result, so "not found" can't pass: the status + # write is rejected and the XR never goes Ready. type: array + minItems: 1 items: type: object x-kubernetes-preserve-unknown-fields: true From 6fe06c4c48097ab192259c53669c988868cc63e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=A4sser?= Date: Tue, 24 Nov 2026 17:32:38 +0100 Subject: [PATCH 3/3] e2e: rewrap composition comment --- e2e/apis/xqueries/composition.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/apis/xqueries/composition.yaml b/e2e/apis/xqueries/composition.yaml index afd5e9d..370121d 100644 --- a/e2e/apis/xqueries/composition.yaml +++ b/e2e/apis/xqueries/composition.yaml @@ -1,8 +1,8 @@ # One read-only Microsoft Graph query: the details of the e2e app's own service # principal. A service principal can read its own details without any Graph -# permission, so the app needs no admin consent. No user data. The function signs in -# with Azure workload identity, exchanging the Upbound OIDC token for an Entra -# token. Any sign-in or query error is fatal, and an empty result fails the +# permission, so the app needs no admin consent. No user data. The function +# signs in with Azure workload identity, exchanging the Upbound OIDC token for an +# Entra token. Any sign-in or query error is fatal, and an empty result fails the # XRD's minItems, so in both cases the XR never goes Ready. apiVersion: apiextensions.crossplane.io/v1 kind: Composition