-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable mtls by default by using smallstep as local pki
Signed-off-by: Reuben Miller <reuben.d.miller@gmail.com>
- Loading branch information
1 parent
afd896e
commit bda2c0e
Showing
10 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# Enroll device with mtls | ||
PROVISION_PASSWORD_FILE=/tmp/provisioner-password | ||
if [ -n "$PROVISION_PASSWORD" ]; then | ||
printf -- '%s' "$PROVISION_PASSWORD" > "$PROVISION_PASSWORD_FILE" | ||
chmod 600 "$PROVISION_PASSWORD_FILE" | ||
fi | ||
(cd /tmp && sudo /usr/bin/enroll.sh --no-inherit-env --provisioner-password-file "$PROVISION_PASSWORD_FILE") | ||
rm -f "$PROVISION_PASSWORD_FILE" | ||
|
||
# start agent | ||
exec /usr/bin/tedge-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tedge ALL = (ALL) NOPASSWD: /usr/bin/step-ca-admin.sh, /usr/bin/step-ca, /usr/sbin/update-ca-certificates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
set -ex | ||
|
||
systemctl enable tedge-agent | ||
systemctl restart tedge-agent | ||
systemctl start tedge-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
INHERIT_ENV=${INHERIT_ENV:-1} | ||
|
||
OLD_PWD="$(pwd)" | ||
cd /etc | ||
|
||
while [ $# -gt 0 ]; do | ||
case "$1" in | ||
--inherit-env) | ||
INHERIT_ENV=1 | ||
;; | ||
--no-inherit-env) | ||
INHERIT_ENV=0 | ||
;; | ||
--provisioner-password-file) | ||
PROVISION_PASSWORD_FILE="$2" | ||
shift | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ "$INHERIT_ENV" = 1 ]; then | ||
# Create env file from PID 1 | ||
# (as this is the old service which inherits the container environment variables) | ||
echo "Loading environment from PID 1" | ||
tr '\0' '\n' </proc/1/environ \ | ||
| grep -v "^\(_\|HOME\|PATH\|TERM\|HOSTNAME\|PWD\|SHLVL\)=" | tee > /etc/container.env | ||
|
||
# Load env | ||
# shellcheck disable=SC1091 | ||
. /etc/container.env | ||
fi | ||
|
||
|
||
PROVISION_PASSWORD="${PROVISION_PASSWORD:-}" | ||
PROVISION_PASSWORD_FILE=${PROVISION_PASSWORD_FILE:-/etc/provisioner_password} | ||
if [ -n "$PROVISION_PASSWORD" ]; then | ||
printf -- '%s' "$PROVISION_PASSWORD" > "$PROVISION_PASSWORD_FILE" | ||
chmod 600 "$PROVISION_PASSWORD_FILE" | ||
fi | ||
|
||
enroll_device() { | ||
# Enable downloading of root cert (this can be trusted when running in a controlled container env) | ||
if [ -f "$PROVISION_PASSWORD_FILE" ]; then | ||
/usr/bin/step-ca-admin.sh enroll "$(hostname)" \ | ||
--ca-url https://tedge:8443 \ | ||
--allow-insecure-root \ | ||
--provisioner-password-file "$PROVISION_PASSWORD_FILE" | ||
else | ||
/usr/bin/step-ca-admin.sh enroll "$(hostname)" \ | ||
--ca-url https://tedge:8443 \ | ||
--allow-insecure-root | ||
fi | ||
} | ||
|
||
while :; do | ||
if enroll_device; then | ||
echo "Enrollment was successful" | ||
exit 0 | ||
fi | ||
sleep 2 | ||
done | ||
|
||
# restore previous working directory | ||
cd "$OLD_PWD" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
set -e | ||
# | ||
# Initialize the local pki | ||
# | ||
|
||
# Create env file from PID 1 | ||
# (as this is the old service which inherits the container environment variables) | ||
echo "Loading environment from PID 1" | ||
tr '\0' '\n' </proc/1/environ \ | ||
| grep -v "^\(_\|HOME\|PATH\|TERM\|HOSTNAME\|PWD\|SHLVL\)=" | tee > /etc/container.env | ||
|
||
# Load and export env | ||
set -a | ||
# shellcheck disable=SC1091 | ||
. /etc/container.env | ||
set +a | ||
|
||
step-ca-init.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters