Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/configure-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
AUTH_DOMAIN: ${{ vars.AUTH_DOMAIN }}
AUTH_INSTANCE: ${{ vars.AUTH_INSTANCE || 'https://login.microsoftonline.com/' }}
AUTH_TENANT_ID: ${{ vars.AUTH_TENANT_ID }}
GRAPH__REDIRECT_URI: ${{ vars.GRAPH__REDIRECT_URI }}
NOTIFICATION_BASE_URL: ${{ vars.NOTIFICATION_BASE_URL }}
NOTIFICATION_DEFAULT_APP_NAME: ${{ vars.NOTIFICATION_DEFAULT_APP_NAME }}
NOTIFICATION_DEFAULT_BUTTON_TEXT: ${{ vars.NOTIFICATION_DEFAULT_BUTTON_TEXT }}
Expand Down Expand Up @@ -251,6 +252,7 @@ jobs:
add_setting "Auth__Domain" "$AUTH_DOMAIN"
add_setting "Auth__Instance" "$AUTH_INSTANCE"
add_setting "Auth__TenantId" "$AUTH_TENANT_ID"
add_setting "Graph__RedirectUri" "$GRAPH__REDIRECT_URI"
add_setting "Notification__BaseUrl" "$NOTIFICATION_BASE_URL"
add_setting "Notification__DefaultAppName" "$NOTIFICATION_DEFAULT_APP_NAME"
add_setting "Notification__DefaultButtonText" "$NOTIFICATION_DEFAULT_BUTTON_TEXT"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-azure-appservice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ jobs:
AUTH_DOMAIN: ${{ vars.AUTH_DOMAIN }}
AUTH_INSTANCE: ${{ vars.AUTH_INSTANCE || 'https://login.microsoftonline.com/' }}
AUTH_TENANT_ID: ${{ vars.AUTH_TENANT_ID }}
GRAPH__REDIRECT_URI: ${{ vars.GRAPH__REDIRECT_URI }}
NOTIFICATION_BASE_URL: ${{ vars.NOTIFICATION_BASE_URL }}
NOTIFICATION_DEFAULT_APP_NAME: ${{ vars.NOTIFICATION_DEFAULT_APP_NAME }}
NOTIFICATION_DEFAULT_BUTTON_TEXT: ${{ vars.NOTIFICATION_DEFAULT_BUTTON_TEXT }}
Expand Down Expand Up @@ -284,6 +285,7 @@ jobs:
add_setting "Auth__Domain" "$AUTH_DOMAIN"
add_setting "Auth__Instance" "$AUTH_INSTANCE"
add_setting "Auth__TenantId" "$AUTH_TENANT_ID"
add_setting "Graph__RedirectUri" "$GRAPH__REDIRECT_URI"
add_setting "Notification__BaseUrl" "$NOTIFICATION_BASE_URL"
add_setting "Notification__DefaultAppName" "$NOTIFICATION_DEFAULT_APP_NAME"
add_setting "Notification__DefaultButtonText" "$NOTIFICATION_DEFAULT_BUTTON_TEXT"
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,16 @@ mode, with no additional feature flag.

### Key Vault secrets

