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" <