Coverage Report

Created: 2026-03-13 03:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/common/kerberos/kerberos_config.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <chrono>
21
#include <string>
22
23
#include "common/status.h"
24
25
namespace doris::kerberos {
26
27
// Configuration class for Kerberos authentication
28
class KerberosConfig {
29
public:
30
    // Constructor with default values for refresh intervals
31
    KerberosConfig();
32
33
    // Set the Kerberos principal and keytab file path
34
    void set_principal_and_keytab(const std::string& principal, const std::string& keytab) {
35
        _principal = principal;
36
        _keytab_path = keytab;
37
    }
38
    // Set the path to krb5.conf configuration file
39
    void set_krb5_conf_path(const std::string& path) { _krb5_conf_path = path; }
40
    // Set the interval for refreshing Kerberos tickets (in seconds)
41
    void set_refresh_interval(int32_t interval) { _refresh_interval_second = interval; }
42
    // Set the minimum time before refreshing tickets (in seconds)
43
    void set_min_time_before_refresh(int32_t time) { _min_time_before_refresh_second = time; }
44
45
    // Get the Kerberos principal name
46
21
    const std::string& get_principal() const { return _principal; }
47
    // Get the path to the keytab file
48
10
    const std::string& get_keytab_path() const { return _keytab_path; }
49
    // Get the path to krb5.conf configuration file
50
14
    const std::string& get_krb5_conf_path() const { return _krb5_conf_path; }
51
    // Get the ticket refresh interval in seconds
52
3
    int32_t get_refresh_interval_second() const { return _refresh_interval_second; }
53
    // Get the minimum time before refresh in seconds
54
    int32_t get_min_time_before_refresh_second() const { return _min_time_before_refresh_second; }
55
56
7
    std::string get_hash_code() const { return _get_hash_code(_principal, _keytab_path); }
57
58
    // Use principal and keytab to generate a hash code.
59
    static std::string get_hash_code(const std::string& principal, const std::string& keytab);
60
61
private:
62
    static std::string _get_hash_code(const std::string& principal, const std::string& keytab);
63
64
private:
65
    // Kerberos principal name (e.g., "user@REALM.COM")
66
    std::string _principal;
67
    // Path to the Kerberos keytab file
68
    std::string _keytab_path;
69
    // Path to the Kerberos configuration file (krb5.conf)
70
    std::string _krb5_conf_path;
71
    // Interval for refreshing Kerberos tickets (in seconds)
72
    int32_t _refresh_interval_second;
73
    // Minimum time before refreshing tickets (in seconds)
74
    int32_t _min_time_before_refresh_second;
75
};
76
77
} // namespace doris::kerberos