azure-search-openai-demo icon indicating copy to clipboard operation
azure-search-openai-demo copied to clipboard

Make it possible to deploy for accounts without owner level access

Open JimGaleForce opened this issue 1 year ago • 35 comments

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [x] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

azp up (as an employee, i.e. Microsoft)

Any log messages given by the failure

ERROR: deployment failed: error deploying infrastructure: failed deploying: starting deployment to subscription: PUT https://management.azure.com/subscriptions/12341234-1234-1234-1234-123412341234/providers/Microsoft.Resources/deployments/myNewOrExistingResource


RESPONSE 403: 403 Forbidden ERROR CODE: AuthorizationFailed

{ "error": { "code": "AuthorizationFailed", "message": "The client '[email protected]' with object id '12341234-1234-1234-1234-123412341234' does not have authorization to perform action 'Microsoft.Resources/deployments/write' over scope '/subscriptions/12341234-1234-1234-1234-123412341234/providers/Microsoft.Resources/deployments/myNewOrExistingResource' or the scope is invalid. If access was recently granted, please refresh your credentials." } }

Expected/desired behavior

Ideally (if possible), there should be a path to set up preexisting resources in Azure Portal, such as an Azure OpenAI resource, deploying specific models, etc, all which require less creds than requiring a SAW machine to get write access.

(I already have all of these resources, the OpenAI service, two models, blob storage, search service). I changed the app.py to have those values. Not sure how to run/access it all.

OS and Version?

Windows 11

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

JimGaleForce avatar Mar 11 '23 06:03 JimGaleForce

I agree, if the above corporate/enterprise scenario with limited rights are addressed in the reference architecture, we can get our poc’s done lot quicker when we do not have these openai instances available under our msdn subscriptions or personal ones.

vikramhn avatar Mar 11 '23 10:03 vikramhn

I've made progress going at it manually, inserting service names and keys where referenced. However, I'm stuck on this one error in preparing the (sample) docs: Ensuring search index edgegrowthopenaisearchindex exists Traceback (most recent call last): File "C:\CODE\git\azure-search-openai-demo\scripts\prepdocs.py", line 208, in create_search_index() File "C:\CODE\git\azure-search-openai-demo\scripts\prepdocs.py", line 146, in create_search_index if args.index not in index_client.list_index_names(): File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\core\paging.py", line 132, in next return next(self._page_iterator) File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\core\paging.py", line 76, in next self._response = self._get_next(self.continuation_token) File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\search\documents\indexes_generated\operations_indexes_operations.py", line 520, in get_next raise HttpResponseError(response=response, model=error) azure.core.exceptions.HttpResponseError: () Authorization failed.

I've done az login. I'm even hardcoded urls in case the environment wasn't reading. I've switched the key from the query key (search service) to the admin key. They do different things, but I'm pretty sure it's the query key being needed. (admin key produces Unsupported credential).

I'd appreciate any hints on what key this supposed to be, or what might cause this. I feel I'm close to getting around the prevented corp deployment. (running locally).

JimGaleForce avatar Mar 11 '23 11:03 JimGaleForce

myNewOrExistingResource

Hi Jim, I also meet this issue. did you fix your issue , any suggestion for me . thanks

Gaigaisun avatar Mar 16 '23 03:03 Gaigaisun

@JimGaleForce , are you using your own subscription where your user is actually the owner ?

There's an issue in this scenario where the expected access-roles are not created and the prepdocs.py script is not able to get the index key or push files to storage.

One way to workaround this is to create another User within your Azure Active Directory with the role User Acess Administrator. Then login to azd within this user and tun azd up.

Let me know if that works for you

vhvb1989 avatar Mar 24 '23 17:03 vhvb1989

You're a life saver, thanks mate

timmyfrazer avatar Apr 02 '23 00:04 timmyfrazer

I've made progress going at it manually, inserting service names and keys where referenced. However, I'm stuck on this one error in preparing the (sample) docs: Ensuring search index edgegrowthopenaisearchindex exists Traceback (most recent call last): File "C:\CODE\git\azure-search-openai-demo\scripts\prepdocs.py", line 208, in create_search_index() File "C:\CODE\git\azure-search-openai-demo\scripts\prepdocs.py", line 146, in create_search_index if args.index not in index_client.list_index_names(): File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\core\paging.py", line 132, in next return next(self._page_iterator) File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\core\paging.py", line 76, in next self._response = self._get_next(self.continuation_token) File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\search\documents\indexes_generated\operations_indexes_operations.py", line 520, in get_next raise HttpResponseError(response=response, model=error) azure.core.exceptions.HttpResponseError: () Authorization failed.

