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

Code ingress with git #611

Closed
wants to merge 164 commits into from
Closed
Show file tree
Hide file tree
Changes from 116 commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
fc6e91f
(broken) Set up two GitLab VMs, "internal" and "external", for code i…
ots22 Apr 23, 2020
3c0aecd
Add a basic cloud init template for gitlab external
jack89roberts Apr 24, 2020
6056af1
Remove debugging print statement and unused variable
jack89roberts Apr 24, 2020
8b8d20c
add network security group rule (InboundDenyAll) for nsgGitlabExternal
nbarlowATI Apr 27, 2020
2ab0fce
Add a user with an API key to gitlab internal
jack89roberts Apr 27, 2020
424bbd3
Add a new session server for holding connections to review boxes
jemrobinson Apr 28, 2020
3f04679
Add SSH key and git setup on gitlab external
jack89roberts Apr 29, 2020
ff48810
WIP Script to update GitLab projects from whitelist
ots22 Apr 29, 2020
8507b63
Updated review session server settings
jemrobinson Apr 28, 2020
7c8d377
Updated RDS deployment configuration
jemrobinson Apr 28, 2020
9a52480
Add gitlab server to gitlab external
jack89roberts May 1, 2020
b9d5788
Updated SRE teardown script
jemrobinson Apr 30, 2020
f8c415a
Removed cw20 configs as we are using testa now
jemrobinson Apr 30, 2020
ccdc93f
WIP script for monitoring and accepting merge requests on gitlab exte…
jack89roberts May 1, 2020
fd62e1f
Merge requests script: Replace print statements with logging
jack89roberts May 4, 2020
f139b2f
Remove localhost token accidentally added in previous commit
jack89roberts May 4, 2020
69df12d
Changed name of test researcher
jemrobinson May 14, 2020
49df919
Updated RDS scripts
jemrobinson May 1, 2020
23a2733
wait for gitlab server health check before interacting with api
jack89roberts May 4, 2020
59d3073
replace bash syntax
jack89roberts May 4, 2020
ab9de4c
Script to create zipfile from specified commit on a git repo, then up…
nbarlowATI May 5, 2020
0881963
couple more shell formatting fixes
jack89roberts May 4, 2020
b5b2337
Add function to create or push to a repo on GITLAB-INTERNAL
ots22 May 4, 2020
53485ba
Remove old update from whitelist script
ots22 May 4, 2020
22f8c4b
add a line break to tidy up logging
jack89roberts May 11, 2020
b511029
add quotes around url in curl command
nbarlowATI May 5, 2020
bddd44d
add python script for creating projects and merge request in gitlab-e…
nbarlowATI May 6, 2020
e3b99ac
don't write curl output to file
nbarlowATI May 6, 2020
d995c47
add container name for blob storage for zipfiles from git repos
nbarlowATI May 6, 2020
c831b0e
Move python script content out of cloud-init yaml file into scripts/ …
nbarlowATI May 7, 2020
46b778d
substitute scripts into cloud init
nbarlowATI May 7, 2020
56cd9ca
temporarily allow 500 status code when creating merge request
nbarlowATI May 7, 2020
bbb965b
check_merge_requests docstrings, comments and formatting
jack89roberts May 11, 2020
a3c0323
Add crontab entries for GitLab scripts
ots22 May 11, 2020
f7dfccc
Switched gitlab airlock container name back to something simple as th…
jemrobinson May 11, 2020
3550638
Fixed typo
jemrobinson May 12, 2020
e4d16e2
Added explicit ConnectionBroker argument as first argument to all RD …
jemrobinson May 15, 2020
bfe7147
Remove unused Set-RDPublishedName script
jemrobinson May 15, 2020
f5eb496
Remove hard-coded drive letters
jemrobinson May 15, 2020
2e45544
refactor script to upload git project to gitlab-external (git clone b…
nbarlowATI May 14, 2020
f9b685a
minor fixes after testing locally
nbarlowATI May 14, 2020
c6c2ca7
Add missing quotation mark
jack89roberts May 15, 2020
9efc447
Use the 'artifacts' resource group for the blob storage when uploadin…
nbarlowATI May 18, 2020
a15a703
protect against non-existing zipfile directory
nbarlowATI May 18, 2020
3bc913c
test using webapps resource group for blob upload
nbarlowATI May 18, 2020
2906264
revert to using artifacts resource group for gitlab zip upload
nbarlowATI May 18, 2020
6182e04
add path to create_gitlab_project to force correct case being preserved
jack89roberts May 18, 2020
bdd6f65
create branch on approval project after fork to unapproved
nbarlowATI May 18, 2020
59761df
Merge branch '264-gitlab-ingress' of https://github.com/alan-turing-i…
nbarlowATI May 18, 2020
d76ab25
fix path for downloading git repo zipfiles on gitlab-external
nbarlowATI May 18, 2020
0fd1356
change ownership of zipfile dir on gitlab-external
nbarlowATI May 18, 2020
e4a3304
check if project already exists before creating on gitlab-external
nbarlowATI May 18, 2020
c639e47
simplifications to how disk is mounted, and fix to gitlab datadisk path
nbarlowATI May 18, 2020
5bd6752
Force path to match case of name in internal_update_repo
jack89roberts May 19, 2020
d70ed67
import Security.psm1 to use Resolve-KeyvaultSecret function
nbarlowATI May 19, 2020
fdef7f2
Robustify zipfile_to_gitlab_project and check_merge_requests to cope …
jack89roberts May 19, 2020
aebd59a
ssh-keyscan localhost instead of external IP address
jack89roberts May 19, 2020
8525dbd
Get gitlab external ssh keys from /etc/ssh/
jack89roberts May 20, 2020
9af6278
Change commit message when importing snapshot of requested repo
ots22 May 20, 2020
8c8b8c5
Use same branch name on source (unapproved) and target (approval) rep…
ots22 May 20, 2020
f4c0a9e
Change public groups and projects to internal
jack89roberts May 21, 2020
162e611
Change default branch and commit a README file to 'approval'
ots22 May 21, 2020
dfd1dc9
Move docstrings into a separate file, to fit within the character lim…
ots22 May 21, 2020
837b2da
Get gitlab internal ssh keys by invoking remote script
jack89roberts May 29, 2020
a4ca583
Remove commented code
ots22 Jun 1, 2020
16573fc
Remove unnecessary logging
ots22 Jun 1, 2020
7e9ab18
Factor return out of if/else
ots22 Jun 1, 2020
1fc2bac
Correct name for the review session host
ots22 Jun 1, 2020
74fd45b
No template substitution in cloud-init runcmd for GitLab API tokens
ots22 Jun 1, 2020
5c1026b
Merge master into 264-gitlab-ingress
ots22 Jun 1, 2020
aa05a61
Factor out deploying empty blob storage container
ots22 Jun 1, 2020
3efe4bc
Log file to match script name
ots22 Jun 1, 2020
1c927b8
start refactoring gitlab secrets files
jack89roberts Jun 2, 2020
6738f75
Merge branch '264-gitlab-ingress' of https://github.com/alan-turing-i…
jack89roberts Jun 2, 2020
c8619c7
Refactor gitlab credentials files and functions
jack89roberts Jun 2, 2020
1b703e5
black python scripts
jack89roberts Jun 2, 2020
7275923
add missing file path argument
jack89roberts Jun 2, 2020
77884e8
fix not updated secrets file location
jack89roberts Jun 2, 2020
f6ec3fa
Changes to creating merge request from unzipped repo
ots22 Jun 3, 2020
9416fba
Update docstrings (after some functions were renamed)
ots22 Jun 5, 2020
db81a4d
Rename Gitlab and Hack MD servers
jack89roberts Jun 5, 2020
ebbe624
Merge branch '264-gitlab-ingress' of https://github.com/alan-turing-i…
jack89roberts Jun 5, 2020
36e464d
Add SRE User documentation for the code ingress process
ots22 Jun 5, 2020
9406ce2
Merge branch '264-gitlab-ingress' of https://github.com/alan-turing-i…
jack89roberts Jun 5, 2020
1b5248b
Fix overwritten vmName variable for gitlab server names
jack89roberts Jun 5, 2020
3f68aae
Update docs/safe_haven_user_guide.md
ots22 Jun 8, 2020
b6cafdd
Update docs/safe_haven_user_guide.md
ots22 Jun 8, 2020
6619fc7
Documentation: overall description of the code ingress process
ots22 Jun 8, 2020
4d91a42
Remove duplicate git clone
ots22 Jun 10, 2020
2f25476
Name 'reviewUsersGroup' consistently with the other group name variables
ots22 Jun 10, 2020
cead499
Add (and use) function for clearing a storage container
ots22 Jun 10, 2020
a878316
Rename some variables in GitLab upload powershell script
ots22 Jun 10, 2020
63e8401
Remove all default IP addresses in the ARM template for RDS hosts/gat…
ots22 Jun 10, 2020
18f37db
Delete misleading comment
ots22 Jun 12, 2020
6b67674
Exit with status code 1 if any error encountered in check_merge_requests
jack89roberts Jun 12, 2020
60a7ab6
Remove work in progress check
jack89roberts Jun 12, 2020
4e733d5
Add effect of thumbs down to readme docs of approval conditions
jack89roberts Jun 12, 2020
1b5f85f
Give ingress users dummy email addresses rather than using the SHM fqdn
jack89roberts Jun 12, 2020
4a01cd4
Add default value for targetRepoName based on sourceGitURL
ots22 Jun 12, 2020
de0c669
Use a temporary container with a unique name to store the repo zipfil…
ots22 Jun 12, 2020
fd72517
Merge branch 'master' into 264-gitlab-ingress
jemrobinson Jun 18, 2020
c2b01c0
Updated NSG rules. Reordered webapp server deployment. Use a stronger…
jemrobinson Jun 19, 2020
ef3ac43
Added gitlab and hackmd daemon users
jemrobinson Jun 19, 2020
cf1c8e6
Updated disk provisioning to native cloud-init syntax
jemrobinson Jun 19, 2020
ad02e44
Switch to using gitlabdaemon for GitLab review server automation
jemrobinson Jun 19, 2020
ae42dc7
Updated to newer version of HackMD. Ensure that service will restart …
jemrobinson Jun 19, 2020
e6716ed
Add a rule to allow inbound SSH from VPN admin subnet
jemrobinson Jun 19, 2020
a2bc238
Updated NSG rules
jemrobinson Jun 19, 2020
0f512c7
WIP: refactor gitlab ingress py and ps1 scripts
ots22 Jun 19, 2020
edbcc1f
Combine review steps scripts in crontab; enforce a single concurrent run
ots22 Jun 25, 2020
cde38a9
Move utilities to gitlab_config.py
ots22 Jun 25, 2020
5811409
WIP: continue refactor of gitlab ingress scripts
ots22 Jun 25, 2020
4514a98
Remove stray pylint headers
ots22 Jun 26, 2020
274c93b
Handle 'successful' 500 and 201 returns in a similar way in merge req…
ots22 Jun 26, 2020
4416003
Adjust crontab entry for gitlab script
ots22 Jun 26, 2020
c147ba7
Lint
ots22 Jun 26, 2020
be37161
Add some docstrings back; remove the 'docstrings only' file
ots22 Jun 26, 2020
2dab934
Revert removal of gitlab_config.py command-line functionality
ots22 Jun 26, 2020
c82dfab
Lint
ots22 Jun 26, 2020
90064ac
Lint
ots22 Jun 26, 2020
c77453d
Flake8: ignore W503 (line break before binary operator)
ots22 Jun 26, 2020
5c858fb
Fix to flake8 config file
ots22 Jun 26, 2020
435b33a
Fix NSG rules
ots22 Jun 26, 2020
b96fc4e
set subnet to airlock (setup webapp servers)
ots22 Jun 29, 2020
9fa64be
Fix to crontab entry (gitlab review scripts)
ots22 Jun 29, 2020
4c3dbca
Store both subnets (WebApp servers)
ots22 Jun 29, 2020
7fc3f86
Log message before slow key retrieval step
ots22 Jun 29, 2020
17ce3b6
Test C region now centralus (was uksouth)
ots22 Jun 29, 2020
44b74ee
Test C region centralus (was uksouth) - full config
ots22 Jun 29, 2020
7acd3e5
Full path to scripts in crontab
ots22 Jun 30, 2020
14a0b9d
Merge branch 'master' into 264-gitlab-ingress
jemrobinson Jul 1, 2020
66964e0
Working ARM template for NSG webapps
jemrobinson Jul 1, 2020
978db16
Added ARM template rules for airlock NSG
jemrobinson Jul 1, 2020
3be6504
Simplified webapp servers deployment flow
jemrobinson Jul 1, 2020
a845ba7
Reflect Azure portal change in deployment (Point-to-Site -> User VPN)
ots22 Jun 30, 2020
71774f8
Allow (not deny) outbound access to GitLab Internal from Gitlab-Review
ots22 Jun 30, 2020
32a4de5
Clarify doc comment
ots22 Jul 2, 2020
ccab24d
Style changes for SRE_Upload_Git_Repo_to_GitlabReview
jemrobinson Jul 2, 2020
f8ee363
Fix removing storage container: needs context; don't prompt user
ots22 Jul 3, 2020
67baafa
Add missing gitlab-rb-host template substitution (fixes inability to …
ots22 Jul 3, 2020
cae41f3
containerName -> tmpContainerName
ots22 Jul 3, 2020
7b844c3
Fix cleaning up resources
ots22 Jul 3, 2020
815f2f0
Fix flag to Remove-AzStorageContainer
ots22 Jul 3, 2020
e832a0b
Merge branch 'master' into 264-gitlab-ingress
jemrobinson Jul 6, 2020
86bba46
Merge branch 'master' into 264-gitlab-ingress
jemrobinson Jul 6, 2020
0018a69
Minor fix to blob storage cleaner
jemrobinson Jul 6, 2020
243980d
RDS fixes from redeploying. Includes a fix to make Deploy_RDS_Environ…
jemrobinson Jul 6, 2020
59b5d08
Removed wait for cloud-init as this is included in the deployment scr…
jemrobinson Jul 6, 2020
6d36d72
Updates from webapps redeploy
jemrobinson Jul 6, 2020
a80cb82
Pass subprocess.run args as a list
ots22 Jul 3, 2020
48d2be3
Use correct LDAP OU for research users on webapp VMs
ots22 Jul 7, 2020
2f505d2
Make the GitLab service user the owner of the zipfiles
ots22 Jul 9, 2020
8041233
Fix: string interpolation
ots22 Jul 9, 2020
a77afc9
Recover from partially-completed run: ensure cloned repo doesn't alre…
ots22 Jul 9, 2020
b7ca0da
Fix: argument order
ots22 Jul 9, 2020
8d477fc
Lint
ots22 Jul 9, 2020
6173b11
Fix typo: gitlabreview -> gitlabReview
ots22 Jul 9, 2020
bb6ca85
Check for correct (created) status code
ots22 Jul 9, 2020
cc4977b
Inline clone, commit and push
ots22 Jul 9, 2020
2ab4d54
gitlabUsername -> gitlabUserIngressUsername for cloud-init substitution
ots22 Jul 9, 2020
678be5b
Partial fix to NSG rules
ots22 Jul 9, 2020
6e7d2a1
Rename NSG rules template; adjust rules
ots22 Jul 16, 2020
3462ba6
Return PSNetworkSecurityGroup object from Add-NetworkSecurityGroupRule
ots22 Jul 16, 2020
53f8e63
Add back rule permitting inbound RDP connections to the webapp NSG
ots22 Jul 22, 2020
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
5 changes: 0 additions & 5 deletions deployment/administration/SHM_Teardown.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ $adDnsRecordname = "@"
Add-LogMessage -Level Info "[ ] Removing '$adDnsRecordname' TXT record from SHM $shmId DNS zone ($shmDomain)"
Remove-AzDnsRecordSet -Name $adDnsRecordname -RecordType TXT -ZoneName $shmDomain -ResourceGroupName $dnsResourceGroup
$success = $?
# # RDS ACME record
# $rdsAcmeDnsRecordname = "_acme-challenge"
# Add-LogMessage -Level Info "[ ] Removing '$rdsAcmeDnsRecordname' TXT record from SRE $sreId DNS zone ($shmDomain)"
# Remove-AzDnsRecordSet -Name $rdsAcmeDnsRecordname -RecordType TXT -ZoneName $shmDomain -ResourceGroupName $dnsResourceGroup
# $success = $success -and $?
# Print success/failure message
if ($success) {
Add-LogMessage -Level Success "Record removal succeeded"
Expand Down
137 changes: 137 additions & 0 deletions deployment/administration/SRE_Upload_Git_Repo_to_GitlabReview.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
param(
[Parameter(Mandatory = $true, HelpMessage = "Enter SRE ID (usually a number e.g enter '9' for DSG9)")]
[string]$sreId,
[Parameter( Mandatory = $true, HelpMessage = "Enter the git URL of the source repository")]
[string]$sourceGitURL,
## interpret the basename of the final path segment in a (possibly encoded) URI as the name of the repository
[Parameter( Mandatory = $false, HelpMessage = "Enter the name of the repository as it should appear within SRE GITLAB (default is the basename of the final path segment of the git URL)")]
[string]$targetRepoName = [uri]::UnescapeDataString((Split-Path -Path ([uri]$sourceGitURL).Segments[-1] -LeafBase)),
[Parameter( Mandatory = $true, HelpMessage = "Enter the full commit hash of the commit in the source repository to snapshot")]
[string]$sourceCommitHash,
[Parameter( Mandatory = $true, HelpMessage = "Enter the desired branch name where the snapshot should be placed (in the repository inside SRE GITLAB)")]
[string]$targetBranchName
)

Import-Module Az
Import-Module $PSScriptRoot/../common/Configuration.psm1 -Force
Import-Module $PSScriptRoot/../common/Security.psm1 -Force
Import-Module $PSScriptRoot/../common/Logging.psm1 -Force
Import-Module $PSScriptRoot/../common/Deployments.psm1 -Force
Import-Module $PSScriptRoot/../common/GenerateSasToken.psm1 -Force

# Get config and original context before changing subscription
# ------------------------------------------------------------
$config = Get-SreConfig $sreId
$originalContext = Get-AzContext
$_ = Set-AzContext -SubscriptionId $config.sre.subscriptionName

# Create local zip file
# ---------------------

# The zipfile is called "repo.zip", with the following contents:
#
# repo/
# sourceGitURL
# targetRepoName
# sourceCommitHash
# targetBranchName
# snapshot/
# ... repository contents


Add-LogMessage -Level Info "Creating zipfilepath."
## $zipFileName = "${targetRepoName}_${sourceCommitHash}_${targetBranchName}.zip"
$zipFileName = "repo.zip"

$tempDir = New-Item -ItemType Directory -Path (Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()))

$repoPath = Join-Path $tempDir "repo"
New-Item -ItemType Directory $repoPath

##
$workingDir = Get-Location
Set-Location $repoPath

Add-LogMessage -Level Info "About to git clone "
git clone $sourceGitURL snapshot

Set-Location "snapshot"

git checkout $sourceCommitHash
# Remove the .git directory
Remove-Item -Path ".git" -Recurse -Force

## Record some metadata about the repository
Set-Location $repoPath
$sourceGitURL > sourceGitURL
$targetRepoName > targetRepoName
$sourceCommitHash > sourceCommitHash
$targetBranchName > targetBranchName

# Zip contents and meta
Set-Location $tempDir

$zipFilePath = Join-Path $tempDir $zipFileName
Compress-Archive -CompressionLevel NoCompression -Path $repoPath -DestinationPath $zipFilePath
if ($?) {
Add-LogMessage -Level Success "Zip file creation succeeded! $zipFilePath"
} else {
Add-LogMessage -Level Fatal "Zip file creation failed!"
}
Set-Location $workingDir


# Upload the zip file to the VM, via blob storage
# -----------------------------------------------

$gitlabReviewVmName = $config.sre.webapps.gitlabreview.vmName
# Go via blob storage - first create storage account if not already there
$storageResourceGroupName = $config.sre.storage.artifacts.rg
$sreStorageAccountName = $config.sre.storage.artifacts.accountName
$sreStorageAccount = Deploy-StorageAccount -Name $sreStorageAccountName -ResourceGroupName $storageResourceGroupName -Location $config.sre.location

# Create a temporary storage container
$containerName = $config.sre.storage.artifacts.containers.gitlabAirlockName + "-" + [Guid]::NewGuid().ToString()

# Ensure an empty storage container of the given name exists
$_ = Deploy-StorageContainer -Name $containerName -StorageAccount $sreStorageAccount

# copy zipfile to blob storage
# ----------------------------
Add-LogMessage -Level Info "Upload zipfile to storage..."

Set-AzStorageBlobContent -Container $containerName -Context $sreStorageAccount.Context -File $zipFilePath -Blob $zipFileName -Force

# Download zipfile onto the remote machine
# ----------------------------------------
# Get a SAS token and construct URL
$sasToken = New-ReadOnlyAccountSasToken -ResourceGroup $storageResourceGroupName -AccountName $sreStorageAccount.StorageAccountName -SubscriptionName $config.sre.subscriptionName
$remoteUrl = "https://$($sreStorageAccount.StorageAccountName).blob.core.windows.net/${containerName}/${zipFileName}${sasToken}"
Add-LogMessage -Level Info "Got SAS token and URL $remoteUrl"

$sreAdminUsername = Resolve-KeyVaultSecret -VaultName $config.sre.keyVault.Name -SecretName $config.sre.keyVault.secretNames.adminUsername -DefaultValue "sre$($config.sre.id)admin".ToLower()

# Create remote script (make a subdirectory of /tmp/zipfiles and run CURL to download blob to there)
$script = @"
#!/bin/bash
mkdir -p /tmp/zipfiles/
tmpdir=`$(mktemp -d /tmp/zipfiles/XXXXXXXXXXXXXXXXXXXX)
curl -X GET -o `$tmpdir/${zipFileName} "${remoteUrl}"

chown -R ${sreAdminUsername}:${sreAdminUsername} /tmp/zipfiles/
"@

$resourceGroupName = $config.sre.webapps.rg
Add-LogMessage -Level Info "[ ] Running remote script to download zipfile onto $gitlabReviewVmName"
$result = Invoke-RemoteScript -Shell "UnixShell" -Script $script -VMName $gitlabReviewVmName -ResourceGroupName $resourceGroupName

# clean up - remove the zipfile from local machine.
Add-LogMessage -Level Info "[ ] Removing original zipfile $zipFilePath"
Remove-Item -Path $zipFilePath
ots22 marked this conversation as resolved.
Show resolved Hide resolved

# Remove the temporary storage container
Remove-AzStorageContainer -Name $containerName

# Switch back to original subscription
# ------------------------------------
$_ = Set-AzContext -Context $originalContext
44 changes: 40 additions & 4 deletions deployment/common/Configuration.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function Add-SreConfig {
$dataAdministratorsGroup = "SG $($config.sre.domain.netbiosName) Data Administrators"
$systemAdministratorsGroup = "SG $($config.sre.domain.netbiosName) System Administrators"
$researchUsersGroup = "SG $($config.sre.domain.netbiosName) Research Users"
$reviewUsersGroup = "SG $($config.sre.domain.netbiosName) Review Users"
$config.sre.domain.securityGroups = [ordered]@{
dataAdministrators = [ordered]@{
name = $dataAdministratorsGroup
Expand All @@ -313,6 +314,10 @@ function Add-SreConfig {
name = $researchUsersGroup
description = $researchUsersGroup
}
reviewUsers = [ordered]@{
name = $reviewUsersGroup
description = $reviewUsersGroup
}
}

# --- Network config ---
Expand Down Expand Up @@ -340,12 +345,20 @@ function Add-SreConfig {
prefix = "${sreBasePrefix}.$([int]$sreThirdOctet + 3)"
nsg = "databases"
}
airlock = [ordered]@{
name = "AirlockSubnet"
prefix = "${sreBasePrefix}.$([int]$sreThirdOctet + 4)"
nsg = "airlock"
}
jemrobinson marked this conversation as resolved.
Show resolved Hide resolved
}
nsg = [ordered]@{
data = [ordered]@{}
databases = [ordered]@{
name = "NSG_SRE_$($config.sre.id)_DATABASES".ToUpper()
}
airlock = [ordered]@{
name = "NSG_SRE_$($config.sre.id)_AIRLOCK".ToUpper()
}
}
}
# Construct the CIDR for each subnet based on the prefix. Using '/24' gives 256 address for each subnet
Expand All @@ -360,6 +373,9 @@ function Add-SreConfig {
artifacts = [ordered]@{
rg = $storageRg
accountName = "sre$($shm.id)artifacts${storageSuffix}".ToLower() | TrimToLength 24
containers = [ordered]@{
gitlabAirlockName = "gitlabairlock"
}
ots22 marked this conversation as resolved.
Show resolved Hide resolved
}
bootdiagnostics = [ordered]@{
rg = $storageRg
Expand All @@ -383,8 +399,14 @@ function Add-SreConfig {
gitlabLdapPassword = "$($config.sre.shortName)-gitlab-ldap-password"
gitlabRootPassword = "$($config.sre.shortName)-gitlab-root-password"
gitlabUserPassword = "$($config.sre.shortName)-gitlab-user-password"
gitlabUsername = "$($config.sre.shortName)-gitlab-username"
gitlabPassword = "$($config.sre.shortName)-gitlab-password"
gitlabAPIToken = "$($config.sre.shortName)-gitlab-api-token"
hackmdLdapPassword = "$($config.sre.shortName)-hackmd-ldap-password"
hackmdUserPassword = "$($config.sre.shortName)-hackmd-user-password"
gitlabReviewUsername = "$($config.sre.shortName)-gitlab-review-username"
gitlabReviewPassword = "$($config.sre.shortName)-gitlab-review-password"
gitlabReviewAPIToken = "$($config.sre.shortName)-gitlab-review-api-token"
letsEncryptCertificate = "$($config.sre.shortName)-lets-encrypt-certificate"
npsSecret = "$($config.sre.shortName)-nps-secret"
postgresDbAdminUsername = "$($config.sre.shortName)-postgresdb-admin-username"
Expand Down Expand Up @@ -434,7 +456,7 @@ function Add-SreConfig {
researchers = [ordered]@{
test = [ordered]@{
name = "$($config.sre.domain.netbiosName) Test Researcher"
samAccountName = "testresrch$($sreConfigBase.sreId)".ToLower() | TrimToLength 20
samAccountName = "researcher$($sreConfigBase.sreId)".ToLower() | TrimToLength 20
jemrobinson marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand All @@ -458,6 +480,11 @@ function Add-SreConfig {
vmSize = "Standard_DS2_v2"
nsg = "NSG_SRE_$($config.sre.id)_RDS_SESSION_HOSTS".ToUpper()
}
sessionHost3 = [ordered]@{
vmName = "REV-SRE-$($config.sre.id)".ToUpper() | TrimToLength 15
vmSize = "Standard_DS2_v2"
nsg = "NSG_SRE_$($config.sre.id)_RDS_SESSION_HOSTS".ToUpper()
}
}

# Set which IPs can access the Safe Haven: if 'default' is given then apply sensible defaults
Expand Down Expand Up @@ -491,6 +518,9 @@ function Add-SreConfig {
$config.sre.rds.sessionHost2.hostname = $config.sre.rds.sessionHost2.vmName
$config.sre.rds.sessionHost2.fqdn = "$($config.sre.rds.sessionHost2.hostname).$($config.shm.domain.fqdn)"
$config.sre.rds.sessionHost2.ip = "$($config.sre.network.subnets.rds.prefix).248"
$config.sre.rds.sessionHost3.hostname = $config.sre.rds.sessionHost3.vmName
$config.sre.rds.sessionHost3.fqdn = "$($config.sre.rds.sessionHost3.hostname).$($config.shm.domain.fqdn)"
$config.sre.rds.sessionHost3.ip = "$($config.sre.network.subnets.rds.prefix).247"

# --- Secure servers ---

Expand All @@ -512,17 +542,24 @@ function Add-SreConfig {
rg = "RG_SRE_WEBAPPS"
nsg = "NSG_SRE_$($config.sre.id)_WEBAPPS".ToUpper()
jemrobinson marked this conversation as resolved.
Show resolved Hide resolved
gitlab = [ordered]@{
vmName = "GITLAB-SRE-$($config.sre.id)".ToUpper()
vmName = "GITLAB-$($config.sre.id)".ToUpper()
vmSize = "Standard_D2s_v3"
}
gitlabreview = [ordered]@{
vmName = "GITLAB-REVIEW-$($config.sre.id)".ToUpper()
vmSize = "Standard_D2s_v3"
}
hackmd = [ordered]@{
vmName = "HACKMD-SRE-$($config.sre.id)".ToUpper()
vmName = "HACKMD-$($config.sre.id)".ToUpper()
vmSize = "Standard_D2s_v3"
}
}
$config.sre.webapps.gitlab.hostname = $config.sre.webapps.gitlab.vmName
$config.sre.webapps.gitlab.fqdn = "$($config.sre.webapps.gitlab.hostname).$($config.shm.domain.fqdn)"
$config.sre.webapps.gitlab.ip = "$($config.sre.network.subnets.data.prefix).151"
$config.sre.webapps.gitlabreview.hostname = $config.sre.webapps.gitlabreview.vmName
$config.sre.webapps.gitlabreview.fqdn = "$($config.sre.webapps.gitlabreview.hostname).$($config.shm.domain.fqdn)"
$config.sre.webapps.gitlabreview.ip = "$($config.sre.network.subnets.airlock.prefix).151"
$config.sre.webapps.hackmd.hostname = $config.sre.webapps.hackmd.vmName
$config.sre.webapps.hackmd.fqdn = "$($config.sre.webapps.hackmd.hostname).$($config.shm.domain.fqdn)"
$config.sre.webapps.hackmd.ip = "$($config.sre.network.subnets.data.prefix).152"
Expand Down Expand Up @@ -603,7 +640,6 @@ function Add-SreConfig {
}

$jsonOut = ($config | ConvertTo-Json -Depth 10)
# Write-Host $jsonOut
Out-File -FilePath $sreFullConfigPath -Encoding "UTF8" -InputObject $jsonOut
}
Export-ModuleMember -Function Add-SreConfig
Expand Down
31 changes: 30 additions & 1 deletion deployment/common/Deployments.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,35 @@ function Deploy-StorageContainer {
Export-ModuleMember -Function Deploy-StorageContainer


# Ensure the specified storage container is empty
# -----------------------------------------------
function Clear-StorageContainer {
param(
[Parameter(Mandatory = $true, HelpMessage = "Name of storage container to clear")]
$Name,
[Parameter(Mandatory = $true, HelpMessage = "Name of storage account where the container exists")]
$StorageAccount
)
# delete existing blobs in the container
$blobs = @(Get-AzStorageBlob -Container $Name -Context $StorageAccount.Context)
$numBlobs = $blobs.Length
if ($numBlobs -gt 0) {
Add-LogMessage -Level Info "[ ] deleting $numBlobs blobs aready in container '$Name'..."
$blobs | ForEach-Object { Remove-AzStorageBlob -Blob $_.Name -Container $Name -Context $StorageAccount.Context -Force }
while ($numBlobs -gt 0) {
Start-Sleep -Seconds 5
$numBlobs = (Get-AzStorageBlob -Container $Name -Context $StorageAccount.Context).Length
}
if ($?) {
Add-LogMessage -Level Success "Blob deletion succeeded"
} else {
Add-LogMessage -Level Fatal "Blob deletion failed!"
}
}
}
Export-ModuleMember -Function Clear-StorageContainer


# Create Linux virtual machine if it does not exist
# -------------------------------------------------
function Deploy-UbuntuVirtualMachine {
Expand Down Expand Up @@ -375,7 +404,7 @@ function Deploy-UbuntuVirtualMachine {
# Add optional data disks
$lun = 0
foreach ($diskId in $DataDiskIds) {
$lun += 1
$lun += 1 # NB. this line means that our first disk gets deployed at lun1 and we do not use lun0. Consider changing this.
$vmConfig = Add-AzVMDataDisk -VM $vmConfig -ManagedDiskId $diskId -CreateOption Attach -Lun $lun
}
Add-LogMessage -Level Info "[ ] Creating virtual machine '$Name'"
Expand Down
Loading