smolnar82 opened a new pull request, #799:
URL: https://github.com/apache/knox/pull/799
## What changes were proposed in this pull request?
In phase II, the following features are implemented:
- Pre-configured users can see all tokens on the Token Management page.
- End-users can execute batch operations on selected Knox Tokens.
- Allowing end-users to show/hide previously disabled KnoxSSO Cookies on the
Token Management page.
There is a new Gateway-level configuration that controls who can see all
tokens on the Token Management UI:
```
<property>
<name>gateway.knox.token.management.users.can.see.all.tokens</name>
<value>admin</value>
<description>A comma-separated list of user names who can see all
tokens on the Token Management page</description>
</property>
```
OOTB, the `admin` user acts as the superuser who has the power of
controlling tokens created for others. The rest of the users can only see their
own tokens only (impersonated or not).
This is how the Token Management UI looks like after my changes:
<img width="1786" alt="Screenshot 2023-10-06 at 10 06 44"
src="https://github.com/apache/knox/assets/34065904/304317b0-d23d-4b23-9f40-629fc9d96b2d">
As you can see, there is only one table (compared to the previous tables of
own/impersonated tokens), where all the information is displayed in a compact
form:
- Each row starts with a selection checkbox for batch operations (except for
disabled KnoxSSO cookies, as there is no point in doing anything with them)
- The disabled token's `Token ID` value is shown in `orange`
- `Username` indicates the user for whom the token is created for
- `Impersonated` is a `boolean` flag indicating if this is an impersonated
token:
- `green check`: yes, this is impersonated. You'll see the user who
created the token under the icon
- `red cross`: no, this is not an impersonated token
- `KnoxSSO` is another `boolean` flag that indicates if this token is
created by the `KNOXSSO` service if the feature was enabled
- `green check`: yes, this is KnoxSSO cookie (token)
- `red cross`: no, this is not a KnoxSSO cookie (it was created by a
regular token API call or on the Token Generation page)
- In the `Actions` column you will see
- the enable/disable/revoke actions are visible for impersonated tokens too
- KnoxSSO cookies cannot be revoked nor re-enabled
Batch operations:
- when at least one token is selected, we show the following buttons under
the table:
- `Disable Selected Tokens`: when executed, all the selected tokens become
disabled (if they were disabled originally, they will remain disabled)
- `Enable Selected Tokens`: when executed, all the selected tokens become
enabled (if they were enabled originally, they will remain enabled)
- `Revoke Selected Tokens`: when executed, all the selected tokens will be
revoked. Please note this option is shown only, if there is no KnoxSSO cookie
(token) selected (i.e. batch revocation only works with regular tokens).
Toggles:
- `Show Disabled KnoxSSO Cookies`: this is `true` by default. Since disabled
KnoxSSO cookies remain in the underlying token state service until they expire,
it may bother users to see them in the tokens table. Flipping this toggle
button helps to hide them.
- `Show My Tokens Only`: this toggle button is only visible to users, who
can see all tokens. By default, this is `false`. Enabling it will filter the
tokens table in a way such that it will contain tokens only that were generated
for the logged in user (impersonated or not).
Token API changes:
- new API endpoints, `enableTokens` and `disableTokens`, to enable/disable
tokens in one batch. Sample `curl` command:
```
curl -iku admin:admin-password -H "Content-Type: application/json" -d
'["62445b09-adb3-4f18-a89d-e5091d87b815","c2ee4646-b695-49af-8910-371ae40f6f75","10c46471-0ff0-4e47-8dac-7c226255d80f"]'
-X PUT
https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/disableTokens
```
When this API is used, the state check (if it's already enabled/disabled) is
not in use. That is, you can include already enabled/disabled tokens in your
batch operation.
- new API endpoint, `revokeTokens`, to revoke tokens in one batch. Sample
`curl` command:
```
curl -iku admin:admin-password -H "Content-Type: application/json" -d
'["62445b09-adb3-4f18-a89d-e5091d87b815","c2ee4646-b695-49af-8910-371ae40f6f75","10c46471-0ff0-4e47-8dac-7c226255d80f"]'
-X DELETE
https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/revokeTokens
```
- the `revoke` endpoint throws an error upon attempting to revoke a KnoxSSO
cookie
```
$ curl -iku admin:admin-password -H "Content-Type: application/json" -d
'c236d20c-4a05-4cfa-b35e-2ba6dc451de0' -X DELETE
https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/revoke
HTTP/1.1 403 Forbidden
Date: Fri, 06 Oct 2023 08:55:25 GMT
Set-Cookie: KNOXSESSIONID=node03e9y0cy8giy31rh00xc1mrcfx0.node0;
Path=/gateway/sandbox; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/sandbox; Max-Age=0;
Expires=Thu, 05-Oct-2023 08:55:25 GMT; SameSite=lax
Content-Type: application/json
Content-Length: 113
{
"revoked": "false",
"error": "SSO cookie (c236d20c...2ba6dc451de0) cannot not be revoked.",
"code": 20
}
```
- the `enable` endpoint throws an error upon attempting to enable a disabled
KnoxSSO cookie:
```
$ curl -iku admin:admin-password -H "Content-Type: application/json" -d
'107824ab-c54d-4db3-b3b5-5c964892ad05' -X PUT
https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/enable
HTTP/1.1 400 Bad Request
Date: Fri, 06 Oct 2023 08:57:58 GMT
Set-Cookie: KNOXSESSIONID=node011ejmvgcjnlpl13mchqmqjtdjc1.node0;
Path=/gateway/sandbox; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/sandbox; Max-Age=0;
Expires=Thu, 05-Oct-2023 08:57:58 GMT; SameSite=lax
Content-Type: application/json
Content-Length: 107
{
"setEnabledFlag": "false",
"error": "Disabled KnoxSSO Cookies cannot not be enabled",
"code": 80
}
```
## How was this patch tested?
Updated relevant JUnit tests and executed comprehensive manual testing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]