Secure Swagger Configuration #584
Replies: 3 comments 5 replies
|
👋🏼 Hello @MH61Aus, First of all, thanks for reading the post. Always appreciated. The short answer to your question of "Does Duende also advise against putitng the swagger ui on production?" is it depends. OpenAPI and the Swagger UI element are dev-focused tools, and it depends on what you and your organization are trying to do. We don't make any recommendations for production/staging/dev environments because we don't know what you're trying to accomplish with them. Let's walk through a couple of scenarios in which you may or may not want to deploy these elements across different environments: DevelopmentIf you are implementing OpenAPI schema and Swagger to enable your local development team to build C# SDKs that ultimately only apply during the development process, then you likely wouldn't deploy the OpenAPI schema or Swagger UI outside of development. You can build these C# SDKs locally and use the libraries during development. Dev & StagingIf you are creating a business partnership with an outside party, you may only publish the OpenAPI schema and allow them to generate their own client, and use their own UI tools to exercise the endpoints. Security and identity are still important, but you don't need to provide the Swagger UI in this case (and thus don't need to secure it). Dev, Staging, & ProductionIf you are building a business where the API is the product, you will want to deploy both the schema and the UI to create an enjoyable developer experience that enables potential customers to try the API as frictionlessly as possible. In this case, you would deploy (and secure) these in a production environment. In this case, the schema and UI would be present and accessible throughout your CI/CD process, from dev, staging, and production. ConclusionThe answer is, it depends on what you're attempting to accomplish and what your team's goals are. I hope that clarifies why we didn't make a recommendation and instead wrote about how to address the security aspect of hosting a Swagger UI instance. While these tools are developer-focused, empowering developers to build faster and better apps, they do not specify which environment they are best suited for; that's a question you have to answer. Cheers, Khalid |
|
Thanks for the response @khalidabuhakmeh. This does clear a few things up for me - and makes me lean towards pulling it off of production since we're only using it for internal operational use, and we should probably focus our time on building some admin screens for these scenarios. The remining thing I'm curious about though is whether its possible to enforce PAR via swagger UI. If we're trying to achieve FAPI compliance, I imagine this failing on conformance report will be further justification to pull it off production. |
|
@khalidabuhakmeh - thanks for all of this. Setting up a BFF for the swagger UI is a little out of scope for now, but I'll be bookmarking this for whenever I get a quiet day, as i'd love to give it a go. you mentioned Postman allows PAR - I tried to get that working as we do already have a Postmen client defined, but I can't figure it out. |
Uh oh!
There was an error while loading. Please reload this page.
We've implemented swaggerui for a couple of APIs, and secured it following the blog post here: https://duendesoftware.com/blog/20251126-securing-openapi-and-swagger-ui-with-oauth-in-dotnet-10
We've allowed swagger on our production environment, since it allows easy interaction with endpoints that we haven't built UI for. We felt this wasn't an issue since only a few internal users that have an admin role are able to load the swagger UI.
however, we're looking at FAPI conformance since we work in healthcare, and the swagger client failed on PAR and other checks. when digging into the swagger and open API docs, I see that microsoft and swagger both say that swagger is intended for DEV environments only.
When I worketh though securing swagger, the Dunde blog post didn't give me the impression that it was intended for DEV only. the samples don't guard
AddOpenApi()with an environment check.Does Duende also advise against putitng the swagger ui on production? if so, the blog post should make that explicit.
All reactions