Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security: remove API key auth #92

Closed
wants to merge 16 commits into from
Closed

Conversation

gitri-ms
Copy link
Collaborator

@gitri-ms gitri-ms commented Aug 2, 2023

Motivation and Context

This PR addresses microsoft/semantic-kernel#1639

Description

  1. Remove API key authorization
  2. Use "AzureAD" as default authentication configuration for deployments, "None" for running locally (Note: UI changes to disable sign in flow for the latter case are still forthcoming)
  3. Enable auth policy on controllers that checks if the user is part of the conversation they are trying to access
  4. Update routes to better align to Microsoft API design principles

Breaking change: This PR changes the contract between the frontend and backend around how user IDs are communicated. Users who have been signing into the frontend with AAD will now only see their chats if the backend is also gated by AAD authentication, which was not the case previously.

Contribution Checklist

@github-actions github-actions bot added webapp Pull requests that update Typescript code webapi Pull requests that update .net code deployment Issues related to deploying Chat-Copilot PR: ready for review github actions Pull requests that update GitHub Actions code labels Aug 2, 2023
@gitri-ms gitri-ms self-assigned this Aug 2, 2023
@github-actions github-actions bot added documentation Improvements or additions to documentation PR: ready for review labels Aug 2, 2023
@@ -112,8 +112,6 @@ This will get you to the CORS page where you can add your allowed hosts.

## Authorization
All of endpoints (except `/healthz`) require authorization to access.
By default, an API key is required for access which can be found in the `Authorization:ApiKey` configuration setting.
Copy link
Collaborator Author

@gitri-ms gitri-ms Aug 3, 2023

Choose a reason for hiding this comment

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

TODO: update this section. Also update deployment commands

[string]
# Authority for client applications that are not configured as multi-tenant.
$Authority="https://login.microsoftonline.com/common"
$Authority = "https://login.microsoftonline.com/common"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is some weirdness here -- the backend expects instance + tenant ID, while the frontend expects authority. However the values need to match. This could be confusing for the user. Perhaps change to make them more consistent (e.g. both use instance + tenant id)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the format expected from the client side?


[string]
# Azure AD tenant ID for authenticating users
$AzureAdTenantId = "common",
Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed during bug bash, we might want to not put "common" as the default and force users to provide a tenant

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, I am currently going through and changing all of these

echo " -ai, --ai-service AI_SERVICE_TYPE Type of AI service to use (i.e., OpenAI or AzureOpenAI)"
echo " -aikey, --ai-service-key AI_SERVICE_KEY API key for existing Azure OpenAI resource or OpenAI account"
echo " -aiend, --ai-endpoint AI_ENDPOINT Endpoint for existing Azure OpenAI resource"
echo " -rg, --resource-group RESOURCE_GROUP Resource group to which to make the deployment (default: \"rg-\$DEPLOYMENT_NAME\")"
echo " -r, --region REGION Region to which to make the deployment (default: \"South Central US\")"
echo " -wr, --web-app-region WEB_APP_REGION Region to deploy to the static web app into. This must be a region that supports static web apps. (default: \"West US 2\")"
echo " -a, --app-service-sku WEB_APP_SVC_SKU SKU for the Azure App Service plan (default: \"B1\")"
echo " -i, --instance AZURE_AD_INSTANCE Azure AD cloud instance for authenticating users"
echo " (default: \"https://login.microsoftonline.com/\")"
echo " -t, --tenant-id AZURE_AD_TENANT_ID Azure AD tenant ID for authenticating users (default: \"common\")"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, might want to make this mandatory...

@@ -171,20 +179,24 @@ az account set -s "$SUBSCRIPTION"
: "${REGION:="southcentralus"}"
: "${WEB_APP_SVC_SKU:="B1"}"
: "${WEB_APP_REGION:="westus2"}"
: "${AZURE_AD_INSTANCE:="https://login.microsoftonline.com/"}"
: "${AZURE_AD_TENANT_ID:="common"}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again...

param azureAdInstance string = environment().authentication.loginEndpoint

@description('Azure AD tenant ID for authenticating users')
param azureAdTenantId string = 'common'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Default again...

@gitri-ms
Copy link
Collaborator Author

gitri-ms commented Aug 8, 2023

Closing this PR as it is now covered by #126

@gitri-ms gitri-ms closed this Aug 8, 2023
github-merge-queue bot pushed a commit that referenced this pull request Aug 18, 2023
### Motivation and Context
This PR addresses
microsoft/semantic-kernel#1639. It is a
combination of PRs #92 and #110

### Description

#### Backend changes
- Remove API key authorization
- Use "AzureAD" as default authentication configuration for deployments,
"None" for running locally (Note: UI changes to disable sign in flow for
the latter case are still forthcoming)
- Enable auth policy on controllers that checks if the user is part of
the conversation they are trying to access

This PR changes the contract between the frontend and backend around how
user IDs are communicated. Users who have been signing into the frontend
with AAD will now only see their chats if the backend is also gated by
AAD authentication, which was not the case previously.

#### Frontend changes
- adds `REACT_APP_AUTH_TYPE` and changes AAD variables in `.env` to be
optional
- adds `AuthHelper.IsAuthAAD` to conditionally render different elements
throughout the app
- changes user settings menu popup to instead just show as a settings
button:

![image](https://github.com/microsoft/chat-copilot/assets/52973358/342f977d-d011-464d-b122-5eff5f8222ac)

Existing users will need to uncomment `REACT_APP_AUTH_TYPE=AzureAd` in
`webapp/.env` to continue using AAD as their authorization type.


### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [Contribution
Guidelines](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Desmond Howard <[email protected]>
teamleader-dev pushed a commit to vlink-group/chat-copilot that referenced this pull request Oct 7, 2024
### Motivation and Context
This PR addresses
microsoft/semantic-kernel#1639. It is a
combination of PRs microsoft#92 and microsoft#110

### Description

#### Backend changes
- Remove API key authorization
- Use "AzureAD" as default authentication configuration for deployments,
"None" for running locally (Note: UI changes to disable sign in flow for
the latter case are still forthcoming)
- Enable auth policy on controllers that checks if the user is part of
the conversation they are trying to access

This PR changes the contract between the frontend and backend around how
user IDs are communicated. Users who have been signing into the frontend
with AAD will now only see their chats if the backend is also gated by
AAD authentication, which was not the case previously.

#### Frontend changes
- adds `REACT_APP_AUTH_TYPE` and changes AAD variables in `.env` to be
optional
- adds `AuthHelper.IsAuthAAD` to conditionally render different elements
throughout the app
- changes user settings menu popup to instead just show as a settings
button:

![image](https://github.com/microsoft/chat-copilot/assets/52973358/342f977d-d011-464d-b122-5eff5f8222ac)

Existing users will need to uncomment `REACT_APP_AUTH_TYPE=AzureAd` in
`webapp/.env` to continue using AAD as their authorization type.


### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [Contribution
Guidelines](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/copilot-chat/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Desmond Howard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployment Issues related to deploying Chat-Copilot documentation Improvements or additions to documentation github actions Pull requests that update GitHub Actions code PR: breaking change Pull requests that introduce breaking changes webapi Pull requests that update .net code webapp Pull requests that update Typescript code
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

2 participants