Skip to content

Commit

Permalink
Defender security profile - preview not enabled in subscriptions. (#196)
Browse files Browse the repository at this point in the history
* Update StandardCI.yml

* using union for properties
* added note to AKS issue
  • Loading branch information
Gordon Byers authored Feb 8, 2022
1 parent 6086eea commit ce14328
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 91 deletions.
35 changes: 10 additions & 25 deletions .github/workflows/StandardCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ on:
#Run on Manual execution
workflow_dispatch:

#Run when our bicep code changes
push:
paths:
- "bicep/*"

#Run when PR's are made to main, where the changes are in the bicep directory or this workflow file itself
pull_request:
branches: [main]
Expand All @@ -24,7 +19,7 @@ on:
# At 11:00pm, every Tuesday week
- cron: "0 23 * * 2"
env:
RG: "Automation-Actions-AksDeployStanCI" #The resource group we're deploying to.
RG: "AksBicepAcc-Ci-BasicCluster" #The resource group we're deploying to.
ParamFilePath: ".github/workflows_dep/AksDeploy-Basic.parameters.json" #Path to parameter file
RESNAME: "AksStan" #Used in Azure Resource Naming, overrides the default in the parameter file
DEPNAME: "Dep${{ github.run_number }}" #Deployment Name
Expand All @@ -33,6 +28,7 @@ env:
jobs:
Validation:
runs-on: ubuntu-latest
environment: csu
if: ${{ !github.event.pull_request.head.repo.fork }}

steps:
Expand Down Expand Up @@ -73,16 +69,14 @@ jobs:
with:
azcliversion: ${{ env.AZCLIVERSION }}
inlineScript: |
RG='${{ env.RG }}'
RESNAME='${{ env.RESNAME }}'
DEPNAME='Dep${{ github.run_number }}'
az account show --query name -o tsv
az deployment group validate -f bicep/main.bicep -g $RG -p ${{ env.ParamFilePath }} -p resourceName=$RESNAME
Deploy:
runs-on: ubuntu-latest
environment: csu
needs: [Validation]
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/develop'
environment: azurecirgs
outputs:
AKSNAME: ${{ steps.deployAks.outputs.AKSNAME}}
steps:
Expand All @@ -102,9 +96,6 @@ jobs:
with:
azcliversion: ${{ env.AZCLIVERSION }}
inlineScript: |
RG='${{ env.RG }}'
RESNAME='${{ env.RESNAME }}'
DEPNAME='Dep${{ github.run_number }}'
az deployment group create -f bicep/main.bicep -g $RG -p ${{ env.ParamFilePath }} -p resourceName=$RESNAME --name $DEPNAME --verbose
DEPSTATUS=$(az deployment operation group list --resource-group $RG --name $DEPNAME) #--query "[?properties.provisioningState=='Failed']"
Expand All @@ -113,12 +104,12 @@ jobs:
#outputs
AKSNAME=$(az deployment group show -n $DEPNAME -g $RG --query "properties.outputs.aksClusterName.value" -o tsv)
echo "AKSName returned from az deployment = $AKSNAME"
echo "::set-output name=AKSNAME::$AKSNAME" #outputting for conditon
echo "::set-output name=AKSNAME::$AKSNAME"
SmokeTest_SimpleApp:
runs-on: ubuntu-latest
environment: csu
needs: [Deploy]
environment: azurecirgs
steps:
- uses: actions/checkout@v2

Expand All @@ -130,17 +121,10 @@ jobs:
environment: azurecloud
allow-no-subscriptions: false

# - name: AKS Connect
# uses: Azure/aks-set-context@v1
# with:
# creds: '${{ secrets.AZURE_CREDENTIALS }}'
# cluster-name: ${{ needs.Deploy.outputs.AKSNAME }}
# resource-group: ${{ env.RG }}

- name: AKS Connect
run: |
AKSNAME='${{ needs.Deploy.outputs.AKSNAME}}'
az aks get-credentials -n $AKSNAME -g $RG --overwrite-existing
env:
AKSNAME: ${{ needs.Deploy.outputs.AKSNAME}}
run: az aks get-credentials -n $AKSNAME -g $RG --overwrite-existing

- name: Kubelogin
env:
Expand Down Expand Up @@ -180,6 +164,7 @@ jobs:
Cleanup:
runs-on: ubuntu-latest
environment: csu
needs: [Validation, Deploy, SmokeTest_SimpleApp]
if: github.event_name == 'schedule'
steps:
Expand Down
37 changes: 10 additions & 27 deletions bicep/compiled/main.json

Large diffs are not rendered by default.

84 changes: 45 additions & 39 deletions bicep/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -1017,48 +1017,54 @@ var aks_identity = {
}
}

