Skip to content
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

On-behalf-of token and service account authorization tokens doc #5123

Merged
merged 69 commits into from
Feb 1, 2024
Merged
Changes from 5 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
badb6ca
readd auth token doc
stephen-crawford Nov 7, 2023
a95956f
Merge branch 'opensearch-project:main' into main
stephen-crawford Nov 8, 2023
29c6b4e
Merge branch 'main' into main
stephen-crawford Nov 10, 2023
4921bcc
Merge branch 'opensearch-project:main' into main
stephen-crawford Nov 13, 2023
10158d3
Fix vale
stephen-crawford Nov 13, 2023
031054c
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
57858d5
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
7aabc93
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
231b571
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
f2c257b
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
89f2ea6
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
b65267e
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
8be7a23
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
3702667
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
b07d204
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
f196b48
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
b97006f
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
05c2cf4
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
66ff464
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
813bcb5
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
6b5c8e3
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
5510088
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
f542553
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
ef0f543
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
c0ef181
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
035cae6
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
e51cff1
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
de00af4
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
69663c9
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
7e78e8e
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
c7d6c79
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
e178fa2
Apply suggestions from code review
stephen-crawford Nov 14, 2023
e3c764d
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
db16f8a
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
1f18c74
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
c0f22a5
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
21beb15
Apply suggestions from code review
stephen-crawford Nov 14, 2023
663ac2c
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 14, 2023
ffe5bfa
Fix embedded command
stephen-crawford Nov 14, 2023
b96a080
Merge branch 'main' into main
stephen-crawford Nov 14, 2023
b6f1bd8
Blank lines after headings
stephen-crawford Nov 14, 2023
5b15faa
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
ee7a698
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
f720020
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
8575296
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
7a104c3
change
stephen-crawford Nov 16, 2023
811922a
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
fe674d4
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
705bd90
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
d7210f1
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
3e3cd24
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
027718d
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
97d6d58
Apply suggestions from code review
stephen-crawford Nov 16, 2023
580b4d9
Style guidelines
stephen-crawford Nov 16, 2023
46a15ff
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 16, 2023
2e0ccd5
Merge branch 'main' into main
stephen-crawford Nov 16, 2023
f62c004
Apply suggestions from code review
stephen-crawford Nov 16, 2023
8be2f8a
Merge branch 'opensearch-project:main' into main
stephen-crawford Nov 17, 2023
314bd7b
Merge branch 'main' into main
stephen-crawford Nov 20, 2023
9b42310
Merge branch 'main' into main
stephen-crawford Nov 20, 2023
03d2186
Merge branch 'main' into main
stephen-crawford Nov 20, 2023
edd48d1
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 28, 2023
c3e2c5b
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 28, 2023
0476791
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 28, 2023
26d20eb
Update _security/access-control/authentication-tokens.md
stephen-crawford Nov 28, 2023
4da1911
Merge branch 'main' into main
stephen-crawford Nov 28, 2023
0385cdf
Merge branch 'opensearch-project:main' into main
stephen-crawford Dec 19, 2023
caf209b
Merge branch 'main' into main
kolchfa-aws Dec 22, 2023
371457f
Merge branch 'opensearch-project:main' into main
stephen-crawford Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions _security/access-control/authentication-tokens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
layout: default
title: Authorization tokens
parent: Access control
nav_order: 125
redirect_from:
- /security/access-control/authorization-tokens/
- /security-plugin/access-control/authorization-tokens/
---

## On-Behalf-Of authentication

