-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Expose API key name to the ingest pipeline #51305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
88ff001
d1592f8
620554a
f2ac3f6
d481a56
29f33ce
b81c6e3
deb7ca9
4d508a3
919edb1
9f7ca68
ac2efff
d488471
cc63be7
e7af393
1e1d801
44a77d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,9 @@ | |
}, | ||
"realm" : { | ||
"type" : "keyword" | ||
}, | ||
"realm_type" : { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a new field for realm type as discussed |
||
"type" : "keyword" | ||
} | ||
} | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* | ||
* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* * or more contributor license agreements. Licensed under the Elastic License; | ||
* * you may not use this file except in compliance with the Elastic License. | ||
* | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.authc; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.core.security.user.User; | ||
|
||
public class AuthenticationTests extends ESTestCase { | ||
|
||
public void testWillGetLookedUpByWhenItExists() { | ||
final Authentication.RealmRef authenticatedBy = new Authentication.RealmRef("auth_by", "auth_by_type", "node"); | ||
final Authentication.RealmRef lookedUpBy = new Authentication.RealmRef("lookup_by", "lookup_by_type", "node"); | ||
final Authentication authentication = new Authentication( | ||
new User("user"), authenticatedBy, lookedUpBy); | ||
|
||
assertEquals(lookedUpBy, authentication.getSourceRealm()); | ||
} | ||
|
||
public void testWillGetAuthenticateByWhenLookupIsNull() { | ||
final Authentication.RealmRef authenticatedBy = new Authentication.RealmRef("auth_by", "auth_by_type", "node"); | ||
final Authentication authentication = new Authentication( | ||
new User("user"), authenticatedBy, null); | ||
|
||
assertEquals(authenticatedBy, authentication.getSourceRealm()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import org.elasticsearch.ingest.Processor; | ||
import org.elasticsearch.xpack.core.security.authc.Authentication; | ||
import org.elasticsearch.xpack.core.security.user.User; | ||
import org.elasticsearch.xpack.security.authc.ApiKeyService; | ||
|
||
import java.util.Arrays; | ||
import java.util.EnumSet; | ||
|
@@ -85,6 +86,54 @@ public IngestDocument execute(IngestDocument ingestDocument) throws Exception { | |
userObject.put("metadata", user.metadata()); | ||
} | ||
break; | ||
case API_KEY: | ||
final String apiKey = "api_key"; | ||
final Object existingApiKeyField = userObject.get(apiKey); | ||
@SuppressWarnings("unchecked") | ||
final Map<String, Object> apiKeyField = | ||
existingApiKeyField instanceof Map ? (Map<String, Object>) existingApiKeyField : new HashMap<>(); | ||
Object apiKeyName = authentication.getMetadata().get(ApiKeyService.API_KEY_NAME_KEY); | ||
if (apiKeyName != null) { | ||
apiKeyField.put("name", apiKeyName); | ||
} | ||
Object apiKeyId = authentication.getMetadata().get(ApiKeyService.API_KEY_ID_KEY); | ||
if (apiKeyId != null) { | ||
apiKeyField.put("id", apiKeyId); | ||
} | ||
if (false == apiKeyField.isEmpty()) { | ||
userObject.put(apiKey, apiKeyField); | ||
} | ||
break; | ||
case REALM: | ||
final String realmKey = "realm"; | ||
final Object existingRealmField = userObject.get(realmKey); | ||
@SuppressWarnings("unchecked") | ||
final Map<String, Object> realmField = | ||
existingRealmField instanceof Map ? (Map<String, Object>) existingRealmField : new HashMap<>(); | ||
|
||
final Object realmName, realmType; | ||
if (Authentication.AuthenticationType.API_KEY == authentication.getAuthenticationType()) { | ||
realmName = authentication.getMetadata().get(ApiKeyService.API_KEY_CREATOR_REALM_NAME); | ||
realmType = authentication.getMetadata().get(ApiKeyService.API_KEY_CREATOR_REALM_TYPE); | ||
} else { | ||
realmName = authentication.getSourceRealm().getName(); | ||
realmType = authentication.getSourceRealm().getType(); | ||
} | ||
if (realmName != null) { | ||
realmField.put("name", realmName); | ||
} | ||
if (realmType != null) { | ||
realmField.put("type", realmType); | ||
} | ||
if (false == realmField.isEmpty()) { | ||
userObject.put(realmKey, realmField); | ||
} | ||
break; | ||
case AUTHENTICATION_TYPE: | ||
if (authentication.getAuthenticationType() != null) { | ||
userObject.put("authentication_type", authentication.getAuthenticationType().toString()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comment about wanting the id etc as well.
|
||
break; | ||
default: | ||
throw new UnsupportedOperationException("unsupported property [" + property + "]"); | ||
} | ||
|
@@ -138,7 +187,10 @@ public enum Property { | |
FULL_NAME, | ||
EMAIL, | ||
ROLES, | ||
METADATA; | ||
METADATA, | ||
API_KEY, | ||
REALM, | ||
AUTHENTICATION_TYPE; | ||
|
||
static Property parse(String tag, String value) { | ||
try { | ||
|
Uh oh!
There was an error while loading. Please reload this page.