From 2356c2543f09cd9d780fd1dc657c0892f78efc07 Mon Sep 17 00:00:00 2001 From: Jim Wang Date: Sun, 28 Feb 2021 14:47:11 -0700 Subject: [PATCH] build(snap): Add implementation for set up Consul ACL - Add token for consul secret engine in snap - Add env. for ACL enable: ENABLE_REGISTRY_ACL: true - Add env. for consul secret engine admin token: SECRETSTORE_CONSULSECRETSADMINTOKENPATH - Add logic for copying the needed configuration toml from security-bootstrapper - Add consul-bootstrapper one-shot service for setting up Consul's ACL - Add feature flag logic in start_consul.sh shell script - Add env. overrides for consul-bootstrapper - Make consul-bootstrapper use shell script as command to run setupRegistryACL Closes: #3222 Signed-off-by: Jim Wang --- snap/hooks/install | 10 +++-- .../runtime-helpers/bin/setup-consul-acl.sh | 17 +++++++++ .../local/runtime-helpers/bin/start-consul.sh | 31 +++++++++++++++ snap/snapcraft.yaml | 38 +++++++++++++++---- 4 files changed, 84 insertions(+), 12 deletions(-) create mode 100755 snap/local/runtime-helpers/bin/setup-consul-acl.sh diff --git a/snap/hooks/install b/snap/hooks/install index 78a50b6b74..78963959f0 100755 --- a/snap/hooks/install +++ b/snap/hooks/install @@ -14,14 +14,16 @@ for service in security-file-token-provider security-proxy-setup security-secret if [ ! -f "$SNAP_DATA/config/$service/res/configuration.toml" ]; then mkdir -p "$SNAP_DATA/config/$service/res" - # for security-bootstrapper, we only need the configureRedis subcommand portion and associated + # for security-bootstrapper, we have two different configuration toml, one for bootstrap-redis and one for security-bootstrapper itself + # the bootstrap-redis run the configureRedis subcommand portion and associated # configuration.toml file + # the bootstrap-consul or consul-bootstrapper runs the setupRegistryACL subcommand portion and associated configuration.toml file if [ "$service" == "security-bootstrapper" ]; then + mkdir -p "$SNAP_DATA/config/$service/res-bootstrap-redis" cp "$SNAP/config/$service/res-bootstrap-redis/configuration.toml" \ - "$SNAP_DATA/config/$service/res/configuration.toml" - else - cp "$SNAP/config/$service/res/configuration.toml" "$SNAP_DATA/config/$service/res/configuration.toml" + "$SNAP_DATA/config/$service/res-bootstrap-redis/configuration.toml" fi + cp "$SNAP/config/$service/res/configuration.toml" "$SNAP_DATA/config/$service/res/configuration.toml" # replace $SNAP, $SNAP_DATA, $SNAP_COMMON env vars for file-token-provider, # as it doesn't support env var overrides diff --git a/snap/local/runtime-helpers/bin/setup-consul-acl.sh b/snap/local/runtime-helpers/bin/setup-consul-acl.sh new file mode 100755 index 0000000000..a386844e1b --- /dev/null +++ b/snap/local/runtime-helpers/bin/setup-consul-acl.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# note: -e flag is not used in this one-shot service +# we don't want to exit out the whole Consul process when ACL bootstrapping failed, just that +# Consul won't have ACL to be used + +echo "$(date) in setup-consul-acl.sh: ENABLE_REGISTRY_ACL = ${ENABLE_REGISTRY_ACL}" + +if [ "${ENABLE_REGISTRY_ACL}" == "true" ]; then + # setup Consul's ACL via security-bootstrapper's subcommand + "$SNAP"/bin/security-bootstrapper -confdir "$SNAP_DATA"/config/security-bootstrapper/res setupRegistryACL + setupACL_code=$? + if [ "${setupACL_code}" -ne 0 ]; then + echo "$(date) failed to set up Consul ACL" + fi +else + echo "$(date) ACL not enabled, skip Consul's ACL setup" +fi diff --git a/snap/local/runtime-helpers/bin/start-consul.sh b/snap/local/runtime-helpers/bin/start-consul.sh index b4fbe45d77..b1f0a987bb 100755 --- a/snap/local/runtime-helpers/bin/start-consul.sh +++ b/snap/local/runtime-helpers/bin/start-consul.sh @@ -1,5 +1,36 @@ #!/bin/bash -e +echo "$(date) deploying the default EdgeX configuration for Consul" +# the default Consul local configuration is applied to all cases no matter ACL is enabled or not +# note that Consul's DNS port is disabled based on the securing Consul ADR +# https://github.com/edgexfoundry/edgex-docs/blob/master/docs_src/design/adr/security/0017-consul-security.md#phase-1 +cat > "$SNAP_DATA/consul/config/consul_default.json" < "$SNAP_DATA/consul/config/consul_acl.json" <