zoukankan      html  css  js  c++  java
  • Kerberos 入门实战(2)Kerberos 安装及使用

    Kerberos 的基本原理已在上文(Kerberos 入门实战(1)--Kerberos 基本原理)介绍过了,本文主要介绍 Kerberos 的安装及使用,文中使用到的软件版本:CentOS 7.6、Kerberos5 1.15.1。

    1、规划

    ip 主机名 用途
    10.49.196.10 pxc1 Kerberos Server
    10.49.196.11 pxc2 Kerberos Client
    10.49.196.12 pxc3 Kerberos Client

    三台机器上修改 /etc/hosts 文件:

    10.49.196.10 pxc1
    10.49.196.11 pxc2
    10.49.196.12 pxc3

    Kerberos Client 根据需要进行安装,安装后可以使用 kadmin 命令;对应在 Kerberos Server 上使用 kadmin.local 命令。

    2、Kerberos Server 安装

    在 10.49.196.10 上执行如下命令:

    yum install krb5-server

    2.1、配置 krb5.conf

    根据需要修改 /etc/krb5.conf:

    # Configuration snippets may be placed in this directory as well
    includedir /etc/krb5.conf.d/
    
    [logging]
     default = FILE:/var/log/krb5libs.log
     kdc = FILE:/var/log/krb5kdc.log
     admin_server = FILE:/var/log/kadmind.log
    
    [libdefaults]
     dns_lookup_realm = false
     ticket_lifetime = 24h
     renew_lifetime = 7d
     forwardable = true
     rdns = false
     pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt
     default_realm = ABC.COM
     default_ccache_name = KEYRING:persistent:%{uid}
    
    [realms]
     ABC.COM = {
      kdc = 10.49.196.10
      admin_server = 10.49.196.10
     }
    
    [domain_realm]
    # .example.com = EXAMPLE.COM
    # example.com = EXAMPLE.COM

    相关参数说明:

    [logging]:日志的位置
    [libdefaults]:每种连接的默认配置
      dns_lookup_realm:是否通过 dns 查找需使用的 releam
      ticket_lifetime:凭证的有效时限,一般为 24 小时
      renew_lifetime:凭证最长可以被延期的时限,一般为一周。当凭证过期之后,对安全认证的服务后续访问就会失败
      forwardable:ticket 是否可以被转发(如果用户已经有了一个TGT,当他登入到另一个远程系统,KDC会为他重新创建一个TGT,而不需要让用户重新进行身份认证)
      rdns:如果为 true,则除根据 hostname 正向查找外,同时反向查找对应的 principal。如果 dns_canonicalize_hostname 设置为 false,则此标志不起作用。默认值为 true。
      pkinit_anchors:受信任锚(根)证书的位置;如果用户在命令行上指定X509_anchors,则不使用该配置。
      default_realm:默认的 realm,必须跟要配置的 realm 名称一致
      default_ccache_name:指定默认凭据缓存的名称。默认值为 DEFCCNAME
    [realms]:列举使用的 realm
      kdc:kdc 运行的机器
      admin_server:kdc 数据库管理服务运行的机器
    [domain_realm]:配置 domain name 或 hostname 对应的 releam

    详细说明可参考官网文档:http://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/krb5_conf.html

    2.2、配置 kdc.conf

    根据需要修改 /var/kerberos/krb5kdc/kdc.conf:

    [kdcdefaults]
     kdc_ports = 88
     kdc_tcp_ports = 88
    
    [realms]
     ABC.COM = {
      #master_key_type = aes256-cts
      acl_file = /var/kerberos/krb5kdc/kadm5.acl
      dict_file = /usr/share/dict/words
      admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab
      supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia12
    8-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal
     }

    相关参数说明:

    [kdcdefaults]:KDC 默认配置
    kdc_ports:UDP 端口号
    kdc_tcp_ports:TCP 端口号
    [realms]:realm 数据库配置
    master_key_type:主密钥的密钥类型;默认值为 aes256-cts-hmac-sha1-96。
    acl_file:用于指定哪些用户可以访问 kdc 数据库的控制文件;如果不需要现在用户访问,该值可以设为空
    dict_file:字典文件位置,该文件中的单词不能被用于密码;如果文件为空,或者没有为用户分配策略,则不会执行密码字典检查。
    admin_keytab:KDC 进行校验的 keytab。
    supported_enctypes:支持的加密方式,默认为 aes256-cts-hmac-sha1-96:normal aes128-cts-hmac-sha1-96:normal。

    详细说明可参考官网文档:https://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/kdc_conf.html

    2.3、配置 kdc.conf

    根据需要修改 /var/kerberos/krb5kdc/kadm5.acl:

    */admin@ABC.COM *

    Kerberos kadmind 使用该文件来管理对 Kerberos 数据库的访问权限。对于影响 principa 的操作,ACL 文件还控制哪些 principa 可以对哪些其他 principa 进行操作。文件格式如下:

    principal  permissions  [target_principal  [restrictions] ]

    ACL 文件中的行顺序很重要,会使用第一个匹配的行来设置用户权限。

    相关参数说明:

    principal:设置该 principal 的权限;principal 的每个部分都可以使用 *。
    permissions: 权限,有如下一些权限:

    a [Dis]allows the addition of principals or policies
    c [Dis]allows the changing of passwords for principals
    d [Dis]allows the deletion of principals or policies
    e [Dis]allows the extraction of principal keys
    i [Dis]allows inquiries about principals or policies
    l [Dis]allows the listing of all principals or policies
    m [Dis]allows the modification of principals or policies
    p [Dis]allows the propagation of the principal database (used in Incremental database propagation)
    s [Dis]allows the explicit setting of the key for a principal
    x Short for admcilsp. All privileges (except e)
    * Same as x.

    target_principal:目标 principal,目标 principal 的每个部分都可以使用 *。
    restrictions:针对权限的一些补充限制,如:限制创建的 principal 的票据最长时效。

     详细说明可参考官网文档:https://web.mit.edu/kerberos/krb5-latest/doc/admin/conf_files/kadm5_acl.html

    2.4、创建 Kerberos 数据库

     执行如下命令:

    kdb5_util create -s -r ABC.COM

    -s:表示生成 stash file,并在其中存储 master server key(krb5kdc)
    -r:指定 realm name

    Kerberos 数据库的目录为:/var/kerberos/krb5kdc,如果需要重建数据库,可删除改目录。

    2.5、启停 Kerberos 服务

    启动:

    systemctl start krb5kdc
    systemctl start kadmin

    停止:

    systemctl stop krb5kdc
    systemctl stop kadmin

    2.6、kadmin.local

    Kerberos 服务机器上可以使用 kadmin.local 来执行各种管理的操作。进入 kadmin.local:

    [root@pxc1 kerberos]# kadmin.local 
    Authenticating as principal root/admin@ABC.COM with password.
    kadmin.local:  

    常用操作:

    操作 描述 例子
    add_principal, addprinc, ank 增加 principal add_principal -rnadkey test@ABC.COM
    delete_principal, delprinc 删除 principal delete_principal test@ABC.COM
    modify_principal, modprinc 修改 principal modify_principal test@ABC.COM
    rename_principal, renprinc 重命名 principal rename_principal test@ABC.COM test2@ABC.COM
    get_principal, getprinc 获取 principal get_principal test@ABC.COM
    list_principals, listprincs, get_principals, getprincs 显示所有 principal listprincs
    ktadd, xst 导出条目到 keytab xst -k /root/test.keytab test@ABC.COM

    这里先创建一个 principal,方便 Kerberos Client 登录 kadmin:

    kadmin.local:  add_principal root/admin@ABC.COM
    WARNING: no policy specified for root/admin@ABC.COM; defaulting to no policy
    Enter password for principal "root/admin@ABC.COM": 
    Re-enter password for principal "root/admin@ABC.COM": 
    Principal "root/admin@ABC.COM" created.
    kadmin.local:  

    输入两次密码,创建成功。

    3、Kerberos Client 安装

    在 10.49.196.11、10.49.196.12 上执行如下命令:

    yum install krb5-workstation

    3.1、配置 krb5.conf

    从 10.49.196.10 上拷贝 /etc/krb5.conf 并覆盖本地的 /etc/krb5.conf。

    3.2、kadmin

    Kerberos 客户端机器上可以使用 kadmin 来执行各种管理的操作。需先在 Kerbers Server 上创建登录的 principal,默认为 {当前用户}/admin@realm;

    [root@pxc2 krb5]# kadmin 
    Authenticating as principal root/admin@ABC.COM with password.
    Password for root/admin@ABC.COM: 
    kadmin:  

    输入密码,登录成功。kadmin 的操作和 kadmin.local 类似。

    3.3、kinit(在客户端认证用户)

    [root@pxc2 krb5]# kinit root/admin@ABC.COM
    Password for root/admin@ABC.COM:

    输入密码认证成功。

    3.4、klist(查看当前的认证用户)

    [root@pxc2 krb5]# klist
    Ticket cache: KEYRING:persistent:0:0
    Default principal: root/admin@ABC.COM
    
    Valid starting       Expires              Service principal
    2021-12-03T17:23:07  2021-12-04T17:23:07  krbtgt/ABC.COM@ABC.COM

    3.5、kdestroy(删除当前的认证缓存)

    [root@pxc2 krb5]# kdestroy
  • 相关阅读:
    【数量技术宅|金融数据分析系列分享】为什么中证500(IC)是最适合长期做多的指数
    异常控制流
    链接
    最小生成树的Prim算法(待修正版)
    最小生成树的Kruskal算法
    优先队列用法(转载)
    不相交集合的链表实现
    寻找通用汇点
    找零问题
    【Angular06】管道(类似vue的过滤器)、变更检测的工作原理
  • 原文地址:https://www.cnblogs.com/wuyongyin/p/15634397.html
Copyright © 2011-2022 走看看