Skip to content

Commit bba9404

Browse files
fix: do not create obs in function app if public access disabled
1 parent de97971 commit bba9404

File tree

6 files changed

+62
-33
lines changed

6 files changed

+62
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private_dns_rg_name = "myResourceGroup"
6868
## Using pre-created storage account with disabled public access
6969
To use secured storage account with function app, user should create private storage account first, and then upload our function code zip file to the container `<deployment_container_name>`.
7070
Zip file is accessible in our public storage acccount by this url:
71-
https://wekaeastus.blob.core.windows.net/weka-tf-functions-deployment-eastus/dev/c52522f254123df61cd906bbf3dce6af.zip
71+
https://wekaeastus.blob.core.windows.net/weka-tf-functions-deployment-eastus/dev/144dd946da08cb0cf72a8ce1947c1a71.zip
7272

7373
```hcl
7474
allow_sa_public_network_access = false
@@ -441,7 +441,7 @@ proxy_url = VALUE
441441
| <a name="input_function_app_storage_account_prefix"></a> [function\_app\_storage\_account\_prefix](#input\_function\_app\_storage\_account\_prefix) | Weka storage account name prefix | `string` | `"weka"` | no |
442442
| <a name="input_function_app_subnet_delegation_cidr"></a> [function\_app\_subnet\_delegation\_cidr](#input\_function\_app\_subnet\_delegation\_cidr) | Subnet delegation enables you to designate a specific subnet for an Azure PaaS service. | `string` | `"10.0.1.0/25"` | no |
443443
| <a name="input_function_app_subnet_delegation_id"></a> [function\_app\_subnet\_delegation\_id](#input\_function\_app\_subnet\_delegation\_id) | Required to specify if subnet\_name were used to specify pre-defined subnets for weka. Function subnet delegation requires an additional subnet, and in the case of pre-defined networking this one also should be pre-defined | `string` | `""` | no |
444-
| <a name="input_function_app_version"></a> [function\_app\_version](#input\_function\_app\_version) | Function app code version (hash) | `string` | `"0e787ecc4b4936228cdb784e52ec408a"` | no |
444+
| <a name="input_function_app_version"></a> [function\_app\_version](#input\_function\_app\_version) | Function app code version (hash) | `string` | `"144dd946da08cb0cf72a8ce1947c1a71"` | no |
445445
| <a name="input_get_weka_io_token"></a> [get\_weka\_io\_token](#input\_get\_weka\_io\_token) | The token to download the Weka release from get.weka.io. | `string` | `""` | no |
446446
| <a name="input_hotspare"></a> [hotspare](#input\_hotspare) | Number of hotspares to set on weka cluster. Refer to https://docs.weka.io/overview/ssd-capacity-management#hot-spare | `number` | `1` | no |
447447
| <a name="input_install_cluster_dpdk"></a> [install\_cluster\_dpdk](#input\_install\_cluster\_dpdk) | Install weka cluster with DPDK | `bool` | `true` | no |

blob.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,43 @@ resource "azurerm_private_endpoint" "blob_endpoint" {
172172
}
173173
}
174174

175+
data "azurerm_storage_account" "weka_obs" {
176+
count = var.tiering_obs_name != "" ? 1 : 0
177+
name = var.tiering_obs_name
178+
resource_group_name = var.rg_name
179+
}
180+
181+
resource "azurerm_private_endpoint" "weka_obs_blob_endpoint" {
182+
count = !var.allow_sa_public_network_access && var.create_storage_account_private_links && var.tiering_blob_obs_access_key != "" ? 1 : 0
183+
name = "${var.prefix}-${var.cluster_name}-obs-blob-endpoint"
184+
location = data.azurerm_resource_group.rg.location
185+
resource_group_name = data.azurerm_resource_group.rg.name
186+
subnet_id = data.azurerm_subnet.subnet.id
187+
tags = merge(var.tags_map, { "weka_cluster" : var.cluster_name })
188+
189+
private_dns_zone_group {
190+
name = "${var.prefix}-${var.cluster_name}-dns-zone-group-obs-blob"
191+
private_dns_zone_ids = [azurerm_private_dns_zone.blob[0].id]
192+
}
193+
private_service_connection {
194+
name = "${var.prefix}-${var.cluster_name}-private-obs-BlobSvcCon"
195+
is_manual_connection = false
196+
private_connection_resource_id = data.azurerm_storage_account.weka_obs[0].id
197+
subresource_names = ["blob"]
198+
}
199+
200+
lifecycle {
201+
precondition {
202+
condition = var.tiering_obs_name != ""
203+
error_message = "Tiering OBS is not provided"
204+
}
205+
precondition {
206+
condition = var.tiering_obs_container_name != ""
207+
error_message = "Tiering OBS container name is not provided"
208+
}
209+
}
210+
}
211+
175212
data "azurerm_storage_account_blob_container_sas" "function_app_code_sas" {
176213
count = var.allow_sa_public_network_access ? 0 : 1
177214
connection_string = local.deployment_sa_connection_string

function-app/code/common/common.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,6 @@ func ReadBlobObject(ctx context.Context, bl BlobObjParams) (state []byte, err er
235235

236236
}
237237

238-
// func getStorageAccountKey(ctx context.Context, credential *azidentity.TokenCredential, subscriptionId, resourceGroupName, storageName string) (string, error) {
239-
// saClient, err := armstorage.NewAccountsClient(subscriptionId, credential, nil)
240-
// if err != nil {
241-
// err = fmt.Errorf("failed to create storage account client: %v", err)
242-
// return "", err
243-
// }
244-
// resp, err := saClient.ListKeys(ctx, resourceGroupName, storageName, nil)
245-
// if err != nil {
246-
// err = fmt.Errorf("failed to list storage account keys: %v", err)
247-
// return "", err
248-
// }
249-
// if len(resp.Keys) == 0 {
250-
// err = fmt.Errorf("no storage account keys found")
251-
// return "", err
252-
// }
253-
// return *resp.Keys[0].Value, nil
254-
// }
255-
256238
func containerExists(ctx context.Context, containerClient *container.Client, storageName, containerName string) (bool, error) {
257239
_, err := containerClient.GetProperties(ctx, nil)
258240
if err != nil {
@@ -514,16 +496,16 @@ func CreateStorageAccount(ctx context.Context, subscriptionId, resourceGroupName
514496
}
515497
skuName := armstorage.SKUNameStandardZRS
516498
kind := armstorage.KindStorageV2
517-
publicAccessDisabled := armstorage.PublicNetworkAccessDisabled
499+
// publicAccessDisabled := armstorage.PublicNetworkAccessDisabled
518500
_, err = client.BeginCreate(ctx, resourceGroupName, obsName, armstorage.AccountCreateParameters{
519501
Kind: &kind,
520502
Location: &location,
521503
SKU: &armstorage.SKU{
522504
Name: &skuName,
523505
},
524-
Properties: &armstorage.AccountPropertiesCreateParameters{
525-
PublicNetworkAccess: &publicAccessDisabled,
526-
},
506+
// Properties: &armstorage.AccountPropertiesCreateParameters{
507+
// PublicNetworkAccess: &publicAccessDisabled,
508+
// },
527509
}, nil)
528510

529511
if err != nil {

function-app/code/functions/clusterize/clusterize.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ import (
2525
)
2626

2727
type AzureObsParams struct {
28-
Name string
29-
ContainerName string
30-
AccessKey string
31-
TieringSsdPercent string
28+
Name string
29+
ContainerName string
30+
AccessKey string
31+
TieringSsdPercent string
32+
PublicAccessDisabled bool
3233
}
3334

3435
func GetObsScript(obsParams AzureObsParams) string {
@@ -93,6 +94,12 @@ func HandleLastClusterVm(ctx context.Context, state protocol.ClusterState, p Clu
9394

9495
if p.Cluster.SetObs {
9596
if p.Obs.AccessKey == "" {
97+
if p.Obs.PublicAccessDisabled {
98+
err = fmt.Errorf("public access is disabled for the storage account, please provide pre-created storage account info in terraform")
99+
logger.Error().Err(err).Send()
100+
return
101+
}
102+
96103
p.Obs.AccessKey, err = common.CreateStorageAccount(
97104
ctx, p.SubscriptionId, p.ResourceGroupName, p.Obs.Name, p.Location,
98105
)
@@ -348,6 +355,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
348355
obsName := os.Getenv("OBS_NAME")
349356
obsContainerName := os.Getenv("OBS_CONTAINER_NAME")
350357
obsAccessKey := os.Getenv("OBS_ACCESS_KEY")
358+
obsPublicAccessDisabled, _ := strconv.ParseBool(os.Getenv("OBS_PUBLIC_ACCESS_DISABLED"))
351359
location := os.Getenv("LOCATION")
352360
tieringSsdPercent := os.Getenv("TIERING_SSD_PERCENT")
353361
tieringTargetSsdRetention, _ := strconv.Atoi(os.Getenv("TIERING_TARGET_SSD_RETENTION"))
@@ -429,10 +437,11 @@ func Handler(w http.ResponseWriter, r *http.Request) {
429437
TieringStartDemote: tieringStartDemote,
430438
},
431439
Obs: AzureObsParams{
432-
Name: obsName,
433-
ContainerName: obsContainerName,
434-
AccessKey: obsAccessKey,
435-
TieringSsdPercent: tieringSsdPercent,
440+
Name: obsName,
441+
ContainerName: obsContainerName,
442+
AccessKey: obsAccessKey,
443+
TieringSsdPercent: tieringSsdPercent,
444+
PublicAccessDisabled: obsPublicAccessDisabled,
436445
},
437446
NFSStateParams: common.BlobObjParams{StorageName: stateStorageName, ContainerName: nfsStateContainerName, BlobName: nfsStateBlobName},
438447
FunctionAppName: functionAppName,

functions.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ locals {
118118
"OBS_NAME" = local.obs_storage_account_name
119119
"OBS_CONTAINER_NAME" = local.obs_container_name
120120
"OBS_ACCESS_KEY" = var.tiering_blob_obs_access_key
121+
"OBS_PUBLIC_ACCESS_DISABLED" = !var.allow_sa_public_network_access
121122
DRIVE_CONTAINER_CORES_NUM = var.containers_config_map[var.instance_type].drive
122123
COMPUTE_CONTAINER_CORES_NUM = var.set_dedicated_fe_container == false ? var.containers_config_map[var.instance_type].compute + 1 : var.containers_config_map[var.instance_type].compute
123124
FRONTEND_CONTAINER_CORES_NUM = var.set_dedicated_fe_container == false ? 0 : var.containers_config_map[var.instance_type].frontend

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ variable "function_app_storage_account_container_prefix" {
387387
variable "function_app_version" {
388388
type = string
389389
description = "Function app code version (hash)"
390-
default = "c52522f254123df61cd906bbf3dce6af"
390+
default = "144dd946da08cb0cf72a8ce1947c1a71"
391391
}
392392

393393
variable "function_app_dist" {

0 commit comments

Comments
 (0)