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

Add optional AAD auth #534

Closed
wants to merge 12 commits into from
Closed

Add optional AAD auth #534

wants to merge 12 commits into from

Conversation

pamelafox
Copy link
Collaborator

Purpose

This PR adds optional AAD authentication to the App Service app, using the same approach I used in https://github.com/microsoft/sample-app-aoai-chatGPT/blob/main/README_azd.md

This is opt-in, developers must enable it using azd env set AZURE_USE_AUTHENTICATION true
That's similar to how @tonybaloney made App Insights opt-in.

This does not currently work on GitHub actions due to the service principal lacking the permissions.

In the future, I would prefer to set it up completely in Bicep (vs Bicep + 2 scripts), but am eagerly awaiting Azure/bicep#7724 for that to be possible.

Does this introduce a breaking change?

[ ] Yes
[X] No

Pull Request Type

What kind of change does this Pull Request introduce?

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

How to Test

  • azd up, confirm that it works with no auth
  • azd env set AZURE_USE_AUTHENTICATION true
  • azd up, confirm auth is required

@pamelafox pamelafox changed the title Aad auth Add optional AAD auth Aug 14, 2023
README.md Outdated
@@ -146,6 +146,23 @@ Once in the web app:

### FAQ

<details>
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 could be a section versus an FAQ, I don't mind either way. I think our README could use a TOC at some point soon though. :)

@@ -0,0 +1,5 @@
#!/bin/sh

. ./scripts/loadenv.sh
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI: Calling loadenv.sh in every script (auth_init, auth_update, prepdocs) means that it pip installs requirements every time. I could just call it in the first script, but then other hooks won't work if a dev deletes the first script hook for some reason.
I believe I also tried calling load_env as its own hook, but then the other hooks executed in a separated environment and didnt have access to the exported variables.

Another approach is to dump the env variables into a .env file and load them that way, but that'd be a larger change. That is what I do in https://github.com/pamelafox/chatgpt-quickstart/blob/main/azure.yaml

@@ -0,0 +1,9 @@
. ./scripts/loadenv.ps1

$venvPythonPath = "./.venv/scripts/python.exe"

Choose a reason for hiding this comment

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

this path give me an error I replaced it with "./scripts/.venv/scripts/python.exe" and "./scripts/.venv/bin/python" in line 6

Choose a reason for hiding this comment

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

As for auth_init.ps1 line 3 and 6 should be replaced with this path:
line 3:
$venvPythonPath = "./scripts/.venv/scripts/python.exe"
line 6:
$venvPythonPath = "./scripts/.venv/bin/python"

@pamelafox
Copy link
Collaborator Author

@zaffaste I just pushed loadenv.ps1 and a related change to prepdocs.ps1, they both work for me now inside pwsh, can you try?

@zaffaste
Copy link

@zaffaste I just pushed loadenv.ps1 and a related change to prepdocs.ps1, they both work for me now inside pwsh, can you try?

@pamelafox
If I don't change $venvPythonPath = "./.venv/scripts/python.exe" to $venvPythonPath = "./scripts/.venv/scripts/python.exe" in auth_init.ps1 and auth_update.ps1 files the scripts execution returns me an error
`Line |
9 | Start-Process -FilePath $venvPythonPath -ArgumentList "./scripts/auth …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| This command cannot be run due to the error: The system cannot find the file specified.

ERROR: failed running post hooks: 'postprovision' hook failed with exit code: '1', Path: 'xxx\Local\Temp\azd-postprovision-3370852331.ps1'. : exit code: 1`

The script in loadenv.ps1 and the updates to prepdocs.ps1 works good for me, thank you!

scripts/prepdocs.ps1 Outdated Show resolved Hide resolved
@pamelafox
Copy link
Collaborator Author

Moving this to a draft as the new doc ACL requires slightly different setup (client/server) and @mattmsft is investigating scripting that (based on these scripts).

Copy link

github-actions bot commented Dec 2, 2023

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

@github-actions github-actions bot added the Stale label Dec 2, 2023
@pamelafox
Copy link
Collaborator Author

Closing in favor of Matt's new PR.

@pamelafox pamelafox closed this Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants