FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Guides

Your RAG index may not notice when SharePoint access is revoked

A separate permissions job, with its own signals and a fail-closed limit, keeps a chatbot from quoting salary files to someone who has just lost access.

ShareLinkedInFacebookX

In brief

  • A webhook only signals that something changed; the data itself must come from delta. Keep running delta on a schedule as a safety net.
  • Track items by id, make upserts idempotent, remove items with the deleted facet, and always have a full resync path ready for a 410.
  • Permissions need their own job: a change feed does not reflect revocations by itself, and Confluence space permissions do not show up in CQL.
Decision tree for the retrieval step. First question: is the source's most recent permission reconciliation older than 15 minutes? If yes, the system drops all documents from that source and reports "Temporarily unavailable". If no, it checks whether the person asking is in the ACL: if so, the document is used; if not, it is dropped.
Fail-closed: when the permissions job falls behind a set threshold, the retrieval step does not use the stale ACL but drops all documents from that source. The 15-minute threshold is only an example; the client's security team chooses the figure. Source: walkthrough in the article, based on Microsoft Graph and Wavect documentation.

At 9 a.m., an employee loses read access to a salary folder on SharePoint. In this hypothetical case, a RAG pipeline that syncs only content will let the chatbot keep quoting salary documents to that person, because the files themselves were never edited.

Wavect’s analysis of RAG on SharePoint and Confluence stresses this point: permissions copied into an index do not update themselves when the source revokes them.

One such incident is enough for a client to halt a pilot. The first question from the client’s security team is therefore likely to be about access rights, ahead of answer quality.

This guide builds two jobs. The content job uses delta queries to bring file changes into the vector index. The permissions job runs separately, with its own signals and a fail-closed limit. The code below is Python-style pseudocode, simplified for readability; it is not a ready-to-run SDK.

What do you need before writing the first line of code?

You need an app registered in the client’s Microsoft 365 tenant, a Confluence Cloud account with an API token, and a vector index that supports upserts and deletes by key. The hardest part is not technical. Microsoft’s guidance on large-scale scanning says an app needs the Sites.FullControl.All permission to process permissions correctly.

That permission is very broad, so the client’s admins usually need time to approve it. Request it in the first week, with a one-page explanation of what the app reads, what it writes, and why the chatbot cannot filter documents by user without it.

The first time you call delta without parameters, Graph enumerates the entire drive. Results come back in multiple pages, each with an @odata.nextLink. Only the last page carries an @odata.deltaLink, which you store for the next sync.

# Simplified: no retries, auth or parallel paging
def sync_drive(state, drive_id):
    url = state.get("delta_link") or f"{GRAPH}/drives/{drive_id}/root/delta"
    while url:
        body = graph_get(url).json()
        for item in body["value"]:
            handle_item(item)
        url = body.get("@odata.nextLink")
        if not url:
            state["delta_link"] = body["@odata.deltaLink"]
            save(state)

Check: save delta_link only after the last page has been processed. If you save it early and the job dies midway, the next run will skip the pages that were never processed.

Step 2: track by id, not by path

The delta feed returns only an item’s latest state, and an item can appear more than once. Microsoft advises always tracking items by id, because when a folder is renamed the feed does not return the files inside it.

If path is the key in your index, a single folder rename creates a batch of orphaned records. Use id as the key and keep path as metadata for displaying citations.

def handle_item(item):
    doc_id = item["id"]
    if "deleted" in item:
        index.delete(doc_id)              # remove from local state
        return
    if item.get("@microsoft.graph.sharedChanged") == "True":
        permission_queue.put(doc_id)      # for the permissions job to process
    if "file" in item:
        content_queue.put(doc_id)         # download, chunk, embed, upsert

Note the two separate if statements. Because the feed returns only the latest state, a file whose content and permissions have both changed may appear just once, carrying the sharedChanged annotation.

With elif, that file’s new content would be silently dropped. Pushing to both queues is safer. The cost is one redundant embedding, which is harmless if step 3 is done correctly.

Check: delete a file on SharePoint and run the sync again. An item with the deleted facet must disappear from the index as well as from the metadata table.

Step 3: upserts must be safe to repeat

Graph’s delta query overview states that applications must tolerate replays, meaning the same change can come back in later responses. Writes to the index must therefore be idempotent. Delete all old chunks for doc_id before writing new ones, or build chunk keys in the form doc_id + sequence number.

Common mistake: appending chunks every time an item appears. A week later, the same passage shows up three times in the top-k, and users complain that answers repeat themselves.

Step 4: 410 Gone is not an error to ignore

