Skip to content

Commit

Permalink
fixing acceptance test to recognize that long lived tokens will not e…
Browse files Browse the repository at this point in the history
…xist and we ahve to update the role.
  • Loading branch information
jmurret committed Mar 18, 2022
1 parent a2df993 commit 27fb9ea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func TestTerminatingGatewaySingleNamespace(t *testing.T) {
// Register the external service.
registerExternalService(t, consulClient, testNamespace)

// If ACLs are enabled we need to update the token of the terminating gateway
// If ACLs are enabled we need to update the role of the terminating gateway
// with service:write permissions to the static-server service
// so that it can can request Connect certificates for it.
if c.secure {
updateTerminatingGatewayToken(t, consulClient, fmt.Sprintf(staticServerPolicyRulesNamespace, testNamespace))
updateTerminatingGatewayRole(t, consulClient, fmt.Sprintf(staticServerPolicyRulesNamespace, testNamespace))
}

// Create the config entry for the terminating gateway.
Expand Down Expand Up @@ -205,11 +205,11 @@ func TestTerminatingGatewayNamespaceMirroring(t *testing.T) {
// Register the external service
registerExternalService(t, consulClient, testNamespace)

// If ACLs are enabled we need to update the token of the terminating gateway
// If ACLs are enabled we need to update the role of the terminating gateway
// with service:write permissions to the static-server service
// so that it can can request Connect certificates for it.
if c.secure {
updateTerminatingGatewayToken(t, consulClient, fmt.Sprintf(staticServerPolicyRulesNamespace, testNamespace))
updateTerminatingGatewayRole(t, consulClient, fmt.Sprintf(staticServerPolicyRulesNamespace, testNamespace))
}

// Create the config entry for the terminating gateway
Expand Down
30 changes: 15 additions & 15 deletions acceptance/tests/terminating-gateway/terminating_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func TestTerminatingGateway(t *testing.T) {
// Register the external service
registerExternalService(t, consulClient, "")

// If ACLs are enabled we need to update the token of the terminating gateway
// If ACLs are enabled we need to update the role of the terminating gateway
// with service:write permissions to the static-server service
// so that it can can request Connect certificates for it.
if c.secure {
updateTerminatingGatewayToken(t, consulClient, staticServerPolicyRules)
updateTerminatingGatewayRole(t, consulClient, staticServerPolicyRules)
}

// Create the config entry for the terminating gateway.
Expand Down Expand Up @@ -133,32 +133,32 @@ func registerExternalService(t *testing.T, consulClient *api.Client, namespace s
require.NoError(t, err)
}

func updateTerminatingGatewayToken(t *testing.T, consulClient *api.Client, rules string) {
func updateTerminatingGatewayRole(t *testing.T, consulClient *api.Client, rules string) {
t.Helper()

// Create a write policy for the static-server.
logger.Log(t, "creating a write policy for the static-server")
_, _, err := consulClient.ACL().PolicyCreate(&api.ACLPolicy{
Name: "static-server-write-policy",
Rules: rules,
}, nil)
require.NoError(t, err)

// Get the terminating gateway token.
tokens, _, err := consulClient.ACL().TokenList(nil)
logger.Log(t, "getting the terminating gateway role")
roles, _, err := consulClient.ACL().RoleList(nil)
require.NoError(t, err)
var termGwTokenID string
for _, token := range tokens {
if strings.Contains(token.Description, "token created via login: {\"component\":\"terminating-gateway\"}") {
termGwTokenID = token.AccessorID
terminatingGatewayRoleID := ""
for _, role := range roles {
if strings.Contains(role.Name, "terminating-gateway") {
terminatingGatewayRoleID = role.ID
break
}
}
termGwToken, _, err := consulClient.ACL().TokenRead(termGwTokenID, nil)
require.NoError(t, err)

// Add policy to the token and update it
termGwToken.Policies = append(termGwToken.Policies, &api.ACLTokenPolicyLink{Name: "static-server-write-policy"})
_, _, err = consulClient.ACL().TokenUpdate(termGwToken, nil)
logger.Log(t, "update role with policy")
termGwRole, _, err := consulClient.ACL().RoleRead(terminatingGatewayRoleID, nil)
require.NoError(t, err)
termGwRole.Policies = append(termGwRole.Policies, &api.ACLTokenPolicyLink{Name: "static-server-write-policy"})
_, _, err = consulClient.ACL().RoleUpdate(termGwRole, nil)
require.NoError(t, err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "consul.fullname" $root }}-{{ .name }}
name: {{ template "consul.fullname" $root }}-{{ .name }}-terminating-gateway
namespace: {{ $root.Release.Namespace }}
labels:
app: {{ template "consul.name" $root }}
chart: {{ template "consul.chart" $root }}
heritage: {{ $root.Release.Service }}
release: {{ $root.Release.Name }}
component: terminating-gateway
terminating-gateway-name: {{ template "consul.fullname" $root }}-{{ .name }}
terminating-gateway-name: {{ template "consul.fullname" $root }}-{{ .name }}-terminating-gateway
{{- if (or $defaults.serviceAccount.annotations $serviceAccount.annotations) }}
annotations:
{{- if $defaults.serviceAccount.annotations }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ load _helpers
yq -s -r '.' | tee /dev/stderr)

local actual=$(echo $object | yq -r '.[0].metadata.name' | tee /dev/stderr)
[ "${actual}" = "RELEASE-NAME-consul-gateway1" ]
[ "${actual}" = "RELEASE-NAME-consul-gateway1-terminating-gateway" ]

local actual=$(echo $object | yq -r '.[1].metadata.name' | tee /dev/stderr)
[ "${actual}" = "RELEASE-NAME-consul-gateway2" ]
[ "${actual}" = "RELEASE-NAME-consul-gateway2-terminating-gateway" ]

local actual=$(echo "$object" |
yq -r '.[2] | length > 0' | tee /dev/stderr)
Expand Down

0 comments on commit 27fb9ea

Please sign in to comment.