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

Improve Auth flow local vs Azure #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ericsche
Copy link

@ericsche ericsche commented Nov 1, 2024

Proposing a small code update to run token validation only when the code is ran locally, when hosted in Azure we use EasyAuth.
When doing the lab we ran into issue because we had the double Token check, EasyAuth was accepting the token but we still got a 401 because some of the env Variables were not set correctly.
This took us 4hrs to troubleshoot. Proposing this new code so there is only one Authentication validation :
Local you check your code
Azure you check easy Auth.

FYI : @BobGerman @waldekmastykarz

…run in Azure. It's been an issue for us for the CC training when we ran in Azure.
@BobGerman
Copy link
Contributor

How does one debug a 401 when Copilot is calling Easy Auth directly and there is no way to look at the token? I agree the double auth should go and was an oversight on my part, but I suggest removing Easy Auth not the coded validation ...

@ericsche
Copy link
Author

ericsche commented Nov 1, 2024 via email

@waldekmastykarz
Copy link
Member

While I understand the point, I think it's a dangerous pattern to introduce. The proposed approach means including a branch of code that's used only during local development and doesn't match how the API will run in production. Say that there's a bug in the local validation logic: is there a chance that developers might waste time fixing it while the production version would work just fine?

If we want to show implementing custom validation logic, I suggest we use a different sample that doesn't use Easy Auth in production and uses custom validation both locally and in prod. That way, we have a realistic setup that's relevant to developers and teaches them a pattern they're likely to use in real life.

@ericsche
Copy link
Author

ericsche commented Nov 4, 2024 via email

@waldekmastykarz
Copy link
Member

100% that service auth is preferred because it minimizes the chance of developer error. Like you noticed, it's not trivial and requires a solid understanding of security.
That said, I suspect that some organizations might have to/prefer to use a custom solution and we should meet them where they are too 🙂

@BobGerman
Copy link
Contributor

A compromise idea is to add logic similar to what @ericsche proposes but instead of checking for local hosting, it would check for Easy Auth headers.
If the headers are there, the code would use them, and show how to access the user name and upn as well for authentication. This would be more interesting in the Trey Research sample where we could assign consulting projects to the actual user. If Easy Auth headers are there, Waldek's lib won't help anyway since they do not include the original token.
If the headers are missing, the code would use Waldek's library as written.
Thus the code would work with or without Easy Auth.

@waldekmastykarz would that address your concerns on having 2 code paths? One might go untested - in particular the Easy Auth one which doesn't work locally ...

@waldekmastykarz
Copy link
Member

I'm trying to decide based on: is this code you'd put in production. In my eyes, you'd either use Easy Auth or not, but not both, and you'd align the code based on your architectural decision. I suggest we keep the sample simple and focused on the scenario: if it's meant to illustrate using Easy Auth, let's do that. If we want to show custom validation logic, let's show that, in as close to real setup as possible.

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.

3 participants