Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
31c2596
Add circle config. Add decrypt script. Ignore plain and encrypt files
sayadi Aug 26, 2018
999e50f
Fix circle syntax. Print env vars for testing
sayadi Aug 26, 2018
9c663c4
Avoid simplified env var reference
sayadi Aug 26, 2018
b13e514
echo openssl version on the CI engine
sayadi Aug 26, 2018
b8b68dd
Install openssl on the CI
sayadi Aug 26, 2018
5e3dcf5
Install latest openssl
sayadi Aug 26, 2018
8e08001
Install libressl
sayadi Aug 26, 2018
1a94a0f
Install libressl from apt-get
sayadi Aug 26, 2018
b6f2431
Use md5
sayadi Aug 26, 2018
17f53cc
Use sha256
sayadi Aug 26, 2018
02266cc
Use ISO encoding
sayadi Aug 26, 2018
5c5b40d
Change password
sayadi Aug 26, 2018
f7ea63d
Use proper password. Remove echo openssl version
sayadi Aug 26, 2018
dbf923f
Use shorter password
sayadi Aug 26, 2018
3f04cc1
Add the encrypt script to source code
sayadi Aug 26, 2018
699e0e0
git-ignore: Remove the encrypt script
sayadi Aug 26, 2018
2906da3
Rename env script
sayadi Aug 26, 2018
ffa27ae
Try plain with no export
sayadi Aug 27, 2018
d658665
Print vars for testing
sayadi Aug 27, 2018
7778f60
Access env vars in a later step-script
sayadi Aug 27, 2018
db27c2b
Set env vars with export
sayadi Aug 27, 2018
04e79cb
Set vars in the parent shell
sayadi Aug 27, 2018
0630752
Change to correct directory in decrypt step
sayadi Aug 27, 2018
b981576
Source to bash env
sayadi Aug 27, 2018
ec44f8d
Use set script again. Source vars for the current step
sayadi Aug 27, 2018
9a87fd1
Only export to bash env
sayadi Aug 27, 2018
de128f7
Test without export
sayadi Aug 27, 2018
375a571
Change file and script names
sayadi Aug 27, 2018
b8cb807
Change mode of decrypt to +x
sayadi Aug 27, 2018
efa8ba5
Add content to the cipher file
sayadi Aug 27, 2018
b12246c
Change the secret file name in set-env-vars script
sayadi Aug 27, 2018
aac9ba0
Change secret file name in print env script
sayadi Aug 27, 2018
bf6dc01
Change the decrypt command to actaully decrypt
sayadi Aug 27, 2018
bc686af
Change test env var values for testing
sayadi Aug 27, 2018
cc76315
Change the password env var name
sayadi Aug 27, 2018
20455d3
Re-arrange openssl options
sayadi Aug 27, 2018
06179da
Decrypt values
sayadi Aug 27, 2018
2bf27ba
Use proper password
sayadi Aug 27, 2018
67e13e1
Update read me
sayadi Aug 27, 2018
2eddb30
Update read me with the results of the example
sayadi Aug 27, 2018
32c4306
Delete extra space
sayadi Aug 27, 2018
2d5eaeb
Add warning comments in print step
sayadi Aug 27, 2018
2951f0a
Fix typo. Clarify clone step
sayadi Aug 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2
general:
branches:
only:
- master

jobs:
build:

docker:
- image: circleci/openjdk:8-jdk

working_directory: ~/project

steps:

- checkout

- run:
name: Decrypt and source env vars
command: |
cd .circleci
chmod +x set-env-vars.sh
./set-env-vars.sh

- run:
name: Access env vars in another script
command: |
cd .circleci
chmod +x print-env-vars.sh
./print-env-vars.sh
6 changes: 6 additions & 0 deletions .circleci/decrypt-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

openssl aes-256-cbc -d -md sha256 \
-in env.cipher \
-out env.generated \
-pass env:CIRCLE_OPEN_SSL_PASSWORD
6 changes: 6 additions & 0 deletions .circleci/encrypt-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