Check failure on line 11 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.HeadingCapitalization] 'On-Behalf-Of authentication' is a heading and should be in sentence case. Raw Output: {"message": "[OpenSearch.HeadingCapitalization] 'On-Behalf-Of authentication' is a heading and should be in sentence case.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 11, "column": 4}}}, "severity": "ERROR"}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

The Security plugin allows you to configure two types of authentication tokens. The first of these is On-Behalf-Of (OBO) tokens.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

### 1.0 Usage
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
On-behalf-of tokens are a special form of JSON Web Token used for managing authentication requests between a user's client and an extension. These tokens operate "just-in-time," meaning that a token is issued immediately before it is required for authentication. A token will have a configurable window of validity (with a maximum duration of five minutes) after which it expires and cannot be used.

Check warning on line 16 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Simple] Don't use 'just' because it's not neutral in tone. If you mean 'only', use 'only' instead. Raw Output: {"message": "[OpenSearch.Simple] Don't use 'just' because it's not neutral in tone. If you mean 'only', use 'only' instead.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 16, "column": 164}}}, "severity": "WARNING"}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

On-behalf-of tokens will allow an extension to interact with the OpenSearch cluster using the same privileges as the initiating user (the reason the tokens are “on-behalf-of”). However, since these tokens do not have any restrictions in place, they also provide services the ability to operate as if they are the original user until token expiration. This implies that this feature can be used more broadly and is not limited to extension related use cases.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

### 2.0 Configuration

Check failure on line 20 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.HeadingCapitalization] '2.0 Configuration' is a heading and should be in sentence case. Raw Output: {"message": "[OpenSearch.HeadingCapitalization] '2.0 Configuration' is a heading and should be in sentence case.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 20, "column": 5}}}, "severity": "ERROR"}
In the security config file, the on-behalf-of configuration is located under the dynamic config section. It contains the signing key for the token signature and the encryption key for the token payload (role information) decryption:
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

```
config:
dynamic:
on_behalf_of:
enabled: #'true'/non-specified will be consider as 'enabled'
signing_key: #encoded signing key here
encryption_key: #encoded encryption key here
...
```

The encoding algorithm is HMAC SHA512 by default for the signing of the JWT. Both the signing key and encryption key are Base64 encoded and stored on the file system of the OpenSearch node. The keys should be the same on all hosts, otherwise it encryption and decryption operations may fail. Deployment of these keys is managed by the cluster operator.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

### 3.0 Token structure

Check failure on line 35 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.HeadingCapitalization] '3.0 Token structure' is a heading and should be in sentence case. Raw Output: {"message": "[OpenSearch.HeadingCapitalization] '3.0 Token structure' is a heading and should be in sentence case.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 35, "column": 5}}}, "severity": "ERROR"}
The payload of an on-behalf-of token must include all standard configurations of a JWT (JSON Web Token), along with encrypted and decrypted roles. Depending on the setting of the "Plugin Backward Compatibility Mode," backend roles should also be incorporated into role claims. It is important to note that the absence of any of these claims will result in a malformed token, failing to meet the required standard for authentication.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

The on-behalf-of token contains the following claims:
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Issuer (`iss`): OpenSearch Cluster Identifier
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* It is essential that the issuer is validated as a part of security control measures. This strategy is forward-thinking, particularly in the context of potential multi-tenant scenarios like OpenSearch Serverless, where differing cryptographic keys could be associated with each issuer. By checking the value of issuer, each on-behalf-of token is restricted to its associated issuer.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Issue-at (`iat`): Current time of issuing this token
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Used as the reference of the expiration.
* Not-before (`nbf`): The earliest point at which the token can be used.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Given that the on-behalf-of token is designed for just-in-time usage, its `nbf` should align with the `iat` (issued-at) time, indicating the moment when the token was created.

Check warning on line 44 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Simple] Don't use 'just' because it's not neutral in tone. If you mean 'only', use 'only' instead. Raw Output: {"message": "[OpenSearch.Simple] Don't use 'just' because it's not neutral in tone. If you mean 'only', use 'only' instead.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 44, "column": 54}}}, "severity": "WARNING"}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Expiry (`exp`): Expiration time
* Each on-behalf-of token incorporates an expiration mechanism, which is verified upon its receipt. Once a token is issued, it cannot be revoked. Instead, the only token is only invalidated upon its expiration. Furthermore, the generation of on-behalf-of tokens by extensions is subject to dynamic settings. This functionality safeguards the system by preventing the issuance of future tokens under certain conditions.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* The default configuration establishes an expiration time of 300 seconds for on-beahalf-of tokens. Recognizing that different scenarios may necessitate different token durations, we have incorporated the capability for users to personalize this expiration time. At present, the maximum duration that can be assigned to a token is 600 seconds.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* In reference to the current design of the On-Behalf-Of token, it's accurate to say that token revocation isn't a current concern, given its intended just-in-time use and brief lifespan. However, if future adjustments necessitate an extended lifespan for this token, token revocation will be added. This strategy will be adopted to improve and solidify the security measures associated with on-behalf-of token use.

Check warning on line 48 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Simple] Don't use 'just' because it's not neutral in tone. If you mean 'only', use 'only' instead. Raw Output: {"message": "[OpenSearch.Simple] Don't use 'just' because it's not neutral in tone. If you mean 'only', use 'only' instead.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 48, "column": 153}}}, "severity": "WARNING"}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Subject (`sub`): User Identifier
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Name of the user with which this on-behalf-of token is associated.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Audience (`aud`): Extension’s unique identifier
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* For the extension use case, the aud field is a reference to the specific extension that represents the target service.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* For the REST API use case, the API parameter “service” will let user to specify the target service(s) using this token, and the default value is set to “self-issued“
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Roles: Security Privilege Evaluation
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Role Security Mode [[source code](https://github.com/opensearch-project/security/blob/main/src/main/java/org/opensearch/security/authtoken/jwt/JwtVendor.java#L151)], this configuration determines the encryption of the roles claim.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Role Security Mode On (default value) - Roles claim will be encrypted.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Encrypted mapped roles (`er`)
* Role Security Mode Off - Roles claims will be in plain-text, and both mapped roles and backend roles will be included in the claim [[related discussion](https://github.com/opensearch-project/security/issues/2865)]
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Decrypted mapped roles in plain text (`dr`)
* Decrypted backend roles (`br`)

The OpenSearch Security plugin will be responsible for handling encryption and decryption processes. This approach ensures the protection of user information, even when traversing the trust boundary between OpenSearch and any third party services.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

### 3.0 API endpoint

Check failure on line 64 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.HeadingCapitalization] '3.0 API endpoint' is a heading and should be in sentence case. Raw Output: {"message": "[OpenSearch.HeadingCapitalization] '3.0 API endpoint' is a heading and should be in sentence case.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 64, "column": 5}}}, "severity": "ERROR"}
There will be an new API endpoint `POST /_plugins/_security/api/generateonbehalfoftoken` on the security plugin that will allow users to create a short-lived self-issued on-behalf-of token to perform certain actions on behalf of a user.

Check failure on line 65 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [Vale.Terms] Use 'Security plugin' instead of 'security plugin'. Raw Output: {"message": "[Vale.Terms] Use 'Security plugin' instead of 'security plugin'.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 65, "column": 97}}}, "severity": "ERROR"}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

To access this API endpoint, the request body should contain three API parameters:

* description: This allows the use to articulate the purpose for requesting this token, providing clarity and transparency.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* service (optional): This parameter is directed to the audience claim of the on-behalf-of token. It offers users the opportunity to designate the target service for which they intend to use the token. Although this is an optional parameter, if not specified, the default value is set to "self-issued".
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* durationSeconds (optional): This parameter allows users to customize the token's expiration time according to its anticipated usage. However, the maximum duration is capped at 600 seconds to maintain security. If not specified, the default duration is set to 300 seconds.

Check failure on line 71 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: durationSeconds. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: durationSeconds. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 71, "column": 3}}}, "severity": "ERROR"}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Here is an example of requesting an on-behalf-of token with lifespan of 3 mins as user '“admin” for testing purpose:

Check failure on line 72 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: mins. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: mins. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 72, "column": 77}}}, "severity": "ERROR"}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
```
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
curl -XPOST https://localhost:9200/_plugins/_security/api/generateonbehalfoftoken -u 'admin:admin' -H 'Content-Type: application/json' --data
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
'{
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
"description":"Testing",
"service":"Testing Service",
"durationSeconds":"180"
}'
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
```
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

