Skip to content

Commit 109a35f

Browse files
author
Varun Rao Bhamidimarri
committed
Add optional Ranger HDFS plugin and updates to the policy
1 parent 607159f commit 109a35f

File tree

7 files changed

+94
-24
lines changed

7 files changed

+94
-24
lines changed

aws_emr_blog_v3/cloudformation/ec2-win-ad.template

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,22 @@ Resources:
290290
- !Ref 'DefaultADUserPassword'
291291
- "' -Force)\n"
292292
- "Enable-ADAccount -Identity \"analyst2\"\n"
293+
- "New-ADUser -Name \"tina\" -OtherAttributes @{'title'=\"tina\";'mail'=\"tina@"
294+
- !Ref 'DomainDNSName'
295+
- "\"}\n"
296+
- "Enable-ADAccount -Identity \"tina\"\n"
297+
- "Set-ADAccountPassword -Identity 'tina' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText '"
298+
- !Ref 'DefaultADUserPassword'
299+
- "' -Force)\n"
300+
- "Enable-ADAccount -Identity \"tina\"\n"
301+
- "New-ADUser -Name \"alex\" -OtherAttributes @{'title'=\"alex\";'mail'=\"alex@"
302+
- !Ref 'DomainDNSName'
303+
- "\"}\n"
304+
- "Enable-ADAccount -Identity \"alex\"\n"
305+
- "Set-ADAccountPassword -Identity 'alex' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText '"
306+
- !Ref 'DefaultADUserPassword'
307+
- "' -Force)\n"
308+
- "Enable-ADAccount -Identity \"alex\"\n"
293309
services:
294310
windows:
295311
cfn-hup:

aws_emr_blog_v3/cloudformation/step2_ranger-rds-emr.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ Parameters:
311311
Default: false
312312
Type: String
313313
AllowedValues: [ true, false ]
314+
InstallRangerHDFSPlugin:
315+
Description: Flag to control if the Ranger HDFS plugin will be added
316+
Default: false
317+
Type: String
318+
AllowedValues: [ true, false ]
314319
Metadata:
315320
AWS::CloudFormation::Interface:
316321
ParameterGroups:
@@ -417,6 +422,7 @@ Resources:
417422
VPC: !Ref VPC
418423
emrReleaseLabel: !Ref emrReleaseLabel
419424
CreateNonEMRResources: !Ref CreateNonEMRResources
425+
InstallRangerHDFSPlugin: !Ref InstallRangerHDFSPlugin
420426
ClusterSubnetID: !If [ InstallEMRRangerinPublicSubnet, !Ref PublicSubnet1AID, !Ref PrivateSubnet1AID ]
421427
EMRLogDir: !Ref EMRLogDir
422428
MasterInstanceCount: !Ref 'MasterInstanceCount'

aws_emr_blog_v3/code/launch-cluster/cremr.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ def create(event, context):
6262
],
6363
'Applications': applist,
6464
'Steps': [
65-
{
66-
"Name": "InstallHiveHDFSRangerPlugin",
67-
"ActionOnFailure": "CONTINUE",
68-
"HadoopJarStep": {
69-
"Jar": scriptRunnerJar,
70-
"Args": [
71-
"/mnt/tmp/aws-blog-emr-ranger/scripts/emr-steps/install-hdfs-ranger-plugin.sh",
72-
event["ResourceProperties"]["RangerHostname"],
73-
event["ResourceProperties"]["StackRegion"]
74-
]
75-
}
76-
},
7765
{
7866
"Name": "CreateDefaultHiveTables",
7967
"ActionOnFailure": "CONTINUE",
@@ -317,6 +305,19 @@ def create(event, context):
317305
}
318306
})
319307

308+
if event["ResourceProperties"]["InstallRangerHDFSPlugin"] == "true":
309+
cluster_parameters['Steps'].append({
310+
"Name": "InstallHiveHDFSRangerPlugin",
311+
"ActionOnFailure": "CONTINUE",
312+
"HadoopJarStep": {
313+
"Jar": scriptRunnerJar,
314+
"Args": [
315+
"/mnt/tmp/aws-blog-emr-ranger/scripts/emr-steps/install-hdfs-ranger-plugin.sh",
316+
event["ResourceProperties"]["RangerHostname"],
317+
event["ResourceProperties"]["StackRegion"]
318+
]
319+
}
320+
},)
320321
# Set the default hive properties
321322
if event["ResourceProperties"]["EnableGlueSupport"] == "true":
322323
hive_site_properties = {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"service": "hadoopdev",
3+
"name": "Access to /user for home dir",
4+
"policyType": 0,
5+
"policyPriority": 0,
6+
"description": "",
7+
"isAuditEnabled": true,
8+
"resources": {
9+
"path": {
10+
"values": [
11+
"/user"
12+
],
13+
"isExcludes": false,
14+
"isRecursive": false
15+
}
16+
},
17+
"policyItems": [
18+
{
19+
"accesses": [
20+
{
21+
"type": "write",
22+
"isAllowed": true
23+
}
24+
],
25+
"users": [
26+
"{USER}"
27+
],
28+
"groups": [],
29+
"roles": [],
30+
"conditions": [],
31+
"delegateAdmin": false
32+
}
33+
],
34+
"denyPolicyItems": [],
35+
"allowExceptions": [],
36+
"denyExceptions": [],
37+
"dataMaskPolicyItems": [],
38+
"rowFilterPolicyItems": [],
39+
"serviceType": "hdfs",
40+
"options": {},
41+
"validitySchedules": [],
42+
"policyLabels": [],
43+
"zoneName": "",
44+
"isDenyAllElse": false,
45+
"id": 108,
46+
"isEnabled": true,
47+
"version": 1
48+
}

aws_emr_blog_v3/inputdata/ranger-hdfs-policy-user-home-dir.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"service": "hadoopdev",
3-
"name": "User path",
3+
"name": "User home dir in HDFS",
44
"policyType": 0,
55
"policyPriority": 0,
66
"description": "",

aws_emr_blog_v3/scripts/emr-steps/install-hdfs-ranger-plugin.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ aws secretsmanager get-secret-value --secret-id emr/rangerGAagentkey --version-s
7676

7777
openssl pkcs12 -export -in ${ranger_agents_certs_path}/certificateChain.pem -inkey ${ranger_agents_certs_path}/privateKey.pem -chain -CAfile ${ranger_agents_certs_path}/certificateChain.pem -name ${keystore_alias} -out ${ranger_agents_certs_path}/keystore.p12 -password pass:${keystore_password}
7878
keytool -delete -alias ${keystore_alias} -keystore ${keystore_location} -storepass ${keystore_password} -noprompt || true
79-
sudo keytool -importkeystore -deststorepass ${keystore_password} -destkeystore ${keystore_location} -srckeystore ${ranger_agents_certs_path}/keystore.p12 -srcstoretype PKCS12 -srcstorepass ${keystore_password}
79+
sudo keytool -importkeystore -deststorepass ${keystore_password} -destkeystore ${keystore_location} -srckeystore ${ranger_agents_certs_path}/keystore.p12 -srcstoretype PKCS12 -srcstorepass ${keystore_password} -noprompt || true
8080
sudo chmod 444 ${keystore_location}
8181
# -----
8282

@@ -101,17 +101,12 @@ cd $installpath/$ranger_hdfs_plugin
101101

102102
## Updates for new Ranger
103103
mkdir -p /usr/lib/ranger/hadoop/etc
104-
sudo ln -s /etc/hadoop /usr/lib/ranger/hadoop/etc/
104+
sudo ln -s /etc/hadoop /usr/lib/ranger/hadoop/etc/ || true
105105
sudo ln -s /usr/lib/ranger/hadoop/etc/hadoop/conf/hdfs-site.xml /usr/lib/ranger/hadoop/etc/hadoop/hdfs-site.xml || true
106106
sudo cp -r $installpath/$ranger_hdfs_plugin/lib/* /usr/lib/hadoop-hdfs/lib/
107107
sudo cp /usr/lib/hadoop-hdfs/lib/ranger-hdfs-plugin-impl/*.jar /usr/lib/hadoop-hdfs/lib/ || true
108-
sudo ln -s /etc/hadoop/ /usr/lib/ranger/hadoop/
108+
sudo ln -s /etc/hadoop/ /usr/lib/ranger/hadoop/ || true
109109

110-
## Copy the keystore and strustone information
111-
sudo cp /etc/hive/conf/ranger-plugin-keystore.jks /etc/hadoop/conf/
112-
sudo cp /etc/hive/conf/ranger-keystore-creds.jceks /etc/hadoop/conf/
113-
sudo cp /etc/hive/conf/ranger-plugin-truststore.jks /etc/hadoop/conf/
114-
sudo cp /etc/hive/conf/ranger-truststore-creds.jceks /etc/hadoop/conf/
115110
#SSL configs
116111
sudo sed -i "s|POLICY_MGR_URL=.*|POLICY_MGR_URL=$RANGER_HTTP_URL|g" install.properties
117112
sudo sed -i "s|SSL_TRUSTSTORE_FILE_PATH=.*|SSL_TRUSTSTORE_FILE_PATH=${truststore_location}|g" install.properties

aws_emr_blog_v3/scripts/emr-steps/loadDataIntoHDFS.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ set -x
55
# Creates dummy HDFS data for testing
66
#================================================================
77
#% SYNOPSIS
8-
#+ createHiveTables.sh args ...
8+
#+ loadDataIntoHDFS.sh args ...
99
#%
1010
#% DESCRIPTION
1111
#% Uses Hadoop commands to create dummy HDFS data for testing
1212
#%
1313
#% EXAMPLES
14-
#% createHiveTables.sh args ..
14+
#% loadDataIntoHDFS.sh args ..
1515
#%
1616
#================================================================
1717
#- IMPLEMENTATION
18-
#- version createHiveTables.sh 1.0
18+
#- version loadDataIntoHDFS.sh 1.0
1919
#- author Varun Bhamidimarri
2020
#- license MIT license
2121
#-
@@ -32,7 +32,11 @@ sudo aws s3 cp $hdfs_data_location/football_coach.tsv . --region us-east-1
3232
sudo aws s3 cp $hdfs_data_location/football_coach_position.tsv . --region us-east-1
3333
sudo -u hdfs hadoop fs -mkdir -p /user/analyst1
3434
sudo -u hdfs hadoop fs -mkdir -p /user/analyst2
35+
sudo -u hdfs hadoop fs -mkdir -p /user/tina
36+
sudo -u hdfs hadoop fs -mkdir -p /user/alex
3537
sudo -u hdfs hadoop fs -put -f football_coach.tsv /user/analyst1
3638
sudo -u hdfs hadoop fs -put -f football_coach_position.tsv /user/analyst2
3739
sudo -u hdfs hadoop fs -chown -R analyst1:analyst1 /user/analyst1
3840
sudo -u hdfs hadoop fs -chown -R analyst2:analyst2 /user/analyst2
41+
sudo -u hdfs hadoop fs -chown -R tina:tina /user/tina
42+
sudo -u hdfs hadoop fs -chown -R alex:alex /user/alex

0 commit comments

Comments
 (0)