|
@@ -0,0 +1,348 @@
|
|
|
+---
|
|
|
+setup:
|
|
|
+ - skip:
|
|
|
+ features: [ headers, transform_and_set ]
|
|
|
+
|
|
|
+ - do:
|
|
|
+ cluster.health:
|
|
|
+ wait_for_status: yellow
|
|
|
+
|
|
|
+ - do:
|
|
|
+ security.put_role:
|
|
|
+ name: "user_role"
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "cluster": ["manage_own_api_key"],
|
|
|
+ "indices": [
|
|
|
+ {
|
|
|
+ "names": "*",
|
|
|
+ "privileges": ["all"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ - do:
|
|
|
+ security.put_user:
|
|
|
+ username: "api_key_user_1"
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "password" : "x-pack-test-password",
|
|
|
+ "roles" : [ "user_role" ],
|
|
|
+ "full_name" : "API key user"
|
|
|
+ }
|
|
|
+
|
|
|
+---
|
|
|
+teardown:
|
|
|
+ - do:
|
|
|
+ security.delete_role:
|
|
|
+ name: "user_role"
|
|
|
+ ignore: 404
|
|
|
+
|
|
|
+ - do:
|
|
|
+ security.delete_user:
|
|
|
+ username: "api_key_user_1"
|
|
|
+ ignore: 404
|
|
|
+
|
|
|
+---
|
|
|
+"Test update api key":
|
|
|
+
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.create_api_key:
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "name": "user1-api-key",
|
|
|
+ "role_descriptors": {
|
|
|
+ "role-a": {
|
|
|
+ "cluster": ["none"],
|
|
|
+ "index": [
|
|
|
+ {
|
|
|
+ "names": ["index-a"],
|
|
|
+ "privileges": ["read"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ - match: { name: "user1-api-key" }
|
|
|
+ - is_true: id
|
|
|
+ - is_true: api_key
|
|
|
+ - set: { id: user1_key_id }
|
|
|
+ - transform_and_set: { login_creds: "#base64EncodeCredentials(id,api_key)" }
|
|
|
+ - match: { encoded: $login_creds }
|
|
|
+
|
|
|
+ # Check API key does not have requested privileges
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: ApiKey ${login_creds}
|
|
|
+ security.has_privileges:
|
|
|
+ user: null
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "cluster": ["manage_own_api_key"],
|
|
|
+ "index": [
|
|
|
+ {
|
|
|
+ "names": ["index-a"],
|
|
|
+ "privileges": ["write"]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "names": ["index-b"],
|
|
|
+ "privileges": ["read"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ - match: { "has_all_requested": false }
|
|
|
+
|
|
|
+ # Update API key to above privileges
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.update_api_key:
|
|
|
+ id: "$user1_key_id"
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "role_descriptors": {
|
|
|
+ "role-a": {
|
|
|
+ "cluster": ["all"],
|
|
|
+ "index": [
|
|
|
+ {
|
|
|
+ "names": ["index-a"],
|
|
|
+ "privileges": ["write"]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "names": ["index-b"],
|
|
|
+ "privileges": ["read"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "metadata": {
|
|
|
+ "letter": "a",
|
|
|
+ "number": 42
|
|
|
+ }
|
|
|
+ }
|
|
|
+ - match: { updated: true }
|
|
|
+
|
|
|
+ # Check updated privileges
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: ApiKey ${login_creds}
|
|
|
+ security.has_privileges:
|
|
|
+ user: null
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "cluster": ["manage_own_api_key"],
|
|
|
+ "index": [
|
|
|
+ {
|
|
|
+ "names": ["index-a"],
|
|
|
+ "privileges": ["write"]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "names": ["index-b"],
|
|
|
+ "privileges": ["read"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ - match: { "has_all_requested": true }
|
|
|
+
|
|
|
+ # Check that metadata was updated
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.get_api_key:
|
|
|
+ id: "$user1_key_id"
|
|
|
+ owner: true
|
|
|
+ - length: { "api_keys" : 1 }
|
|
|
+ - match: {
|
|
|
+ "api_keys.0.metadata": {
|
|
|
+ "letter": "a",
|
|
|
+ "number": 42
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+---
|
|
|
+"Test update api key without request fields":
|
|
|
+
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.create_api_key:
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "name": "user1-api-key",
|
|
|
+ "role_descriptors": {
|
|
|
+ "role-a": {
|
|
|
+ "cluster": ["all"],
|
|
|
+ "index": [
|
|
|
+ {
|
|
|
+ "names": ["index-a"],
|
|
|
+ "privileges": ["read"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "metadata": {
|
|
|
+ "letter": "a",
|
|
|
+ "number": 42
|
|
|
+ }
|
|
|
+ }
|
|
|
+ - match: { name: "user1-api-key" }
|
|
|
+ - is_true: id
|
|
|
+ - is_true: api_key
|
|
|
+ - set: { id: user1_key_id }
|
|
|
+ - transform_and_set: { login_creds: "#base64EncodeCredentials(id,api_key)" }
|
|
|
+ - match: { encoded: $login_creds }
|
|
|
+
|
|
|
+ # Give user new cluster privilege to test auto update
|
|
|
+ - do:
|
|
|
+ security.put_role:
|
|
|
+ name: "user_role"
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "cluster": ["all"],
|
|
|
+ "indices": [
|
|
|
+ {
|
|
|
+ "names": "index-a",
|
|
|
+ "privileges": ["all"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.update_api_key:
|
|
|
+ id: "$user1_key_id"
|
|
|
+ body: {}
|
|
|
+ - match: { updated: true }
|
|
|
+
|
|
|
+ # Check update works without a body
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.update_api_key:
|
|
|
+ id: "$user1_key_id"
|
|
|
+ - match: { updated: true }
|
|
|
+
|
|
|
+ # Check metadata did not change
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.get_api_key:
|
|
|
+ id: "$user1_key_id"
|
|
|
+ owner: true
|
|
|
+ - length: { "api_keys": 1 }
|
|
|
+ - match: {
|
|
|
+ "api_keys.0.metadata": {
|
|
|
+ "letter": "a",
|
|
|
+ "number": 42
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # Check privileges auto-updated to owner user's
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: ApiKey ${login_creds}
|
|
|
+ security.has_privileges:
|
|
|
+ user: null
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "cluster": ["all"],
|
|
|
+ "index": [
|
|
|
+ {
|
|
|
+ "names": ["index-a"],
|
|
|
+ "privileges": ["read"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ - match: { "has_all_requested": true }
|
|
|
+
|
|
|
+---
|
|
|
+"Test update api key with empty request fields":
|
|
|
+
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.create_api_key:
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "name": "user1-api-key",
|
|
|
+ "role_descriptors": {
|
|
|
+ "role-a": {
|
|
|
+ "cluster": ["none"],
|
|
|
+ "index": [
|
|
|
+ {
|
|
|
+ "names": ["index-a"],
|
|
|
+ "privileges": ["none"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "metadata": {
|
|
|
+ "letter": "a",
|
|
|
+ "number": 42
|
|
|
+ }
|
|
|
+ }
|
|
|
+ - match: { name: "user1-api-key" }
|
|
|
+ - is_true: id
|
|
|
+ - is_true: api_key
|
|
|
+ - set: { id: user1_key_id }
|
|
|
+ - transform_and_set: { login_creds: "#base64EncodeCredentials(id,api_key)" }
|
|
|
+ - match: { encoded: $login_creds }
|
|
|
+
|
|
|
+ # Give user new cluster privilege to test auto update
|
|
|
+ - do:
|
|
|
+ security.put_role:
|
|
|
+ name: "user_role"
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "cluster": ["all"],
|
|
|
+ "indices": [
|
|
|
+ {
|
|
|
+ "names": "index-a",
|
|
|
+ "privileges": ["all"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.update_api_key:
|
|
|
+ id: "$user1_key_id"
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "role_descriptors": {},
|
|
|
+ "metadata": {}
|
|
|
+ }
|
|
|
+ - match: { updated: true }
|
|
|
+
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: "Basic YXBpX2tleV91c2VyXzE6eC1wYWNrLXRlc3QtcGFzc3dvcmQ=" # api_key_user_1
|
|
|
+ security.get_api_key:
|
|
|
+ id: "$user1_key_id"
|
|
|
+ owner: true
|
|
|
+ - length: { "api_keys": 1 }
|
|
|
+ - match: {
|
|
|
+ "api_keys.0.metadata": {}
|
|
|
+ }
|
|
|
+
|
|
|
+ # Check privileges auto-updated to owner user's
|
|
|
+ - do:
|
|
|
+ headers:
|
|
|
+ Authorization: ApiKey ${login_creds}
|
|
|
+ security.has_privileges:
|
|
|
+ user: null
|
|
|
+ body: >
|
|
|
+ {
|
|
|
+ "cluster": ["all"],
|
|
|
+ "index": [
|
|
|
+ {
|
|
|
+ "names": ["index-a"],
|
|
|
+ "privileges": ["read"]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ - match: { "has_all_requested": true }
|