Skip to content

Commit

Permalink
Chirp ticket time limit (#3985)
Browse files Browse the repository at this point in the history
* change debug message on duration

* get ticket after register, check duration

* imposer duration limit

* add --max-ticket-duration to chirp_server
  • Loading branch information
btovar authored Nov 19, 2024
1 parent 323df45 commit 46122bd
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion chirp/src/chirp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ INT64_T chirp_client_ticket_register(struct chirp_client * c, const char *name,
result = -1;
goto out;
}
fprintf(file, "# %s: Registered with %s as \"%s\". Expires on %s\n", now, c->hostport, subject, expiration);
fprintf(file, "# %s: Registered with %s as \"%s\". Requested expiration on %s\n", now, c->hostport, subject, expiration);
fclose(file);
}
}
Expand Down
26 changes: 25 additions & 1 deletion chirp/src/chirp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static const char *safe_username = 0;
static int sim_latency = 0;
static int stall_timeout = 3600; /* one hour */
static time_t starttime;
static char *ticket_duration_limit = 0;

/* space_available() is a simple mechanism to ensure that a runaway client does
* not use up every last drop of disk space on a machine. This function
Expand Down Expand Up @@ -532,6 +533,22 @@ static INT64_T getvarstring (struct link *l, time_t stalltime, void *buffer, INT
}
}

static const char *impose_ticket_duration_limit(const char *duration_requested) {
if (!ticket_duration_limit) {
return duration_requested;
}

INT64_T requested = strtoul(duration_requested, NULL, 10);
INT64_T limit = strtoul(ticket_duration_limit, NULL, 10);

if (requested < limit) {
return duration_requested;
}

return ticket_duration_limit;
}


/* A note on integers:
*
* Various operating systems employ integers of different sizes for fields such
Expand Down Expand Up @@ -1261,7 +1278,7 @@ static void chirp_handler(struct link *l, const char *addr, const char *subject)
if ((length = getvarstring(l, stalltime, buffer, length, 0)) == -1)
goto failure;
char *newsubject = chararg1;
char *duration = chararg2;
const char *duration = impose_ticket_duration_limit(chararg2);
if(strcmp(newsubject, "self") == 0)
strcpy(newsubject, esubject);
if(strcmp(esubject, newsubject) != 0 && strcmp(esubject, chirp_super_user) != 0) { /* must be superuser to create a ticket for someone else */
Expand Down Expand Up @@ -1824,6 +1841,7 @@ static void show_help(const char *cmd)
fprintf(stdout, " %-30s Location of transient data. (default: `.')\n", "-y,--transient=<dir>");
fprintf(stdout, " %-30s Select port at random and write it to this file. (default: disabled)\n", "-Z,--port-file=<file>");
fprintf(stdout, " %-30s Set max timeout for unix filesystem authentication. (default: 5s)\n", "-z,--unix-timeout=<file>");
fprintf(stdout, " %-30s Set max duration for authentication tickets, in seconds. (default is unlimited)\n", "--max-ticket-duration=<time>");
fprintf(stdout, "\n");
fprintf(stdout, "Where debug flags are: ");
debug_flags_print(stdout);
Expand All @@ -1838,6 +1856,7 @@ int main(int argc, char *argv[])
LONGOPT_JOB_TIME_LIMIT = INT_MAX-2,
LONGOPT_INHERIT_DEFAULT_ACL = INT_MAX-3,
LONGOPT_PROJECT_NAME = INT_MAX-4,
LONGOPT_MAX_TICKET_DURATION = INT_MAX-5,
};

static const struct option long_options[] = {
Expand All @@ -1861,6 +1880,7 @@ int main(int argc, char *argv[])
{"job-concurrency", required_argument, 0, LONGOPT_JOB_CONCURRENCY},
{"job-time-limit", required_argument, 0, LONGOPT_JOB_TIME_LIMIT},
{"max-clients", required_argument, 0, 'M'},
{"max-ticket-duration", required_argument, 0, LONGOPT_MAX_TICKET_DURATION},
{"no-core-dump", no_argument, 0, 'C'},
{"owner", required_argument, 0, 'w'},
{"parent-check", required_argument, 0, 'e'},
Expand Down Expand Up @@ -2044,6 +2064,10 @@ int main(int argc, char *argv[])
case LONGOPT_PROJECT_NAME:
strncpy(chirp_project_name, optarg, sizeof(chirp_project_name)-1);
break;
case LONGOPT_MAX_TICKET_DURATION:
free(ticket_duration_limit);
ticket_duration_limit = strdup(optarg);
break;
case 'h':
default:
show_help(argv[0]);
Expand Down
30 changes: 27 additions & 3 deletions chirp/src/chirp_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,30 @@ static INT64_T do_put(int argc, char **argv)
return result;
}

