-
Notifications
You must be signed in to change notification settings - Fork 3
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
Buildpack is converted to a supply buildpack #19
Changes from 5 commits
4e3a0e2
c111b2b
c173b80
c087ae0
be53ec3
8df828a
615bdbc
7fb322e
9a2076a
120b145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
#!/bin/bash -e | ||
# bin/compile <build-dir> | ||
#!/bin/bash | ||
|
||
echo "[cyberark-conjur-buildpack]: compiling" | ||
# bin/compile is currently required, even though it's deprecated. This is likely a bug. | ||
|
||
BUILD_DIR=$1 | ||
BIN_DIR=$(cd $(dirname $0); pwd) | ||
BUILDPACK_DIR=$(dirname $BIN_DIR) | ||
|
||
pushd ${BUILD_DIR} | ||
mkdir -p .profile.d vendor | ||
cp ${BUILDPACK_DIR}/vendor/conjur-env ./vendor/conjur-env | ||
cp ${BUILDPACK_DIR}/lib/0001_retrieve-secrets.sh ./.profile.d/0001_retrieve-secrets.sh | ||
popd | ||
exit | ||
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash -e | ||
# bin/supply <build-dir> <cache-dir> <deps-dir> <index> | ||
|
||
BUILD_DIR=$1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be helpful to add a quick comment for each of the directories and their purpose/role, either here or in the README. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comments. |
||
CACHE_DIR=$2 | ||
DEPS_DIR=$3 | ||
INDEX_DIR=$4 | ||
|
||
BIN_DIR=$(cd $(dirname $0); pwd) | ||
BUILDPACK_DIR=$(dirname $BIN_DIR) | ||
|
||
echo "[cyberark-conjur-buildpack]: supplying" | ||
|
||
if [ ! -f $BUILD_DIR/secrets.yml ]; then | ||
echo "No secrets.yml file found in $BUILD_DIR." | ||
exit 1 | ||
fi | ||
|
||
if [[ false = $(echo $VCAP_SERVICES | jq 'has("cyberark-conjur")') ]]; then | ||
echo "No credentials for cyberark-conjur service found in VCAP_SERVICES." | ||
exit 1 | ||
fi | ||
|
||
pushd ${DEPS_DIR}/${INDEX_DIR} | ||
# We add the lib/0001_retrieve-secrets.sh script to .profile.d so that it will | ||
# be run automatically to retrieve secrets when the app starts. | ||
mkdir -p .profile.d | ||
cp ${BUILDPACK_DIR}/lib/0001_retrieve-secrets.sh ./.profile.d/0001_retrieve-secrets.sh | ||
sed "s/__BUILDPACK_INDEX__/$INDEX_DIR/g" ./.profile.d/0001_retrieve-secrets.sh -i | ||
|
||
# conjur-env reads a secrets.yml file and uses it to retrieve secrets from | ||
# Conjur. We copy it to the dependency directory to make it accessible to the | ||
# /.profile.d script. The /vendor subdirectory is just for convenience. | ||
mkdir -p vendor | ||
cp ${BUILDPACK_DIR}/vendor/conjur-env ./vendor/conjur-env | ||
popd |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ Feature: profile d scripts without the buildpack | |
|
||
@BUILD_DIR | ||
Scenario: Populates environment with secrets from Conjur | ||
Given the compile script is run against the app's root folder | ||
Given the build directory has a secrets.yml file | ||
And VCAP_SERVICES contains cyberark-conjur credentials | ||
And the supply script is run against the app's root folder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also have two tests that validate what happens when
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These conditions are already tested in the |
||
And conjur-env is installed | ||
And a root policy: | ||
""" | ||
|
@@ -26,7 +28,7 @@ Feature: profile d scripts without the buildpack | |
CONJUR_MULTI_LINE_SECRET: !var conjur_multi_line_secret_id | ||
LITERAL_SECRET: some literal secret | ||
""" | ||
When the .profile.d scripts are sourced | ||
When the retrieve secrets .profile.d script is sourced | ||
And the 'env' command is run | ||
Then the environment contains | ||
""" | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ Feature: profile d script | |
|
||
@BUILD_DIR | ||
Scenario: Populates environment with secrets from Conjur | ||
Given the 'compile' script is run | ||
Given the build directory has a secrets.yml file | ||
And VCAP_SERVICES contains cyberark-conjur credentials | ||
And the supply script is run against the app's root folder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here, should we test when the conditions are not right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm this feature appears to be identical to the buildpackless one. They use different step definitions on |
||
And conjur-env is installed | ||
And a root policy: | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
When(/^the retrieve secrets \.profile\.d script is sourced$/) do | ||
@commands ||= [] | ||
@commands << <<EOL | ||
. #{@BUILD_DIR}/.profile.d/0001_retrieve-secrets.sh #{@BUILD_DIR} | ||
HOME=#{@BUILD_DIR} DEPS_DIR=#{@DEPS_DIR} . #{@DEPS_DIR}/#{@INDEX_DIR}/.profile.d/0001_retrieve-secrets.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment here explaining the reason for passing in HOME / DEPS_DIR and the syntax being used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, added a comment. |
||
EOL | ||
end | ||
|
||
Then(/^the environment contains$/) do |text| | ||
expect(@output).to include(text) | ||
end | ||
|
||
When(/^the \.profile\.d scripts are sourced$/) do | ||
@commands ||= [] | ||
@commands << <<EOL | ||
. #{@BUILD_DIR}/.profile.d/0001_retrieve-secrets.sh #{@BUILD_DIR} | ||
EOL | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Feature: Supply script | ||
Supply script installs conjur-env and .profile.d script | ||
|
||
@BUILD_DIR | ||
Scenario: Successfully installs conjur-env and .profile.d scripts | ||
Given the build directory has a secrets.yml file | ||
And VCAP_SERVICES contains cyberark-conjur credentials | ||
When the supply script is run against the app's root folder | ||
Then the result should have a 0 exit status | ||
And conjur-env is installed | ||
And the retrieve secrets .profile.d script is installed | ||
|
||
@BUILD_DIR | ||
Scenario: When the app does not have a secrets.yml file | ||
When the supply script is run against the app's root folder | ||
Then the result should have a 1 exit status | ||
|
||
@BUILD_DIR | ||
Scenario: When VCAP_SERVICES does not have Conjur credentials | ||
Given the build directory has a secrets.yml file | ||
And VCAP_SERVICES does not have a cyberark-conjur key | ||
When the supply script is run against the app's root folder | ||
Then the result should have a 1 exit status |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,16 +25,17 @@ trap 'err_report $LINENO' ERR | |
#} | ||
#' | ||
|
||
# making sure that no tracing takes place, we're dealing with secrets here :) | ||
# Prevent tracing to ensures secrets won't be leaked. | ||
declare xtrace="" | ||
case $- in | ||
(*x*) xtrace="xtrace";; | ||
esac | ||
set +x | ||
|
||
# inject secrets into environment | ||
pushd $1 | ||
eval "$(./vendor/conjur-env)" | ||
# $HOME points to the app directory, which should contains a secrets.yml file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there documentation we can link to that will share how we know HOME and DEPS_DIR will be set when this script is run? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately no. This is knowledge I gained from the examples linked to in Slack conversations (and the conversations themselves). This seems to be quite poorly documented. |
||
pushd $HOME | ||
# __BUILDPACK_INDEX__ is replaced by sed in the 'supply' script. | ||
eval "$($DEPS_DIR/__BUILDPACK_INDEX__/vendor/conjur-env)" | ||
popd | ||
|
||
[ ! -z "$xtrace" ] && set -x | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding the newline here at the end?