I've done az login. I'm even hardcoded urls in case the environment wasn't reading. I've switched the key from the query key (search service) to the admin key. They do different things, but I'm pretty sure it's the query key being needed. (admin key produces Unsupported credential).

I'd appreciate any hints on what key this supposed to be, or what might cause this. I feel I'm close to getting around the prevented corp deployment. (running locally).

@JimGaleForce - DM’d you. Would you mind sharing how you deployed it manually?

chulahlou avatar Apr 13 '23 00:04 chulahlou

@chulahlou I had the same issue. I was logging into Azure with an account that had subscription-level role assignment of Owner. The workaround was to create and use a separate account with subscription-level role assignments of Owner and User Access Administrator. I was then able to deploy as normal.

timmyfrazer avatar Apr 13 '23 04:04 timmyfrazer

@timmyfrazer - thanks. The issue is the enterprise users don't have permission to elevate roles. They only have Contributor role assignments. They can create resources within an existing resource group so I'm looking for ways to stand up the application manually

chulahlou avatar Apr 13 '23 12:04 chulahlou

@timmyfrazer I can confirm creating a separate account with Owner and User Access Administrator assignments allow the deployment to complete. Thank you!

cacarroll avatar Apr 13 '23 13:04 cacarroll

I fixed it by changing the main.bicep to target an existing resource group.

main_bicep.txt

wtyeung avatar Apr 18 '23 17:04 wtyeung

I fixed it by changing the main.bicep to target an existing resource group.

main_bicep.txt

Thanks @wtyeung . That also failed as they don't have permission to assign roles. In your case, do you have Owner level permission to run the bicep script?

chulahlou avatar Apr 18 '23 18:04 chulahlou

Owner role in the existing resourceGroup is required. you can comment out the whole roles section and wire up manually using keys.

wtyeung avatar Apr 19 '23 04:04 wtyeung

Hey, @chulahlou, have you had any success deploying this on an account with the Contributor role?

nkong6789 avatar May 11 '23 19:05 nkong6789

@nkong6789 , the action "Microsoft.Resources/deployments/write" is required. This action is part of the Owner role.

You can also create a custom-role which includes this action and assign the custom-role to the user before deployment. After deployment you can remove the custom-role.

I got this approach from @gbecerra1982

vhvb1989 avatar May 12 '23 17:05 vhvb1989

I fixed it by changing the main.bicep to target an existing resource group.

main_bicep.txt

I get "A resource with the same name cannot be created in location 'eastus'. Please select a new resource name." I thought it would use existing resources which have been set using azd env set command

f00z avatar May 19 '23 21:05 f00z

Also agreed to this point with extra security care on exposed storage accounts and cognitive services. PR to added some level of validations via github or ADO pipelines: https://github.com/Azure-Samples/azure-search-openai-demo/pull/329

juju4 avatar Jun 17 '23 20:06 juju4

+1 this

I am the owner of the resource group, but I'm still getting the above error.

szelesaron avatar Jun 21 '23 09:06 szelesaron

Maybe with inspiration from https://github.com/Azure-Samples/openai-python-enterprise-logging

juju4 avatar Jun 24 '23 18:06 juju4

So some detailed steps in the documentation on adding the special role for a user with only contributor access to the subscription would be good.. This is a great example but a lot of what it does is opaque many of us.

davidwboyd avatar Jul 26 '23 21:07 davidwboyd

Other chatgpt repo https://github.com/microsoft/azurechatgpt

juju4 avatar Aug 05 '23 15:08 juju4

Can someone explain why we even need role assignments for this repo? I mean, you can typically deploy resources just fine w/o it

Timmate avatar Aug 16 '23 13:08 Timmate

@Timmate You can see the roles in the bottom of infra/main.bicep:

https://github.com/Azure-Samples/azure-search-openai-demo/blob/f76673c44c63a99cc28e635663893638de3511b0/infra/main.bicep#L254

