Skip to content

Commit 17171ff

Browse files
nagarajg17Nagaraj Gcwperks
authored
Add AuthZ initialization completion check in health check API (#5626)
Signed-off-by: Nagaraj G <narajg@amazon.com> Signed-off-by: Nagaraj G <nagaraj170297@gmail.com> Co-authored-by: Nagaraj G <narajg@amazon.com> Co-authored-by: Craig Perkins <craig5008@gmail.com>
1 parent c75efdc commit 17171ff

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1111

1212
- [Resource Sharing] Keep track of list of principals for which sharable resource is visible for searching ([#5596](https://github.com/opensearch-project/security/pull/5596))
1313
- [Resource Sharing] Keep track of tenant for sharable resources by persisting user requested tenant with sharing info ([#5588](https://github.com/opensearch-project/security/pull/5588))
14+
- [SecurityPlugin Health Check] Add AuthZ initialization completion check in health check API [(#5626)](https://github.com/opensearch-project/security/pull/5626)
1415

1516
### Bug Fixes
1617

src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,14 @@ public List<RestHandler> getRestHandlers(
629629
handlers.add(
630630
new SecurityInfoAction(settings, restController, Objects.requireNonNull(evaluator), Objects.requireNonNull(threadPool))
631631
);
632-
handlers.add(new SecurityHealthAction(settings, restController, Objects.requireNonNull(backendRegistry)));
632+
handlers.add(
633+
new SecurityHealthAction(
634+
settings,
635+
restController,
636+
Objects.requireNonNull(backendRegistry),
637+
Objects.requireNonNull(evaluator)
638+
)
639+
);
633640
handlers.add(
634641
new DashboardsInfoAction(
635642
settings,

src/main/java/org/opensearch/security/rest/SecurityHealthAction.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.opensearch.rest.RestController;
4141
import org.opensearch.rest.RestRequest;
4242
import org.opensearch.security.auth.BackendRegistry;
43+
import org.opensearch.security.privileges.PrivilegesEvaluator;
4344
import org.opensearch.transport.client.node.NodeClient;
4445

4546
import static org.opensearch.rest.RestRequest.Method.GET;
@@ -66,10 +67,17 @@ public class SecurityHealthAction extends BaseRestHandler {
6667
);
6768

6869
private final BackendRegistry registry;
69-
70-
public SecurityHealthAction(final Settings settings, final RestController controller, final BackendRegistry registry) {
70+
private final PrivilegesEvaluator privilegesEvaluator;
71+
72+
public SecurityHealthAction(
73+
final Settings settings,
74+
final RestController controller,
75+
final BackendRegistry registry,
76+
final PrivilegesEvaluator privilegesEvaluator
77+
) {
7178
super();
7279
this.registry = registry;
80+
this.privilegesEvaluator = privilegesEvaluator;
7381
}
7482

7583
@Override
@@ -100,7 +108,7 @@ public void accept(RestChannel channel) throws Exception {
100108

101109
builder.startObject();
102110

103-
if ("strict".equalsIgnoreCase(mode) && registry.isInitialized() == false) {
111+
if ("strict".equalsIgnoreCase(mode) && !(registry.isInitialized() && privilegesEvaluator.isInitialized())) {
104112
status = "DOWN";
105113
message = "Not initialized";
106114
restStatus = RestStatus.SERVICE_UNAVAILABLE;

src/test/java/org/opensearch/security/HealthTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,19 @@ public void testHealthUnitialized() throws Exception {
7676
assertContains(res, "*strict*");
7777
assertNotContains(res, "*UP*");
7878
}
79+
80+
@Test
81+
public void testHealthUninitialized_securityNotInitialized() throws Exception {
82+
setup(Settings.EMPTY, new DynamicSecurityConfig(), Settings.EMPTY, false);
83+
84+
RestHelper rh = nonSslRestHelper();
85+
HttpResponse res;
86+
assertThat(
87+
HttpStatus.SC_SERVICE_UNAVAILABLE,
88+
is((res = rh.executeGetRequest("_opendistro/_security/health?pretty")).getStatusCode())
89+
);
90+
assertContains(res, "*DOWN*");
91+
assertContains(res, "*strict*");
92+
assertNotContains(res, "*UP*");
93+
}
7994
}

0 commit comments

Comments
 (0)