大网数据广告活动
服务器运维问答

Use cases for kerberos credential cache type MEMORY?

· 52CE 我爱测

One of the credential cache types offered by MIT Kerberos is MEMORY . According to the documentation it is used by kadmin. MEMORY caches are for storage of credentials that don’t need to be made available outside of the current p…

问题原文

原帖链接 · rlf · CC BY-SA 3.0

One of the credential cache types offered by MIT Kerberos is MEMORY. According to the documentation it is used by kadmin.

MEMORY caches are for storage of credentials that don’t need to be made available outside of the current process. For example, a memory ccache is used by kadmin to store the administrative ticket used to contact the admin server.

I have tried setting default_ccache_name = MEMORY: in /etc/krb5.conf. After doing so I made a packet capture while issuing the kinit command. From this capture I can see that a TGT was successfully obtained from the KDC. This ticket was then (obviously) lost as soon as the kinit process finished. Furthermore, it seems if persistent memory based tickets are required one can use the KEYRING ccache type.

What are the other use cases of the MEMORY credential cache type?

I assume this is not useful from a bash script for example. When the script calls kinit it will fork and upon completion the obtained ticket will not be accessible to the parent.

Is there perhaps a kerberos header file that can be included so as to keep obtained tickets in the same address space as the rest of your logic?

已采纳解答

原帖链接 · rlf · CC BY-SA 3.0

The answer to this question is exactly what was postulated in the comments. From your code you can include the krb5.h header. This will give you access to the functions that make up the Kerberos code base.

Below is a toy example that is adapted from the documentation.

#include <string.h>
#include <krb5.h>

int main(void)
{
    krb5_error_code ret;
    krb5_creds creds;
    krb5_principal client_princ = NULL;

    krb5_context context;
    const char* princname = "user@REALM";
    const char* password = "secret";

    krb5_init_context(&context);

    memset(&creds, 0, sizeof(creds));
    ret = krb5_parse_name(context, princname, &client_princ);
    if (ret)
        goto cleanup;
    ret = krb5_get_init_creds_password(context, &creds, client_princ,
                                       password, NULL, NULL, 0, NULL, NULL);
    if (ret)
        goto cleanup;
    ret = krb5_verify_init_creds(context, &creds, NULL, NULL, NULL, NULL);

    /* do things with the ticket (&creds) here */

    cleanup:
    krb5_free_principal(context, client_princ);
    krb5_free_cred_contents(context, &creds);

    return 0;
}

The function krb5_init_context() is what reads your configuration file and honours the MEMORY: ccache type. The obtained ticket will then be stored in this processes memory space.

This code does indeed obtain a TGT. We can verify this by taking a packet capture while it runs. We can also just dump the memory of this process and verify that the TGT is contained in it.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。