Skip to content

Commit 03f0c55

Browse files
committed
[API] Adds SAML security endpoints
1 parent 228e4c7 commit 03f0c55

File tree

12 files changed

+422
-51
lines changed

12 files changed

+422
-51
lines changed

elasticsearch-api/lib/elasticsearch/api.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def self.included(base)
7474
Elasticsearch::API::Remote,
7575
Elasticsearch::API::DanglingIndices,
7676
Elasticsearch::API::Features,
77-
Elasticsearch::API::Shutdown
77+
Elasticsearch::API::Shutdown,
78+
Elasticsearch::API::Security
7879
end
7980

8081
# The serializer class
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
module ParamsRegistry
23+
extend self
24+
25+
# A Mapping of all the actions to their list of valid params.
26+
#
27+
# @since 6.1.1
28+
PARAMS = {}
29+
30+
# Register an action with its list of valid params.
31+
#
32+
# @example Register the action.
33+
# ParamsRegistry.register(:benchmark, [ :verbose ])
34+
#
35+
# @param [ Symbol ] action The action to register.
36+
# @param [ Array[Symbol] ] valid_params The list of valid params.
37+
#
38+
# @since 6.1.1
39+
def register(action, valid_params)
40+
PARAMS[action.to_sym] = valid_params
41+
end
42+
43+
# Get the list of valid params for a given action.
44+
#
45+
# @example Get the list of valid params.
46+
# ParamsRegistry.get(:benchmark)
47+
#
48+
# @param [ Symbol ] action The action.
49+
#
50+
# @return [ Array<Symbol> ] The list of valid params for the action.
51+
#
52+
# @since 6.1.1
53+
def get(action)
54+
PARAMS.fetch(action, [])
55+
end
56+
end
57+
end
58+
end
59+
end
60+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Exchanges a SAML Response message for an Elasticsearch access token and refresh token pair
23+
#
24+
# @option arguments [Hash] :headers Custom HTTP headers
25+
# @option arguments [Hash] :body The SAML response to authenticate (*Required*)
26+
#
27+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-saml-authenticate.html
28+
#
29+
def saml_authenticate(arguments = {})
30+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
31+
32+
headers = arguments.delete(:headers) || {}
33+
34+
arguments = arguments.clone
35+
36+
method = Elasticsearch::API::HTTP_POST
37+
path = "_security/saml/authenticate"
38+
params = {}
39+
40+
body = arguments[:body]
41+
perform_request(method, path, params, body, headers).body
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Verifies the logout response sent from the SAML IdP
23+
#
24+
# @option arguments [Hash] :headers Custom HTTP headers
25+
# @option arguments [Hash] :body The logout response to verify (*Required*)
26+
#
27+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-saml-complete-logout.html
28+
#
29+
def saml_complete_logout(arguments = {})
30+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
31+
32+
headers = arguments.delete(:headers) || {}
33+
34+
arguments = arguments.clone
35+
36+
method = Elasticsearch::API::HTTP_POST
37+
path = "_security/saml/complete_logout"
38+
params = {}
39+
40+
body = arguments[:body]
41+
perform_request(method, path, params, body, headers).body
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Consumes a SAML LogoutRequest
23+
#
24+
# @option arguments [Hash] :headers Custom HTTP headers
25+
# @option arguments [Hash] :body The LogoutRequest message (*Required*)
26+
#
27+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-saml-invalidate.html
28+
#
29+
def saml_invalidate(arguments = {})
30+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
31+
32+
headers = arguments.delete(:headers) || {}
33+
34+
arguments = arguments.clone
35+
36+
method = Elasticsearch::API::HTTP_POST
37+
path = "_security/saml/invalidate"
38+
params = {}
39+
40+
body = arguments[:body]
41+
perform_request(method, path, params, body, headers).body
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Invalidates an access token and a refresh token that were generated via the SAML Authenticate API
23+
#
24+
# @option arguments [Hash] :headers Custom HTTP headers
25+
# @option arguments [Hash] :body The tokens to invalidate (*Required*)
26+
#
27+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-saml-logout.html
28+
#
29+
def saml_logout(arguments = {})
30+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
31+
32+
headers = arguments.delete(:headers) || {}
33+
34+
arguments = arguments.clone
35+
36+
method = Elasticsearch::API::HTTP_POST
37+
path = "_security/saml/logout"
38+
params = {}
39+
40+
body = arguments[:body]
41+
perform_request(method, path, params, body, headers).body
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Creates a SAML authentication request
23+
#
24+
# @option arguments [Hash] :headers Custom HTTP headers
25+
# @option arguments [Hash] :body The realm for which to create the authentication request, identified by either its name or the ACS URL (*Required*)
26+
#
27+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-saml-prepare-authentication.html
28+
#
29+
def saml_prepare_authentication(arguments = {})
30+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
31+
32+
headers = arguments.delete(:headers) || {}
33+
34+
arguments = arguments.clone
35+
36+
method = Elasticsearch::API::HTTP_POST
37+
path = "_security/saml/prepare"
38+
params = {}
39+
40+
body = arguments[:body]
41+
perform_request(method, path, params, body, headers).body
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions
22+
# Generates SAML metadata for the Elastic stack SAML 2.0 Service Provider
23+
#
24+
# @option arguments [String] :realm_name The name of the SAML realm to get the metadata for
25+
# @option arguments [Hash] :headers Custom HTTP headers
26+
#
27+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-saml-sp-metadata.html
28+
#
29+
def saml_service_provider_metadata(arguments = {})
30+
raise ArgumentError, "Required argument 'realm_name' missing" unless arguments[:realm_name]
31+
32+
headers = arguments.delete(:headers) || {}
33+
34+
arguments = arguments.clone
35+
36+
_realm_name = arguments.delete(:realm_name)
37+
38+
method = Elasticsearch::API::HTTP_GET
39+
path = "_security/saml/metadata/#{Elasticsearch::API::Utils.__listify(_realm_name)}"
40+
params = {}
41+
42+
body = nil
43+
perform_request(method, path, params, body, headers).body
44+
end
45+
end
46+
end
47+
end
48+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module Security
21+
module Actions; end
22+
23+
# Client for the "security" namespace (includes the {Security::Actions} methods)
24+
#
25+
class SecurityClient
26+
include Common::Client, Common::Client::Base, Security::Actions
27+
end
28+
29+
# Proxy method for {SecurityClient}, available in the receiving object
30+
#
31+
def security
32+
@security ||= SecurityClient.new(self)
33+
end
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)