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

Support for custom authentication scheme without adding data protection #43624

Closed
1 task done
brendonparker opened this issue Aug 29, 2022 · 5 comments
Closed
1 task done
Labels
area-dataprotection Includes: DataProtection
Milestone

Comments

@brendonparker
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I'd like to revisit this issue: #33779

If you are building a custom authentication scheme that doesn't need data protection, there is currently no way to add authentication without adding data protection services. This means that at startup, keys are generated and logging is created (if they aren't persisted or encrypted) - when it's completely unnecessary.

This is because inside Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions the code looks like this:

public static AuthenticationBuilder AddAuthentication(this IServiceCollection services)
{
    services.AddAuthenticationCore();
    services.AddDataProtection();
    services.AddWebEncoders();
    services.TryAddSingleton<ISystemClock, SystemClock>();
    return new AuthenticationBuilder(services);
}

The call to AddDataProtection is added indiscriminately. From a developers point of view this can be worked around by replicating this code and the call to AddDataProtection() is removed:

    services.AddAuthenticationCore();
    services.AddWebEncoders();
    services.TryAddSingleton<ISystemClock, SystemClock>();
    var authBuilder = new AuthenticationBuilder(services);

But I expect this code to break in the future as it's not documented or supported.

As a possible solution maybe a new boolean property named RequiresDataProtection that defaults to true could be added to the AuthenticationOptions class, and if set to false, Data Protection is not added?

Describe the solution you'd like

A new boolean property on the AuthenticationOptions class that can optionally exclude the AddDataProtection API call.

Additional context

I'm running a simple stateless web api in an AWS Lambda function. As it stands, this results in a bunch of warning log messages occuring on every startup. Ideally this overhead doesn't take place at all, as I do not have the need for the DataProtection APIs.

@javiercn javiercn added the area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer label Aug 29, 2022
@Tratcher
Copy link
Member

Auth isn't the only component that requires data protection, it's also used by session, anti-forgery, and other components. Rather than tweaking each of these components to avoid adding the service, how about configuring data protection itself to turn off?

@brendonparker
Copy link
Author

I’m only using JWT bearer. Not using session or anti-forgery. Not sure what the “other components” are.

how about configuring data protection itself to turn off?

I’m open to any more specifics on how to go about this.

@adityamandaleeka
Copy link
Member

Triage: we should have a way to make data protection no-op safely (and anything that needed the data protection keys would throw).

This could be a sample.

@adityamandaleeka adityamandaleeka added this to the .NET 8 Planning milestone Sep 2, 2022
@adityamandaleeka adityamandaleeka added area-dataprotection Includes: DataProtection and removed area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer labels Sep 2, 2022
@amcasey amcasey modified the milestones: .NET 8 Planning, Backlog Jan 26, 2024
@ghost
Copy link

ghost commented Jan 26, 2024

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@halter73
Copy link
Member

While this was the original, I think much more of the discussion about this issue is now in #47410.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dataprotection Includes: DataProtection
Projects
None yet
Development

No branches or pull requests

7 participants
@halter73 @adityamandaleeka @brendonparker @Tratcher @javiercn @amcasey and others