[ 
https://issues.apache.org/jira/browse/KNOX-2602?focusedWorklogId=592970&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-592970
 ]

ASF GitHub Bot logged work on KNOX-2602:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/May/21 19:49
            Start Date: 04/May/21 19:49
    Worklog Time Spent: 10m 
      Work Description: smolnar82 opened a new pull request #447:
URL: https://github.com/apache/knox/pull/447


   ## What changes were proposed in this pull request?
   
   There is a new `KNOXTOKEN` service API to enable/disable a Knox-generated 
token.
   Instead of adding another column in KNOX_TABLES, a brand new DB table was 
introduced where an arbitrary number of token metadata can be stored 
(identified by the given token's ID and the metadata name).
   In our alias-based token state management implementations, this is stored as 
a new JSON field whereas in the file journal-based implementation the new flag 
is added before the user name.
   
   ## How was this patch tested?
   
   Updated and executed JUnit tests.
   
   Additionally, the following manual test steps were executed:
   
   1. Created a token using the tokengen application:
   
   <img width="591" alt="Screen Shot 2021-05-04 at 9 45 52 PM" 
src="https://user-images.githubusercontent.com/34065904/117061141-1eabc900-ad22-11eb-8f09-8420b8cbd5ca.png";>
   
   ```
   postgres=# select * from knox_tokens kt, knox_token_metadata ktm WHERE 
kt.token_id = ktm.token_id;
                  token_id               |  issue_time   |  expiration   | 
max_lifetime  |               token_id               | md_name  |               
                  md_value                                  
   
--------------------------------------+---------------+---------------+---------------+--------------------------------------+----------+---------------------------------------------------------------------------
    1e2f286e-9df1-4123-8d41-e6af523d6923 | 1620155983024 | 1620249883013 | 
1620760783024 | 1e2f286e-9df1-4123-8d41-e6af523d6923 | enabled  | true
    1e2f286e-9df1-4123-8d41-e6af523d6923 | 1620155983024 | 1620249883013 | 
1620760783024 | 1e2f286e-9df1-4123-8d41-e6af523d6923 | userName | admin
    1e2f286e-9df1-4123-8d41-e6af523d6923 | 1620155983024 | 1620249883013 | 
1620760783024 | 1e2f286e-9df1-4123-8d41-e6af523d6923 | comment  | comment with 
a question mark ? and my favorite cartoon tom & jerry !!! :)
   (3 rows)
   ```
   
   2. Tried to enable an already enabled token
   ```
   $ curl -ku admin:admin-password -d "1e2f286e-9df1-4123-8d41-e6af523d6923" -X 
POST https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/enable
   {
     "setEnabledFlag": "false",
     "error": "Token is already enabled"
   }
   ```
   3. Disabled the token
   ```
   $ curl -ku admin:admin-password -d "1e2f286e-9df1-4123-8d41-e6af523d6923" -X 
POST https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/disable
   {
     "setEnabledFlag": "true",
     "isEnabled": "false"
   }
   ```
   ```
   postgres=# select * from knox_tokens kt, knox_token_metadata ktm WHERE 
kt.token_id = ktm.token_id AND ktm.md_name = 'enabled';
                  token_id               |  issue_time   |  expiration   | 
max_lifetime  |               token_id               | md_name | md_value 
   
--------------------------------------+---------------+---------------+---------------+--------------------------------------+---------+----------
    1e2f286e-9df1-4123-8d41-e6af523d6923 | 1620155983024 | 1620249883013 | 
1620760783024 | 1e2f286e-9df1-4123-8d41-e6af523d6923 | enabled | false
   (1 row)
   ```
   4. Tried to disable an already disabled token
   ```
   $ curl -ku admin:admin-password -d "1e2f286e-9df1-4123-8d41-e6af523d6923" -X 
POST https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/disable
   {
     "setEnabledFlag": "false",
     "error": "Token is already disabled"
   }
   ```
   
   5. Enabled the token
   ```
   $ curl -ku admin:admin-password -d "1e2f286e-9df1-4123-8d41-e6af523d6923" -X 
POST https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/enable
   {
     "setEnabledFlag": "true",
     "isEnabled": "true"
   }
   ```
   ```
   postgres=# select * from knox_tokens kt, knox_token_metadata ktm WHERE 
kt.token_id = ktm.token_id AND ktm.md_name = 'enabled';
                  token_id               |  issue_time   |  expiration   | 
max_lifetime  |               token_id               | md_name | md_value 
   
--------------------------------------+---------------+---------------+---------------+--------------------------------------+---------+----------
    1e2f286e-9df1-4123-8d41-e6af523d6923 | 1620155983024 | 1620249883013 | 
1620760783024 | 1e2f286e-9df1-4123-8d41-e6af523d6923 | enabled | true
   (1 row)
   ```
   
   6. Renewed the token
   ```
   $ curl -ku admin:admin-password -d "@token.txt" -X POST 
https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/renew
   {
     "renewed": "true",
     "expires": "1620243157437"
   }
   ```
   ```
   postgres=# select * from knox_tokens;
                  token_id               |  issue_time   |  expiration   | 
max_lifetime  
   
--------------------------------------+---------------+---------------+---------------
    1e2f286e-9df1-4123-8d41-e6af523d6923 | 1620155983024 | 1620243157437 | 
1620760783024
   (1 row)
   ```
   7. Revoked the token
   ```
   $ curl -ku admin:admin-password -d "@token.txt" -X POST 
https://localhost:8443/gateway/sandbox/knoxtoken/api/v1/token/revoke
   {
     "revoked": "true"
   }
   ```
   ```
   postgres=# select * from knox_tokens kt, knox_token_metadata ktm WHERE 
kt.token_id = ktm.token_id;
    token_id | issue_time | expiration | max_lifetime | token_id | md_name | 
md_value 
   
----------+------------+------------+--------------+----------+---------+----------
   (0 rows)
   ```
   


-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

            Worklog Id:     (was: 592970)
    Remaining Estimate: 0h
            Time Spent: 10m

> Add token status in JDBC token state management
> -----------------------------------------------
>
>                 Key: KNOX-2602
>                 URL: https://issues.apache.org/jira/browse/KNOX-2602
>             Project: Apache Knox
>          Issue Type: Improvement
>    Affects Versions: 1.6.0
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> A new DB column needs to be added, called {{status}} in {{KNOX_TOKENS}}. The 
> following values are allowed:
>  * ENABLED
>  * DISABLED
> When a token is being created and saved, the status is going to be enabled. 
> However, end-users should be able to change it using a new {{KNOXTOKEN}} 
> service API.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to