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

Enable white-listing features & tests and self-hosted agents #350

Merged
merged 25 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
15a577e
Edits to support whitelisting self-hosted build agents.
Sep 27, 2019
dfae41d
Merge remote-tracking branch 'origin/master' into feature/242
Sep 27, 2019
bb688c8
Updating unit test counts
Sep 27, 2019
b205089
updating lint error
tasdevani21 Sep 27, 2019
02bd6b2
updating unit tests
tasdevani21 Sep 27, 2019
0e5c414
removing dynamic name key
tasdevani21 Sep 27, 2019
f9c039d
formatting
Oct 1, 2019
8dd76c7
formatting
Oct 1, 2019
2234039
remove workstream-specific prefixes
Oct 1, 2019
3f3c5fd
Merge remote-tracking branch 'remotes/origin/master' into feature/242
Oct 1, 2019
902f565
update test expectation
Oct 1, 2019
8ebcf77
removed out-modded tests
Oct 1, 2019
8f03199
removed un-needed integration tests
Oct 1, 2019
1dcca29
Merge remote-tracking branch 'origin/master' into feature/242
Oct 3, 2019
4d8b116
update test resource count
Oct 3, 2019
96c99e6
disable webhook int testing
Oct 4, 2019
ae38702
remove source code providing a default for `resource_ip_whitelist`
Oct 4, 2019
b1adedc
remove source code providing a default for `resource_ip_whitelist`
Oct 4, 2019
6d279dd
remove source code providing a default for `resource_ip_whitelist`
Oct 4, 2019
6347ed9
update unit_test to match expectations
Oct 4, 2019
f95a43a
force TF CLI to gen errors for missing-but-required vars
Oct 4, 2019
e4cbb0c
ensure certain new env vars are exported
Oct 4, 2019
da3e776
update int test
Oct 4, 2019
f49b8d5
remove dead code
Oct 7, 2019
8bda174
the list of IPs for unit tesings are misleading (these particular val…
Oct 7, 2019
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# type that will pass linting

* text=auto eol=lf

*.png -text
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ steps:
env:
TF_VAR_remote_state_container: $(REMOTE_STATE_CONTAINER)
TF_VAR_remote_state_account: $(REMOTE_STATE_ACCOUNT)
TF_VAR_resource_ip_whitelist: $(TF_VAR_resource_ip_whitelist)
inputs:
azureSubscription: '$(SERVICE_CONNECTION_NAME)'
addSpnToEnvironment: true
Expand Down Expand Up @@ -56,4 +57,4 @@ steps:
TF_PLAN_FILE="${TF_WORKSPACE_NAME}_plan.out"
TF_CLI_ARGS=${TF_CLI_ARGS:-}

terraform apply $TF_CLI_ARGS -auto-approve $TF_PLAN_FILE
terraform apply $TF_CLI_ARGS -input=false -auto-approve $TF_PLAN_FILE
ThePhen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ steps:
env:
TF_VAR_remote_state_container: $(REMOTE_STATE_CONTAINER)
TF_VAR_remote_state_account: $(REMOTE_STATE_ACCOUNT)
TF_VAR_resource_ip_whitelist: $(TF_VAR_resource_ip_whitelist)
inputs:
azureSubscription: '$(SERVICE_CONNECTION_NAME)'
addSpnToEnvironment: true
Expand Down Expand Up @@ -37,4 +38,4 @@ steps:
TF_PLAN_FILE="${TF_WORKSPACE_NAME}_plan.out"
TF_CLI_ARGS=${TF_CLI_ARGS:-}

terraform plan $TF_CLI_ARGS -out $TF_PLAN_FILE
terraform plan $TF_CLI_ARGS -input=false -out $TF_PLAN_FILE
14 changes: 7 additions & 7 deletions infra/templates/az-isolated-service-single-region/app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ data "external" "ase_subnets" {
}

module "keyvault" {
source = "../../modules/providers/azure/keyvault"
keyvault_name = local.kv_name
resource_group_name = azurerm_resource_group.app_rg.name
# subnet_id_whitelist = values(data.external.ase_subnets.result)
# resource_ip_whitelist = var.resource_ip_whitelist
source = "../../modules/providers/azure/keyvault"
keyvault_name = local.kv_name
resource_group_name = azurerm_resource_group.app_rg.name
subnet_id_whitelist = values(data.external.ase_subnets.result)
resource_ip_whitelist = var.resource_ip_whitelist
providers = {
"azurerm" = "azurerm.app_dev"
}
Expand All @@ -54,8 +54,8 @@ module "container_registry" {
container_registry_admin_enabled = false
// Note: only premium ACRs allow configuration of network access restrictions
container_registry_sku = "Premium"
# subnet_id_whitelist = values(data.external.ase_subnets.result)
# resource_ip_whitelist = var.resource_ip_whitelist
subnet_id_whitelist = values(data.external.ase_subnets.result)
resource_ip_whitelist = var.resource_ip_whitelist
providers = {
"azurerm" = "azurerm.app_dev"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ unauthn_deployment_targets = [

# Note: this is configured as such only to test IP Whitelists. This is a well
# known DNS address
resource_ip_whitelist = ["13.107.6.0/24", "13.107.9.0/24", "13.107.42.0/24", "13.107.43.0/24", "40.74.0.0/15", "40.76.0.0/14", "40.80.0.0/12", "40.96.0.0/12", "40.112.0.0/13", "40.120.0.0/14", "40.124.0.0/16", "40.125.0.0/17"]
ase_name = "co-static-ase"
ase_resource_group = "co-static-ase-rg"
ase_vnet_name = "co-static-ase-vnet"
ase_name = "co-static-ase"
ase_resource_group = "co-static-ase-rg"
ase_vnet_name = "co-static-ase-vnet"
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ func verifyVnetIntegrationForACR(goTest *testing.T, output infratests.TerraformO
acrName := output["acr_name"].(string)
acrACLs := azure.ACRNetworkAcls(goTest, adminSubscription, appDevResourceGroup, acrName)
verifyVnetSubnetWhitelistForACR(goTest, acrACLs)
verifyIPWhitelistForACR(goTest, acrACLs)
}

// Verify that only the correct IPs have access to the ACR
func verifyIPWhitelistForACR(goTest *testing.T, acrACLs *containerregistry.NetworkRuleSet) {
// Refer to the documentation in `terraform.tfvars` to understand why this IP address
// is whitelisted
expectedIpsWithACRAccess := []string{}
ipsWithACRAccess := make([]string, len(*acrACLs.IPRules))
for i, rule := range *acrACLs.IPRules {
ipsWithACRAccess[i] = *rule.IPAddressOrRange
}

requireEqualIgnoringOrderAndCase(goTest, ipsWithACRAccess, expectedIpsWithACRAccess)
}

// Verify that only the correct subnets have access to the ACR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ func TestIsoSingleRegion(t *testing.T) {
TfOptions: tfOptions,
ExpectedTfOutputCount: 10,
TfOutputAssertions: []infratests.TerraformOutputValidation{
// These are commented because we are using hosted build agents
// and would need to add all azure ips in whitelist. When we move to
// custom build agents we can uncomment as part of acceptance criteria.
// integration tests will need to add IPs of the agents and uncomment code in
// app.tf that enables the white list.
// verifyVnetIntegrationForKeyVault,
// verifyVnetIntegrationForACR,
verifyCDHooksConfiguredProperly,
verifyCorrectWebhookEndpointForApps,
verifyCorrectDeploymentTargetForApps,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ func verifyVnetIntegrationForKeyVault(goTest *testing.T, output infratests.Terra
vaultName := output["keyvault_name"].(string)
keyVaultACLs := azure.KeyVaultNetworkAcls(goTest, adminSubscription, appDevResourceGroup, vaultName)
verifyVnetSubnetWhitelistForKeyvault(goTest, keyVaultACLs)
verifyIPWhitelistForKeyvault(goTest, keyVaultACLs)
}

// Verify that only the correct IPs have access to the Keyvault
func verifyIPWhitelistForKeyvault(goTest *testing.T, keyVaultACLs *keyvault.NetworkRuleSet) {
// Refer to the documentation in `terraform.tfvars` to understand why this IP address
// is whitelisted
// Terraform seems to be adding a CIDR block with the IPs provided, for example the expected IP below of 1.1.1.1 would be 1.1.1.1/32 in the CIDR format.
expectedIpsWithKeyvaultAccess := []string{}
ipsWithKeyvaultAccess := make([]string, len(*keyVaultACLs.IPRules))
for i, rule := range *keyVaultACLs.IPRules {
ipsWithKeyvaultAccess[i] = *rule.Value
}

requireEqualIgnoringOrderAndCase(goTest, ipsWithKeyvaultAccess, expectedIpsWithKeyvaultAccess)
}

// Verify that only the correct subnets have access to the ACR
Expand All @@ -46,7 +31,7 @@ func verifyVnetSubnetWhitelistForKeyvault(goTest *testing.T, keyVaultACLs *keyva
require.Equal(
goTest,
keyVaultACLs.DefaultAction,
keyvault.Allow, fmt.Sprintf("Expected default option of %s but got %s", keyvault.Deny, keyVaultACLs.DefaultAction))
keyvault.Deny, fmt.Sprintf("Expected default option of %s but got %s", keyvault.Deny, keyVaultACLs.DefaultAction))

subnetsWithKeyVaultAccess := make([]string, len(*keyVaultACLs.VirtualNetworkRules))
for i, rule := range *keyVaultACLs.VirtualNetworkRules {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,12 @@ func verifyCorrectWebhookEndpointForApps(goTest *testing.T, output infratests.Te
// correct webapp.
func verifyCorrectDeploymentTargetForApps(goTest *testing.T, output infratests.TerraformOutput) {
adminResourceGroup := output["admin_resource_group"].(string)
acrName := output["acr_name"].(string)

for appIndex, appName := range output["webapp_names"].([]interface{}) {
appConfig := azure.WebAppSiteConfiguration(goTest, adminSubscription, adminResourceGroup, appName.(string))
linuxFxVersion := strings.Trim(*appConfig.LinuxFxVersion, "{}")

fmt.Println("Verifying webapp #", appIndex)
var expectedImageName string = ""
var expectedImageTagPrefix string = ""

for targetIndex := range unauthn_deploymentTargets {
if strings.Contains(linuxFxVersion, fmt.Sprintf("%s:%s", unauthn_deploymentTargets[targetIndex]["image_name"], unauthn_deploymentTargets[targetIndex]["image_release_tag_prefix"])) {
expectedImageName = unauthn_deploymentTargets[targetIndex]["image_name"]
expectedImageTagPrefix = unauthn_deploymentTargets[targetIndex]["image_release_tag_prefix"]
}
}

for targetIndex := range authn_deploymentTargets {
if strings.Contains(linuxFxVersion, fmt.Sprintf("%s:%s", authn_deploymentTargets[targetIndex]["image_name"], authn_deploymentTargets[targetIndex]["image_release_tag_prefix"])) {
expectedImageName = authn_deploymentTargets[targetIndex]["image_name"]
expectedImageTagPrefix = authn_deploymentTargets[targetIndex]["image_release_tag_prefix"]
}
}

expectedAcr := acrName + ".azurecr.io"
expectedLinuxFxVersion := fmt.Sprintf(
"DOCKER|%s/%s:%s",
expectedAcr,
expectedImageName,
expectedImageTagPrefix)

expectedLinuxFxVersion := "DOCKER"
require.Equal(goTest, expectedLinuxFxVersion, linuxFxVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ var tfOptions = &terraform.Options{
TerraformDir: "../../",
Upgrade: true,
Vars: map[string]interface{}{
"resource_ip_whitelist": []string{
erikschlegel marked this conversation as resolved.
Show resolved Hide resolved
"13.89.34.162/32",
"13.107.6.0/24",
"13.107.9.0/24",
"13.107.42.0/24",
"13.107.43.0/24",
"40.74.0.0/15",
"40.76.0.0/14",
"40.80.0.0/12",
"40.96.0.0/12",
"40.112.0.0/13",
"40.120.0.0/14",
"40.124.0.0/16",
"40.125.0.0/17"},
"resource_group_location": region,
"ase_subscription_id": adminSubscription,
"ase_name": aseName,
Expand Down Expand Up @@ -68,72 +82,75 @@ func TestTemplate(t *testing.T) {
expectedAppInsights := asMap(t, `{
"application_type": "Web"
}`)
// expectedKeyVault := asMap(t, `{
// "network_acls": [{
// "bypass": "None",
// "default_action": "Deny",
// "ip_rules": ["13.107.6.0/24", "13.107.9.0/24", "13.107.42.0/24", "13.107.43.0/24", "40.74.0.0/15", "40.76.0.0/14", "40.80.0.0/12", "40.96.0.0/12", "40.112.0.0/13", "40.120.0.0/14", "40.124.0.0/16", "40.125.0.0/17"]
// }]
// }`)
expectedKeyVault := asMap(t, `{
"network_acls": [{
"bypass": "None",
"default_action": "Deny",
"ip_rules": ["13.89.34.162/32", "13.107.6.0/24", "13.107.9.0/24", "13.107.42.0/24", "13.107.43.0/24", "40.74.0.0/15", "40.76.0.0/14", "40.80.0.0/12", "40.96.0.0/12", "40.112.0.0/13", "40.120.0.0/14", "40.124.0.0/16", "40.125.0.0/17"]
}]
}`)

expectedAzureContainerRegistry := asMap(t, `{
"admin_enabled": false,
"sku": "Premium",
"network_rule_set": [{
"default_action": "Deny",
"ip_rule": [{
"action": "Allow",
"ip_range": "13.107.6.0/24"
},
{
"action": "Allow",
"ip_range": "13.107.9.0/24"
},
{
"action": "Allow",
"ip_range": "13.89.34.162/32"
},
{
"action": "Allow",
"ip_range": "13.107.42.0/24"
},
{
"action": "Allow",
"ip_range": "13.107.43.0/24"
},
{
"action": "Allow",
"ip_range": "40.74.0.0/15"
},
{
"action": "Allow",
"ip_range": "40.76.0.0/14"
},
{
"action": "Allow",
"ip_range": "40.80.0.0/12"
},
{
"action": "Allow",
"ip_range": "40.96.0.0/12"
},
{
"action": "Allow",
"ip_range": "40.112.0.0/13"
},
{
"action": "Allow",
"ip_range": "40.120.0.0/14"
},
{
"action": "Allow",
"ip_range": "40.124.0.0/16"
},
{
"action": "Allow",
"ip_range": "40.125.0.0/17"
}
]
}]
}`)

// expectedAzureContainerRegistry := asMap(t, `{
// "admin_enabled": false,
// "name": "isolatedsazisolateacr",
// "resource_group_name": "isolated-service-`+workspace+`-app-rg",
// "sku": "Premium",
// "network_rule_set": [{
// "default_action": "Deny",
// "ip_rule": [{
// "action": "Allow",
// "ip_range": "13.107.6.0/24"
// },
// {
// "action": "Allow",
// "ip_range": "13.107.9.0/24"
// },
// {
// "action": "Allow",
// "ip_range": "13.107.42.0/24"
// },
// {
// "action": "Allow",
// "ip_range": "13.107.43.0/24"
// },
// {
// "action": "Allow",
// "ip_range": "40.74.0.0/15"
// },
// {
// "action": "Allow",
// "ip_range": "40.76.0.0/14"
// },
// {
// "action": "Allow",
// "ip_range": "40.80.0.0/12"
// },
// {
// "action": "Allow",
// "ip_range": "40.96.0.0/12"
// },
// {
// "action": "Allow",
// "ip_range": "40.112.0.0/13"
// },
// {
// "action": "Allow",
// "ip_range": "40.120.0.0/14"
// },
// {
// "action": "Allow",
// "ip_range": "40.124.0.0/16"
// },
// {
// "action": "Allow",
// "ip_range": "40.125.0.0/17"
// }
// ]
// }]
// }`)
expectedAppServiceEnvID := fmt.Sprintf(
"/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/hostingEnvironments/%s",
adminSubscription,
Expand Down Expand Up @@ -226,10 +243,10 @@ func TestTemplate(t *testing.T) {
TfOptions: tfOptions,
Workspace: workspace,
PlanAssertions: nil,
ExpectedResourceCount: 58,
ExpectedResourceCount: 59,
ExpectedResourceAttributeValues: infratests.ResourceDescription{
// "module.keyvault.azurerm_key_vault.keyvault": expectedKeyVault,
// "module.container_registry.azurerm_container_registry.container_registry": expectedAzureContainerRegistry,
"module.keyvault.azurerm_key_vault.keyvault": expectedKeyVault,
"module.container_registry.azurerm_container_registry.container_registry": expectedAzureContainerRegistry,
"azurerm_resource_group.app_rg": expectedAppDevResourceGroup,
"azurerm_resource_group.admin_rg": expectedAdminResourceGroup,
"module.service_plan.azurerm_app_service_plan.svcplan": expectedAppServicePlan,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ variable "app_dev_subscription_id" {
variable "resource_ip_whitelist" {
description = "A list of IPs and/or IP ranges that should have access to VNET isolated resources provisioned by this template"
type = list(string)
default = []
}

# Note: We won't be supporting monitoring rules until we have more direction from the
Expand Down