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

[WIP] ✨Disable/enable PortSecurity at port level #914

Closed

Conversation

Xenwar
Copy link

@Xenwar Xenwar commented Jun 21, 2021

This PR adds the capability of enabling/disabling PortSecurity at the port level.

Example Manifest

apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: OpenStackCluster
metadata:
  name: basic-8
  namespace: default
spec:
  disablePortSecurity: false
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: OpenStackMachineTemplate
metadata:
  name: basic-8-control-plane
  namespace: default
spec:
  template:
    spec:
      ports:
      - description: "primary with PortSecurity enabled, required for proper k8s cluster"
        disablePortSecurity: false
        allowedAddressPairs:
        - macAddress: "a4:b8:34:2b:ab:01"
          ipAddress: "10.10.10.10/24"
      - description: "secondary with PortSecurity disabled"
        disablePortSecurity: true
        allowedAddressPairs:
        - macAddress: "a4:b8:34:2b:ab:02"
          ipAddress: "20.20.20.20/24"

Example output:
`

(openstack) port show primary-port
+-----------------------+--------------------------------------------------------------------+
| Field                 | Value                                                              |
+-----------------------+--------------------------------------------------------------------+
| allowed_address_pairs | ip_address='10.10.10.10/24', mac_address='a4:b8:34:2b:ab:01'       |
| description           | primary with PortSecurity enabled, required for proper k8s cluster |
| port_security_enabled | True                                                               |
| security_group_ids    | 37e42488-1417-4e2c-980f-d2ef71ffbacc                               |
+-----------------------+--------------------------------------------------------------------+
(openstack) port show secondary-port
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| allowed_address_pairs |                                      |
| description           | secondary with PortSecurity disabled |
| port_security_enabled | False                                |
| security_group_ids    |                                      |
+-----------------------+--------------------------------------+

`

Fixes #911
Signed-off-by: Anwar Hassen [email protected]

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 21, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @Xenwar. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 21, 2021
@Xenwar
Copy link
Author

Xenwar commented Jun 21, 2021

/assign @sbueringer

@@ -1264,6 +1264,11 @@ spec:
type: array
description:
type: string
disablePortSecurity:
description: DisablePortSecurity disables the port security
Copy link
Contributor

Choose a reason for hiding this comment

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

Where this description come from? Description should be auto generated from a comment in api/v1alpha4/types.go.

Copy link
Author

Choose a reason for hiding this comment

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

You are right. I did not re-generate the yaml files after removing the comment.
Will add the comment back.

@@ -505,6 +515,28 @@ func (s *Service) getOrCreatePort(eventObject runtime.Object, clusterName string
}

