Skip to content

Commit

Permalink
Update the issuer to represent the cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Jun 28, 2023
1 parent 8540862 commit b4be662
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
Objects.requireNonNull(cs), Objects.requireNonNull(adminDns), Objects.requireNonNull(cr)));
handlers.add(new SecurityConfigUpdateAction(settings, restController, Objects.requireNonNull(threadPool), adminDns, configPath, principalExtractor));
handlers.add(new SecurityWhoAmIAction(settings, restController, Objects.requireNonNull(threadPool), adminDns, configPath, principalExtractor));
CreateOnBehalfOfTokenAction cobot = new CreateOnBehalfOfTokenAction(settings, threadPool);
CreateOnBehalfOfTokenAction cobot = new CreateOnBehalfOfTokenAction(settings, threadPool, Objects.requireNonNull(cs));
dcf.registerDCFListener(cobot);
handlers.add(cobot);
handlers.addAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.greenrobot.eventbus.Subscribe;

import org.opensearch.client.node.NodeClient;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.core.xcontent.XContentBuilder;
Expand All @@ -31,6 +32,7 @@
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestRequest.Method;
import org.opensearch.rest.RestStatus;
import org.opensearch.security.OpenSearchSecurityPlugin;
import org.opensearch.security.authtoken.jwt.JwtVendor;
import org.opensearch.security.securityconf.ConfigModel;
import org.opensearch.security.securityconf.DynamicConfigModel;
Expand All @@ -44,6 +46,7 @@ public class CreateOnBehalfOfTokenAction extends BaseRestHandler {

private JwtVendor vendor;
private final ThreadPool threadPool;
private final ClusterService clusterService;

private ConfigModel configModel;

Expand All @@ -64,8 +67,9 @@ public void onDynamicConfigModelChanged(DynamicConfigModel dcm) {
}
}

public CreateOnBehalfOfTokenAction(final Settings settings, final ThreadPool threadPool) {
public CreateOnBehalfOfTokenAction(final Settings settings, final ThreadPool threadPool, final ClusterService clusterService) {
this.threadPool = threadPool;
this.clusterService = clusterService;
}

@Override
Expand Down Expand Up @@ -104,6 +108,8 @@ public void accept(RestChannel channel) throws Exception {
return;
}

final String clusterIdentifier = clusterService.getClusterName().value();

final Map<String, Object> requestBody = request.contentOrSourceParamParser().map();
final String reason = (String)requestBody.getOrDefault("reason", null);

Expand All @@ -121,9 +127,8 @@ public void accept(RestChannel channel) throws Exception {
builder.startObject();
builder.field("user", user.getName());

/* TODO: Update the issuer to represent the cluster */
final String token = vendor.createJwt(
"OpenSearch",
clusterIdentifier,
user.getName(),
source,
tokenDuration,
Expand Down

0 comments on commit b4be662

Please sign in to comment.