Skip to content
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

Validate port on mesh service registration #12881

Merged
merged 9 commits into from
May 5, 2022
Merged

Conversation

riddhi89
Copy link
Contributor

@riddhi89 riddhi89 commented Apr 28, 2022

Description

Without a port in the registration, the mesh is not functional. For Agentless, there will not be any client agent for auto port assignment. Agentless phase 1 is for k8s workloads which are already able to specify a port on mesh service registration.
This PR change is to require a port to be specified on registration of a mesh service (connect proxy, all gateway types (except ingress), sidecar definitions, connect native services) - this is mostly the case already except the validation was missing for connect native services.
Centralized port allocation by servers would be done in the future to support other workloads (example: VM based) that depend on port assignment.

agent/structs/structs.go Outdated Show resolved Hide resolved
result = multierror.Append(result, fmt.Errorf(
"Connect native service must have non-zero port"))
}

return result
}
Copy link
Contributor Author

@riddhi89 riddhi89 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This Validate() helper is used by both the catalog and agent endpoints.

@riddhi89 riddhi89 requested review from mkeeler and boxofrad May 4, 2022 14:04
@@ -1333,9 +1333,8 @@ func (s *NodeService) Validate() error {
"services"))
}

if s.Port == 0 && s.SocketPath == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think that we should require one of port or socket path everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Let me know if it is not the case for gateway types - in which case I will remove the sockpath validation below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed for gateway types per our discussion.

@@ -204,6 +204,10 @@ func servicePreApply(service *structs.NodeService, authz ACLResolveResult, authz
}
}

if service.Connect.SidecarService != nil && service.Connect.SidecarService.Port == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will generally never be hit because SidecarService will always be nil.

// The sidecar service is nilled since it is only config sugar and
// shouldn't be represented in state. We assert that the translations
// there worked by inspecting the registered sidecar below.
SidecarService: nil,

So I think the better validation would be to check the top level Port (or I guess SocketPath) to ensure one of those is filled in for services with kind connect-proxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this check.

Without a port in the registration, the mesh is not functional.
For agentless, since there will not be any client agents for auto port assignment,
require a port to be specified on registration of a mesh service
(connect proxy, gateway types, sidecar definitions, connect native services).
Move the check for the side car service having a port specified only
for the catalog endpoint.
@riddhi89 riddhi89 force-pushed the validate-port-service-mesh branch from 9ee5ed6 to 3e7aa17 Compare May 4, 2022 23:44
@riddhi89 riddhi89 requested a review from mkeeler May 4, 2022 23:57
Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, validating that a port is specified for connect native services seems like the right thing to do here.

@riddhi89 riddhi89 merged commit 0c855fa into main May 5, 2022
@riddhi89 riddhi89 deleted the validate-port-service-mesh branch May 5, 2022 16:13
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/662637.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants