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 option to disable Swagger #2981

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/actions/devcontainer_run_command/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ inputs:
TRE_ADDRESS_SPACE:
description: "TRE address apace."
required: false
ENABLE_SWAGGER:
description: "Determines whether the Swagger interface for the API will be available."
required: false
SWAGGER_UI_CLIENT_ID:
description: "The Swagger UI Client ID."
required: false
Expand Down Expand Up @@ -154,6 +157,7 @@ runs:
-e TF_VAR_application_admin_client_id="${{ inputs.APPLICATION_ADMIN_CLIENT_ID }}" \
-e TF_VAR_application_admin_client_secret="${{ inputs.APPLICATION_ADMIN_CLIENT_SECRET }}" \
-e TF_VAR_arm_subscription_id="${{ fromJSON(inputs.AZURE_CREDENTIALS).subscriptionId }}" \
-e ENABLE_SWAGGER="${{ inputs.ENABLE_SWAGGER }}" \
-e SWAGGER_UI_CLIENT_ID="${{ inputs.SWAGGER_UI_CLIENT_ID }}" \
-e TF_VAR_swagger_ui_client_id="${{ inputs.SWAGGER_UI_CLIENT_ID }}" \
-e TF_VAR_core_address_space="${{ inputs.core_address_space }}" \
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ENHANCEMENTS:
* Update docker base images to bullseye ([#2946](https://github.com/microsoft/AzureTRE/pull/2946)
* Support updating the firewall when installing via makefile/CICD ([#2942](https://github.com/microsoft/AzureTRE/pull/2942))
* Airlock processor function and api app service work with http2
* Added the option to disable Swagger ([#2981](https://github.com/microsoft/AzureTRE/pull/2981))

BUG FIXES:
* Private endpoints for AppInsights are now provisioning successfully and consistently ([#2841](https://github.com/microsoft/AzureTRE/pull/2841))
Expand Down
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.5"
__version__ = "0.6.6"
22 changes: 19 additions & 3 deletions api_app/api/routes/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from collections import defaultdict
from typing import Any, DefaultDict, Dict, Optional

from starlette.responses import PlainTextResponse
from starlette.status import HTTP_403_FORBIDDEN

from fastapi import APIRouter, Request, Depends
from fastapi.openapi.docs import get_swagger_ui_html, get_swagger_ui_oauth2_redirect_html
from fastapi.openapi.utils import get_openapi
Expand Down Expand Up @@ -90,8 +93,6 @@ async def get_swagger(request: Request):
async def swagger_ui_redirect():
return get_swagger_ui_oauth2_redirect_html()

core_router.include_router(core_swagger_router)
router.include_router(core_router)

# Workspace API
workspace_router = APIRouter(prefix=config.API_PREFIX)
Expand Down Expand Up @@ -157,5 +158,20 @@ async def get_workspace_swagger(workspace_id, request: Request, workspace_repo=D

return swagger_ui_html

workspace_router.include_router(workspace_swagger_router)

swagger_disabled_router = APIRouter()


@swagger_disabled_router.get("/docs", include_in_schema=False, name="swagger_disabled")
async def get_disabled_swagger():
return PlainTextResponse("Swagger is disabled. Set 'ENABLE_SWAGGER' to true in order to access Swagger.", status_code=HTTP_403_FORBIDDEN)


if config.ENABLE_SWAGGER:
core_router.include_router(core_swagger_router)
workspace_router.include_router(workspace_swagger_router)
else:
core_router.include_router(swagger_disabled_router)

router.include_router(core_router)
router.include_router(workspace_router)
1 change: 1 addition & 0 deletions api_app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
PROJECT_NAME: str = config("PROJECT_NAME", default="Azure TRE API")
DEBUG: bool = config("DEBUG", cast=bool, default=False)
ENABLE_LOCAL_DEBUGGING: bool = config("ENABLE_LOCAL_DEBUGGING", cast=bool, default=False)
ENABLE_SWAGGER: bool = config("ENABLE_SWAGGER", cast=bool, default=False)
VERSION = __version__
API_DESCRIPTION = "Welcome to the Azure TRE API - for more information about templates and workspaces see the [Azure TRE documentation](https://microsoft.github.io/AzureTRE)"

Expand Down
1 change: 1 addition & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tre:

core_app_service_plan_sku: P1v2
resource_processor_vmss_sku: Standard_B2s
enable_swagger: true
enable_airlock_malware_scanning: false

# TODO: move to RP default with https://github.com/microsoft/AzureTRE/issues/2948
Expand Down
1 change: 1 addition & 0 deletions docs/tre-admins/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| `TRE_URL`| This will be generated for you by populating your `TRE_ID`. This is used so that you can automatically register bundles |
| `CORE_ADDRESS_SPACE` | The address space for the Azure TRE core virtual network. `/22` or larger. |
| `TRE_ADDRESS_SPACE` | The address space for the whole TRE environment virtual network where workspaces networks will be created (can include the core network as well). E.g. `10.0.0.0/12`|
| `ENABLE_SWAGGER` | Determines whether the Swagger interface for the API will be available. |
| `SWAGGER_UI_CLIENT_ID` | Generated when following [pre-deployment steps](./setup-instructions/setup-auth-entities.md) guide. Client ID for swagger client to make requests. |
| `AAD_TENANT_ID` | Generated when following [pre-deployment steps](./setup-instructions/setup-auth-entities.md) guide. Tenant id against which auth is performed. |
| `API_CLIENT_ID` | Generated when following [pre-deployment steps](./setup-instructions/setup-auth-entities.md) guide. Client id of the "TRE API". |
Expand Down
1 change: 1 addition & 0 deletions templates/core/terraform/api-webapp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ resource "azurerm_linux_web_app" "api" {
"MANAGED_IDENTITY_CLIENT_ID" = azurerm_user_assigned_identity.id.client_id
"TRE_ID" = var.tre_id
"RESOURCE_LOCATION" = azurerm_resource_group.core.location
"ENABLE_SWAGGER" = var.enable_swagger
"SWAGGER_UI_CLIENT_ID" = var.swagger_ui_client_id
"AAD_TENANT_ID" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.auth_tenant_id.id})"
"API_CLIENT_ID" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.api_client_id.id})"
Expand Down
6 changes: 6 additions & 0 deletions templates/core/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ variable "resource_processor_number_processes_per_instance" {
description = "The number of CPU processes to run the RP on per VM instance"
}

variable "enable_swagger" {
type = bool
description = "Determines whether the Swagger interface for the API will be available."
sensitive = false
}

variable "swagger_ui_client_id" {
type = string
description = "The client id (app id) of the registration in Azure AD for the Swagger UI"
Expand Down
2 changes: 1 addition & 1 deletion templates/core/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.48"
__version__ = "0.4.49"