### 4.0 Additional Authorization Restriction ([related discussion](https://github.com/opensearch-project/security/issues/2891))

Check failure on line 82 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.HeadingCapitalization] '4.0 Additional Authorization Restriction ( related discussion )' is a heading and should be in sentence case. Raw Output: {"message": "[OpenSearch.HeadingCapitalization] '4.0 Additional Authorization Restriction ( related discussion )' is a heading and should be in sentence case.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 82, "column": 1}}}, "severity": "ERROR"}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

While the conversation about the usage of on-behalf-of (OBO) tokens continues, it is critical to manage certain edge cases. Even though an OBO token can act as a valid Bearer authorization header for any API access, there needs to be certain limitations. For instance, it should be forbidden to use an OBO token to access the API endpoint to issue another OBO token. Similarly, using an OBO token to access the reset password API in order to modify a user's authentication information should be disallowed. These preventive measures are necessary to uphold the integrity and security of the system.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
## Service Accounts

Check failure on line 86 in _security/access-control/authentication-tokens.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.HeadingCapitalization] 'Service Accounts' is a heading and should be in sentence case. Raw Output: {"message": "[OpenSearch.HeadingCapitalization] 'Service Accounts' is a heading and should be in sentence case.", "location": {"path": "_security/access-control/authentication-tokens.md", "range": {"start": {"line": 86, "column": 4}}}, "severity": "ERROR"}

stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
### 1.0 Introduction of Service Accounts
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
Service Accounts are a new authC/authZ path where extensions can execute requests without assuming the role(s) of the active user. Service Accounts are a special type of principal associated with each extension and have a set of permissions. The permissions assigned to a Service Account grant the associated extension the authorization to execute any of the mapped operations without needing to assume the roles of the active user or stash the user’s role(s) in the ephemeral user context. **Currently, Service Account only permit operations on system indices associated with the mapped extension.**
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

### 2.0 Service Account Background
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
Before the introduction of Service Accounts, it was not possible for an extension to execute a request without assuming the roles of the active user. Instead, when a request is processed, an ephemeral “Plugin User” was created. The Plugin User then assumed all the permissions of the currently authenticated operator (human user). The result was a Plugin User which acted on the extension’s behalf but had all of the privileges of the operator. In this way, the previous model can be said to have had extensions “impersonate” the operator. This impersonation approach lead to two main issues:
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Impersonation compromises referential integrity, meaning it is difficult for auditors to identify which requests were executed by an extension or by an operator. A system with referential integrity maintains a transactional record in its audit log. The record provides a clear history of actions taken by various subjects at specific times. When extensions impersonate users for both requests they make on behalf of the operator, and requests they execute on their own, the audit log lacks referential integrity.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Impersonation also makes it impossible to restrict an extension’s permissions beyond those of the user it impersonates. When an extension assumes the roles of the active subject, it copies all of the roles. This includes even those permissions which are uneccessary for executing its intended actions. This practice not only deviates from the principal of least-privileges, but also increases the threat surface area. With each additional permission granted to the Plugin User, the potential impact a misconfigured or malicious extension may have grows.

### 3.0 Service Account Benefit
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
Service Accounts address the issues listed in 2.0 by defining a separate state which autonomously executing extensions run in. Service Accounts maintain referential integrity by introducing a distinct state which extensions run in when executing requests on their own behalf. Audit logging can then record when an extension executes on its own—it will make authC/authZ calls against the Service Account—or whether it is executing an action on behalf of the operator and therefore making use of the OnBehalfOf tokens.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

