Skip to content

Conversation

@mattgotteiner
Copy link
Collaborator

@mattgotteiner mattgotteiner commented Oct 20, 2025

Purpose

  • Use the built-in document access control from Azure Search instead of manual security filters

Does this introduce a breaking change?

When developers merge from main and run the server, azd up, or azd deploy, will this produce an error?
If you're not sure, try it out on an old environment.

Note that global document access won't work the same, it will now work as the built-in access control does

[ ] Yes
[X] No

Does this require changes to learn.microsoft.com docs?

This repository is referenced by this tutorial
which includes deployment, settings and usage instructions. If text or screenshot need to change in the tutorial,
check the box below and notify the tutorial author. A Microsoft employee can do this for you if you're an external contributor.

[ ] Yes
[X] No

Type of change

[ ] Bugfix
[X] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

Code quality checklist

See CONTRIBUTING.md for more details.

  • The current tests all pass (python -m pytest).
  • I added tests that prove my fix is effective or that my feature works
  • I ran python -m pytest --cov to verify 100% coverage of added lines
  • I ran python -m mypy to check for type errors
  • I either used the pre-commit hooks or ran ruff and black manually on my code.

@mattgotteiner
Copy link
Collaborator Author

need to update docs

@mattgotteiner
Copy link
Collaborator Author

need to update UX to remove security filter options

@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
data/Contoso_Electronics_Company_Overview.md
#LinkLine Number
1http://www.contoso.com48

@pamelafox pamelafox self-requested a review October 27, 2025 19:20
@github-actions
Copy link

Check Country Locale in URLs

We have automatically detected added country locale to URLs in your files.
Review and remove country-specific locale from URLs to resolve this issue.

Check the file paths and associated URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
docs/login_and_acl.md
#LinkLine Number
1https://learn.microsoft.com/en-us/azure/search/search-index-access-control-lists-and-rbac-push-api#special-acl-values-all-and-none305

@github-actions
Copy link

Check Broken URLs

We have automatically detected the following broken URLs in your files. Review and fix the paths to resolve this issue.

Check the file paths and associated broken URLs inside them.
For more details, check our Contributing Guide.

File Full Path Issues
docs/deploy_features.md
#LinkLine Number
1https://learn.microsoft.com/azure/ai-services/openai/how-to/deployment-types#deployment-types117
2https://learn.microsoft.com/azure/ai-services/openai/how-to/deployment-types#deployment-types209

@mattgotteiner mattgotteiner marked this pull request as ready for review October 28, 2025 17:15
@pamelafox pamelafox requested a review from Copilot October 28, 2025 17:20

class AuthenticationHelper:
scope: str = "https://graph.microsoft.com/.default"
scope: str = "https://search.azure.com/.default"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change may make it slightly harder for people to extend the sample for arbitrary Graph API access, like to read emails, as I once demo'ed. Not sure who's actually doing that though. Just noting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - unfortunately, we cannot request both scopes here. We can give guidance to do this twice though in the custom code

],
)
),
x_ms_query_source_authorization=access_token,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: Ensure that tests were added to verify that token is passed in for all calls to search()/retrieve()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


raise AuthError(error="Authorization header is expected", status_code=401)

def build_security_filters(self, overrides: dict[str, Any], auth_claims: dict[str, Any]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay code removal!

# Only pass on the access token if access control is required
if self.require_access_control:
access_token = search_resource_access_token["access_token"]
auth_claims["access_token"] = access_token
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we don't need groups anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except AuthError as e:
logging.exception("Exception getting authorization information - " + json.dumps(e.error))
if self.require_access_control and not self.enable_unauthenticated_access:
if not self.enable_unauthenticated_access:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me why this check can be simplified?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fail here regardless of if we require access control or not
The only reason we may succeed is if unauthenticated access was enabled


1. (Optional) **Allow unauthenticated access**
To allow unauthenticated users to use the app, even when access control is enforced, run the following command:
To allow unauthenticated users to use the app, run the following command:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed that comment, so does that mean access control is not enforced in that case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a user is not authenticated and access control is enabled, there's no way for them to see the global files anymore, we still need to pass in that access token.
You can put up a login screen though without access control, so the comment is updated here, correct

- Select **Add permissions**.
- Select **API Permissions** in the left hand menu. The server app will use the `user_impersonation` permission from Azure AI Search to issue a token for security filtering on behalf of the logged in user.
- Select **Add a permission**, and then **APIs my organization uses**.
- Search for and select **Azure Cognitive Search**.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it never got renamed to AI Search there aye?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Entra app didn't change, correct



async def main():
load_azd_env()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm how come I didn't need that before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was an oversight as we only tested this in the "full azd up" scenario where we loaded the env vars

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@mattgotteiner mattgotteiner merged commit f178601 into Azure-Samples:main Oct 28, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants