Skip to content

Commit

Permalink
specs: support aws assume role
Browse files Browse the repository at this point in the history
All pipeline jobs are moving away from direct AWS access to access
via a service-user that can assume a role with privileges.
See cloudfoundry/buildpacks-ci#318

The pipeline for the specs test is currently red. This change doesn't
attempt to fix that.
  • Loading branch information
arjun024 authored and robdimsdale committed Oct 4, 2023
1 parent b54badc commit 2d87ac6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ The project backlog is on [Pivotal Tracker](https://www.pivotaltracker.com/proje

# Running the tests

The integration test suite includes specs that test the functionality for building [PHP with Oracle client libraries](./PHP-Oracle.md). These tests are tagged `:run_oracle_php_tests` and require access to an S3 bucket containing the Oracle client libraries. This is configured using the environment variables `AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY`
The integration test suite includes specs that test the functionality for building [PHP with Oracle client libraries](./PHP-Oracle.md). These tests are tagged `:run_oracle_php_tests` and require access to an S3 bucket containing the Oracle client libraries. This is configured using the environment variables `AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY`.

Optionally provide `AWS_ASSUME_ROLE_ARN` to assume a role.

If you do not need to test this functionality, exclude the tag `:run_oracle_php_tests` when you run `rspec`.
2 changes: 2 additions & 0 deletions cflinuxfs4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ The project backlog is on [Pivotal Tracker](https://www.pivotaltracker.com/proje

The integration test suite includes specs that test the functionality for building [PHP with Oracle client libraries](./PHP-Oracle.md). These tests are tagged `:run_oracle_php_tests` and require access to an S3 bucket containing the Oracle client libraries. This is configured using the environment variables `AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY`

Optionally provide `AWS_ASSUME_ROLE_ARN` to assume a role.

If you do not need to test this functionality, exclude the tag `:run_oracle_php_tests` when you run `rspec`.
14 changes: 13 additions & 1 deletion cflinuxfs4/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ def setup_oracle_libs(dir_to_contain_oracle)
s3_bucket = ENV['ORACLE_LIBS_AWS_BUCKET']
libs_filename = ENV['ORACLE_LIBS_FILENAME']

system "aws s3 cp s3://#{s3_bucket}/#{libs_filename} ."
## If AWS_ASSUME_ROLE_ARN is provides, switch to aws assume-role mode
if ENV['AWS_ASSUME_ROLE_ARN'] && !ENV['AWS_ASSUME_ROLE_ARN'].empty?
system <<-eof
uuid=$(cat /proc/sys/kernel/random/uuid)
RESULT="$(aws sts assume-role --role-arn "${AWS_ASSUME_ROLE_ARN}" --role-session-name "binary-builder-spec-${uuid}")"
export AWS_ACCESS_KEY_ID="$(echo "${RESULT}" |jq -r .Credentials.AccessKeyId)"
export AWS_SECRET_ACCESS_KEY="$(echo "${RESULT}" |jq -r .Credentials.SecretAccessKey)"
export AWS_SESSION_TOKEN="$(echo "${RESULT}" |jq -r .Credentials.SessionToken)"
aws s3 cp s3://#{s3_bucket}/#{libs_filename} .
eof
else
system "aws s3 cp s3://#{s3_bucket}/#{libs_filename} ."
end
system "tar -xvf #{libs_filename}"
end
end
Expand Down
14 changes: 13 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ def setup_oracle_libs(dir_to_contain_oracle)
s3_bucket = ENV['ORACLE_LIBS_AWS_BUCKET']
libs_filename = ENV['ORACLE_LIBS_FILENAME']

system "aws s3 cp s3://#{s3_bucket}/#{libs_filename} ."
## If AWS_ASSUME_ROLE_ARN is provides, switch to aws assume-role mode
if ENV['AWS_ASSUME_ROLE_ARN'] && !ENV['AWS_ASSUME_ROLE_ARN'].empty?
system <<-eof
uuid=$(cat /proc/sys/kernel/random/uuid)
RESULT="$(aws sts assume-role --role-arn "${AWS_ASSUME_ROLE_ARN}" --role-session-name "binary-builder-spec-${uuid}")"
export AWS_ACCESS_KEY_ID="$(echo "${RESULT}" |jq -r .Credentials.AccessKeyId)"
export AWS_SECRET_ACCESS_KEY="$(echo "${RESULT}" |jq -r .Credentials.SecretAccessKey)"
export AWS_SESSION_TOKEN="$(echo "${RESULT}" |jq -r .Credentials.SessionToken)"
aws s3 cp s3://#{s3_bucket}/#{libs_filename} .
eof
else
system "aws s3 cp s3://#{s3_bucket}/#{libs_filename} ."
end
system "tar -xvf #{libs_filename}"
end
end
Expand Down

0 comments on commit 2d87ac6

Please sign in to comment.