Similarly, Service Accounts address threat exposure concerns by separating the roles an extension assumes from those of the operator or a generic hard coded user (such as those in the `internal_users.yml` file). Service Accounts will not assume the roles of the operator, but instead have their own privileges listed in the Service Account. The roles associated with a Service Account can therefore, be as a restrictive as possible in alignment with the principle of least-privileges. In order to avoid providing extensions overly-permissive service accounts, extension authors should have a strong understanding of what types of operations their extensions hopes to execute.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

### 4.0 API Endpoint
As suggested by the name, the boolean flag `service` denotes whether a given internal user account is Service Account. If an account is not a Service Account, then any attempts to generate an associated auth token for the account will fail. Similarly, the `enabled` field dictates when a Service Account can be used by an extensions to perform operations. If a Service Account is not `enabled` attempts to fetch its auth token will be blocked and it will be unable to execute requests on its own behalf using a previously issued auth token.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
* Here is an example of create a service account with ALL PERMISSIONS for your service/extension:
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
```
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
curl -XPUT "[https://localhost:9200/_plugins/_security/api/internalusers/admin-extension https://localhost:9200/_plugins/_security/api/internalusers/hello-world" -H 'Content-Type: application/json' -d'
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
{
"opendistro_security_roles": ["all_access"],
"backend_roles": [],
"attributes": {
"enabled": "true",
"service": "true"
}
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
}' -u "admin:admin" --insecure
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
```
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
## Handling On-Behalf-Of and Service Account Requests
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
While both on-behalf-of token handling and Service Accounts can be viewed as independent features, the most significant benefits are realized when coupled. Specifically, OpenSearch exposes a client which is used to connect to the OpenSearch cluster and provides Plugins the ability to execute requests. With the introduction of on-behalf-of tokens and Service Accounts the client is now able to be used to handle requests which will make use of both of these new features. Now, when the client executes a request which requires an extension to use an on-behalf-of token, the first step of handling the request is the forwarding of the request to the Security Plugin. In the Security Plugin, the request is authenticated and authorized against the active user. If the active user is permitted, the request returns to OpenSearch’s core code base where a request to create an on-behalf-of for the target extension using the active user’s identity is created. This request to generate the on-behalf-of token is then handled by the `IdentityPlugin` implementation. In the standard scenario this is the Security Plugin, so the request is returned to the Security Plugin’s implementation of the `TokenManager` interface which generates a new on-behalf-of token for the request. After generating the token, the Security Plugin forwards the request with the on-behalf-of token to the extension. At that point, the extension is then able to call OpenSearch’s REST methods with the token. The permissions associated with the token will then be evaluated for the authorization of the request. If the token conveys the permissions required for the operation, the action will be performed and the response will be sent back to the extension. After processing OpenSearch’s response, the extension will forward its own handling of the response to the client. If instead, the on-behalf-of token does not entail the permissions required for execution of the target action, the a forbidden response is returned to the extension.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

Extensions acting on their own behalf also make use of the client exposed by OpenSearch. When an extension is first initialized in OpenSearch, the `IdentityPlugin` is triggered to create a new Service Account for it and provide the associated Service Account token. In the default configuration, the Security Plugin is the `IdentityPlugin` and handles these processes. After OpenSearch receives the Service Account token, it forwards that token to the associated extension. After the extension has received its token, requests by the client to make use of the Service Account associated with the extension are operable. In these scenarios, the extension receives the requests from the client, and then forwards the request along with the Service Account token to OpenSearch. OpenSearch further transfers the packages to the Security Plugin where the token is parsed and the request is treated as a traditional request using Basic Authentication in the `InternalAuthenticationBackend`.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

In both on-behalf-of and Service Account token request flows, the `IdentityPlugin`'s `TokenManager` interface is used by the `IdentityPlugin` to handle the distribution and processing of the tokens. This interface is implemented by the Security Plugin as an `IdentityPlugin` and contains logic for issuing a token which is either an on-behalf-of or Service Account token.
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved


Loading