Graph reuses the existing `Azure__TenantId`, `Azure__ClientId`, and
`Azure__ClientSecret` settings. Its hosted MSAL cache is saved in the fixed Key Vault
secret `graph-calendar-token-cache`, created by the app after verified sign-in.
There are no separate Graph credential overrides or credential-secret references.
Configure `Graph__RedirectUri` for the separate calendar callback. Local development
uses file caching; see
[Graph credential setup](docs/GRAPH-DEVELOPMENT.md#key-vault-credentials-and-future-federation).
Graph reads its client secret directly from the environment Key Vault under the
fixed name `azure-client-secret`, including in local Development. Calendar IDs
use Booking's existing `Auth__TenantId` and `Auth__ClientId`. There are no separate
Graph ID overrides. Set the GitHub Environment variable
`GRAPH__REDIRECT_URI`; deployment maps it to `Graph__RedirectUri`. No client secret
or vault reference is passed through GitHub. Each calendar operation reads the
latest credential, so rotation needs no app deployment or restart. The hosted MSAL
cache is saved separately in `graph-calendar-token-cache`, created by the app after
verified sign-in; local Development keeps the token cache in files. See
[Graph credential setup](docs/GRAPH-DEVELOPMENT.md#hosted-setup-and-rotation).

`ISecretsService` provides asynchronous reads and writes by secret name. Configure
`Azure__KeyVaultUrl` when the service is needed. Azure deployment creates a vault in
Expand All @@ -227,7 +230,8 @@ Azure__KeyVaultUrl="https://<test-vault-name>.vault.azure.net/"
An operator must grant your user or developer security group **Key Vault Secrets Officer**
on the test vault for reads and writes. See [local development access](infrastructure/azure/README.md#local-development-access)
for setup. The service uses `DefaultAzureCredential` to authenticate with your Azure CLI
login locally and managed identity in Azure.
login locally. Hosted environments explicitly use `ManagedIdentityCredential`.
Calendar credentials and legacy `Azure__*` credentials do not change vault authentication.

Local sign-in and unrelated features, including the Docker sandbox, can run without
Key Vault settings because the client is created on demand. The sandbox does not inherit
Expand Down
145 changes: 89 additions & 56 deletions docs/GRAPH-DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,69 +30,102 @@ callback preserves the original Booking session and correlation cookie.
are rejected. The implementation discovers `/me/calendar` for the account that signs in. No
calendar-email setting is required, and another user's shared calendar is not selected.

## Local configuration
## Calendar configuration

Reuse the application's existing Azure registration and credentials. Graph reads
`Azure__TenantId`, `Azure__ClientId`, and `Azure__ClientSecret` directly; there are
no separate Graph credential overrides or application-secret vault references.
The same registration must have the delegated calendar permission and approved
calendar callback from the prerequisites above.
Calendar authentication and Key Vault access use different identities. The calendar
uses Booking's existing login registration: `Auth__TenantId` and `Auth__ClientId`
supply its IDs. There are no separate Graph ID overrides. That registration must
have the delegated calendar permission and approved callback from the prerequisites
above. The deployment identity's `AZURE_CLIENT_ID` is unrelated.

The application reads the calendar client secret directly from the environment's
Key Vault under the fixed name `azure-client-secret`. An operator stores the
Entra credential's **Value**, not its Secret ID, under that name. The credential
must belong to the registration selected by the calendar client and tenant IDs.
There is no client-secret environment variable, configurable secret-name setting,
or App Service Key Vault reference.

| Setting | Value |
| --- | --- |
| `Azure__TenantId` | Existing application tenant GUID |
| `Azure__ClientId` | Existing application client GUID |
| `Azure__ClientSecret` | Existing application secret value |
| `Azure__KeyVaultUrl` | Environment vault URL; supplied by Bicep in hosted environments |
| `Graph__RedirectUri` | Registered calendar callback URI |

The calendar callback is separate from Booking login's `/signin-oidc` callback.
Configure it through the existing private configuration mechanism. OS environment
variables take precedence. Local token persistence uses files and does not contact
Key Vault.

Start normally with `npm start`, sign into Booking as an active site administrator,
stop emulating, and open `/admin`. The development panel also allows a read-only
connectivity check and an explicit test-meeting write.

## Key Vault credentials and future federation

Hosted connections reuse `Azure__TenantId`, `Azure__ClientId`, and
`Azure__ClientSecret` already configured in Azure App Service. The application
reads those settings at runtime; no separate Graph tenant/client settings or
client-secret entry in Key Vault are needed. Set `Graph__RedirectUri` to the
registered calendar callback for that environment.

Only the mutable token cache needs a Key Vault secret. The application always uses
the fixed name `graph-calendar-token-cache` and creates it after verified Microsoft
sign-in. Neither the name nor the token contents need deployment parameters. The
application credential is not included in the cache secret.

`Azure__KeyVaultUrl` selects the environment vault and is supplied by the existing
Bicep template. Because the Azure credential trio is configured, the existing
secrets service uses that service principal for vault access. It must have secret
read/write access to the environment vault; granting access only to the App
Service's managed identity does not authorize that service principal. The existing
secrets service remains unchanged.
| `Auth__TenantId` | Existing Booking login tenant GUID |
| `Auth__ClientId` | Existing Booking login client GUID |

Calendar authentication reuses Booking’s existing login tenant and client IDs and reads the application client secret directly from Key Vault. Configuration validation reports
all invalid or missing calendar IDs, callback, and scopes together before trying
to access the vault. Vault access failures then produce safe configuration guidance.

## Hosted setup and rotation

1. Store the Entra client secret value in the environment vault as
`azure-client-secret`.
2. Set the GitHub Environment variable `GRAPH__REDIRECT_URI` to the registered
calendar callback. For test, use
`https://booking-test.ucdavis.edu/api/development-graph/callback`, registered
exactly as a Web redirect URI in Entra.
3. Keep the existing `AUTH_TENANT_ID` and `AUTH_CLIENT_ID` variables for the Booking
login registration. The calendar uses these same IDs; no additional ID
variables are required.
4. Deploy the updated application and runtime settings. Verify the connection in
`/admin` before creating a test meeting.

Both **CI/CD** and **Configure Azure** apply nonempty runtime variable values to
App Service. The local deploy wrapper accepts the same variable names. Changing a
GitHub variable alone does not apply it; run a deployment workflow. Calendar
settings remain optional for deployments that do not use the calendar. No client
secret or reference needs to be added to GitHub. If previously configured, remove
the obsolete `GRAPH__CLIENT_SECRET_REFERENCE` GitHub variable and the
`Graph__ClientSecret` App Service setting; neither is read by the new code.

Bicep already provisions the environment vault, the App Service system-assigned
managed identity, vault URL, and the identity's **Key Vault Secrets Officer** grant.
No additional Bicep parameters or role grants for the calendar registration are
needed. The application retrieves the credential through the same secrets service
used by Payments. There is no credential-value cache in the Graph client factory:
it requests the latest vault version each time it creates a Microsoft client.

To rotate, create a replacement credential in Entra and save its value as a new
version of `azure-client-secret`. The next calendar operation reads that value;
no GitHub update, App Service reference refresh, app restart, or deployment is
required. An operation already in progress may still use the earlier value. Verify
calendar access before revoking the old credential. Key Vault does not create or
renew the Entra credential itself. Vault failure stops the operation; no old
credential or environment-variable fallback is used.

## Local development

Local calendar operations also read `azure-client-secret` from Key Vault.
Configure the test vault URL through your private configuration mechanism and
sign in with `az login`. Your user or developer security group needs vault secret
read access. No shared client secret needs to be kept in a local configuration
file. The Docker sandbox does not inherit your host's Azure CLI login; use the
backend running on your host when connecting to the real test vault.

Set `Graph__RedirectUri` to the approved localhost callback. OS environment
variables take precedence. Start normally with `npm start`, sign into Booking as
an active site administrator, stop emulating, and open `/admin`. Local token
persistence uses files; only the application credential is retrieved from Key Vault.

## Key Vault access and token cache

Vault access is independent of calendar credentials. Hosted environments use
`ManagedIdentityCredential`; local Development uses `DefaultAzureCredential`,
including the developer's Azure CLI login. The secrets service ignores both the
legacy `Azure__*` credential trio and `Graph__*` application credentials. Payments
keys and calendar secrets therefore continue using the App Service identity when
calendar credentials are added or rotated. The calendar app registration does not
need Key Vault access.

The mutable token cache uses the fixed secret name `graph-calendar-token-cache`,
created by the application after verified Microsoft sign-in. No placeholder cache
secret or cached token values need to be deployed. The app registration's secret
and the mutable token cache are separate vault secrets with separate purposes.
The application credential is never saved in the token cache.

Federated application credentials remain a future replacement for
`IGraphClientFactory`. Federation does not by itself remove delegated calendar
consent, refresh tokens, or reconnect requirements. Deployment OIDC federation is
separate from runtime Graph authentication.

## Hosted deployment through Bicep

The existing template creates environment-specific vaults, grants the App Service
identity **Key Vault Secrets Officer** (read/write), and sets the vault URI. Graph
uses the existing Azure service-principal credentials as described above; ensure
that identity also has vault access. No additional Graph parameters are added to
`main.bicep`, `compute.bicep`, or `deploy.sh`. They do not provision a client-secret
entry, the token-cache secret, or token values for calendar authentication.

Maintain the existing `Azure__TenantId`, `Azure__ClientId`, and `Azure__ClientSecret`
settings in App Service, and configure `Graph__RedirectUri` there for the approved
public HTTPS callback. Infrastructure deployments replace the settings managed by
their templates; preserve or reapply these runtime settings through your existing
configuration process when deploying infrastructure.
`IGraphClientFactory`. Deployment OIDC federation is separate from runtime calendar
authentication and does not remove delegated consent or reconnect requirements.

The connection interface is available to site administrators in all environments;
no enablement flag is required. Missing credentials, callback configuration, or
Expand Down
31 changes: 19 additions & 12 deletions infrastructure/azure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,25 @@ The existing environment vault holds the delegated calendar's MSAL cache under
the fixed secret name `graph-calendar-token-cache`. The application creates it
after verified Microsoft sign-in; Bicep never handles cached token values.

Calendar authentication reuses the existing `Azure__TenantId`, `Azure__ClientId`,
and `Azure__ClientSecret` App Service settings. Configure `Graph__RedirectUri` in
App Service for the approved calendar callback. There are no additional Graph
parameters in `main.bicep`, `compute.bicep`, or the local deploy wrapper, and no
separate application-secret entry in Key Vault is required. Preserve or reapply
these runtime settings through your existing configuration process after
infrastructure deployments that replace App Service settings.

The existing secrets service uses the configured Azure service principal to
access Key Vault. That identity needs secret read/write access to the environment
vault; the template's grant to the App Service managed identity alone is not
sufficient for service-principal authentication.
Calendar authentication reads the latest `azure-client-secret` directly from
the environment vault through the existing secrets service. An operator stores
the Entra application's client secret **Value** there. No client secret or Key
Vault reference is passed through GitHub or App Service settings.

Set `GRAPH__REDIRECT_URI` to the registered calendar callback. Calendar IDs use
the existing Booking login settings (`AUTH_TENANT_ID` and `AUTH_CLIENT_ID`).
There are no separate Graph ID overrides.
**CI/CD**, **Configure Azure**, and the local deploy wrapper apply these runtime
settings. No new Bicep parameters are required. To rotate the credential, save the
replacement Entra secret value as a new version of `azure-client-secret`.
The next calendar operation reads it without deployment or restart.

The secrets service always uses managed identity in hosted environments, independently
of the calendar credentials. Payments keys, the calendar credential, and calendar
tokens use this same vault identity; the calendar app registration does not need
vault permissions. Local Development uses `DefaultAzureCredential` with the
developer's Azure CLI login and also reads the calendar credential from the test
vault. The local token cache remains file-based.

Test meetings with email invitations are allowed in the `Development` and `test`
backend environments. They are hidden and blocked in `prod`; calendar connection
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/azure/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ USAGE
'AGGIEENTERPRISE__CONSUMERKEY, AGGIEENTERPRISE__CONSUMERSECRET' \
' AGGIEENTERPRISE__GRAPHQLURL, AGGIEENTERPRISE__SCOPEAPP' \
' AGGIEENTERPRISE__SCOPEENV, AGGIEENTERPRISE__TOKENENDPOINT, AUTH_CALLBACK_PATH' \
' AUTH_CLIENT_ID, AUTH_DOMAIN, AUTH_INSTANCE, AUTH_TENANT_ID' \
' AUTH_CLIENT_ID, AUTH_DOMAIN, AUTH_INSTANCE, AUTH_TENANT_ID, GRAPH__REDIRECT_URI' \
' NOTIFICATION_BASE_URL, NOTIFICATION_DEFAULT_APP_NAME' \
' NOTIFICATION_DEFAULT_BUTTON_TEXT, OTEL_EXPORTER_OTLP_ENDPOINT' \
' OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_PROTOCOL' \
Expand Down Expand Up @@ -284,6 +284,7 @@ add_setting "Auth__ClientId" "${AUTH_CLIENT_ID:-}"
add_setting "Auth__Domain" "${AUTH_DOMAIN:-}"
add_setting "Auth__Instance" "${AUTH_INSTANCE:-https://login.microsoftonline.com/}"
add_setting "Auth__TenantId" "${AUTH_TENANT_ID:-}"
add_setting "Graph__RedirectUri" "${GRAPH__REDIRECT_URI:-}"
add_setting "Notification__BaseUrl" "${NOTIFICATION_BASE_URL:-}"
add_setting "Notification__DefaultAppName" "${NOTIFICATION_DEFAULT_APP_NAME:-}"
add_setting "Notification__DefaultButtonText" "${NOTIFICATION_DEFAULT_BUTTON_TEXT:-}"
Expand Down
7 changes: 7 additions & 0 deletions infrastructure/azure/deployment-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
"valueType": "string",
"description": "Environment portion of the Aggie Enterprise OAuth scope."
},
{
"githubName": "GRAPH__REDIRECT_URI",
"appServiceName": "Graph__RedirectUri",
"classification": "variable",
"valueType": "string",
"description": "Public HTTPS calendar callback URI registered as a Web redirect in Entra."
},
{
"githubName": "PAYMENTS_BASE_URL",
"appServiceName": "Payments__BaseUrl",
Expand Down
27 changes: 21 additions & 6 deletions server/Development/Graph/GraphClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Identity.Client;
using Server.Services;

namespace Server.Development.Graph;

Expand All @@ -9,20 +10,34 @@ public interface IGraphClientFactory
}

/// <summary>Secret-based authentication today; replace this registration for future federated assertions.</summary>
public sealed class GraphClientFactory : IGraphClientFactory
public sealed class GraphClientFactory(ISecretsService secrets) : IGraphClientFactory
{
public Task<IConfidentialClientApplication> CreateAsync(
public const string ClientSecretName = "azure-client-secret";

public async Task<IConfidentialClientApplication> CreateAsync(
GraphProbeSettings settings, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var secret = settings.ClientSecret;
string secret;
try
{
// Read the latest version for each operation so rotation needs no app deployment.
secret = await secrets.GetSecretAsync(ClientSecretName, cancellationToken);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) { throw; }
catch (Exception)
{
throw new GraphProbeConfigurationException(
"Could not read azure-client-secret from Key Vault. Check Azure__KeyVaultUrl, the secret's existence, and vault permissions.");
}

if (string.IsNullOrWhiteSpace(secret))
throw new GraphProbeConfigurationException("Azure__ClientSecret is empty. Configure a nonempty secret value before connecting the calendar.");
throw new GraphProbeConfigurationException("Store a nonempty Entra client secret value in Key Vault as azure-client-secret before connecting the calendar.");

return Task.FromResult(ConfidentialClientApplicationBuilder.Create(settings.ClientId)
return ConfidentialClientApplicationBuilder.Create(settings.ClientId)
.WithClientSecret(secret)
.WithRedirectUri(settings.RedirectUri.AbsoluteUri)
.WithAuthority($"https://login.microsoftonline.com/{settings.TenantId}")
.Build());
.Build();
}
}
Loading
Loading