#!/usr/bin/env bash # Copyright (c) Microsoft Corporation. # Licensed under the MIT license. PRJ_ROOT="$(cd `dirname "${BASH_SOURCE}"`/../..; pwd)" ENV_CODE=${1:-${ENV_CODE}} AKS_NAMESPACE=${AKS_NAMESPACE:-"pgstac"} AKS_INGRESS_NAMESPACE=${AKS_INGRESS_NAMESPACE:-"ingress"} [[ -z "$ENV_CODE" ]] && { echo "Environment Code value not supplied"; exit 1; } set -a set -e echo "Retrieving required properties from Azure resources." PROCESSING_RESOURCE_GROUP=${PROCESSING_RESOURCE_GROUP:-"${ENV_CODE}-processing-rg"} AAD_ENDPOINT=$(az cloud show --query endpoints.activeDirectory -otsv) TENANT_ID=$(az account show --query tenantId -otsv) # Retrieve the public IP address we created in the deployment FQDN=$(az network public-ip show -g $PROCESSING_RESOURCE_GROUP \ -n ${ENV_CODE}-stac-ingress-public-ip --query dnsSettings.fqdn -o tsv) DNS_DOMAIN=${FQDN#*.} # Create an Azure AD application to perform authentication on the STAC endpoints echo "Creating Azure AD application to secure the STAC endpoints" APP_ID=$(az ad app create \ --display-name "STAC Endpoints for $ENV_CODE" \ --sign-in-audience AzureADMyOrg \ --web-redirect-uris "https://$FQDN/oauth2/callback" \ --optional-claims @$PRJ_ROOT/deploy/data/claims.json \ --required-resource-accesses @$PRJ_ROOT/deploy/data/resource_access.json \ --app-roles @$PRJ_ROOT/deploy/data/roles.json \ --query "appId" -otsv) # Generate a password for the app APP_PW=$(az ad app credential reset \ --id $APP_ID \ --append \ --display-name "oauth2-proxy access for STAC endpoints on $(az account show --query name -otsv)" \ --query "password" -otsv) helm repo add oauth2-proxy https://oauth2-proxy.github.io/manifests || true helm repo update # Install the oauth2-proxy Helm chart echo "Installing the oauth2-proxy Helm chart" AKS_RESOURCE_GROUP=${AKS_RESOURCE_GROUP:-${PROCESSING_RESOURCE_GROUP}} AKS_CLUSTER_NAME=$(az aks list -g ${AKS_RESOURCE_GROUP} --query "[?tags.type && tags.type == 'k8s'].name" -otsv) AKS_ISSUER_URL=$(az aks show --resource-group $AKS_RESOURCE_GROUP --name $AKS_CLUSTER_NAME --query oidcIssuerProfile.issuerUrl -otsv) OAUTH_PROXY_VALUES_FILE=$(mktemp -t oauth2-proxy-values) trap 'rm -f -- "$OAUTH_PROXY_VALUES_FILE"' EXIT cat > $OAUTH_PROXY_VALUES_FILE <