record.Eventf(eventObject, "SuccessfulCreatePort", "Created port %s with id %s", port.Name, port.ID)
if portOpts.DisablePortSecurity == true || networkDisabledPortSecurity == true {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we create port with/without port security not updating after creating port?

Copy link
Author

Choose a reason for hiding this comment

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

no, we cannot.
At the port level, PortSecurity is immutable.
For the network level, there is a bug reporter (#913)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is possible from gophercloud docs.

Copy link
Author

Choose a reason for hiding this comment

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

Indeed. The link you provided is more efficient as it does not need retrieving the port to update it, I will update my PR accordingly.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks a lot

@Xenwar Xenwar force-pushed the toggle_port_level_security branch from b6347f9 to 84a4551 Compare June 23, 2021 11:12
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Xenwar
To complete the pull request process, please ask for approval from sbueringer after the PR has been reviewed.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hidekazuna
Copy link
Contributor

@Xenwar I think we need to discuss motivation and spec more. Please see #911 #913

@Xenwar
Copy link
Author

Xenwar commented Jun 23, 2021

@Xenwar I think we need to discuss motivation and spec more. Please see #911 #913

Thanks, I will try it again and update the issue accordingly.

@Xenwar
Copy link
Author

Xenwar commented Jun 23, 2021

@hidekazuna
Having difficulty combining these two options.
The ports.Create(s.networkClient, takes only one of them. Option2 does not allow setting HostID, VNICType and Profile properties.
Any idea if combining them is possible ?


	option1 := portsbinding.CreateOptsExt{
		CreateOptsBuilder: createOpts,
		HostID:            portOpts.HostID,
		VNICType:          portOpts.VNICType,
		Profile:           nil,

	}
	option2 := portsecurity.PortCreateOptsExt{
		CreateOptsBuilder:   createOpts,
		PortSecurityEnabled: &enablePortSecurity,
	}

@hidekazuna
Copy link
Contributor

@hidekazuna
Having difficulty combining these two options.
The ports.Create(s.networkClient, takes only one of them. Option2 does not allow setting HostID, VNICType and Profile properties.
Any idea if combining them is possible ?


	option1 := portsbinding.CreateOptsExt{
		CreateOptsBuilder: createOpts,
		HostID:            portOpts.HostID,
		VNICType:          portOpts.VNICType,
		Profile:           nil,

	}
	option2 := portsecurity.PortCreateOptsExt{
		CreateOptsBuilder:   createOpts,
		PortSecurityEnabled: &enablePortSecurity,
	}

@Xenwar Thanks investigating. I have no idea to combine them as of now.

@Xenwar
Copy link
Author

Xenwar commented Jun 24, 2021

@hidekazuna Thanks.

@Xenwar Xenwar force-pushed the toggle_port_level_security branch from 84a4551 to 6bfa2fa Compare June 24, 2021 06:32
@jichenjc
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 29, 2021
@iamemilio
Copy link
Contributor

I just made a similar PR not realizing this was already out there. Lets combine efforts and share homework: #921

Rather than inheriting the port security settings from the cluster spec, I think its better to just inherit them from the network (which openstack does automatically on create) since these ports can be created on any network in theory. This is why I chose to make it *bool.

@iamemilio
Copy link
Contributor

iamemilio commented Jun 29, 2021

Another thing to watch out for is that because we typically set the security groups at the instance level, OpenStack will apply that security group to all port interfaces of that instance. This will cause ugly bugs when setting the port security on those ports.

@Xenwar
Copy link
Author

Xenwar commented Jun 30, 2021

I just made a similar PR not realizing this was already out there. Lets combine efforts and share homework: #921

Rather than inheriting the port security settings from the cluster spec, I think its better to just inherit them from the network (which openstack does automatically on create) since these ports can be created on any network in theory. This is why I chose to make it *bool.

Thanks, we can combine efforts.
On inheriting portSecurity from the network, my reasoning was there should be a single source of truth for the setting. So, if one changes the setting at the OSCluster spec, then it is propagated to the the Network.

Also, Network level setting is relevant when PortSecurity is disabled at the network level so the setting is disabled for each port. i.e. Ports do not inherit the setting from the network in all cases.

@Xenwar
Copy link
Author

Xenwar commented Jun 30, 2021

Another thing to watch out for is that because we typically set the security groups at the instance level, OpenStack will apply that security group to all port interfaces of that instance. This will cause ugly bugs when setting the port security on those ports.

We have a use case to enable/disable PortSecurity at the port(s) level. I am not quite sure yet at what point the bug you mentioned could show up, during Port creation or during an update as we have the option of specifying security groups at the port level.

We could probably open a discussion on slack on the this and the other comment.

@iamemilio
Copy link
Contributor

/assign @iamemilio
going to assign myself to this so that I get notifications :)

@Xenwar Xenwar force-pushed the toggle_port_level_security branch from 6bfa2fa to 4db197b Compare June 30, 2021 20:24
@Xenwar
Copy link
Author

Xenwar commented Jun 30, 2021

/hold alternatives ways under discussion, #921

@Xenwar
Copy link
Author

Xenwar commented Jul 14, 2021

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 14, 2021
@Xenwar Xenwar force-pushed the toggle_port_level_security branch from ac16771 to 4816166 Compare July 14, 2021 08:52
@hidekazuna
Copy link
Contributor

@Xenwar hold/unfold does not mean ready for review. If PR is not ready for review, rename title starting with WIP, please.

@Xenwar
Copy link
Author

Xenwar commented Jul 14, 2021

/test pull-cluster-api-provider-openstack-e2e-test

@Xenwar Xenwar force-pushed the toggle_port_level_security branch 2 times, most recently from 6f72039 to be7d601 Compare July 15, 2021 12:37
@@ -327,6 +327,13 @@ A floating IP is created and associated to the bastion host automatically, but y

If `managedSecurityGroups: true`, security group rule opening 22/tcp is added to security groups for bastion, controller, and worker nodes respectively. Otherwise, you have to add `securityGroups` to the `bastion` in `OpenStackCluster` spec and `OpenStackMachineTemplate` spec template respectively.

If PortSecurity disable for all ports either by setting `OpenStackCluster.spec.disablePortSecurity: true` or for each port individually, `managedSecurityGroups: false` is the only valid option. The following is not a valid coonfiguration and is not supported.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is in "Accessing nodes through the bastion host via SSH" section, not security group section. How about moving to Ports?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, moved

@Xenwar Xenwar force-pushed the toggle_port_level_security branch from be7d601 to 7d71d42 Compare July 15, 2021 14:20
@Xenwar
Copy link
Author

Xenwar commented Jul 15, 2021

/test pull-cluster-api-provider-openstack-e2e-test

@Xenwar Xenwar changed the title ✨ Disable/enable PortSecurity at port level ✨[WIP] Disable/enable PortSecurity at port level Jul 16, 2021
@Xenwar Xenwar changed the title ✨[WIP] Disable/enable PortSecurity at port level [WIP] ✨Disable/enable PortSecurity at port level Jul 16, 2021
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 16, 2021
@Xenwar Xenwar force-pushed the toggle_port_level_security branch from 7d71d42 to b5fe28a Compare July 16, 2021 11:22
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 16, 2021
@Xenwar Xenwar force-pushed the toggle_port_level_security branch 2 times, most recently from 11b6d31 to 4e9edf6 Compare July 21, 2021 10:16
@Xenwar Xenwar force-pushed the toggle_port_level_security branch 2 times, most recently from d8e2ee7 to 248dcaa Compare July 23, 2021 11:47
@Xenwar
Copy link
Author

Xenwar commented Jul 26, 2021

/test pull-cluster-api-provider-openstack-e2e-test

@Xenwar Xenwar force-pushed the toggle_port_level_security branch from 248dcaa to 3537479 Compare July 26, 2021 09:13
@Xenwar
Copy link
Author

Xenwar commented Jul 29, 2021

/test pull-cluster-api-provider-openstack-e2e-test

@k8s-ci-robot
Copy link
Contributor

@Xenwar: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Rerun command
pull-cluster-api-provider-openstack-e2e-test 3537479 link /test pull-cluster-api-provider-openstack-e2e-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@Xenwar
Copy link
Author

Xenwar commented Jul 30, 2021

This PR is no longer needed.
Feature is merged by #921

@Xenwar Xenwar closed this Jul 30, 2021
@k8s-ci-robot
Copy link
Contributor

@Xenwar: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a feature to configure Port level PortSecurity
6 participants