Skip to content

Commit 5815f1e

Browse files
committed
POST user
1 parent 195f841 commit 5815f1e

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
FROM docker.stackable.tech/stackable/hadoop:3.3.6-stackable0.0.0-dev
22

3-
COPY --chown=stackable:stackable ./group-mapper-0.1.0-SNAPSHOT.jar /stackable/hadoop/share/hadoop/tools/lib/
3+
COPY --chown=stackable:stackable ./hdfs-group-mapper-0.1.0-SNAPSHOT.jar /stackable/hadoop/share/hadoop/tools/lib/

Tiltfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
k8s_yaml('test/stack/05-opa.yaml')
22
k8s_yaml('test/stack/10-hdfs.yaml')
3-
k8s_yaml('test/stack/15-rolebinding.yaml')
43

54
local_resource(
65
'compile authorizer',

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>tech.stackable</groupId>
6-
<artifactId>group-mapper</artifactId>
6+
<artifactId>hdfs-group-mapper</artifactId>
77
<version>0.1.0-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

10-
<name>group-mapper</name>
10+
<name>hdfs-group-mapper</name>
1111
<url>http://maven.apache.org</url>
1212

1313
<properties>
@@ -27,6 +27,12 @@
2727
</exclusion>
2828
</exclusions>
2929
</dependency>
30+
<dependency>
31+
<groupId>org.slf4j</groupId>
32+
<artifactId>slf4j-api</artifactId>
33+
<version>1.7.36</version>
34+
<scope>provided</scope>
35+
</dependency>
3036
<dependency>
3137
<groupId>junit</groupId>
3238
<artifactId>junit</artifactId>

src/main/java/tech/stackable/hadoop/StackableGroupMapper.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package tech.stackable.hadoop;
22

3-
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
4-
import io.fabric8.kubernetes.client.KubernetesClient;
53
import org.apache.hadoop.conf.Configuration;
64
import org.apache.hadoop.security.GroupMappingServiceProvider;
75
import org.apache.hadoop.util.Lists;
@@ -18,12 +16,10 @@
1816
public class StackableGroupMapper implements GroupMappingServiceProvider {
1917
private static final String OPA_MAPPING_URL_PROP = "hadoop.security.group.mapping.opa.url";
2018
private final Logger LOG = LoggerFactory.getLogger(StackableGroupMapper.class);
21-
private final KubernetesClient client;
2219
private final Configuration configuration;
2320
private final HttpClient httpClient = HttpClient.newHttpClient();
2421

2522
public StackableGroupMapper() {
26-
this.client = new DefaultKubernetesClient();
2723
this.configuration = new Configuration();
2824
}
2925

@@ -35,7 +31,7 @@ public StackableGroupMapper() {
3531
*/
3632
@Override
3733
public List<String> getGroups(String user) throws IOException {
38-
LOG.info("Calling StackableGroupMapper.getGroups...");
34+
LOG.info("Calling StackableGroupMapper.getGroups for user [{}]", user);
3935

4036
String opaMappingUrl = configuration.get(OPA_MAPPING_URL_PROP);
4137

@@ -45,12 +41,15 @@ public List<String> getGroups(String user) throws IOException {
4541

4642
URI opaUri = URI.create(opaMappingUrl);
4743
HttpResponse<String> response = null;
44+
45+
String body = String.format("{\"input\":{\"username\": \"%s\"}}", user);
46+
LOG.info("Request body [{}]", body);
4847
try {
4948
response = httpClient.send(
50-
HttpRequest.newBuilder(opaUri).header("Content-Type", "application/json").GET().build(),
51-
//.POST(HttpRequest.BodyPublishers.ofByteArray(user.getBytes())).build(),
49+
HttpRequest.newBuilder(opaUri).header("Content-Type", "application/json")
50+
.POST(HttpRequest.BodyPublishers.ofString(body)).build(),
5251
HttpResponse.BodyHandlers.ofString());
53-
LOG.info("Opa response [{}]", response);
52+
LOG.info("Opa response [{}]", response.body());
5453
} catch (InterruptedException e) {
5554
LOG.error(e.getMessage());
5655
}
@@ -73,7 +72,7 @@ public List<String> getGroups(String user) throws IOException {
7372
@Override
7473
public void cacheGroupsRefresh() {
7574
// does nothing in this provider of user to groups mapping
76-
LOG.info("cacheGroupsRefresh: caching should be provided by the policy provider");
75+
LOG.info("ignoring cacheGroupsRefresh: caching should be provided by the policy provider");
7776
}
7877

7978
/**
@@ -84,6 +83,6 @@ public void cacheGroupsRefresh() {
8483
@Override
8584
public void cacheGroupsAdd(List<String> groups) {
8685
// does nothing in this provider of user to groups mapping
87-
LOG.info("cacheGroupsAdd: caching should be provided by the policy provider");
86+
LOG.info("ignoring cacheGroupsAdd: caching should be provided by the policy provider");
8887
}
8988
}

test/stack/05-opa.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,30 @@ data:
99
test.rego: |
1010
package hdfs
1111
12-
users := "me,myself,I"
12+
groups := json.filter(users_by_name[input.username], ["groups"])
13+
14+
# returning data in the form presented by the UIF
15+
users_by_name := {
16+
"alice": {
17+
"id": "af07f12c-1234-40a7-93e0-874537bdf3f5",
18+
"username": "alice",
19+
"groups": ["/superset-admin"],
20+
"customAttributes": {},
21+
},
22+
"bob": {
23+
"id": "af07f12c-2345-40a7-93e0-874537bdf3f5",
24+
"username": "bob",
25+
"groups": ["/admin"],
26+
"customAttributes": {},
27+
},
28+
"stackable": {
29+
"id": "af07f12c-3456-40a7-93e0-874537bdf3f5",
30+
"username": "stackable",
31+
"groups": ["/admin", "/superuser"],
32+
"customAttributes": {},
33+
},
34+
}
35+
1336
---
1437
apiVersion: opa.stackable.tech/v1alpha1
1538
kind: OpaCluster

0 commit comments

Comments
 (0)