-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e: add flag to bootstrap Nomad ACLs (#8961)
Adds a `nomad_acls` flag to our Terraform stack that bootstraps Nomad ACLs via a `local-exec` provider. There's no way to set the `NOMAD_TOKEN` in the Nomad TF provider if we're bootstrapping in the same Terraform stack, so instead of using `resource.nomad_acl_token`, we also bootstrap a wide-open anonymous policy. The resulting management token is exported as an environment var with `$(terraform output environment)` and tests that want stricter ACLs will be able to write them using that token. This should also provide a basis to do similar work with Consul ACLs in the future.
- Loading branch information
Showing
14 changed files
with
128 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace "*" { | ||
policy = "write" | ||
capabilities = ["alloc-node-exec"] | ||
} | ||
|
||
agent { | ||
policy = "write" | ||
} | ||
|
||
operator { | ||
policy = "write" | ||
} | ||
|
||
quota { | ||
policy = "write" | ||
} | ||
|
||
node { | ||
policy = "write" | ||
} | ||
|
||
host_volume "*" { | ||
policy = "write" | ||
} |
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,25 @@ | ||
#!/bin/bash | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
while true : | ||
do | ||
ROOT_TOKEN=$(nomad acl bootstrap | awk '/Secret ID/{print $4}') | ||
if [ ! -z $ROOT_TOKEN ]; then break; fi | ||
sleep 5 | ||
done | ||
set -e | ||
|
||
export NOMAD_TOKEN="$ROOT_TOKEN" | ||
|
||
mkdir -p ../keys | ||
echo $NOMAD_TOKEN > "${DIR}/../keys/nomad_root_token" | ||
|
||
# Our default policy after bootstrapping will be full-access. Without | ||
# further policy, we only test that we're hitting the ACL code | ||
# Tests can set their own ACL policy using the management token so | ||
# long as they clean up the ACLs afterwards. | ||
nomad acl policy apply \ | ||
-description "Anonymous policy (full-access)" \ | ||
anonymous \ | ||
"${DIR}/anonymous.policy.hcl" |
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,5 @@ | ||
### Shared configs | ||
|
||
The only configurations that should go here are ones that we want to be able | ||
to toggle on/off for any profile. Adding a new configuration here requires | ||
adding a flag to the provision scripts as well to symlink it. |
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,3 @@ | ||
acl { | ||
enabled = true | ||
} |
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,29 @@ | ||
# Bootstrapping Nomad ACLs: | ||
# We can't both bootstrap the ACLs and use the Nomad TF provider's | ||
# resource.nomad_acl_token in the same Terraform run, because there's no way | ||
# to get the management token into the provider's environment after we bootstrap. | ||
# So we run a bootstrapping script and write our management token into a file | ||
# that we read in for the output of $(terraform output environment) later. | ||
|
||
resource "null_resource" "bootstrap_nomad_acls" { | ||
depends_on = [module.nomad_server] | ||
triggers = { | ||
script = data.template_file.bootstrap_script.rendered | ||
} | ||
|
||
provisioner "local-exec" { | ||
command = data.template_file.bootstrap_script.rendered | ||
} | ||
} | ||
|
||
# write the bootstrap token to the keys/ directory (where the ssh key is) | ||
# so that we can read it into the data.local_file later. If not set, | ||
# ensure that it's empty. | ||
data "template_file" "bootstrap_script" { | ||
template = var.nomad_acls ? "NOMAD_ADDR=http://${aws_instance.server.0.public_ip}:4646 ./acls/bootstrap-nomad.sh" : "mkdir -p ${path.root}/keys; echo > ${path.root}/keys/nomad_root_token" | ||
} | ||
|
||
data "local_file" "nomad_token" { | ||
depends_on = [null_resource.bootstrap_nomad_acls] | ||
filename = "${path.root}/keys/nomad_root_token" | ||
} |
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
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
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
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