-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NET-10567] Fix namespace normalization on external registration/ACL Setup for Terminating Gateways #4224
[NET-10567] Fix namespace normalization on external registration/ACL Setup for Terminating Gateways #4224
Conversation
@@ -165,10 +165,10 @@ func CheckStaticServerConnectionSuccessfulWithMessage(t *testing.T, options *k8s | |||
|
|||
// CheckStaticServerConnectionSuccessful is just like CheckStaticServerConnection | |||
// but it always expects a successful connection. | |||
func CheckStaticServerConnectionSuccessful(t *testing.T, options *k8s.KubectlOptions, sourceApp string, curlArgs ...string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified this argument to make it more clear what options it should be for (in multi-namespace scenarios)
// WaitForInput starts a http server on a random port (which is output in the logs) and waits until you | ||
// issue a request to that endpoint to continue the tests. This is useful for debugging tests that require | ||
// inspecting the current state of a running cluster and you don't need to use long sleeps | ||
func WaitForInput(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was super useful for debugging the state of the cluster during tests and not needing to put a random sleep time in the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this into it's own PR #4225
@@ -231,9 +227,9 @@ func (c *RegistrationCache) updateTermGWACLRole(log logr.Logger, registration *v | |||
var data bytes.Buffer | |||
if err := gatewayTpl.Execute(&data, templateArgs{ | |||
EnablePartitions: c.partitionsEnabled, | |||
Partition: registration.Spec.Service.Partition, | |||
Partition: defaultIfEmpty(registration.Spec.Service.Partition), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these bits here fix the bug, the rest is just updating tests
d05eb97
to
bd7508f
Compare
@@ -90,6 +90,10 @@ func TestControllerNamespaces(t *testing.T) { | |||
|
|||
"global.acls.manageSystemACLs": strconv.FormatBool(c.secure), | |||
"global.tls.enabled": strconv.FormatBool(c.secure), | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test exercises the terminating gateway path and those don't function correctly without this in your helm chart
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
const NotInServiceMeshFilter = "ServiceMeta[\"managed-by\"] != \"consul-k8s-endpoints-controller\"" | ||
|
||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all this moved to the term gateway controller
|
||
if err := c.k8sClient.Get(c.ctx, types.NamespacedName{Name: svc, Namespace: namespace}, registration); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the service name here doesn't necessarily map directly to the registration name
@@ -44,12 +44,12 @@ type RegistrationsController struct { | |||
Log logr.Logger | |||
} | |||
|
|||
// +kubebuilder:rbac:groups=consul.hashicorp.com,resources=servicerouters,verbs=get;list;watch;create;update;patch;delete | |||
// +kubebuilder:rbac:groups=consul.hashicorp.com,resources=servicerouters/status,verbs=get;update;patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found this copy/pasta mistake
|
||
func (r *RegistrationsController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
log := r.Log.V(1).WithValues("registration", req.NamespacedName) | ||
log.Info("Reconciling Registaration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixing typo
t.Run(c.kubeKind, func(t *testing.T) { | ||
req := require.New(t) | ||
ctx := context.Background() | ||
for _, secure := range []bool{true, false} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated these tests to run in secure and non secure mode to ensure config entries are created when acls are enabled
left emtpy in acl policy if not specified in the CRD which results in an invalid acl policy
external service config entry registration from tests
} | ||
|
||
t.Log("input received, continuing test") | ||
go func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was causing the caller to hang if we didn't do it async
@@ -60,18 +60,6 @@ func (r *RegistrationsController) Reconcile(ctx context.Context, req ctrl.Reques | |||
return ctrl.Result{}, client.IgnoreNotFound(err) | |||
} | |||
|
|||
cachedRegistration, ok := r.Cache.get(registration.Spec.Service.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this down so we handle deletion correctly
@@ -143,48 +143,9 @@ func (r *RegistrationsController) handleRegistration(ctx context.Context, log lo | |||
return result | |||
} | |||
|
|||
if r.Cache.aclsEnabled() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the acl updates are done on the terminating gateway now to remove this controller racing with that one
...ating-gateway-namespaces/all-non-default/external-service-registration/external-service.yaml
Show resolved
Hide resolved
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts after walking through the PR with @jm96441n on a call a few minutes ago
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
Co-authored-by: Nathan Coleman <nathan.coleman@hashicorp.com>
needed and updating variable names to be more consistent
control-plane/controllers/configentries/terminatinggateway_controller.go
Outdated
Show resolved
Hide resolved
…Setup for Terminating Gateways (#4224) * fix bug in external service registration ACL creation where namespace is left emtpy in acl policy if not specified in the CRD which results in an invalid acl policy * Remove check for timestamp * update tests! * update to use helper function * all non default working * test cases all working * move wait for it to separate PR * use replace for consul-k8s control-plane * update single namespace test * updated namespaces and destinations test * remove usage of creating terminating gateway config entry creation and external service config entry registration from tests * fix typo * update comment * comment out broken test for the time being * remove unused import and add period to comment * add changelog * fix bug in cache creation for registrations, still debugging issue with termianting gateways and acl roles * fix issue with terminating gateway acl role by moving role modification from registrations controller to terminating gateway controller * appease the linter * add acl status condition to terminating gateways * linter * update config entry terminating gateway tests * Use more robust method of checking if acls are enabled * update config entries controller unit tests to run with acls and without * fix config entries namespaces test setup * fix unused import * fix config entries main test * remove block for deregistering service * fix comment * fix acceptance test registration * handle removing policies when no other gateways reference them * fix terminating gateway configuration for peering connect test * remove unnecessary nodeMeta on fixture, remove unused yaml files from fixtures * fix wildcard service names * use more specific matchers to avoid potential substring collisions * Update .changelog/4224.txt Co-authored-by: Nathan Coleman <nathan.coleman@hashicorp.com> * cleaning up from PR review: moving template execution to where it's needed and updating variable names to be more consistent * add comment * fix typo --------- Co-authored-by: Nathan Coleman <nathan.coleman@hashicorp.com>
…tration/ACL Setup for Terminating Gateways into release/1.5.x (#4259) [NET-10567] Fix namespace normalization on external registration/ACL Setup for Terminating Gateways (#4224) * fix bug in external service registration ACL creation where namespace is left emtpy in acl policy if not specified in the CRD which results in an invalid acl policy * Remove check for timestamp * update tests! * update to use helper function * all non default working * test cases all working * move wait for it to separate PR * use replace for consul-k8s control-plane * update single namespace test * updated namespaces and destinations test * remove usage of creating terminating gateway config entry creation and external service config entry registration from tests * fix typo * update comment * comment out broken test for the time being * remove unused import and add period to comment * add changelog * fix bug in cache creation for registrations, still debugging issue with termianting gateways and acl roles * fix issue with terminating gateway acl role by moving role modification from registrations controller to terminating gateway controller * appease the linter * add acl status condition to terminating gateways * linter * update config entry terminating gateway tests * Use more robust method of checking if acls are enabled * update config entries controller unit tests to run with acls and without * fix config entries namespaces test setup * fix unused import * fix config entries main test * remove block for deregistering service * fix comment * fix acceptance test registration * handle removing policies when no other gateways reference them * fix terminating gateway configuration for peering connect test * remove unnecessary nodeMeta on fixture, remove unused yaml files from fixtures * fix wildcard service names * use more specific matchers to avoid potential substring collisions * Update .changelog/4224.txt * cleaning up from PR review: moving template execution to where it's needed and updating variable names to be more consistent * add comment * fix typo --------- Co-authored-by: John Maguire <john.maguire@hashicorp.com> Co-authored-by: Nathan Coleman <nathan.coleman@hashicorp.com>
@jm96441n -- Awesome update to the TGW workflow! Can you ensure that this gets updated though to account for enabling Admin Partitions -- Testing this I had to manually (tproxy destinations method) update the ACL policy for one of my external services from: namespace "default" {
service "example" {
policy = "write"
}
} to partition "default" {
namespace "default" {
node_prefix "" {
policy = "read"
}
service "example" {
policy = "write"
intention = "read"
}
}
} Additionally, I'm positive the
|
Changes proposed in this PR
How I've tested this PR
How I expect reviewers to test this PR
make docker-dev
CONSUL_K8S_CHART_LOCATION
variable in thestart.sh
file to point to the helm charts in your local version of consul-start.sh
file (this requires you to havekind
andyq
on your machine, and you'll need to runchmod +x ./start.sh
)consul acl role list
and you will see both terminating gateways with the term gateway policy and the zoidberg and nibbler policiesconsul acl policy read -name zoidberg-write-policy
to see the policy include the namespacecurl localhost:1234
to see the request to zoidberg go through, runcurl localhost:5678
to see the request to nibbler go throughtermgw.yaml
file to no longer reference the zoidberg service and apply the fileconsul acl role list
and see the first terminating gateway no longer references the zoidberg policyconsul acl policy list
and you'll see the zoidberg policy still existsconsul acl role list
and see that none of the terminating gateways reference that policyconsul acl policy list
and see that the zoidberg policy no longer exists because no gateway is referencing itChecklist