Repository navigation
Handle IpRestriction roles - #1344
Merged
Merged
Conversation
Required for handling IP based access control
Update calls to iiif-auth-v2 to handle IP roles, adding XFF if IP role is present and altering logic so that existence of cookie is no longer deciding factor in shortcuts
This is auth2 handling, the probe service serves as a separate way for client to check what status the are to expect. Auth1 used info.json. I've added a feature flag to enable the old behaviour again should we run into issues - this should be a relatively short lived feature flag once we remove auth1.
Extended CacheSettings helpers to allow default to be passed if override not found. Updated GetRolesString to ensure consistent order
donaldgray
marked this pull request as draft
November 2, 2026 14:08
CDN can include a header with shared secret. This is then used to determine which XFF to forward to iiif-auth requests
donaldgray
marked this pull request as ready for review
November 2, 2026 15:55
Varnish side car in deployed environment adds a potential hope that isn't accounted for
JackLewis-digirati
approved these changes
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change?
Orchestrator support for the
IpRestrictionrole-provider added to iiif-auth-v2 (see the dlcs/iiif-auth-v2#68). Requests from known CIDR ranges (e.g. a reading room) can be grantedip:roles without signing in. Auth2 evaluates these from the client IP on each request; they are never stored in a session. Orchestrator's job is to:ip:prefix for this.This PR also has two related changes that came up while doing this: predictable ordering of manifest-level access services, and info.json always returning 200 (behind a rollback flag).
IP roles
DLCS.Model.Auth.RoleXwithIsIpRole()/ContainsIpRole(). A role is an IP role if its final path segment starts withip:(e.g.https://api.dlcs.io/customers/2/roles/ip:reading-room). This is the same convention as iiif-auth-v2. The prefix lets Orchestrator decide, without a lookup, whether it needs to call Auth2.IClientIpResolver. Forwarded headers config (ConfigureForwardedHeaders, DLCS.Web) is unchanged: x-forwarded-for isn't processed, soConnection.RemoteIpAddressremains the direct caller.Auth:CdnOriginVerify, default headerX-Origin-Verify). With a valid secret the 2nd XFF entry from the right is used, otherwise the rightmost. With no secrets configured it's always the rightmost.ClientIpCaptureMiddleware, which runs before forwarded headers middleware. It captures the received XFF and caller IP, compares the secret in constant time (SHA256 +FixedTimeEquals, any configured secret, so it can be rotated), then removes the header so it's never logged or proxied downstream. YARP copies request headers to image servers and S3.KnownNetworks/KnownProxies, as the built-in middleware does.IIIFAuth2Client:probe_internalandverifyaccessrequests carryX-Forwarded-For: <client-ip>. The header isn't sent for other roles.Authorizationheader is sent without one.missingCredentialsis returned without calling Auth2 (shortcut response)ProbeServiceSupport): the item is now looked up before the bearer-token check. A missing token still returns 401 (missingCredentials) unless the item has an IP role, in which case Auth2 is called with no token. Behaviour for items without IP roles is unchanged, including not-found items without a token.AssetAccessValidator): Auth2verifyaccessis called when there's an Auth2 cookie or the roles contain an IP role. This covers images, files, timebased and adjuncts.verifyaccesscaching: results are cached in memory for a very short time, so a burst of requests for one image (e.g. hundreds of deep zoom tiles) doesn't make hundreds ofverifyaccesscalls.CacheOverrideKeys.VerifyAccess/VerifyAccessDeniedkeys (Caching:TimeToLive:Memory:Overrides:VerifyAccess). Setting both to 0 disables caching.AuthCookieManager.GetAuth2CookieValueForCustomer. It's hashed so raw session ids aren't kept in cache keys.verifyaccesscontract, and planned appointment-based roles will make the decision depend on it. Deep zoom tiles all share a deliverable, so this costs nothing in the main burst case.GetVerifyAccessCacheKey).false.Manifest access service ordering
ManifestV3Builder.GetDistinctAccessServicesnow orders the manifest-levelserviceswithexternalprofile first, then byid. This ensures viewers will attempt external first.ConcurrentDictionaryfilled by parallelGetAuthServicescalls, so it could differ between builds of the same manifest.info.json always 200
For restricted images, info.json now returns 200 with
Cache-Control: public, regardless of credentials. This is #1132InfoJsonCanBeNon200=trueflag restores the previous behaviour (401 +private, bearer-token validation and Auth1 token refresh). This is a rollback switch while Auth1 support is removed; there are no Auth1 users. This feature flag will be dropped in future when we remove auth1 support.InfoJsonServicealso now logs and returns null if a stored info.json deserialises to null (unlikely in practice, was to silence warning).Infrastructure Changes
Note
This PR requires infrastructure changes.
KnownNetworkson Orchestrator to the load balancer subnets. The client IP is only resolved fromX-Forwarded-Forif the caller is inKnownNetworks, and with the defaultAllNetworksany caller that can reach Orchestrator directly could spoof its IP. The same applies to iiif-auth-v2.X-Origin-Verifyby default) to the CloudFront origin, with the same secret asAuth:CdnOriginVerify:Secrets. Store the secret in Secrets Manager and inject it into both. To rotate, add the new value to Orchestrator'sSecretsfirst, switch CloudFront over, then remove the old value.ForwardLimit=2, with the VPC CIDR and the NAT gateway public IPs in itsKnownNetworks. Otherwise it treats the client IP as unknown and doesn't grant IP roles. Restrict/auth/v2/probe_internal*and/auth/v2/verifyaccess*on the ALB to the NAT gateway IPs with asource-iplistener rule.Configuration Changes
Note
This PR introduces configuration changes.
KnownNetworksx-forwarded-*headers are accepted from. Now also checked before resolving the client IP fromx-forwarded-for"AllNetworks"Auth:CdnOriginVerify:HeaderNameX-Origin-VerifyAuth:CdnOriginVerify:Secrets[]Auth:InternalProxyHops1Caching:TimeToLive:Memory:Overrides:VerifyAccessverifyaccessresult. Set this andVerifyAccessDeniedto 0 to disable5(code default)Caching:TimeToLive:Memory:Overrides:VerifyAccessDeniedverifyaccessresult2(code default)InfoJsonCanBeNon200true, info.json for restricted images returns 401 when the user doesn't have access (legacy behaviour, rollback switch)falseBreaking Changes
Caution
This PR introduces breaking changes.
/iiif-img/{id}/info.jsonfor restricted images returns 200 instead of 401InfoJsonCanBeNon200=trueto revert/iiif-img/{id}/info.jsonfor restricted images returnsCache-Control: publicinstead ofprivateResolves #1342
Resolves #1132