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

Monitor users authority changes #49

Merged
merged 25 commits into from
Jun 17, 2024

Conversation

nshandra
Copy link
Contributor

@nshandra nshandra commented May 30, 2024

📌 References

Issue: Log any modification to a admin user and send a notification to MS Teams

📝 Implementation

Script to monitor users by their assigned authorities. Right now we monitor the "ALL" authority, but its possible to monitor several auths. The script logs the changes to stdout and to a MS Teams channel.

The changes are split into two categories:

  • Users that gained the authority since the last run.
  • Users that lost the authority since the last run.

Execution:

yarn install

yarn build

yarn start usermonitoring run-authorities-monitoring --config-file config.json

# To get the debug logs and store them in a file use:
LOG_LEVEL=debug yarn start usermonitoring run-authorities-monitoring --config-file config.json &> authorities-monitoring.log

Parameters:

  • --config-file: Connection and webhook config file.
  • -s | --set-datastore: Write users data to datastore, use in script setup. It assumes there is a monitoring config in d2-tools/authorities-monitor.

Requirements:

  • A config file with the access info of the server and the message webhook details.
  • A d2-tools/authorities-monitor entry in the datastore.

Check README.md for more info.

Notes:

We had to use feature/report_user_without_2factor branch as a base for this script.

nshandra added 20 commits April 10, 2024 13:30
 - add new users and Lost users check
 - send message to teams and log to file (via log.info)
 - add MessageRepository and MessageMSTeamsRepository
…authority_monitoring

Due to messy automatic merge it was actually performed in the previous commit
…onfigRepository get to script use case. Removed info log from MSTeams repo.
@nshandra nshandra changed the title Feature/user authority monitoring Monitor users authority changes May 30, 2024
@nshandra nshandra self-assigned this May 30, 2024
@nshandra nshandra requested review from ifoche and xurxodev May 30, 2024 08:05
@nshandra nshandra marked this pull request as ready for review May 30, 2024 08:06
Copy link

@xurxodev xurxodev left a comment

Choose a reason for hiding this comment

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

thanks @nshandra

I've reviewed from technical point of view without execute the script.

There is a good job in Clean Architecture, you have added tests and concepts viewed in coding dojos, congratulations!

However, you have added vite and vitest and this provokes errors in other tests using jest mocks when I use yarn test.

Changes requested:

  • Two possible solutions here: remove vite and vitest and use only jest or try fix all tests and remove jest.

  • Please add github action file to the project, so it's easy to know when other tests are failing to do a new PR

Base automatically changed from feature/report_user_without_2factor to development June 3, 2024 08:02
nshandra added 3 commits June 5, 2024 15:01
- some packages were needed for the test to work, they are all added as dev dependencies
- added jsdom as a test environment because of the use of window in some of the tested code
- created a *.data.ts test exclude rule for AuthoritiesMonitoringTests.data.ts (former data.ts)
@nshandra
Copy link
Contributor Author

nshandra commented Jun 7, 2024

@xurxodev As mentioned, requested changes done.
I also managed to solve the groupBy issue buy splitting the users with multiple authorities into single auth copies before the groupBy.

@nshandra nshandra requested a review from xurxodev June 7, 2024 10:50
Copy link

@xurxodev xurxodev left a comment

Choose a reason for hiding this comment

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

thanks @nshandra

Now we have github action and works execute all test

@ifoche ifoche merged commit 70ebd5d into development Jun 17, 2024
1 check passed
@ifoche ifoche deleted the feature/user_authority_monitoring branch June 17, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants