Skip to content

Commit ce14328

Browse files
author
Gordon Byers
authored
Defender security profile - preview not enabled in subscriptions. (#196)
* Update StandardCI.yml * using union for properties * added note to AKS issue
1 parent 6086eea commit ce14328

File tree

3 files changed

+65
-91
lines changed

3 files changed

+65
-91
lines changed

.github/workflows/StandardCI.yml

+10-25
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ on:
77
#Run on Manual execution
88
workflow_dispatch:
99

10-
#Run when our bicep code changes
11-
push:
12-
paths:
13-
- "bicep/*"
14-
1510
#Run when PR's are made to main, where the changes are in the bicep directory or this workflow file itself
1611
pull_request:
1712
branches: [main]
@@ -24,7 +19,7 @@ on:
2419
# At 11:00pm, every Tuesday week
2520
- cron: "0 23 * * 2"
2621
env:
27-
RG: "Automation-Actions-AksDeployStanCI" #The resource group we're deploying to.
22+
RG: "AksBicepAcc-Ci-BasicCluster" #The resource group we're deploying to.
2823
ParamFilePath: ".github/workflows_dep/AksDeploy-Basic.parameters.json" #Path to parameter file
2924
RESNAME: "AksStan" #Used in Azure Resource Naming, overrides the default in the parameter file
3025
DEPNAME: "Dep${{ github.run_number }}" #Deployment Name
@@ -33,6 +28,7 @@ env:
3328
jobs:
3429
Validation:
3530
runs-on: ubuntu-latest
31+
environment: csu
3632
if: ${{ !github.event.pull_request.head.repo.fork }}
3733

3834
steps:
@@ -73,16 +69,14 @@ jobs:
7369
with:
7470
azcliversion: ${{ env.AZCLIVERSION }}
7571
inlineScript: |
76-
RG='${{ env.RG }}'
77-
RESNAME='${{ env.RESNAME }}'
78-
DEPNAME='Dep${{ github.run_number }}'
72+
az account show --query name -o tsv
7973
az deployment group validate -f bicep/main.bicep -g $RG -p ${{ env.ParamFilePath }} -p resourceName=$RESNAME
8074
8175
Deploy:
8276
runs-on: ubuntu-latest
77+
environment: csu
8378
needs: [Validation]
8479
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/develop'
85-
environment: azurecirgs
8680
outputs:
8781
AKSNAME: ${{ steps.deployAks.outputs.AKSNAME}}
8882
steps:
@@ -102,9 +96,6 @@ jobs:
10296
with:
10397
azcliversion: ${{ env.AZCLIVERSION }}
10498
inlineScript: |
105-
RG='${{ env.RG }}'
106-
RESNAME='${{ env.RESNAME }}'
107-
DEPNAME='Dep${{ github.run_number }}'
10899
az deployment group create -f bicep/main.bicep -g $RG -p ${{ env.ParamFilePath }} -p resourceName=$RESNAME --name $DEPNAME --verbose
109100
110101
DEPSTATUS=$(az deployment operation group list --resource-group $RG --name $DEPNAME) #--query "[?properties.provisioningState=='Failed']"
@@ -113,12 +104,12 @@ jobs:
113104
#outputs
114105
AKSNAME=$(az deployment group show -n $DEPNAME -g $RG --query "properties.outputs.aksClusterName.value" -o tsv)
115106
echo "AKSName returned from az deployment = $AKSNAME"
116-
echo "::set-output name=AKSNAME::$AKSNAME" #outputting for conditon
107+
echo "::set-output name=AKSNAME::$AKSNAME"
117108
118109
SmokeTest_SimpleApp:
119110
runs-on: ubuntu-latest
111+
environment: csu
120112
needs: [Deploy]
121-
environment: azurecirgs
122113
steps:
123114
- uses: actions/checkout@v2
124115

@@ -130,17 +121,10 @@ jobs:
130121
environment: azurecloud
131122
allow-no-subscriptions: false
132123

133-
# - name: AKS Connect
134-
# uses: Azure/aks-set-context@v1
135-
# with:
136-
# creds: '${{ secrets.AZURE_CREDENTIALS }}'
137-
# cluster-name: ${{ needs.Deploy.outputs.AKSNAME }}
138-
# resource-group: ${{ env.RG }}
139-
140124
- name: AKS Connect
141-
run: |
142-
AKSNAME='${{ needs.Deploy.outputs.AKSNAME}}'
143-
az aks get-credentials -n $AKSNAME -g $RG --overwrite-existing
125+
env:
126+
AKSNAME: ${{ needs.Deploy.outputs.AKSNAME}}
127+
run: az aks get-credentials -n $AKSNAME -g $RG --overwrite-existing
144128

145129
- name: Kubelogin
146130
env:
@@ -180,6 +164,7 @@ jobs:
180164
181165
Cleanup:
182166
runs-on: ubuntu-latest
167+
environment: csu
183168
needs: [Validation, Deploy, SmokeTest_SimpleApp]
184169
if: github.event_name == 'schedule'
185170
steps:

bicep/compiled/main.json

+10-27
Large diffs are not rendered by default.

bicep/main.bicep

+45-39
Original file line numberDiff line numberDiff line change
@@ -1017,48 +1017,54 @@ var aks_identity = {
10171017
}
10181018
}
10191019

