Skip to content

Commit

Permalink
Merge pull request #3653 from garlick/proxy_version
Browse files Browse the repository at this point in the history
flux-proxy: add flux-core version check
  • Loading branch information
mergify[bot] committed May 14, 2021
2 parents 166bff3 + 8fe652d commit c896ace
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
9 changes: 8 additions & 1 deletion doc/man1/flux-proxy.rst
Expand Up @@ -9,7 +9,7 @@ flux-proxy(1)
SYNOPSIS
========

**flux** **proxy** URI [command [args...]]
**flux** **proxy** [*OPTIONS*] URI [command [args...]]

DESCRIPTION
===========
Expand All @@ -26,6 +26,13 @@ for example where connection establishment has high latency or
requires authentication.


OPTIONS
=======

**-f, --force**
Allow the proxy command to connect to a broker running a different
version of Flux with a warning message instead of a fatal error.

EXAMPLES
========

Expand Down
5 changes: 3 additions & 2 deletions src/broker/broker.c
Expand Up @@ -639,8 +639,9 @@ static void init_attrs (attr_t *attrs, pid_t pid, struct flux_msg_cred *cred)
init_attrs_rc_paths (attrs);
init_attrs_shell_paths (attrs);

if (attr_add (attrs, "version", FLUX_CORE_VERSION_STRING,
FLUX_ATTRFLAG_IMMUTABLE) < 0)
/* Allow version to be changed by instance owner for testing
*/
if (attr_add (attrs, "version", FLUX_CORE_VERSION_STRING, 0) < 0)
log_err_exit ("attr_add version");

char tmp[32];
Expand Down
40 changes: 39 additions & 1 deletion src/cmd/builtin/proxy.c
Expand Up @@ -222,6 +222,34 @@ static void acceptor_cb (struct usock_conn *uconn, void *arg)
usock_conn_destroy (uconn);
}

/* Compare proxy version with broker version.
* Require major, minor, and patch numbers to match, ignoring patch suffix.
*/
static void version_check (flux_t *h, bool force)
{
unsigned int n[3];
const char *version;

if (!(version = flux_attr_get (h, "version")))
log_err_exit ("flux_attr_get version");
if (sscanf (version, "%u.%u.%u", &n[0], &n[1], &n[2]) != 3
|| n[0] != FLUX_CORE_VERSION_MAJOR
|| n[1] != FLUX_CORE_VERSION_MINOR
|| n[2] != FLUX_CORE_VERSION_PATCH) {
if (force) {
log_msg ("warning: proxy version %s != broker version %s",
FLUX_CORE_VERSION_STRING,
version);
}
else {
log_msg_exit ("fatal: proxy version %s != broker version %s "
"(--force to connect anyway)",
FLUX_CORE_VERSION_STRING,
version);
}
}
}

static int cmd_proxy (optparse_t *p, int ac, char *av[])
{
int n;
Expand Down Expand Up @@ -250,6 +278,10 @@ static int cmd_proxy (optparse_t *p, int ac, char *av[])
if (flux_set_reactor (ctx.h, r) < 0)
log_err_exit ("flux_set_reactor");

/* Check proxy version vs broker version
*/
version_check (ctx.h, optparse_hasopt (p, "force"));

/* Create router
*/
if (!(ctx.router = router_create (ctx.h)))
Expand Down Expand Up @@ -296,6 +328,12 @@ static int cmd_proxy (optparse_t *p, int ac, char *av[])
return (0);
}

static struct optparse_option proxy_opts[] = {
{ .name = "force", .key = 'f', .has_arg = 0,
.usage = "Skip version check when connecting to Flux broker", },
OPTPARSE_TABLE_END,
};

int subcommand_proxy_register (optparse_t *p)
{
optparse_err_t e;
Expand All @@ -304,7 +342,7 @@ int subcommand_proxy_register (optparse_t *p)
"[OPTIONS] URI [COMMAND...]",
"Route messages to/from Flux instance",
0,
NULL);
proxy_opts);
if (e != OPTPARSE_SUCCESS)
return (-1);

Expand Down
14 changes: 14 additions & 0 deletions t/t1105-proxy.t
Expand Up @@ -81,4 +81,18 @@ test_expect_success 'flux-proxy forwards LD_LIBRARY_PATH' '
grep -E "ssh.* LD_LIBRARY_PATH=[^ ]*:?/foo .*/flux relay" ./proxinator.log
'

test_expect_success 'set bogus broker version' '
flux getattr version >realversion &&
flux setattr version 0.0.0
'
test_expect_success 'flux-proxy fails with version mismatch' '
test_must_fail flux proxy $FLUX_URI /bin/true
'
test_expect_success 'flux-proxy --force works with version mismatch' '
flux proxy --force $FLUX_URI /bin/true
'
test_expect_success 'restore real broker version' '
flux setattr version $(cat realversion)
'

test_done

0 comments on commit c896ace

Please sign in to comment.