When a token is too old or has expired, Graph returns HTTP 410 Gone with a Location header containing a new nextLink to start enumeration from scratch. That pass must include a comparison with local state: any id in the index that does not appear in the full enumeration belongs to a document that no longer exists at the source.

if resp.status_code == 410:
    url = resp.headers["Location"]
    state["full_resync"] = True       # at the end of the loop: compare id sets, delete leftovers
    seen_ids.clear()

One more rule: on a 429 or 503, wait exactly as long as Retry-After says and stop all requests, including those outside the thread that was blocked. SharePoint throttles per application per tenant, so ten workers racing to retry will only keep the whole app blocked for longer.

Step 5: webhooks for early notice, delta for the data

Microsoft suggests a three-part pattern: crawl with delta, receive webhooks, and run an additional periodic delta, at most once a day, so that no change is missed. A webhook says only that something has just changed. When one arrives, call delta with the stored delta_link. Never use the webhook payload as a data source.

Step 6: the permissions job is a separate system

By default, delta includes sharing information for every changed item, and you must make further calls to get each item’s permissions. The first header to add is Prefer: deltashowsharingchanges. It attaches the sharedChanged annotation to items that appear because their permissions changed, but works only on SharePoint and OneDrive for Business.

The second is Prefer: hierarchicalsharing, which Microsoft presents as a way to better understand how permissions have changed. Its practical purpose is to cut the number of extra calls needed to fetch permissions item by item.

The permissions job takes ids from permission_queue, calls the API that lists a file’s permissions and builds the ACL. Effective permissions combine those assigned directly with those inherited from parent folders, and the inheritedFrom property shows where an inherited permission comes from.

# Simplified: list_permissions() wraps the API that lists a file's permissions
def permission_worker():
    while True:
        doc_id = permission_queue.get()
        acl = {"direct": [], "inherited": []}
        for perm in list_permissions(doc_id):
            if perm.get("inheritedFrom"):
                acl["inherited"].append(perm)
            else:
                acl["direct"].append(perm)
        index.set_acl(doc_id, acl)   # write only the ACL field, do not re-embed

Check: change the permissions on a parent folder that contains several files. The ACL must be recalculated for every file inheriting from that folder, as well as for the folder itself.

There is one more signal: SharePoint and OneDrive have a dedicated webhook for security events, which fires when an item’s permissions change. Connect it directly to the permissions job and bypass the content queue. A revocation should not have to wait behind a 200-page PDF queued for embedding.

Confluence: CQL does not see space permissions

For Confluence, the content job can query CQL by lastModified. But an answer on Atlassian’s developer forum points out that changes to space permissions do not show up in CQL, because they are not content updates. Catching them requires the Audit API or a scheduled permissions job.

At page level, the content restrictions endpoints in the Confluence REST API return the restrictions on each piece of content, enough to build an ACL per document. For 429s, Atlassian recommends exponential backoff with jitter and honoring Retry-After.

Content job Permissions job
SharePoint signals File webhook, periodic delta sharedChanged annotation, security webhook
Confluence signals CQL lastModified Audit API, scheduled restrictions scan
Writes to Chunks and embeddings by id ACL field of each document
When it falls behind Stale answers Data leak: must fail closed

The fail-closed limit: when late, refuse

A change feed is only a signal, so you still need to reconcile permissions periodically and set a lag limit. Say you choose 15 minutes: if a source’s last successful reconcile is more than 15 minutes old, retrieval drops every document from that source instead of trusting the old ACL.

Users will see “temporarily unavailable,” which is far easier to explain than a leaked payroll.

The limit itself is a matter to agree with the client. Have their security team choose it, then write it into the acceptance document.

Taking this skill to client sites and your resume

Return to the salary folder: the hardest question on site is likely to be less about recall than “if I revoke a colleague’s access, how long before the chatbot knows?” An FDE who can answer with a number, a mechanism and a clear behavior for when the system runs late will be easier to trust.

In job descriptions, look for phrases such as “permission-aware retrieval,” “connectors” or “enterprise data sync.” On your resume, be specific: “Built SharePoint/Confluence connectors for RAG with delta queries, a separate ACL job, and fail-closed behavior when permissions lag beyond the limit.” A demo repo with tests for replays, 410s and deleted items is more persuasive than any adjective.

Content sync helps the chatbot answer correctly. The permissions job decides whether the client dares open it to the whole company.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
8 sources
Read next on the roadmap · Stage 3: Applied AIWhen two client documents disagree, your RAG system should cite bothOn WikiContradict every model tested struggled with conflicting context, worst of all when neither passage admits the disagreement.