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

feat: store user last accessed, and sshkey last used timestamps #3675

Merged
merged 4 commits into from
Jun 30, 2024

Conversation

shreddedbacon
Copy link
Member

@shreddedbacon shreddedbacon commented Mar 12, 2024

General Checklist

  • Affected Issues have been mentioned in the Closing issues section
  • Documentation has been written/updated
  • PR title is ready for inclusion in changelog

Database Migrations

  • If your PR contains a database migation, it MUST be the latest in date order alphabetically

Whenever a user accesses the API update the last_accessed attribute on the user.

Alternative approach could be to store this in the API DB to reduce calls to keycloak though.

query allUsers {
  allUsers{
    email
    lastAccessed
  }
}
# result
{
  "data": {
    "allUsers": [
      {
        "email": "[email protected]",
        "lastAccessed": "2024-03-12T00:14:32.000Z"
      }
    ]
  }
}

Also when the api/keys endpoint is hit, and a valid sshkey is detected, a new last_used field is updated to indicate when the key was last used.

      {
        "email": "[email protected]",
        "lastAccessed": "2024-03-12T09:07:13.000",
        "sshKeys": [
          {
            "name": "maintainer-key",
            "lastUsed": "2024-03-12 09:06:07"
          }
        ]
      }

@shreddedbacon shreddedbacon changed the title feat: store user last accessed attribute feat: store user last accessed, and sshkey last used timestamps Mar 12, 2024
@tobybellwood tobybellwood added this to the 2.19.0 milestone Mar 13, 2024
@shreddedbacon shreddedbacon marked this pull request as ready for review March 20, 2024 00:33
@shreddedbacon shreddedbacon modified the milestones: 2.19.0, 2.20.0 May 15, 2024
@shreddedbacon
Copy link
Member Author

shreddedbacon commented May 17, 2024

ssh-portal-api will either need to use the API, or be updated to include the function to update the last used timestamp when an ssh key is used

@smlx
Copy link
Member

smlx commented May 17, 2024

Should the SSH key last used also include the last time it was used to generate a token? From what I can tell this PR doesn't do that but I could be wrong.

@shreddedbacon
Copy link
Member Author

Should the SSH key last used also include the last time it was used to generate a token? From what I can tell this PR doesn't do that but I could be wrong.

In the legacy SSH service, it is called whenever the authorize.sh script is called and hits the /keys endpoint in the API. So whenever a key is used and matches, it will get updated. Token, SSH, whatever.

@shreddedbacon shreddedbacon added the happy-to-delay pullrequest is fine to be left out of a release if required label Jun 12, 2024
Copy link
Member

@tobybellwood tobybellwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good - tested ok - picked up and closed any minor nits already :-)

@tobybellwood tobybellwood merged commit ea51af4 into main Jun 30, 2024
2 checks passed
@tobybellwood tobybellwood deleted the user-last-accessed branch June 30, 2024 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db-migration happy-to-delay pullrequest is fine to be left out of a release if required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants