Skip to content

Commit ebc7f08

Browse files
committed
self-hosted-runner: don't use a public IP in a private repository
Security is a game of layers, the less attack surface the better. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 6269149 commit ebc7f08

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

.github/workflows/create-azure-self-hosted-runners.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ jobs:
176176
base64 -w 0 tmp.zip
177177
)"
178178
179+
PUBLIC_IP_ADDRESS_NAME1="${{ github.repository_visibility != 'private' && format('{0}-ip', steps.generate-vm-name.outputs.vm_name) || '' }}"
180+
179181
AZURE_ARM_PARAMETERS=$(tr '\n' ' ' <<-END
180182
githubActionsRunnerRegistrationUrl="$ACTIONS_RUNNER_REGISTRATION_URL"
181183
githubActionsRunnerToken="$ACTIONS_RUNNER_TOKEN"
@@ -184,7 +186,7 @@ jobs:
184186
virtualMachineImage="$AZURE_VM_IMAGE"
185187
virtualMachineName="${{ steps.generate-vm-name.outputs.vm_name }}"
186188
virtualMachineSize="$AZURE_VM_TYPE"
187-
publicIpAddressName1="${{ steps.generate-vm-name.outputs.vm_name }}-ip"
189+
publicIpAddressName1="$PUBLIC_IP_ADDRESS_NAME1"
188190
adminUsername="${{ secrets.AZURE_VM_USERNAME }}"
189191
adminPassword="${{ secrets.AZURE_VM_PASSWORD }}"
190192
ephemeral="$EPHEMERAL_RUNNER"

azure-self-hosted-runners/azure-arm-template.json

+12-9
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,14 @@
125125
"vnetName": "[concat(parameters('virtualMachineName'), '-vnet')]",
126126
"vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', concat(parameters('virtualMachineName'), '-vnet'))]",
127127
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
128-
"postDeploymentScriptArguments": "[concat('-GitHubActionsRunnerToken ', parameters('githubActionsRunnerToken'), ' -GithubActionsRunnerRegistrationUrl ', parameters('githubActionsRunnerRegistrationUrl'), ' -GithubActionsRunnerName ', parameters('virtualMachineName'), ' -Ephemeral ', parameters('ephemeral'), ' -StopService ', parameters('stopService'), ' -GitHubActionsRunnerPath ', parameters('githubActionsRunnerPath'))]"
128+
"postDeploymentScriptArguments": "[concat('-GitHubActionsRunnerToken ', parameters('githubActionsRunnerToken'), ' -GithubActionsRunnerRegistrationUrl ', parameters('githubActionsRunnerRegistrationUrl'), ' -GithubActionsRunnerName ', parameters('virtualMachineName'), ' -Ephemeral ', parameters('ephemeral'), ' -StopService ', parameters('stopService'), ' -GitHubActionsRunnerPath ', parameters('githubActionsRunnerPath'))]",
129+
"publicIpAddressName1": "[if(equals(parameters('publicIpAddressName1'), ''), 'dummy', parameters('publicIpAddressName1'))]",
130+
"publicIpAddressId": {
131+
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName1'))]",
132+
"properties": {
133+
"deleteOption": "[parameters('pipDeleteOption')]"
134+
}
135+
}
129136
},
130137
"resources": [
131138
{
@@ -136,7 +143,7 @@
136143
"dependsOn": [
137144
"[concat('Microsoft.Network/networkSecurityGroups/', variables('nsgName'))]",
138145
"[concat('Microsoft.Network/virtualNetworks/', variables('vnetName'))]",
139-
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName1'))]"
146+
"[concat('Microsoft.Network/publicIpAddresses/', variables('publicIpAddressName1'))]"
140147
],
141148
"properties": {
142149
"ipConfigurations": [
@@ -147,12 +154,7 @@
147154
"id": "[variables('subnetRef')]"
148155
},
149156
"privateIPAllocationMethod": "Dynamic",
150-
"publicIpAddress": {
151-
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName1'))]",
152-
"properties": {
153-
"deleteOption": "[parameters('pipDeleteOption')]"
154-
}
155-
}
157+
"publicIpAddress": "[if(not(equals(parameters('publicIpAddressName1'), '')), variables('publicIpAddressId'), null())]"
156158
}
157159
}
158160
],
@@ -184,7 +186,8 @@
184186
}
185187
},
186188
{
187-
"name": "[parameters('publicIpAddressName1')]",
189+
"condition": "[not(equals(parameters('publicIpAddressName1'), ''))]",
190+
"name": "[variables('publicIpAddressName1')]",
188191
"type": "Microsoft.Network/publicIpAddresses",
189192
"apiVersion": "2020-08-01",
190193
"location": "[parameters('location')]",

0 commit comments

Comments
 (0)