2020-01-13 16:13:07 +00:00
|
|
|
package connect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-01-28 22:33:59 +00:00
|
|
|
"regexp"
|
2020-01-13 16:13:07 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
consulapi "github.com/hashicorp/consul/api"
|
2022-03-18 13:27:28 +00:00
|
|
|
uuidparse "github.com/hashicorp/go-uuid"
|
2020-06-19 18:03:10 +00:00
|
|
|
nomadapi "github.com/hashicorp/nomad/api"
|
2020-01-13 16:13:07 +00:00
|
|
|
"github.com/hashicorp/nomad/e2e/e2eutil"
|
|
|
|
"github.com/hashicorp/nomad/e2e/framework"
|
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
|
|
"github.com/hashicorp/nomad/jobspec"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ConnectACLsE2ETest struct {
|
|
|
|
framework.TC
|
|
|
|
|
2022-03-18 13:27:28 +00:00
|
|
|
// used to store the root token so we can reset the client back to
|
|
|
|
// it as needed
|
2021-04-20 20:23:30 +00:00
|
|
|
consulManagementToken string
|
2020-01-13 16:13:07 +00:00
|
|
|
|
|
|
|
// things to cleanup after each test case
|
|
|
|
jobIDs []string
|
|
|
|
consulPolicyIDs []string
|
|
|
|
consulTokenIDs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *ConnectACLsE2ETest) BeforeAll(f *framework.F) {
|
|
|
|
// Wait for Nomad to be ready before doing anything.
|
|
|
|
e2eutil.WaitForLeader(f.T(), tc.Nomad())
|
|
|
|
e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 2)
|
|
|
|
|
2022-03-18 13:27:28 +00:00
|
|
|
// Validate the consul root token exists, otherwise tests are just
|
2020-01-13 16:13:07 +00:00
|
|
|
// going to be a train wreck.
|
2022-03-18 13:27:28 +00:00
|
|
|
tc.consulManagementToken = os.Getenv(envConsulToken)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2022-03-18 13:27:28 +00:00
|
|
|
_, err := uuidparse.ParseUUID(tc.consulManagementToken)
|
|
|
|
f.NoError(err, "CONSUL_HTTP_TOKEN not set")
|
2022-03-21 15:05:02 +00:00
|
|
|
|
|
|
|
// ensure SI tokens from previous test cases were removed
|
|
|
|
f.Eventually(func() bool {
|
|
|
|
siTokens := tc.countSITokens(f.T())
|
|
|
|
f.T().Log("cleanup: checking for remaining SI tokens:", siTokens)
|
|
|
|
return len(siTokens) == 0
|
|
|
|
}, 2*time.Minute, 2*time.Second, "SI tokens did not get removed")
|
2020-01-13 16:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AfterEach does cleanup of Consul ACL objects that were created during each
|
|
|
|
// test case. Each test case may assume it is starting from a "fresh" state -
|
|
|
|
// as if the consul ACL bootstrap process had just taken place.
|
|
|
|
func (tc *ConnectACLsE2ETest) AfterEach(f *framework.F) {
|
|
|
|
if os.Getenv("NOMAD_TEST_SKIPCLEANUP") == "1" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
// cleanup jobs
|
|
|
|
for _, id := range tc.jobIDs {
|
|
|
|
t.Log("cleanup: deregister nomad job id:", id)
|
|
|
|
_, _, err := tc.Nomad().Jobs().Deregister(id, true, nil)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err)
|
2020-01-13 16:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup consul tokens
|
|
|
|
for _, id := range tc.consulTokenIDs {
|
|
|
|
t.Log("cleanup: delete consul token id:", id)
|
2021-04-20 20:23:30 +00:00
|
|
|
_, err := tc.Consul().ACL().TokenDelete(id, &consulapi.WriteOptions{Token: tc.consulManagementToken})
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err)
|
2020-01-13 16:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup consul policies
|
|
|
|
for _, id := range tc.consulPolicyIDs {
|
|
|
|
t.Log("cleanup: delete consul policy id:", id)
|
2021-04-20 20:23:30 +00:00
|
|
|
_, err := tc.Consul().ACL().PolicyDelete(id, &consulapi.WriteOptions{Token: tc.consulManagementToken})
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err)
|
2020-01-13 16:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// do garbage collection
|
|
|
|
err := tc.Nomad().System().GarbageCollect()
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
// assert there are no leftover SI tokens, which may take a minute to be
|
|
|
|
// cleaned up
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Eventually(func() bool {
|
2020-01-28 22:33:59 +00:00
|
|
|
siTokens := tc.countSITokens(t)
|
|
|
|
t.Log("cleanup: checking for remaining SI tokens:", siTokens)
|
|
|
|
return len(siTokens) == 0
|
|
|
|
}, 2*time.Minute, 2*time.Second, "SI tokens did not get removed")
|
|
|
|
|
2020-01-13 16:13:07 +00:00
|
|
|
tc.jobIDs = []string{}
|
|
|
|
tc.consulTokenIDs = []string{}
|
|
|
|
tc.consulPolicyIDs = []string{}
|
|
|
|
}
|
|
|
|
|
2021-04-20 20:23:30 +00:00
|
|
|
// todo(shoenig): follow up refactor with e2eutil.ConsulPolicy
|
2020-01-13 16:13:07 +00:00
|
|
|
type consulPolicy struct {
|
|
|
|
Name string // e.g. nomad-operator
|
|
|
|
Rules string // e.g. service "" { policy="write" }
|
|
|
|
}
|
|
|
|
|
2021-04-20 20:23:30 +00:00
|
|
|
// todo(shoenig): follow up refactor with e2eutil.ConsulPolicy
|
2020-01-13 16:13:07 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) createConsulPolicy(p consulPolicy, f *framework.F) string {
|
2020-06-19 18:03:10 +00:00
|
|
|
result, _, err := tc.Consul().ACL().PolicyCreate(&consulapi.ACLPolicy{
|
2020-01-13 16:13:07 +00:00
|
|
|
Name: p.Name,
|
|
|
|
Description: "test policy " + p.Name,
|
|
|
|
Rules: p.Rules,
|
2021-04-20 20:23:30 +00:00
|
|
|
}, &consulapi.WriteOptions{Token: tc.consulManagementToken})
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err, "failed to create consul policy")
|
2020-01-13 16:13:07 +00:00
|
|
|
tc.consulPolicyIDs = append(tc.consulPolicyIDs, result.ID)
|
|
|
|
return result.ID
|
|
|
|
}
|
|
|
|
|
2021-04-20 20:23:30 +00:00
|
|
|
// todo(shoenig): follow up refactor with e2eutil.ConsulPolicy
|
2020-01-13 16:13:07 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) createOperatorToken(policyID string, f *framework.F) string {
|
2020-06-19 18:03:10 +00:00
|
|
|
token, _, err := tc.Consul().ACL().TokenCreate(&consulapi.ACLToken{
|
2020-01-13 16:13:07 +00:00
|
|
|
Description: "operator token",
|
2020-06-19 18:03:10 +00:00
|
|
|
Policies: []*consulapi.ACLTokenPolicyLink{{ID: policyID}},
|
2021-04-20 20:23:30 +00:00
|
|
|
}, &consulapi.WriteOptions{Token: tc.consulManagementToken})
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err, "failed to create operator token")
|
2020-01-13 16:13:07 +00:00
|
|
|
tc.consulTokenIDs = append(tc.consulTokenIDs, token.AccessorID)
|
|
|
|
return token.SecretID
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) TestConnectACLsRegisterMasterToken(f *framework.F) {
|
2020-01-24 18:03:08 +00:00
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
t.Log("test register Connect job w/ ACLs enabled w/ master token")
|
|
|
|
|
|
|
|
jobID := "connect" + uuid.Generate()[0:8]
|
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID)
|
|
|
|
|
|
|
|
jobAPI := tc.Nomad().Jobs()
|
|
|
|
|
|
|
|
job, err := jobspec.ParseFile(demoConnectJob)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err)
|
2020-01-24 18:03:08 +00:00
|
|
|
|
|
|
|
// Set the job file to use the consul master token.
|
|
|
|
// One should never do this in practice, but, it should work.
|
|
|
|
// https://www.consul.io/docs/acl/acl-system.html#builtin-tokens
|
2021-04-20 20:23:30 +00:00
|
|
|
job.ConsulToken = &tc.consulManagementToken
|
2022-03-18 13:27:28 +00:00
|
|
|
job.ID = &jobID
|
2020-01-24 18:03:08 +00:00
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
// Avoid using Register here, because that would actually create and run the
|
|
|
|
// Job which runs the task, creates the SI token, which all needs to be
|
|
|
|
// given time to settle and cleaned up. That is all covered in the big slow
|
|
|
|
// test at the bottom.
|
|
|
|
resp, _, err := jobAPI.Plan(job, false, nil)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err)
|
|
|
|
f.NotNil(resp)
|
2020-01-24 18:03:08 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) TestConnectACLsRegisterMissingOperatorToken(f *framework.F) {
|
2020-01-13 16:13:07 +00:00
|
|
|
t := f.T()
|
|
|
|
|
2022-03-18 13:27:28 +00:00
|
|
|
t.Skip("we don't have consul.allow_unauthenticated=false set because it would required updating every E2E test to pass a Consul token")
|
|
|
|
|
2020-01-13 16:13:07 +00:00
|
|
|
t.Log("test register Connect job w/ ACLs enabled w/o operator token")
|
|
|
|
|
2022-03-18 13:27:28 +00:00
|
|
|
jobID := "connect" + uuid.Short()
|
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID) // need to clean up if the test fails
|
|
|
|
|
2020-01-13 16:13:07 +00:00
|
|
|
job, err := jobspec.ParseFile(demoConnectJob)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.NoError(err)
|
2020-01-13 16:13:07 +00:00
|
|
|
jobAPI := tc.Nomad().Jobs()
|
|
|
|
|
|
|
|
// Explicitly show the ConsulToken is not set
|
|
|
|
job.ConsulToken = nil
|
2022-03-18 13:27:28 +00:00
|
|
|
job.ID = &jobID
|
2020-01-13 16:13:07 +00:00
|
|
|
|
|
|
|
_, _, err = jobAPI.Register(job, nil)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Error(err)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
|
|
|
t.Log("job correctly rejected, with error:", err)
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) TestConnectACLsRegisterFakeOperatorToken(f *framework.F) {
|
2020-01-13 16:13:07 +00:00
|
|
|
t := f.T()
|
|
|
|
|
2022-03-18 13:27:28 +00:00
|
|
|
t.Skip("we don't have consul.allow_unauthenticated=false set because it would required updating every E2E test to pass a Consul token")
|
|
|
|
|
2020-01-13 16:13:07 +00:00
|
|
|
t.Log("test register Connect job w/ ACLs enabled w/ operator token")
|
|
|
|
|
|
|
|
policyID := tc.createConsulPolicy(consulPolicy{
|
|
|
|
Name: "nomad-operator-policy",
|
|
|
|
Rules: `service "count-api" { policy = "write" } service "count-dashboard" { policy = "write" }`,
|
|
|
|
}, f)
|
|
|
|
t.Log("created operator policy:", policyID)
|
|
|
|
|
|
|
|
// generate a fake consul token token
|
|
|
|
fakeToken := uuid.Generate()
|
2022-03-18 13:27:28 +00:00
|
|
|
|
|
|
|
jobID := "connect" + uuid.Short()
|
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID) // need to clean up if the test fails
|
|
|
|
|
2020-01-13 16:13:07 +00:00
|
|
|
job := tc.parseJobSpecFile(t, demoConnectJob)
|
|
|
|
|
|
|
|
jobAPI := tc.Nomad().Jobs()
|
|
|
|
|
|
|
|
// deliberately set the fake Consul token
|
|
|
|
job.ConsulToken = &fakeToken
|
2022-03-18 13:27:28 +00:00
|
|
|
job.ID = &jobID
|
2020-01-13 16:13:07 +00:00
|
|
|
|
|
|
|
// should fail, because the token is fake
|
|
|
|
_, _, err := jobAPI.Register(job, nil)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Error(err)
|
2020-01-13 16:13:07 +00:00
|
|
|
t.Log("job correctly rejected, with error:", err)
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) TestConnectACLsConnectDemo(f *framework.F) {
|
2020-01-13 16:13:07 +00:00
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
t.Log("test register Connect job w/ ACLs enabled w/ operator token")
|
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
// === Setup ACL policy and mint Operator token ===
|
2020-01-13 16:13:07 +00:00
|
|
|
|
|
|
|
// create a policy allowing writes of services "count-api" and "count-dashboard"
|
|
|
|
policyID := tc.createConsulPolicy(consulPolicy{
|
|
|
|
Name: "nomad-operator-policy",
|
|
|
|
Rules: `service "count-api" { policy = "write" } service "count-dashboard" { policy = "write" }`,
|
|
|
|
}, f)
|
|
|
|
t.Log("created operator policy:", policyID)
|
|
|
|
|
|
|
|
// create a Consul "operator token" blessed with the above policy
|
|
|
|
operatorToken := tc.createOperatorToken(policyID, f)
|
|
|
|
t.Log("created operator token:", operatorToken)
|
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectJob, jobID, operatorToken)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Equal(2, len(allocs), "expected 2 allocs for connect demo", allocs)
|
2020-06-19 18:03:10 +00:00
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Equal(2, len(allocIDs), "expected 2 allocIDs for connect demo", allocIDs)
|
2020-06-19 18:03:10 +00:00
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
2020-01-27 19:52:53 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
// === Check Consul SI tokens were generated for sidecars ===
|
|
|
|
foundSITokens := tc.countSITokens(t)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Equal(2, len(foundSITokens), "expected 2 SI tokens total: %v", foundSITokens)
|
|
|
|
f.Equal(1, foundSITokens["connect-proxy-count-api"], "expected 1 SI token for connect-proxy-count-api: %v", foundSITokens)
|
|
|
|
f.Equal(1, foundSITokens["connect-proxy-count-dashboard"], "expected 1 SI token for connect-proxy-count-dashboard: %v", foundSITokens)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
t.Log("connect legacy job with ACLs enable finished")
|
|
|
|
}
|
2020-01-28 22:33:59 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) TestConnectACLsConnectNativeDemo(f *framework.F) {
|
|
|
|
t := f.T()
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
t.Log("test register Connect job w/ ACLs enabled w/ operator token")
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
// === Setup ACL policy and mint Operator token ===
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
// create a policy allowing writes of services "uuid-fe" and "uuid-api"
|
|
|
|
policyID := tc.createConsulPolicy(consulPolicy{
|
|
|
|
Name: "nomad-operator-policy",
|
|
|
|
Rules: `service "uuid-fe" { policy = "write" } service "uuid-api" { policy = "write" }`,
|
|
|
|
}, f)
|
|
|
|
t.Log("created operator policy:", policyID)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
// create a Consul "operator token" blessed with the above policy
|
|
|
|
operatorToken := tc.createOperatorToken(policyID, f)
|
|
|
|
t.Log("created operator token:", operatorToken)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectNativeJob, jobID, operatorToken)
|
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
// === Check Consul SI tokens were generated for native tasks ===
|
2020-01-28 22:33:59 +00:00
|
|
|
foundSITokens := tc.countSITokens(t)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Equal(2, len(foundSITokens), "expected 2 SI tokens total: %v", foundSITokens)
|
|
|
|
f.Equal(1, foundSITokens["frontend"], "expected 1 SI token for frontend: %v", foundSITokens)
|
|
|
|
f.Equal(1, foundSITokens["generate"], "expected 1 SI token for generate: %v", foundSITokens)
|
2020-01-28 22:33:59 +00:00
|
|
|
|
2020-11-25 20:30:22 +00:00
|
|
|
t.Log("connect native job with ACLs enabled finished")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *ConnectACLsE2ETest) TestConnectACLsConnectIngressGatewayDemo(f *framework.F) {
|
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
t.Log("test register Connect Ingress Gateway job w/ ACLs enabled")
|
|
|
|
|
|
|
|
// setup ACL policy and mint operator token
|
|
|
|
|
|
|
|
policyID := tc.createConsulPolicy(consulPolicy{
|
|
|
|
Name: "nomad-operator-policy",
|
|
|
|
Rules: `service "my-ingress-service" { policy = "write" } service "uuid-api" { policy = "write" }`,
|
|
|
|
}, f)
|
|
|
|
operatorToken := tc.createOperatorToken(policyID, f)
|
|
|
|
t.Log("created operator token:", operatorToken)
|
|
|
|
|
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID)
|
|
|
|
|
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectIngressGateway, jobID, operatorToken)
|
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
|
|
|
|
|
|
|
foundSITokens := tc.countSITokens(t)
|
2020-11-30 14:48:40 +00:00
|
|
|
f.Equal(2, len(foundSITokens), "expected 2 SI tokens total: %v", foundSITokens)
|
|
|
|
f.Equal(1, foundSITokens["connect-ingress-my-ingress-service"], "expected 1 SI token for connect-ingress-my-ingress-service: %v", foundSITokens)
|
|
|
|
f.Equal(1, foundSITokens["generate"], "expected 1 SI token for generate: %v", foundSITokens)
|
2020-11-25 20:30:22 +00:00
|
|
|
|
|
|
|
t.Log("connect ingress gateway job with ACLs enabled finished")
|
2020-01-28 22:33:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 20:38:33 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) TestConnectACLsConnectTerminatingGatewayDemo(f *framework.F) {
|
|
|
|
t := f.T()
|
|
|
|
|
|
|
|
t.Log("test register Connect Terminating Gateway job w/ ACLs enabled")
|
|
|
|
|
|
|
|
// setup ACL policy and mint operator token
|
|
|
|
|
|
|
|
policyID := tc.createConsulPolicy(consulPolicy{
|
|
|
|
Name: "nomad-operator-policy",
|
|
|
|
Rules: `service "api-gateway" { policy = "write" } service "count-dashboard" { policy = "write" }`,
|
|
|
|
}, f)
|
|
|
|
operatorToken := tc.createOperatorToken(policyID, f)
|
|
|
|
t.Log("created operator token:", operatorToken)
|
|
|
|
|
|
|
|
jobID := connectJobID()
|
|
|
|
tc.jobIDs = append(tc.jobIDs, jobID)
|
|
|
|
|
|
|
|
allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectTerminatingGateway, jobID, operatorToken)
|
|
|
|
allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs)
|
|
|
|
e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs)
|
|
|
|
|
|
|
|
foundSITokens := tc.countSITokens(t)
|
|
|
|
f.Equal(2, len(foundSITokens), "expected 2 SI tokens total: %v", foundSITokens)
|
|
|
|
f.Equal(1, foundSITokens["connect-terminating-api-gateway"], "expected 1 SI token for connect-terminating-api-gateway: %v", foundSITokens)
|
|
|
|
f.Equal(1, foundSITokens["connect-proxy-count-dashboard"], "expected 1 SI token for count-dashboard: %v", foundSITokens)
|
|
|
|
|
|
|
|
t.Log("connect terminating gateway job with ACLs enabled finished")
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
var (
|
|
|
|
siTokenRe = regexp.MustCompile(`_nomad_si \[[\w-]{36}] \[[\w-]{36}] \[([\S]+)]`)
|
|
|
|
)
|
|
|
|
|
|
|
|
func (tc *ConnectACLsE2ETest) serviceofSIToken(description string) string {
|
|
|
|
if m := siTokenRe.FindStringSubmatch(description); len(m) == 2 {
|
|
|
|
return m[1]
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) countSITokens(t *testing.T) map[string]int {
|
|
|
|
aclAPI := tc.Consul().ACL()
|
2020-06-19 18:03:10 +00:00
|
|
|
tokens, _, err := aclAPI.TokenList(&consulapi.QueryOptions{
|
2021-04-20 20:23:30 +00:00
|
|
|
Token: tc.consulManagementToken,
|
2020-01-13 16:13:07 +00:00
|
|
|
})
|
2020-01-28 22:33:59 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-13 16:13:07 +00:00
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
// count the number of SI tokens matching each service name
|
|
|
|
foundSITokens := make(map[string]int)
|
|
|
|
for _, token := range tokens {
|
|
|
|
if service := tc.serviceofSIToken(token.Description); service != "" {
|
|
|
|
foundSITokens[service]++
|
2020-01-13 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:33:59 +00:00
|
|
|
return foundSITokens
|
2020-01-13 16:13:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 18:03:10 +00:00
|
|
|
func (tc *ConnectACLsE2ETest) parseJobSpecFile(t *testing.T, filename string) *nomadapi.Job {
|
2020-01-13 16:13:07 +00:00
|
|
|
job, err := jobspec.ParseFile(filename)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return job
|
|
|
|
}
|