• All
  • Test
  • Startup
  • Experience Case
  • FAQ
Product line
Search
Cancel
Documents type
Author
Time
Search

★ Using NETCONF to issue security policies for firewalls (implemented in Python ncclient module)

2022-09-21 15:28:12 Published
  • 0Followed
  • -1Collected ,301Browsed
fans:0 follow:0

Network Topology

Device: Firewall

Model: F1070

Software version: D022 and above

Problem Description

Description:

·  Network Configuration Protocol (NETCONF) is an XML-based network management protocol. It provides programmable mechanisms to manage and configure network devices. Through NETCONF, you can configure device parameters, retrieve parameter values, and collect statistics. NETCONF facilitates the development of a NETCONF-based NMS system for you to configure and manage devices from different vendors easily and efficiently.

·  ncclient is a Python library for NETCONF clients. It is designed to corporately map NETCONF's XML encoding features to Python constructs and idioms using an intuitive API, and to make writing network management scripts easier.

 

This case uses the above mentioned tools and components to issue a security policy for the firewall: Block source address 1.1.1.1.

 

Attachment:

H3C Netconf configuration-related guidance

·  H3C NETCONF-BasedDevice Configuration and Management Guide-6W100

·  Comware 7 NETCONF XML API Reference (Please contact the H3C TS team for documentation)

Process Analysis

1.       Make sure that the Python and ncclient libraries have been successfully installed. For installation instructions, please refer to the relevant online links. No error is reported in the following operations, indicating that the ncclient library has been successfully installed.


¡     Using PIP:

# Run the pip install ncclient command at the CLI.

This method will automatically install dependency packages required by ncclient. You do not need to manually download and install the dependency packages or troubleshoot installation errors.

¡     Using the source codes:

# Download the software package file from https://pypi.org/project/ncclient/.

# Decompress the package file.

# Run the python setup.py install command at the CLI.

This method requires you to install multiple dependency packages manually.


2.       Define the steps for script distribution. There are four main steps for issuing security policies for the firewall using NETCONF (find out the XML format of the relevant module for each step separately by looking at the API documentation).

1)         Create IPv4 address object groups


2)         Create IPv4 address objects


3)         Creating Security Policy Rules


4)         Referencing IPv4 address object groups in security policy rules



3.       Python code implementation based on ncclient

·  The appliance enables the NETCONF over SSH server feature, ensuring that port 830 from the NETCONF client to the appliance is available and that the SSH user used for NETCONF has been assigned permissions.

·  Connect to the firewall appliance via Python and issue the configuration script.

Solution

Configuration script

 

#! /usr/bin/env python3.8

import sys, os, warnings

warnings.simplefilter("ignore", DeprecationWarning)

from ncclient import manager

 

xml1 = """

<config

    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"

    xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">

    <top

        xmlns="http://www.h3c.com/netconf/config:1.0" xc:operation="create">

        <OMS>

            <IPv4Groups>

                <Group>

                    <Name>block-ip</Name>

                    <Description>for_block</Description>

                    <SecurityZone>Trust</SecurityZone>

                </Group>

            </IPv4Groups>

        </OMS>

    </top>

</config>

"""

 

xml2 = """

<config

    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"

    xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">

    <top

        xmlns="http://www.h3c.com/netconf/config:1.0" xc:operation="create">

        <OMS>

            <IPv4Objs>

                <Obj>

                    <Group>block-ip</Group>

                    <ID>0</ID>

                    <Type>3</Type>

                    <HostIPv4Address>1.1.1.1</HostIPv4Address>

                </Obj>

            </IPv4Objs>

        </OMS>

    </top>

</config>

"""

 

xml3 = """

<config

    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"

    xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">

    <top

        xmlns="http://www.h3c.com/netconf/config:1.0" xc:operation="create">

        <SecurityPolicies>

            <IPv4Rules>

                <Rule>

                    <ID>1000</ID>

                    <RuleName>block</RuleName>

                    <Action>1</Action>

                </Rule>

            </IPv4Rules>

        </SecurityPolicies>

    </top>

</config>

"""

 

xml4 = """

<config

    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"

    xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">

    <top

        xmlns="http://www.h3c.com/netconf/config:1.0" xc:operation="create">

        <SecurityPolicies>

            <IPv4SrcAddr>

                <SrcAddr>

                    <ID>1000</ID>

                    <SeqNum></SeqNum>

                    <IsIncrement>false</IsIncrement>

                    <NameList>

                        <NameItem>block-ip</NameItem>

                    </NameList>

                </SrcAddr>

            </IPv4SrcAddr>

        </SecurityPolicies>

    </top>

</config>

"""

 

 

with manager.connect( 

        host="192.168.1.13",

        port=830,

        username="admin",

        password="Admin@h3c!",

        hostkey_verify=False,

        device_params={"name":"h3c"},

        timeout=300

        ) as m:

      

        for xml in [xml1, xml2, xml3, xml4]:

                print (m.edit_config(target="running", cOnfig=xml))

Please rate this case:   
0 comments

No comments

Add Comments:

举报

×

侵犯我的权益 >
对根叔知了社区有害的内容 >
辱骂、歧视、挑衅等(不友善)

侵犯我的权益

×

泄露了我的隐私 >
侵犯了我企业的权益 >
抄袭了我的内容 >
诽谤我 >
辱骂、歧视、挑衅等(不友善)
骚扰我

泄露了我的隐私

×

您好,当您发现根叔知了上有泄漏您隐私的内容时,您可以向根叔知了进行举报。 请您把以下内容通过邮件发送到zhiliao@h3c.com 邮箱,我们会尽快处理。
  • 1. 您认为哪些内容泄露了您的隐私?(请在邮件中列出您举报的内容、链接地址,并给出简短的说明)
  • 2. 您是谁?(身份证明材料,可以是身份证或护照等证件)

侵犯了我企业的权益

×

您好,当您发现根叔知了上有关于您企业的造谣与诽谤、商业侵权等内容时,您可以向根叔知了进行举报。 请您把以下内容通过邮件发送到 zhiliao@h3c.com 邮箱,我们会在审核后尽快给您答复。
  • 1. 您举报的内容是什么?(请在邮件中列出您举报的内容和链接地址)
  • 2. 您是谁?(身份证明材料,可以是身份证或护照等证件)
  • 3. 是哪家企业?(营业执照,单位登记证明等证件)
  • 4. 您与该企业的关系是?(您是企业法人或被授权人,需提供企业委托授权书)
我们认为知名企业应该坦然接受公众讨论,对于答案中不准确的部分,我们欢迎您以正式或非正式身份在根叔知了上进行澄清。

抄袭了我的内容

×

原文链接或出处

诽谤我

×

您好,当您发现根叔知了上有诽谤您的内容时,您可以向根叔知了进行举报。 请您把以下内容通过邮件发送到zhiliao@h3c.com 邮箱,我们会尽快处理。
  • 1. 您举报的内容以及侵犯了您什么权益?(请在邮件中列出您举报的内容、链接地址,并给出简短的说明)
  • 2. 您是谁?(身份证明材料,可以是身份证或护照等证件)
我们认为知名企业应该坦然接受公众讨论,对于答案中不准确的部分,我们欢迎您以正式或非正式身份在根叔知了上进行澄清。

对根叔知了社区有害的内容

×

垃圾广告信息
色情、暴力、血腥等违反法律法规的内容
政治敏感
不规范转载 >
辱骂、歧视、挑衅等(不友善)
骚扰我
诱导投票

不规范转载

×

举报说明

提出建议

    +

Login before you can operate!

login

你的邮箱还未认证,请认证邮箱或绑定手机后进行当前操作