1020+
var aksProperties = {
1021+
kubernetesVersion: kubernetesVersion
1022+
enableRBAC: true
1023+
dnsPrefix: dnsPrefix
1024+
aadProfile: enable_aad ? {
1025+
managed: true
1026+
enableAzureRBAC: enableAzureRBAC
1027+
tenantID: aad_tenant_id
1028+
} : null
1029+
apiServerAccessProfile: !empty(authorizedIPRanges) ? {
1030+
authorizedIPRanges: authorizedIPRanges
1031+
} : {
1032+
enablePrivateCluster: enablePrivateCluster
1033+
privateDNSZone: enablePrivateCluster ? 'none' : ''
1034+
enablePrivateClusterPublicFQDN: enablePrivateCluster
1035+
}
1036+
agentPoolProfiles: agentPoolProfiles
1037+
networkProfile: {
1038+
loadBalancerSku: 'standard'
1039+
networkPlugin: networkPlugin
1040+
#disable-next-line BCP036 //Disabling validation of this parameter to cope with empty string to indicate no Network Policy required.
1041+
networkPolicy: networkPolicy
1042+
podCidr: podCidr
1043+
serviceCidr: serviceCidr
1044+
dnsServiceIP: dnsServiceIP
1045+
dockerBridgeCidr: dockerBridgeCidr
1046+
}
1047+
disableLocalAccounts: AksDisableLocalAccounts && enable_aad
1048+
autoUpgradeProfile: !empty(upgradeChannel) ? {
1049+
upgradeChannel: upgradeChannel
1050+
} : {}
1051+
addonProfiles: !empty(aks_addons5) ? aks_addons5 : {}
1052+
}
1053+
1054+
@description('Needing to seperately declare and union this because of https://github.com/Azure/AKS/issues/2774')
1055+
var azureDefenderSecurityProfile = {
1056+
securityProfile : {
1057+
azureDefender: {
1058+
enabled: true
1059+
logAnalyticsWorkspaceResourceId: aks_law.id
1060+
}
1061+
}
1062+
}
1063+
10201064
resource aks 'Microsoft.ContainerService/managedClusters@2021-10-01' = {
10211065
name: 'aks-${resourceName}'
10221066
location: location
1023-
properties: {
1024-
kubernetesVersion: kubernetesVersion
1025-
enableRBAC: true
1026-
dnsPrefix: dnsPrefix
1027-
aadProfile: enable_aad ? {
1028-
managed: true
1029-
enableAzureRBAC: enableAzureRBAC
1030-
tenantID: aad_tenant_id
1031-
} : null
1032-
apiServerAccessProfile: !empty(authorizedIPRanges) ? {
1033-
authorizedIPRanges: authorizedIPRanges
1034-
} : {
1035-
enablePrivateCluster: enablePrivateCluster
1036-
privateDNSZone: enablePrivateCluster ? 'none' : ''
1037-
enablePrivateClusterPublicFQDN: enablePrivateCluster
1038-
}
1039-
agentPoolProfiles: agentPoolProfiles
1040-
networkProfile: {
1041-
loadBalancerSku: 'standard'
1042-
networkPlugin: networkPlugin
1043-
#disable-next-line BCP036 //Disabling validation of this parameter to cope with empty string to indicate no Network Policy required.
1044-
networkPolicy: networkPolicy
1045-
podCidr: podCidr
1046-
serviceCidr: serviceCidr
1047-
dnsServiceIP: dnsServiceIP
1048-
dockerBridgeCidr: dockerBridgeCidr
1049-
}
1050-
disableLocalAccounts: AksDisableLocalAccounts && enable_aad
1051-
securityProfile: {
1052-
azureDefender: {
1053-
enabled: DefenderForContainers && omsagent
1054-
logAnalyticsWorkspaceResourceId: DefenderForContainers && omsagent ? aks_law.id : json('null')
1055-
}
1056-
}
1057-
autoUpgradeProfile: !empty(upgradeChannel) ? {
1058-
upgradeChannel: upgradeChannel
1059-
} : {}
1060-
addonProfiles: !empty(aks_addons5) ? aks_addons5 : {}
1061-
}
1067+
properties: DefenderForContainers && omsagent ? union(aksProperties,azureDefenderSecurityProfile) : aksProperties
10621068
identity: aks_byo_identity ? aks_identity : {
10631069
type: 'SystemAssigned'
10641070
}

0 commit comments

Comments
 (0)