openssl aes-256-cbc -e -md sha256 \
-in env.plain \
-out env.cipher \
-pass env:CIRCLE_OPEN_SSL_PASSWORD
1 change: 1 addition & 0 deletions .circleci/env.cipher
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Salted__�Ѧ�/~�/���q�E�&�d��.�g��q���U`�<
6 changes: 6 additions & 0 deletions .circleci/print-env-vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Printing the values of the env vars for testing and verification.
# Do not do this in a production setup!
# Do not use actual sensitive data for testing!
echo "FOO: ${FOO} BAR: ${BAR}"
6 changes: 6 additions & 0 deletions .circleci/set-env-vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

openssl aes-256-cbc -d -md sha256 \
-in env.cipher \
-pass env:CIRCLE_OPEN_SSL_PASSWORD \
>> $BASH_ENV
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/secret-env-plain
.idea
*.plain
*.generated
99 changes: 91 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,98 @@
# encrypted-files
[![CircleCI](https://circleci.com/gh/muhammed-sayadi/circleci-encrypted-files.svg?style=svg)](https://circleci.com/gh/muhammed-sayadi/circleci-encrypted-files)

This is a simple example of storing encrypted files in source for use in CircleCI builds.
# circleci-encrypted-files

In this example, the gitignored contents of `secret-env-plain` are:
This is a simple example of storing encrypted files in source for use in CircleCI builds, updated to work with
version 2 of Circle.

In this example, the git-ignored contents of `env.plain` are:

```
FOO=secret1
BAR=secret2

```

Checking the build step `Access env vars in another script` on Circle, you can see that the variables were decrypted
and accessed correctly.

## How to Test Yourself

If you'd like to test this for your own project, here's a general step by step on how to re-produce this setup:

1- Fork this repository into your account.

2- Setup Circle project for your newly created repository.

3- In Circle's Project Settings, set the environment variable `CIRCLE_OPEN_SSL_PASSWORD` to a secured password.
Remember this value since you're going to use it later.

4- Clone the repository to your local machine.

5- Set the same environment variable `CIRCLE_OPEN_SSL_PASSWORD` to the same value on your local machine.

6- Create a file called `env.plain` and enter the environment variables you want secured. For example, enter the
following:
```
export FOO=secret
export BAR=alsosecret
FOO=secret3
BAR=secret4

```

If they are encrypted with `openssl aes-256-cbc -e -in secret-env-plain -out secret-env-cipher -k $KEY`, and `$KEY` is set
in the CircleCI project, the variables in `secret-env-plain` will be available in the build.
7- Change directory to the circle directory; where the local encrypt and decrypt scripts are:
```
cd .circleci
```

You could use the same process but replace the `openssl` command in `circle.yml` with `openssl aes-256-cbc -d -in secret-file-cipher -out secret-file-plain -k $KEY` to create plaintext files in the build environment instead of just exporting environment variables.
8- Grant the local encrypt and decrypt scripts execution permissions:
```
chmod +x encrypt-local.sh
chmod +x decrypt-local.sh
```

9- Run the encryption script. This will update the `env.cipher` file with the encrypted values of your `env.plain`:
```
./encrypt-local.sh
```

10- To verify, locally, that decryption would work as expected, run the decrypt script:
```
./decrypt-local.sh
```
This will generate a file called `env.generated`.

11- Check the content of the generated file; `env.generated`. This should match exactly with your `env.plain` content.

12- Open the `print-env-vars.sh` script, and update with your own variables. Please note that if you're forking this
public repository, you will end up with a public repository as well, so avoid testing with actual sensitive data.

If you're following with this example, there's no need to update anything.

13- Commit and push your changes. Note that the only file that would've changed is env.cipher. Note, also, that both
`.plain` and `.generated` extensions are ignored. If you change these, please make sure to update .gitignore as well.

```
# Make sure that only env.cipher is changed.
git status
```

```
# Assuming that you're still in .circleci directory
git add env.cipher
```

```
git commit -m "Updated env vars"
```

```
git push
```

14- Head to Circle's dashboard and check. If everything goes well, you should see your values at the end of the
`Access env vars in another script` step.

If you're following with this example, you should see the values we set in `env.plain`:
```
FOO: secret3 BAR: secret4
```
8 changes: 0 additions & 8 deletions circle.yml

This file was deleted.

Binary file removed secret-env-cipher
Binary file not shown.