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]


Reply via email to