Skip to content

Commit ec07c65

Browse files
Merge pull request #287 from SoftwareAG/bpaskalev-base64
add base64 credentials capability
2 parents e2798c7 + eed2167 commit ec07c65

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

templates/sag-spm-boot-winrm/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ sagcc exec templates composite apply sag-spm-boot-winrm nodes=["host1","host2"]
8787

8888
--sync-job --wait 600
8989
```
90+
If there are special characters in the password base64-encoded credentials in the format user:password could be provided as a parameter using -Base64Credentials. The credentials could be encoded with oneliner as described below
91+
For bash(like):
92+
```bash
93+
echo -n 'username:password' | base64
94+
```
95+
For powershell:
96+
```bash
97+
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('username:password'))
98+
```
99+
In that case the bootstrap should be done:
100+
```bash
101+
sagcc exec templates composite apply sag-spm-boot-winrm nodes=["host1","host2"] \
102+
cc.installer=cc-def-10.2-fix1-w64.zip \
103+
install.dir=C:\\SoftwareaAG2 \
104+
spm.port=8292 \
105+
os.base64credentials=****** \
106+
107+
--sync-job --wait 600
108+
```
109+
90110

91111
## Adding a Windows infrastructure layer to a stack
92112

@@ -115,6 +135,7 @@ See [sag-cc-all-layer-defs](../sag-cc-all-layer-defs/template.yaml) for details
115135
* Specify the required parameters, such as:
116136
* os.username - the username of the remote connection account
117137
* os.password - the password of the remote connection account
138+
* os.base64credentials - base64 encoded credentials in the format user:password of the remote connection
118139
* nodes - one or more host names
119140
* install.dir - the remote installation directory
120141
* Finish the wizard

templates/sag-spm-boot-winrm/push-bootstrap.ps1

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ param
2121
[Parameter(Mandatory)]
2222
[ValidateNotNullOrEmpty()]
2323
[string[]]$Computername,
24-
25-
[Parameter(Mandatory)]
26-
[ValidateNotNullOrEmpty()]
24+
2725
[string]$PlainCredentials,
2826

27+
[string]$Base64Credentials,
28+
2929
[string]$RemoteTempPath="c:\temp",
3030

3131
[string]$RemoteInstallPath="c:\softwareag\",
@@ -47,15 +47,26 @@ $InstallerArgs=" -d $RemoteInstallPath -p $AdministratorPassword -s $HttpPort -S
4747
if($AcceptLicense){
4848
$installerArgs+=" --accept-license"
4949
}
50-
if(($PlainCredentials.Length -gt 0 ) -and ($PlainCredentials.Contains(":"))){
50+
if(($PlainCredentials.Length -gt 0 ) -and ($PlainCredentials.Contains(":")) -and ( $PlainCredentials -ne "changeme:changeme" )){
5151
$ruser=$PlainCredentials.Split(":")[0]
5252
$rpass=$PlainCredentials.Split(":")[1]
5353
$srpass=ConvertTo-SecureString -AsPlainText -Force -string $rpass
5454
$credentials=new-object -TypeName System.Management.Automation.PSCredential -ArgumentList $ruser,$srpass
55+
}ElseIf(($Base64Credentials.Length -gt 0) -and ($Base64Credentials -ne "changeme") ){
56+
$Base64Decoded=([Text.Encoding]::ASCII.GetString([Convert]::FromBase64String($Base64Credentials))).trim()
57+
if (!$?){
58+
Write-Host "Invalid base64 encoded string"
59+
exit 1
60+
}
61+
$ruser=$Base64Decoded.Split(":")[0]
62+
$rpass=$Base64Decoded.Split(":")[1]
63+
$srpass=ConvertTo-SecureString -AsPlainText -Force -string $rpass
64+
$credentials=new-object -TypeName System.Management.Automation.PSCredential -ArgumentList $ruser,$srpass
5565
}else{
56-
Write-Host "Wrong format username:pass"
66+
Write-Host "Wrong format username:password"
5767
exit 1
5868
}
69+
5970
foreach ($comp in $computers.Replace("[","").Replace("]","").Replace("`"","").Replace(" ","").trim()){
6071
start-job -ScriptBlock {
6172
param($comp,$cred,$srz,$rtp,$rip,$iar)

templates/sag-spm-boot-winrm/template.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ environments:
2626
# REQUIRED
2727
nodes: ${} # Remote hostnames to bootstrap, e.g ["host1","host2"]
2828
cc.installer: ${} # Command Central bootstrap installer for Windows, e.g. cc-def-10.2-fix1-w64.zip
29-
os.username: ${} # Remote connection user account username
30-
os.password: ${} # Remove connection user account password
29+
os.username: changeme # Remote connection user account username
30+
os.password: changeme # Remove connection user account password
31+
os.base64credentials: changeme # Remote connection credentials in form user:pass base64 encoded
3132

3233
# OPTIONAL
3334
install.dir: C:\SoftwareAG # Remote installation directory
@@ -43,13 +44,13 @@ environments:
4344
description: Bootstrap SPM on remote Windows hosts from Command Central Windows host
4445
phase: pre
4546
script: |
46-
powershell.exe -command ${com.softwareag.install.root}\profiles\CCE\data\templates\composite\sag-spm-boot-winrm\push-bootstrap.ps1 -Computername '${nodes}' -RemoteTempPath ${os.temp.dir} -LocalInstaller ${com.softwareag.install.root}\profiles\CCE\data\installers\${cc.installer} -RemoteInstallPath ${install.dir} -HttpPort ${spm.port} -HttpsPort ${spm.secure.port} -AcceptLicense -PlainCredentials ${os.username}:${os.password}
47+
powershell.exe -command ${com.softwareag.install.root}\profiles\CCE\data\templates\composite\sag-spm-boot-winrm\push-bootstrap.ps1 -Computername '${nodes}' -RemoteTempPath ${os.temp.dir} -LocalInstaller ${com.softwareag.install.root}\profiles\CCE\data\installers\${cc.installer} -RemoteInstallPath ${install.dir} -HttpPort ${spm.port} -HttpsPort ${spm.secure.port} -AcceptLicense -PlainCredentials ${os.username}:${os.password} -Base64Credentials ${os.base64credentials}
4748
bootstrap.sh:
4849
target: POSIX
4950
description: Bootstrap SPM on remote Windows hosts from Command Central Linux/Mac host
5051
phase: pre
5152
script: |
52-
pwsh -f ${com.softwareag.install.root}/profiles/CCE/data/templates/composite/sag-spm-boot-winrm/push-bootstrap.ps1 -Computername '${nodes}' -RemoteTempPath ${os.temp.dir} -LocalInstaller ${com.softwareag.install.root}/profiles/CCE/data/installers/${cc.installer} -RemoteInstallPath ${install.dir} -HttpPort ${spm.port} -HttpsPort ${spm.secure.port} -AcceptLicense -PlainCredentials ${os.username}:${os.password}
53+
pwsh -f ${com.softwareag.install.root}/profiles/CCE/data/templates/composite/sag-spm-boot-winrm/push-bootstrap.ps1 -Computername '${nodes}' -RemoteTempPath ${os.temp.dir} -LocalInstaller ${com.softwareag.install.root}/profiles/CCE/data/installers/${cc.installer} -RemoteInstallPath ${install.dir} -HttpPort ${spm.port} -HttpsPort ${spm.secure.port} -AcceptLicense -PlainCredentials ${os.username}:${os.password} -Base64Credentials ${os.base64credentials}
5354
5455
layers:
5556
infra:

0 commit comments

Comments
 (0)