Skip to content

Commit 7c0123d

Browse files
jkakavastvernum
andauthored
Add SAML IdP plugin for internal use (#54046) (#54124)
This change merges the "feature-internal-idp" branch into Elasticsearch. This introduces a small identity-provider plugin as a child of the x-pack module. This allows ES to act as a SAML IdP, for users who are authenticated against the Elasticsearch cluster. This feature is intended for internal use within Elastic Cloud environments and is not supported for any other use case. It falls under an enterprise license tier. The IdP is disabled by default. Co-authored-by: Ioannis Kakavas <[email protected]> Co-authored-by: Tim Vernum <[email protected]>
1 parent 82e0414 commit 7c0123d

File tree

164 files changed

+15237
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+15237
-21
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ClientHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public final class ClientHelper {
5353
public static final String ENRICH_ORIGIN = "enrich";
5454
public static final String TRANSFORM_ORIGIN = "transform";
5555
public static final String ASYNC_SEARCH_ORIGIN = "async_search";
56+
public static final String IDP_ORIGIN = "idp";
5657

5758
private ClientHelper() {}
5859

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/SecurityContext.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import org.apache.logging.log4j.LogManager;
99
import org.apache.logging.log4j.Logger;
10+
import org.elasticsearch.ElasticsearchSecurityException;
1011
import org.elasticsearch.Version;
12+
import org.elasticsearch.common.Nullable;
1113
import org.elasticsearch.common.settings.Settings;
1214
import org.elasticsearch.common.util.concurrent.ThreadContext;
1315
import org.elasticsearch.common.util.concurrent.ThreadContext.StoredContext;
@@ -41,13 +43,27 @@ public SecurityContext(Settings settings, ThreadContext threadContext) {
4143
this.nodeName = Node.NODE_NAME_SETTING.get(settings);
4244
}
4345

46+
/**
47+
* Returns the current user information, or throws {@link org.elasticsearch.ElasticsearchSecurityException}
48+
* if the current request has no authentication information.
49+
*/
50+
public User requireUser() {
51+
User user = getUser();
52+
if (user == null) {
53+
throw new ElasticsearchSecurityException("there is no user available in the current context");
54+
}
55+
return user;
56+
}
57+
4458
/** Returns the current user information, or null if the current request has no authentication info. */
59+
@Nullable
4560
public User getUser() {
4661
Authentication authentication = getAuthentication();
4762
return authentication == null ? null : authentication.getUser();
4863
}
4964

5065
/** Returns the authentication information, or null if the current request has no authentication info. */
66+
@Nullable
5167
public Authentication getAuthentication() {
5268
try {
5369
return authenticationSerializer.readFromContext(threadContext);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/SecondaryAuthentication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.common.util.concurrent.ThreadContext;
1111
import org.elasticsearch.xpack.core.security.SecurityContext;
1212
import org.elasticsearch.xpack.core.security.authc.Authentication;
13+
import org.elasticsearch.xpack.core.security.user.User;
1314

1415
import java.io.IOException;
1516
import java.util.Objects;
@@ -55,6 +56,10 @@ public Authentication getAuthentication() {
5556
return authentication;
5657
}
5758

59+
public User getUser() {
60+
return authentication.getUser();
61+
}
62+
5863
public <T> T execute(Function<ThreadContext.StoredContext, T> body) {
5964
return this.securityContext.executeWithAuthentication(this.authentication, body);
6065
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.security.support;
6+
package org.elasticsearch.xpack.core.security.support;
77

88
import java.security.AccessController;
99
import java.security.PrivilegedActionException;

x-pack/plugin/core/src/main/plugin-metadata/plugin-security.policy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ grant {
22
// bouncy castle
33
permission java.security.SecurityPermission "putProviderProperty.BC";
44

5+
// needed in (cf. o.e.x.c.s.s.RestorableContextClassLoader)
6+
permission java.lang.RuntimePermission "getClassLoader";
7+
permission java.lang.RuntimePermission "setContextClassLoader";
8+
59
// needed for x-pack security extension
610
permission java.security.SecurityPermission "createPolicy.JavaPolicy";
711
permission java.security.SecurityPermission "getPolicy";
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"index_patterns": [
3+
"saml-service-provider-*"
4+
],
5+
"aliases": {
6+
"saml-service-provider": {}
7+
},
8+
"order": 100,
9+
"settings": {
10+
"number_of_shards": 1,
11+
"number_of_replicas": 0,
12+
"auto_expand_replicas": "0-1",
13+
"index.priority": 10,
14+
"index.refresh_interval": "1s",
15+
"index.format": 1
16+
},
17+
"mappings": {
18+
"_doc": {
19+
"_meta": {
20+
"idp-version": "${idp.template.version}"
21+
},
22+
"dynamic": "strict",
23+
"properties": {
24+
"name": {
25+
"type": "text"
26+
},
27+
"entity_id": {
28+
"type": "keyword"
29+
},
30+
"acs": {
31+
"type": "keyword"
32+
},
33+
"enabled": {
34+
"type": "boolean"
35+
},
36+
"created": {
37+
"type": "date",
38+
"format": "epoch_millis"
39+
},
40+
"last_modified": {
41+
"type": "date",
42+
"format": "epoch_millis"
43+
},
44+
"name_id_format": {
45+
"type": "keyword"
46+
},
47+
"sign_messages": {
48+
"type": "keyword"
49+
},
50+
"authn_expiry_ms": {
51+
"type": "long"
52+
},
53+
"privileges": {
54+
"type": "object",
55+
"properties": {
56+
"resource": {
57+
"type": "keyword"
58+
},
59+
"roles": {
60+
"type": "object",
61+
"dynamic": false
62+
}
63+
}
64+
},
65+
"attributes": {
66+
"type": "object",
67+
"properties": {
68+
"principal": {
69+
"type": "keyword"
70+
},
71+
"email": {
72+
"type": "keyword"
73+
},
74+
"name": {
75+
"type": "keyword"
76+
},
77+
"roles": {
78+
"type": "keyword"
79+
}
80+
}
81+
},
82+
"certificates": {
83+
"type": "object",
84+
"properties": {
85+
"sp_signing": {
86+
"type": "text"
87+
},
88+
"idp_signing": {
89+
"type": "text"
90+
},
91+
"idp_metadata": {
92+
"type": "text"
93+
}
94+
}
95+
}
96+
}
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)