Page MenuHomePhabricator

D10214.id24577.diff
No OneTemporary

D10214.id24577.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2744,6 +2744,7 @@
'UserQueryConduitAPIMethod' => 'applications/people/conduit/UserQueryConduitAPIMethod.php',
'UserRemoveStatusConduitAPIMethod' => 'applications/people/conduit/UserRemoveStatusConduitAPIMethod.php',
'UserWhoAmIConduitAPIMethod' => 'applications/people/conduit/UserWhoAmIConduitAPIMethod.php',
+ 'WindowsZeroConf' => 'applications/drydock/blueprint/windows/WindowsZeroConf.php',
),
'function' => array(
'_phabricator_time_format' => 'view/viewutils.php',
@@ -5714,5 +5715,6 @@
'UserQueryConduitAPIMethod' => 'UserConduitAPIMethod',
'UserRemoveStatusConduitAPIMethod' => 'UserConduitAPIMethod',
'UserWhoAmIConduitAPIMethod' => 'UserConduitAPIMethod',
+ 'WindowsZeroConf' => 'Phobject',
),
));
diff --git a/src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php b/src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
--- a/src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
+++ b/src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
@@ -95,6 +95,11 @@
$i++;
}
+ if ($this->getDetail('platform') === 'windows') {
+ $settings['UserData'] = id(new WindowsZeroConf())
+ ->getEncodedUserData($credential);
+ }
+
$result = $this->getAWSEC2Future()
->setRawAWSQuery(
'RunInstances',
diff --git a/src/applications/drydock/blueprint/windows/WindowsZeroConf.php b/src/applications/drydock/blueprint/windows/WindowsZeroConf.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/blueprint/windows/WindowsZeroConf.php
@@ -0,0 +1,98 @@
+<?php
+
+final class WindowsZeroConf extends Phobject {
+
+ public function getEncodedUserData(PassphraseCredential $credential) {
+ return base64_encode($this->getUserData($credential));
+ }
+
+ private function getUserData(PassphraseCredential $credential) {
+
+ $type = PassphraseCredentialType::getTypeByConstant(
+ $credential->getCredentialType());
+ if (!$type) {
+ throw new Exception(pht('Credential has invalid type "%s"!', $type));
+ }
+
+ if (!$type->hasPublicKey()) {
+ throw new Exception(pht('Credential has no public key!'));
+ }
+
+ $username = $credential->getUsername();
+ $publickey = $type->getPublicKey(
+ PhabricatorUser::getOmnipotentUser(),
+ $credential);
+ $publickey = trim($publickey);
+
+ $username = str_replace('"', '`"', $username);
+ $publickey = str_replace('"', '`"', $publickey);
+
+ $start = '<powershell>';
+
+ $data = <<<EOF
+
+\$username = "$username";
+\$publickey = "$publickey";
+EOF;
+
+ $script = <<<'EOF'
+
+# Create Cygwin64 directory
+mkdir C:\cygwin64
+
+# Download Cygwin64
+wget https://s3-us-west-2.amazonaws.com/windows-build-agent/CygwinPack.zip `
+ -OutFile C:\CygwinPack.zip
+
+# Extract Cygwin64
+$shell = new-object -com shell.application
+$zip = $shell.NameSpace("C:\CygwinPack.zip")
+foreach($item in $zip.items())
+{
+ $shell.Namespace("C:\cygwin64").copyhere($item)
+}
+
+# Setup SSHD
+$env:PATH = $env:PATH + ";c:\cygwin64\bin"
+C:\cygwin64\bin\chmod.exe +r /etc/passwd
+C:\cygwin64\bin\chmod.exe +r /etc/group
+C:\cygwin64\bin\chmod.exe a+x /var
+C:\cygwin64\bin\mkpasswd.exe -l > C:\cygwin64\etc\passwd
+C:\cygwin64\bin\bash.exe C:\cygwin64\bin\ssh-host-config -y -w SSHPRIV1@
+
+$objOu = [ADSI]"WinNT://localhost"
+$objUser = $objOU.Create("User", $username)
+$objUser.setpassword("SSHPRIV1@")
+$objUser.SetInfo()
+
+C:\cygwin64\bin\mkpasswd.exe > C:\cygwin64\etc\passwd
+
+mkdir C:\cygwin64\home\$username\.ssh
+
+$keyline = "$publickey Automatically Defined Key"
+
+Set-Content `
+ -Path C:\cygwin64\home\$username\.ssh\authorized_keys `
+ -Value $keyline
+
+New-NetFirewallRule -DisplayName "SSHD" `
+ -Direction Inbound –Protocol TCP –LocalPort 22 -Action allow
+
+Set-Service sshd -StartupType Automatic
+
+$sshd_config = Get-Content -Path C:\cygwin64\etc\sshd_config
+$sshd_config = $sshd_config.Replace( `
+ "UsePrivilegeSeparation sandbox", `
+ "UsePrivilegeSeparation no")
+Set-Content -Path C:\cygwin64\etc\sshd_config -Value $sshd_config
+
+Start-Service sshd
+
+</powershell>
+EOF;
+
+ return $start . $data . $script;
+ }
+
+}
+

File Metadata

Mime Type
text/plain
Expires
Wed, May 7, 11:27 AM (1 d, 13 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7731872
Default Alt Text
D10214.id24577.diff (4 KB)

Event Timeline