Skip to content

Commit b78ac9d

Browse files
committed
Made sudo-less mode configurable. Haven't tested yet, will push another commit after testing, and add documentation for configuring sudo when that is what you want to use.
1 parent c771096 commit b78ac9d

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

Diff for: conf/hqt_config.yaml.example

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ jobs_dbm: "data/jobs.db"
4545
# directory from which to load templates
4646
hql_template_dir: "hql_templates/"
4747

48+
# the backend can use sudo to run hive as the users logged into the front-end,
49+
# if the OS is configured to auth against LDAP/NIS and sudo is configured as
50+
# per the instructions in the HQT docs.
51+
# NOTE: if frontend_auth is "none" this should almost always be set to "yes".
52+
backend_use_sudo: "yes"
53+
4854
# what method of authentication to use. Set to "none" or
4955
# comment-out to disable user-authentication.
5056
frontend_auth: "ldap"

Diff for: lib/App/HiveQueryTool/HiveCLI.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use Hash::Merge::Simple qw(merge);
2929
use Moo;
3030

3131
has hive_path => ( is => 'ro', default => sub { __which_or_die('hive') } );
32-
has user => ( is => 'ro' );
32+
has user => ( is => 'ro', required => 0 );
3333
has conf => ( is => 'ro', default => sub { +{} } );
3434
has env => ( is => 'ro', default => sub { +{} } );
3535

Diff for: script/hivecli-server.pl

+9-8
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
# the given configuration and HQL.
9292
my $RUNNER = HiveCLI->new();
9393

94+
use constant TRUE_VALUES => [ qw( 1 true yes on ) ];
95+
use constant FALSE_VALUES => [ qw( 0 false no off ), '', undef ];
9496

9597
# this is a stupid-simple web server running on AnyEvent. I chose it because
9698
# it needs to play nice with Hadoop::HiveCLI which also uses AnyEvent.
@@ -116,12 +118,6 @@
116118
return $req->respond( res_json_xx(400, 'query_id parameter required', {} ) );
117119
};
118120

119-
my $user_name = $req->parm('user_name') // do {
120-
return $req->respond( res_json_xx(400, 'user_name parameter required', {} ) );
121-
};
122-
# set the user to run the hive command as
123-
$hive_opts{user} = $user_name;
124-
125121
my $template_name = $req->parm('template_name') // do {
126122
return $req->respond( res_json_xx(400, 'template_name parameter required', {} ) );
127123
};
@@ -130,8 +126,14 @@
130126
return $req->respond( res_json_xx(400, 'hql parameter required', {} ) );
131127
};
132128

129+
# set the user to run the hive command as
130+
my $user_name = $hive_opts{user} = $req->parm('user_name') || $ENV{USER};
131+
133132
# get the queue permissions of the user
134-
my @queue_perms = capturex(qw(sudo -E -u), $user_name, which('hadoop'), qw(queue -showacls));
133+
my @queue_perm_cmd = ( which('hadoop'), qw(queue -showacls) );
134+
unshift @queue_perm_cmd, ( qw(sudo -E -u), $user_name )
135+
if is_truthy( $CFG->{backend_use_sudo} );
136+
my @queue_perms = capturex( @queue_perm_cmd );
135137

136138
# set the queue if the user specified one
137139
if ( my $queue = $req->parm('queue') ) {
@@ -153,7 +155,6 @@
153155
if ( ! grep { /^\Q$queue\E\s+.*submit-job/ } @queue_perms ) {
154156
warn join " ",
155157
"User [$user_name] does not have permission to submit jobs in queue [$queue]",
156-
#"which is set in the query. Running job as user [$ENV{USER}] until this is resolved.\n";
157158
"which is set in the query. Attempting to remove this line from the query...\n";
158159
#$hive_opts{user} = $ENV{USER};
159160
#last;

0 commit comments

Comments
 (0)