static INT64_T do_register_aux(const char *host, const char *name, const char *subject, time_t duration, time_t stoptime) {
INT64_T status = chirp_reli_ticket_register(host, name, subject, duration, stoptime);
if (status < 0) {
return status;
}

char *subject_actual;
char *ticket_actual;
time_t duration_actual;
char **rights_actual;
status = chirp_reli_ticket_get(current_host, name, &subject_actual, &ticket_actual, &duration_actual, &rights_actual, stoptime);

if (status < 0) {
fprintf(stderr, "Could not get ticket after registering it.\n");
return status;
}

if (duration != duration_actual) {
fprintf(stderr, "ticket '%s': limit imposed by server, duration is: %llu\n", name, (unsigned long long) duration_actual);
}

return 0;
}

static INT64_T do_ticket_create(int argc, char **argv)
{
char name[CHIRP_PATH_MAX] = "";
Expand Down Expand Up @@ -308,7 +332,7 @@ static INT64_T do_ticket_create(int argc, char **argv)
}
fprintf(stderr, "ticket '%s': successfully created with %zu bits.\n", name, bits);

result = chirp_reli_ticket_register(current_host, name, subject, duration, stoptime);
result = do_register_aux(current_host, name, subject, duration, stoptime);
if(result < 0) {
fprintf(stderr, "could not register ticket\n");
return result;
Expand Down Expand Up @@ -338,9 +362,9 @@ static INT64_T do_ticket_register(int argc, char **argv)
{
assert(argc == 3 || argc == 4);
if(argc == 3) {
return chirp_reli_ticket_register(current_host, argv[1], NULL, (time_t) strtoull(argv[2], NULL, 10), stoptime);
return do_register_aux(current_host, argv[1], NULL, (time_t) strtoull(argv[2], NULL, 10), stoptime);
} else {
return chirp_reli_ticket_register(current_host, argv[1], argv[2], (time_t) strtoull(argv[3], NULL, 10), stoptime);
return do_register_aux(current_host, argv[1], argv[2], (time_t) strtoull(argv[3], NULL, 10), stoptime);
}
}

Expand Down
1 change: 1 addition & 0 deletions doc/man/m4/chirp_server.m4
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ OPTION_ARG(G,group-url, url)Base url for group lookups. (default: disabled)
OPTION_FLAG(h,help)Give help information.
OPTION_ARG(I, interface,addr)Listen only on this network interface.
OPTION_ARG(M, max-clients,count)Set the maximum number of clients to accept at once. (default unlimited)
OPTION_ARG_LONG(max-ticket-duration,time)Set max duration for authentication tickets, in seconds. (default is unlimited)
OPTION_ARG(n, catalog-name,name)Use this name when reporting to the catalog.
OPTION_ARG(o,debug-file,file)Write debugging output to this file. By default, debugging is sent to stderr (":stderr"). You may specify logs to be sent to stdout (":stdout") instead.
OPTION_ARG(O, debug-rotate-max,bytes)Rotate debug file once it reaches this size.
Expand Down
1 change: 1 addition & 0 deletions doc/man/md/chirp_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ For complete details with examples, see the [Chirp User's Manual](http://ccl.cse
- **-h**,**--help**<br />Give help information.
- **-I**,**--interface=_&lt;addr&gt;_**<br />Listen only on this network interface.
- **-M**,**--max-clients=_&lt;count&gt;_**<br />Set the maximum number of clients to accept at once. (default unlimited)
- **--max-ticket-duration=_&lt;time&gt;_**<br />Set max duration for authentication tickets, in seconds. (default is unlimited)
- **-n**,**--catalog-name=_&lt;name&gt;_**<br />Use this name when reporting to the catalog.
- **-o**,**--debug-file=_&lt;file&gt;_**<br />Write debugging output to this file. By default, debugging is sent to stderr (":stderr"). You may specify logs to be sent to stdout (":stdout") instead.
- **-O**,**--debug-rotate-max=_&lt;bytes&gt;_**<br />Rotate debug file once it reaches this size.
Expand Down

0 comments on commit 46122bd

Please sign in to comment.