diff --git a/bin/supply.bat b/bin/supply.bat new file mode 100644 index 0000000..eaee136 --- /dev/null +++ b/bin/supply.bat @@ -0,0 +1,2 @@ +@echo off +powershell.exe -ExecutionPolicy Unrestricted %~dp0\supply.ps1 %* \ No newline at end of file diff --git a/bin/supply.ps1 b/bin/supply.ps1 new file mode 100644 index 0000000..795f902 --- /dev/null +++ b/bin/supply.ps1 @@ -0,0 +1,30 @@ + +$buildDir=$args[0] +$depsDir=$args[2] +$indexDir=$args[3] + +# Validate that secret.yml exists +if (![System.IO.File]::Exists("$buildDir\secrets.yml")) +{ + echo "Unable to find a secrets.yml...exiting" + exit 1 +} + +# Validate that VCAP_SERVICES contains 'cyberark-conjur' +$vcapJson = echo $env:VCAP_SERVICES | ConvertFrom-Json + +if( !("cyberark-conjur" -in $vcapJson.PSobject.Properties.Name) ) +{ + echo "No credentials for cyberark-conjur service found in VCAP_SERVICES... exit" + exit 1 +} + +pushd $depsDir\$indexDir + mkdir profile.d | Out-Null + copy $PSScriptRoot\..\lib\0001_retrieve-secrets.bat .\profile.d\ +popd + +pushd $buildDir + mkdir .conjur | Out-Null + copy $PSScriptRoot\..\vendor\conjur-win-env.exe .\.conjur\ +popd \ No newline at end of file diff --git a/conjur-env/Dockerfile b/conjur-env/Dockerfile index 789f9f6..0b5d2df 100644 --- a/conjur-env/Dockerfile +++ b/conjur-env/Dockerfile @@ -1,10 +1,6 @@ FROM golang:1.20 MAINTAINER CyberArk Software, Inc. -ENV GOOS=linux \ - GOARCH=amd64 \ - CGO_ENABLED=0 - WORKDIR /conjur-env COPY go.mod go.sum /conjur-env/ diff --git a/conjur-env/build.sh b/conjur-env/build.sh index 935f9bb..04de772 100755 --- a/conjur-env/build.sh +++ b/conjur-env/build.sh @@ -6,3 +6,4 @@ rm -rf ../vendor/conjur-env docker-compose build docker-compose run --rm conjur-env-builder +docker-compose run --rm conjur-win-env-builder diff --git a/conjur-env/docker-compose.yml b/conjur-env/docker-compose.yml index f39bc71..08d782a 100644 --- a/conjur-env/docker-compose.yml +++ b/conjur-env/docker-compose.yml @@ -2,7 +2,21 @@ version: '2.1' services: conjur-env-builder: build: "" + environment: + - GOOS=linux + - GOARCH=amd64 + - CGO_ENABLED=0 volumes: - .:/conjur-env - ../vendor:/pkg command: go build -o /pkg/conjur-env -a -ldflags '-extldflags "-static"' . + conjur-win-env-builder: + build: "" + environment: + - GOOS=windows + - GOARCH=amd64 + - CGO_ENABLED=0 + volumes: + - .:/conjur-env + - ../vendor:/pkg + command: go build -o /pkg/conjur-win-env.exe -a -ldflags '-extldflags "-static"' . \ No newline at end of file diff --git a/lib/0001_retrieve-secrets.bat b/lib/0001_retrieve-secrets.bat new file mode 100644 index 0000000..1e4bf54 --- /dev/null +++ b/lib/0001_retrieve-secrets.bat @@ -0,0 +1,9 @@ +@echo off + +pushd %USERPROFILE%\app + for /f "tokens=1,2 delims=: " %%a in ('.conjur\conjur-win-env.exe') do ( + for /f %%i in ('powershell -executionpolicy Unrestricted -Command "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('%%b'))"') do ( + set %%a=%%i + ) + ) +popd \ No newline at end of file diff --git a/manifest.yml b/manifest.yml index 41333be..5afbc1a 100644 --- a/manifest.yml +++ b/manifest.yml @@ -56,8 +56,12 @@ include_files: - VERSION - bin/compile - bin/supply +- bin/supply.bat +- bin/supply.ps1 - lib/0001_retrieve-secrets.sh +- lib/0001_retrieve-secrets.bat - lib/install_go.sh - vendor/conjur-env +- vendor/conjur-win-env.exe - manifest.yml language: conjur # used solely to name the .zip