1. 程式人生 > >Python_堡壘機開發基礎

Python_堡壘機開發基礎

_id 審計 pass back int ring col 報警 unique

1. 堡壘機,即在一個特定的網絡環境下,為了保障網絡和數據不受來自外部和內部用戶的入侵和破壞,而運用各種技術手段實時收集和監控網絡環境中每一個組成部分的系統狀態、安全事件、網絡活動,以便集中報警、及時處理及審計定責。 重新封存了用戶的SSH代碼,使得堡壘機變成了監視器。

2. 堡壘機的兩個功能: 1, 記錄操作,2,權限控制。

3,實現多對多的功能。

user_m2m_bindhost = Table(user_m2m_bindhost, Base.metadata,
                        Column(userprofile_id, Integer, ForeignKey(
user_profile.id)), Column(bindhost_id, Integer, ForeignKey(bind_host.id)), ) bindhost_m2m_hostgroup = Table(bindhost_m2m_hostgroup, Base.metadata, Column(bindhost_id, Integer, ForeignKey(bind_host.id)), Column(
hostgroup_id, Integer, ForeignKey(host_group.id)), ) user_m2m_hostgroup = Table(userprofile_m2m_hostgroup, Base.metadata, Column(userprofile_id, Integer, ForeignKey(user_profile.id)), Column(hostgroup_id
, Integer, ForeignKey(host_group.id)), )

4. 創建多個表結構:

class Host(Base):
    __tablename__ = host
    id = Column(Integer,primary_key=True)
    hostname = Column(String(64),unique=True)
    ip = Column(String(64),unique=True)
    port = Column(Integer,default=22)

    def __repr__(self):
        return self.hostname

class HostGroup(Base):
    __tablename__ = host_group
    id = Column(Integer, primary_key=True)
    name = Column(String(64), unique=True)
    bind_hosts = relationship("BindHost",secondary="bindhost_m2m_hostgroup",backref="host_groups")

    def __repr__(self):
        return self.name

class RemoteUser(Base):
    __tablename__ = remote_user
    __table_args__ = (UniqueConstraint(auth_type, username,password, name=_user_passwd_uc),)

    id = Column(Integer, primary_key=True)
    AuthTypes = [
        (ssh-password,SSH/Password),
        (ssh-key,SSH/KEY),
    ]
    auth_type = Column(ChoiceType(AuthTypes))
    username = Column(String(32))
    password = Column(String(128))

    def __repr__(self):
        return self.username

class BindHost(Base):
    ‘‘‘
    192.168.1.11    web
    192.168.1.11    mysql

    ‘‘‘
    __tablename__ = "bind_host"
    __table_args__ = (UniqueConstraint(host_id,remoteuser_id, name=_host_remoteuser_uc),)

    id = Column(Integer, primary_key=True)
    host_id = Column(Integer,ForeignKey(host.id))
    #group_id = Column(Integer,ForeignKey(‘group.id‘))
    remoteuser_id = Column(Integer, ForeignKey(remote_user.id))
    host = relationship("Host",backref="bind_hosts")
    #host_group = relationship("HostGroup",backref="bind_hosts")
    remote_user = relationship("RemoteUser",backref="bind_hosts")

5. 比較復雜,後期再復盤。

Python_堡壘機開發基礎