var aksProperties = {
kubernetesVersion: kubernetesVersion
enableRBAC: true
dnsPrefix: dnsPrefix
aadProfile: enable_aad ? {
managed: true
enableAzureRBAC: enableAzureRBAC
tenantID: aad_tenant_id
} : null
apiServerAccessProfile: !empty(authorizedIPRanges) ? {
authorizedIPRanges: authorizedIPRanges
} : {
enablePrivateCluster: enablePrivateCluster
privateDNSZone: enablePrivateCluster ? 'none' : ''
enablePrivateClusterPublicFQDN: enablePrivateCluster
}
agentPoolProfiles: agentPoolProfiles
networkProfile: {
loadBalancerSku: 'standard'
networkPlugin: networkPlugin
#disable-next-line BCP036 //Disabling validation of this parameter to cope with empty string to indicate no Network Policy required.
networkPolicy: networkPolicy
podCidr: podCidr
serviceCidr: serviceCidr
dnsServiceIP: dnsServiceIP
dockerBridgeCidr: dockerBridgeCidr
}
disableLocalAccounts: AksDisableLocalAccounts && enable_aad
autoUpgradeProfile: !empty(upgradeChannel) ? {
upgradeChannel: upgradeChannel
} : {}
addonProfiles: !empty(aks_addons5) ? aks_addons5 : {}
}

@description('Needing to seperately declare and union this because of https://github.com/Azure/AKS/issues/2774')
var azureDefenderSecurityProfile = {
securityProfile : {
azureDefender: {
enabled: true
logAnalyticsWorkspaceResourceId: aks_law.id
}
}
}

resource aks 'Microsoft.ContainerService/managedClusters@2021-10-01' = {
name: 'aks-${resourceName}'
location: location
properties: {
kubernetesVersion: kubernetesVersion
enableRBAC: true
dnsPrefix: dnsPrefix
aadProfile: enable_aad ? {
managed: true
enableAzureRBAC: enableAzureRBAC
tenantID: aad_tenant_id
} : null
apiServerAccessProfile: !empty(authorizedIPRanges) ? {
authorizedIPRanges: authorizedIPRanges
} : {
enablePrivateCluster: enablePrivateCluster
privateDNSZone: enablePrivateCluster ? 'none' : ''
enablePrivateClusterPublicFQDN: enablePrivateCluster
}
agentPoolProfiles: agentPoolProfiles
networkProfile: {
loadBalancerSku: 'standard'
networkPlugin: networkPlugin
#disable-next-line BCP036 //Disabling validation of this parameter to cope with empty string to indicate no Network Policy required.
networkPolicy: networkPolicy
podCidr: podCidr
serviceCidr: serviceCidr
dnsServiceIP: dnsServiceIP
dockerBridgeCidr: dockerBridgeCidr
}
disableLocalAccounts: AksDisableLocalAccounts && enable_aad
securityProfile: {
azureDefender: {
enabled: DefenderForContainers && omsagent
logAnalyticsWorkspaceResourceId: DefenderForContainers && omsagent ? aks_law.id : json('null')
}
}
autoUpgradeProfile: !empty(upgradeChannel) ? {
upgradeChannel: upgradeChannel
} : {}
addonProfiles: !empty(aks_addons5) ? aks_addons5 : {}
}
properties: DefenderForContainers && omsagent ? union(aksProperties,azureDefenderSecurityProfile) : aksProperties
identity: aks_byo_identity ? aks_identity : {
type: 'SystemAssigned'
}
Expand Down

0 comments on commit ce14328

Please sign in to comment.