Skip to content

Commit 699bfbd

Browse files
authored
Add Python to Codespaces & Test
1 parent 17366e3 commit 699bfbd

File tree

18 files changed

+205
-1
lines changed

18 files changed

+205
-1
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ jobs:
3838
runCmd: |
3939
./amzn/setup
4040
./amzn/test
41+
- name: Build & Run Development Container (w/ Python)
42+
uses: devcontainers/ci@v0.2
43+
with:
44+
env: |
45+
AWS_ACCESS_KEY_ID
46+
AWS_SECRET_ACCESS_KEY
47+
AWS_SESSION_TOKEN
48+
AWS_DEFAULT_REGION
49+
AWS_REGION
50+
imageName: ghcr.io/customink/crypteia-devcontainer
51+
runCmd: |
52+
./py27/setup
53+
./py27/test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/package/package.zip
55
/package/packaged.yaml
66
outputs.json
7+
python/crypteia/build
8+
python/crypteia/src/*.egg-info

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- `ltrace` for debugging
13+
- Patch Python's `os.environ` if `PYTHONPATH` is set accordingly. Needed for Crypteia's binary to work in Python environments.
1314

1415
### Changed
1516

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# 🛡 Crypteia
44

5-
![Node](https://shields.io/badge/x-Node.js-x?logo=node.js&style=plastic&color=339933&label=&labelColor=white) ![Ruby](https://shields.io/badge/x-Ruby-x?logo=ruby&style=plastic&color=CC342D&label=&labelColor=white&logoColor=CC342D) ![PHP](https://shields.io/badge/x-PHP-x?logo=php&style=plastic&color=777BB4&label=&labelColor=white)
5+
![Node](https://shields.io/badge/x-Node.js-x?logo=node.js&style=plastic&color=339933&label=&labelColor=white) ![Ruby](https://shields.io/badge/x-Ruby-x?logo=ruby&style=plastic&color=CC342D&label=&labelColor=white&logoColor=CC342D) ![PHP](https://shields.io/badge/x-PHP-x?logo=php&style=plastic&color=777BB4&label=&labelColor=white) ![Python](https://shields.io/badge/x-Python-x?logo=python&style=plastic&color=3776AB&label=&labelColor=white)
66

77
## Rust Lambda Extension for any Runtime to preload SSM Parameters as Secure Environment Variables!
88

@@ -61,6 +61,12 @@ COPY libcrypteia.so /opt/lib/libcrypteia.so
6161
ENV LD_PRELOAD=/opt/lib/libcrypteia.so
6262
```
6363

64+
If you are using Python you will need to add our Crypteia python package to the PYTHONPATH in order for things to "just work". The result of this will be that `os.environ["SECRET"]`, `os.environ.get("SECRET")`, and `os.getenv("SECRET")` will be routed to the `getenv` system call and therefore take advantage of the Crypteia rust extension.
65+
66+
```dockerfile
67+
ENV PYTHONPATH=${PYTHONPATH:/opt/crypteia/python}
68+
```
69+
6470
⚠️ When building your own Lambda Containers, please make sure [glibc](https://www.gnu.org/software/libc/) is installed since this is used by [redhook](https://github.com/geofft/redhook).
6571

6672
#### Lambda Extension

bin/build-arch

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ rm -rf "./build/${BIN}"
88
rm -rf "./build/${BIN}.zip"
99
rm -rf "./build/{$LIB}"
1010
rm -rf "./build/libcrypteia-${BUILD_ARCH}.zip"
11+
rm -rf ./build/crypteia
12+
rm -rf ./build/crypteia*.egg-info
13+
rm -rf ./build/crypteia*.dist-info
14+
rm -rf ./build/wrapt*
15+
rm -rf ./python/crypteia/build
16+
rm -rf ./python/crypteia/src/crypteia.egg-info
1117

1218
cargo build \
1319
--release \
@@ -28,3 +34,12 @@ mkdir -p ./package/opt/extensions
2834
mkdir -p ./package/opt/lib
2935
cp "./build/crypteia-${BUILD_ARCH}" ./package/opt/extensions/crypteia
3036
cp "./build/libcrypteia-${BUILD_ARCH}.so" ./package/opt/lib/libcrypteia.so
37+
38+
cd ./python/crypteia && pip install . --target ../../build --upgrade && cd ../..
39+
cp ./python/usercustomize.py ./build/
40+
41+
mkdir -p ./package/opt/crypteia/python/crypteia
42+
cp -r ./build/crypteia/ ./package/opt/crypteia/python/
43+
cp -r ./build/crypteia-*.dist-info ./package/opt/crypteia/python/
44+
cp -r ./build/wrapt/ ./package/opt/crypteia/python/crypteia/
45+
cp ./python/usercustomize.py ./package/opt/crypteia/python/usercustomize.py

bin/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ fi
88
TEST_LANG=node ./test/libcrypteia.sh
99
TEST_LANG=ruby ./test/libcrypteia.sh
1010
TEST_LANG=php ./test/libcrypteia.sh
11+
TEST_LANG=python ./test/libcrypteia.sh

py27/Dockerfile-test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM ubuntu:20.04
2+
3+
ENV SHELL=/bin/sh
4+
5+
RUN apt update \
6+
&& apt-get install -y curl \
7+
&& apt-get install -y python2.7 python2.7-dev \
8+
&& update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
9+
10+
RUN curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py \
11+
&& python get-pip.py \
12+
&& pip install --upgrade pip \
13+
&& apt-get clean \
14+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
15+
16+
COPY ./package/opt /opt
17+
18+
ENV BUILD_ARCH=debian
19+
ENV SKIP_CARGO_TEST=1
20+
21+
ENV EXISTING=existingvalue
22+
ENV LD_PRELOAD=/opt/lib/libcrypteia.so
23+
ENV PYTHONPATH=/opt/crypteia/python

py27/setup

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "== [py27/Dockerfile-test] building... =="
5+
docker build --tag crypteia-debian-py27-test --file py27/Dockerfile-test .

py27/test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "== [py27/Dockerfile-test] bin/test =="
5+
docker run \
6+
--rm \
7+
--user root \
8+
--env TEST_LANG=python \
9+
--entrypoint "./test/libcrypteia.sh" \
10+
--volume "${PWD}:/var/task" \
11+
--workdir "/var/task" \
12+
crypteia-debian-py27-test \
13+
sh

python/crypteia/setup.cfg

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[metadata]
2+
name = crypteia
3+
author = Custom Ink (https://customink.com)
4+
description = Crypteia
5+
license = MIT
6+
url = https://github.com/customink/crypteia
7+
classifiers =
8+
Programming Language :: Python :: 2
9+
Programming Language :: Python :: 2.7
10+
Programming Language :: Python :: 3
11+
12+
[options]
13+
package_dir =
14+
= src
15+
packages = find:
16+
python_requires = >=2.7
17+
18+
[options.packages.find]
19+
where = src

0 commit comments

Comments
 (0)