There are both user roles assigned and system roles. The user roles are primarily needed so that prepdocs.py can run locally (to process docs, compute embeddings, and upload to search index). The system roles allow the web app itself to use the OpenAI and Cognitive Search APIs, via DefaultAzureCredential and managed identity.

pamelafox avatar Aug 16 '23 23:08 pamelafox

so, in short, we cannot deploy this app with only "Contributor" role, right?

mzhadigerov avatar Aug 31 '23 16:08 mzhadigerov

Hi all-

We've clarified on the README that at the minimum, you need the RBAC role, or the RBAC role scoped to an existing resource group: https://github.com/Azure-Samples/azure-search-openai-demo#azure-account-requirements

We're interested to hear if your employers are able to give you that level of access (especially resource group scoped) or if that is still high of a level of access.

I also documented in another issue how to manually assign the roles in the Portal, but I assume that will only work if you have RBAC access for that RG:

https://github.com/Azure-Samples/azure-search-openai-demo/issues/634#issuecomment-1721699823

If you cannot be granted RBAC at the resource group level, then I think the only other approach is to use keys instead of managed identity. That should be possible with changes to the credentials in app.py. We generally discourage keys when possible, however, so we haven't yet enabled that in the repo.

pamelafox avatar Sep 15 '23 18:09 pamelafox

We've clarified on the README that at the minimum, you need the RBAC role, or the RBAC role scoped to an existing resource group: https://github.com/Azure-Samples/azure-search-openai-demo#azure-account-requirements

We're interested to hear if your employers are able to give you that level of access (especially resource group scoped) or if that is still high of a level of access.

I've granted one of our developers the owner role for a resource group, and the Role Based Access Control Adminstrator (Preview) role at the resource group level. He still gets an error. Some have mentioned 'User Access Administrator. I've granted him that role at the resource group and will report back the results.

bosco777 avatar Oct 04 '23 14:10 bosco777

@bosco777 Can you clarify which error they get? Just want to make sure the error they're getting is the role error. We're trying to replicate here. Thanks!

pamelafox avatar Oct 05 '23 16:10 pamelafox

After deploying a tiny bicep file and looking at the full scope string, it appears their problem is more about the deployment not being scoped to the resource group. They are using "azd env set azure_resource_group ResourceGroupName", but the access denied PUT Deployment is just /subscription/subscriptionid/providers/microsoft.resources/deployments/deploymentname, rather than sub/subid/resourcegroups/rgname/providers/....

bosco777 avatar Oct 05 '23 16:10 bosco777

Aha, you're right. Victor mentioned that above:

https://github.com/Azure-Samples/azure-search-openai-demo/issues/4#issuecomment-1546070856

I will clarify in the README that there must also be a role that allows "Microsoft.Resources/deployments/write" on the subscription level, at least temporarily.

pamelafox avatar Oct 05 '23 17:10 pamelafox

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this issue will be closed.

github-actions[bot] avatar Jan 04 '24 01:01 github-actions[bot]

I've made progress going at it manually, inserting service names and keys where referenced. However, I'm stuck on this one error in preparing the (sample) docs: Ensuring search index edgegrowthopenaisearchindex exists Traceback (most recent call last): File "C:\CODE\git\azure-search-openai-demo\scripts\prepdocs.py", line 208, in create_search_index() File "C:\CODE\git\azure-search-openai-demo\scripts\prepdocs.py", line 146, in create_search_index if args.index not in index_client.list_index_names(): File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\core\paging.py", line 132, in next return next(self._page_iterator) File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\core\paging.py", line 76, in next self._response = self._get_next(self.continuation_token) File "C:\Users\jimgale\AppData\Roaming\Python\Python39\site-packages\azure\search\documents\indexes_generated\operations_indexes_operations.py", line 520, in get_next raise HttpResponseError(response=response, model=error) azure.core.exceptions.HttpResponseError: () Authorization failed.

I've done az login. I'm even hardcoded urls in case the environment wasn't reading. I've switched the key from the query key (search service) to the admin key. They do different things, but I'm pretty sure it's the query key being needed. (admin key produces Unsupported credential).

I'd appreciate any hints on what key this supposed to be, or what might cause this. I feel I'm close to getting around the prevented corp deployment. (running locally).

By getting access to Search Service Contributor Role it can be resolved.

ayus786 avatar Feb 23 '24 13:02 ayus786