Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min lifetime option #35

Merged
merged 2 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/99-nfs-client.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
allow_any_uid = yes
trusted = yes
euid = 0
min_lifetime = 60
15 changes: 15 additions & 0 deletions man/gssproxy.conf.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@
</listitem>
</varlistentry>

<varlistentry>
<term>min_lifetime (integer)</term>
<listitem>
<para>Minimum lifetime of a cached credential, in seconds.</para>
<para>If non-zero, when gssproxy is deciding whether to use
a cached credential, it will compare the lifetime of the
cached credential to this value. If the lifetime of the
cached credential is lower, gssproxy will treat the cached
credential as expired and will attempt to obtain a new
credential.
</para>
<para>Default: min_lifetime = 15</para>
</listitem>
</varlistentry>

<varlistentry>
<term>program (string)</term>
<listitem>
Expand Down
15 changes: 14 additions & 1 deletion src/gp_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct gp_flag_def flag_names[] = {

#define DEFAULT_FILTERED_FLAGS GSS_C_DELEG_FLAG
#define DEFAULT_ENFORCED_FLAGS 0
#define DEFAULT_MIN_LIFETIME 15

static void free_str_array(const char ***a, int *count)
{
Expand Down Expand Up @@ -538,6 +539,17 @@ static int load_services(struct gp_config *cfg, struct gp_ini_context *ctx)
goto done;
}
}

cfg->svcs[n]->min_lifetime = DEFAULT_MIN_LIFETIME;
ret = gp_config_get_int(ctx, secname, "min_lifetime", &valnum);
if (ret == 0) {
if (valnum >= 0) {
simo5 marked this conversation as resolved.
Show resolved Hide resolved
cfg->svcs[n]->min_lifetime = valnum;
} else {
simo5 marked this conversation as resolved.
Show resolved Hide resolved
GPDEBUG("Invalid value '%d' for min_lifetime in [%s], ignoring.\n",
valnum, secname);
}
}
}
safefree(secname);
}
Expand Down Expand Up @@ -611,6 +623,8 @@ int load_config(struct gp_config *cfg)
goto done;
}

gp_debug_toggle(tmp_dbg_lvl);

ret = gp_config_get_string(ctx, "gssproxy", "syslog_status", &tmpstr);
if (ret == 0)
gp_syslog_status = gp_boolean_is_true(tmpstr);
Expand Down Expand Up @@ -640,7 +654,6 @@ int load_config(struct gp_config *cfg)
if (ret != 0) {
GPERROR("Error reading configuration %d: %s", ret, gp_strerror(ret));
}
gp_debug_toggle(tmp_dbg_lvl);
gp_config_close(ctx);
safefree(ctx);
return ret;
Expand Down
12 changes: 10 additions & 2 deletions src/gp_creds.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ static int gp_get_cred_environment(struct gp_call_ctx *gpcall,
}

static uint32_t gp_check_cred(uint32_t *min,
struct gp_service *svc,
gss_cred_id_t in_cred,
gssx_name *desired_name,
gss_cred_usage_t cred_usage)
Expand Down Expand Up @@ -563,7 +564,14 @@ static uint32_t gp_check_cred(uint32_t *min,
if (lifetime == 0) {
ret_maj = GSS_S_CREDENTIALS_EXPIRED;
} else {
ret_maj = GSS_S_COMPLETE;
if (svc->min_lifetime && lifetime < svc->min_lifetime) {
GPDEBUG("%s: lifetime (%u) less than min_lifetime (%u) "
"for service \"%s\" - returning\n",
__func__, lifetime, svc->min_lifetime, svc->name);
ret_maj = GSS_S_CREDENTIALS_EXPIRED;
} else {
ret_maj = GSS_S_COMPLETE;
}
}

done:
Expand Down Expand Up @@ -622,7 +630,7 @@ uint32_t gp_add_krb5_creds(uint32_t *min,
* function completely */

/* just check if it is a valid krb5 cred */
ret_maj = gp_check_cred(&ret_min, in_cred, desired_name, cred_usage);
ret_maj = gp_check_cred(&ret_min, gpcall->service, in_cred, desired_name, cred_usage);
if (ret_maj == GSS_S_COMPLETE) {
return GSS_S_COMPLETE;
} else if (ret_maj == GSS_S_CREDENTIALS_EXPIRED ||
Expand Down
1 change: 1 addition & 0 deletions src/gp_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct gp_service {
gss_cred_usage_t cred_usage;
uint32_t filter_flags;
uint32_t enforce_flags;
uint32_t min_lifetime;
char *program;

uint32_t mechs;
Expand Down